SoundInstance API WIP
This commit is contained in:
@@ -13,13 +13,11 @@ namespace DaggerFramework.Audio
|
|||||||
// SOUND
|
// SOUND
|
||||||
public abstract void PlaySound(Sound sound, string bus = "Master", float pitch = 1.0f, float volume = 1.0f);
|
public 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, default, default);
|
public void PlaySound(Sound sound, string bus = "Master") => PlaySound(sound, bus, default, default);
|
||||||
public void PlaySoundVariation(Sound sound, string bus = "Master", float pitchVariation = 0.1f, float volume = 1.0f)
|
|
||||||
{
|
|
||||||
var maxPitch = 1.0f + pitchVariation;
|
|
||||||
var minPitch = 1.0f - pitchVariation;
|
|
||||||
|
|
||||||
var pitch = (float)_random.NextDouble() * (maxPitch - minPitch) + minPitch;
|
public SoundInstance CreateInstance(Sound sound)
|
||||||
PlaySound(sound, bus, pitch, volume);
|
{
|
||||||
|
var instance = new SoundInstance(this, sound);
|
||||||
|
return instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
// EFFECTS
|
// EFFECTS
|
||||||
@@ -32,9 +30,4 @@ namespace DaggerFramework.Audio
|
|||||||
|
|
||||||
private LehmerRandom _random = new LehmerRandom();
|
private LehmerRandom _random = new LehmerRandom();
|
||||||
}
|
}
|
||||||
|
|
||||||
public struct SoundInstance
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
46
DaggerFramework/Source/Audio/SoundInstance.cs
Normal file
46
DaggerFramework/Source/Audio/SoundInstance.cs
Normal file
@@ -0,0 +1,46 @@
|
|||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
BIN
TestGame/Resources/sounds/shuffled_test/move_1.ogg
Normal file
BIN
TestGame/Resources/sounds/shuffled_test/move_1.ogg
Normal file
Binary file not shown.
BIN
TestGame/Resources/sounds/shuffled_test/move_2.ogg
Normal file
BIN
TestGame/Resources/sounds/shuffled_test/move_2.ogg
Normal file
Binary file not shown.
BIN
TestGame/Resources/sounds/shuffled_test/move_3.ogg
Normal file
BIN
TestGame/Resources/sounds/shuffled_test/move_3.ogg
Normal file
Binary file not shown.
BIN
TestGame/Resources/sounds/shuffled_test/move_4.ogg
Normal file
BIN
TestGame/Resources/sounds/shuffled_test/move_4.ogg
Normal file
Binary file not shown.
BIN
TestGame/Resources/sounds/shuffled_test/move_5.ogg
Normal file
BIN
TestGame/Resources/sounds/shuffled_test/move_5.ogg
Normal file
Binary file not shown.
@@ -49,7 +49,10 @@ public class TestGame : Game
|
|||||||
|
|
||||||
if (_inputHandler.IsActionJustPressed("play"))
|
if (_inputHandler.IsActionJustPressed("play"))
|
||||||
{
|
{
|
||||||
_audioBackend.PlaySoundVariation(_testSound, "Master", 0.1f);
|
var instance = _audioBackend.CreateInstance(_testSound)
|
||||||
|
.PitchVariation(min: 0.9f, max: 1.2f)
|
||||||
|
.VolumeVariation(min: 0.90f, max: 1.0f);
|
||||||
|
instance.Play();
|
||||||
}
|
}
|
||||||
|
|
||||||
_audioBackend.Update();
|
_audioBackend.Update();
|
||||||
|
|||||||
Reference in New Issue
Block a user