46 lines
1.2 KiB
C#
46 lines
1.2 KiB
C#
namespace DaggerFramework.Audio
|
|
{
|
|
public class SoundInstance
|
|
{
|
|
public SoundInstance(AudioBackend backend, Sound sound)
|
|
{
|
|
_backend = backend;
|
|
_sound = sound;
|
|
}
|
|
|
|
public SoundInstance PitchVariation(float min, float max)
|
|
{
|
|
var random = new LehmerRandom();
|
|
_pitch = (float)random.NextDouble() * (max - min) + min;
|
|
return this;
|
|
}
|
|
|
|
public SoundInstance VolumeVariation(float min, float max)
|
|
{
|
|
var random = new LehmerRandom();
|
|
_volume = (float)random.NextDouble() * (max - min) + min;
|
|
return this;
|
|
}
|
|
|
|
public SoundInstance OnBus(string bus = "Master")
|
|
{
|
|
_bus = bus;
|
|
return this;
|
|
}
|
|
|
|
public void Play()
|
|
{
|
|
_backend.PlaySound(GetSound(), _bus, _pitch, _volume);
|
|
}
|
|
|
|
protected virtual Sound GetSound()
|
|
{
|
|
return _sound;
|
|
}
|
|
|
|
private readonly AudioBackend _backend;
|
|
private readonly Sound _sound;
|
|
private string _bus = "Master";
|
|
private float _pitch, _volume = 1.0f;
|
|
}
|
|
} |