1
1
mirror of https://github.com/OpenDiablo2/OpenDiablo2 synced 2024-11-10 14:26:15 -05:00
OpenDiablo2/d2core/d2audio/d2audio.go
Tim Sarbin 2461142fbd
Minor changes to project layout (#276)
* Minor changes to reduce interdependencies on modules.
2020-01-31 23:18:11 -05:00

48 lines
981 B
Go

package d2audio
import (
"errors"
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2interface"
)
var singleton d2interface.AudioProvider
var (
ErrHasInit error = errors.New("audio system is already initialized")
ErrNotInit error = errors.New("audio system has not been initialized")
)
// CreateManager creates a sound provider
func Initialize(audioProvider d2interface.AudioProvider) error {
if singleton != nil {
return ErrHasInit
}
singleton = audioProvider
return nil
}
// PlayBGM plays an infinitely looping background track
func PlayBGM(song string) error {
if singleton == nil {
return ErrNotInit
}
singleton.PlayBGM(song)
return nil
}
func LoadSoundEffect(sfx string) (d2interface.SoundEffect, error) {
if singleton == nil {
return nil, ErrNotInit
}
return singleton.LoadSoundEffect(sfx)
}
func SetVolumes(bgmVolume, sfxVolume float64) error {
if singleton == nil {
return ErrNotInit
}
singleton.SetVolumes(bgmVolume, sfxVolume)
return nil
}