29 lines
1.2 KiB
C#
29 lines
1.2 KiB
C#
namespace DaggerFramework.Audio
|
|
{
|
|
public abstract class AudioBackend
|
|
{
|
|
public abstract void Initialize();
|
|
public abstract void Update();
|
|
// BUS
|
|
public abstract void CreateBus(string busName);
|
|
public abstract void SetBusVolume(string busName, float volume);
|
|
public abstract float GetBusVolume(string busName);
|
|
|
|
// SOUND
|
|
protected abstract void PlaySound(Sound sound, string bus = "Master", float pitch = 1.0f, float volume = 1.0f);
|
|
public void PlaySound(Sound sound, string bus = "Master") => PlaySound(sound, bus, sound.PitchScale, sound.Volume);
|
|
public void PlaySoundVariation(Sound sound, string bus = "Master", float pitchVariation = 0.1f)
|
|
{
|
|
var maxPitch = sound.PitchScale + pitchVariation;
|
|
var minPitch = sound.PitchScale - pitchVariation;
|
|
|
|
var pitch = (float)_random.NextDouble() * (maxPitch - minPitch) + minPitch;
|
|
PlaySound(sound, bus, pitch, sound.Volume);
|
|
}
|
|
|
|
// EFFECTS
|
|
public abstract void AddBusEffect<T>(T effect, string bus = "Master") where T : AudioEffect;
|
|
|
|
private LehmerRandom _random = new LehmerRandom();
|
|
}
|
|
} |