From a806e3b7640f95c13615c0665de5a24a15921126 Mon Sep 17 00:00:00 2001 From: dnesov Date: Tue, 29 Oct 2024 01:17:55 +0100 Subject: [PATCH] Remove audio, will make it as separate packages instead. --- TestGame/TestGame.cs | 1 - Voile/Source/Audio/AudioSystem.cs | 36 ------------- Voile/Source/Audio/DummyAudioSystem.cs | 43 --------------- Voile/Source/Audio/SoundInstance.cs | 42 --------------- Voile/Source/Audio/StandardAudioSystem.cs | 64 ----------------------- 5 files changed, 186 deletions(-) delete mode 100644 Voile/Source/Audio/AudioSystem.cs delete mode 100644 Voile/Source/Audio/DummyAudioSystem.cs delete mode 100644 Voile/Source/Audio/SoundInstance.cs delete mode 100644 Voile/Source/Audio/StandardAudioSystem.cs diff --git a/TestGame/TestGame.cs b/TestGame/TestGame.cs index 12d2478..f66be3e 100644 --- a/TestGame/TestGame.cs +++ b/TestGame/TestGame.cs @@ -55,7 +55,6 @@ public class TestGame : Game { // ResourceManager.Reload(); // _particleSystem!.RestartEmitter(_emitterId); - AudioSystem.PlaySound(_sound.Value); } if (Input.KeyboardKeyJustPressed(KeyboardKey.One)) diff --git a/Voile/Source/Audio/AudioSystem.cs b/Voile/Source/Audio/AudioSystem.cs deleted file mode 100644 index e0d3eda..0000000 --- a/Voile/Source/Audio/AudioSystem.cs +++ /dev/null @@ -1,36 +0,0 @@ -using Voile; - -namespace Voile.Audio; - -public abstract class AudioSystem : IStartableSystem, IUpdatableSystem, IDisposable -{ - public void Start() => Initialize(); - - public void Update(double deltaTime) => Update(); - - public void Dispose() - { - Shutdown(); - GC.SuppressFinalize(this); - } - - protected abstract void Initialize(); - protected abstract void Update(); - protected abstract void Shutdown(); - // BUS - public abstract void CreateBus(string busName); - public abstract void SetBusVolume(string busName, float volume); - public abstract float GetBusVolume(string busName); - - public abstract void PlaySound(Sound sound, float pitch, float volume, string bus = "Master"); - public void PlaySound(Sound sound, string bus = "Master") => PlaySound(sound, 1.0f, 1.0f, bus); - - public SoundInstance CreateInstance(Sound sound) - { - var instance = new SoundInstance(this, sound); - return instance; - } - - - private LehmerRandom _random = new LehmerRandom(); -} \ No newline at end of file diff --git a/Voile/Source/Audio/DummyAudioSystem.cs b/Voile/Source/Audio/DummyAudioSystem.cs deleted file mode 100644 index 323b0e4..0000000 --- a/Voile/Source/Audio/DummyAudioSystem.cs +++ /dev/null @@ -1,43 +0,0 @@ -namespace Voile.Audio -{ - /// - /// Dummy audio system. - /// - public class DummyAudioSystem : AudioSystem - { - public override void CreateBus(string busName) - { - return; - } - - public override float GetBusVolume(string busName) - { - return 0.0f; - } - - protected override void Initialize() - { - return; - } - - public override void SetBusVolume(string busName, float volume) - { - return; - } - - protected override void Shutdown() - { - return; - } - - protected override void Update() - { - return; - } - - public override void PlaySound(Sound sound, float pitch, float volume, string bus = "Master") - { - return; - } - } -} \ No newline at end of file diff --git a/Voile/Source/Audio/SoundInstance.cs b/Voile/Source/Audio/SoundInstance.cs deleted file mode 100644 index 3fa1c6a..0000000 --- a/Voile/Source/Audio/SoundInstance.cs +++ /dev/null @@ -1,42 +0,0 @@ -namespace Voile.Audio -{ - public class SoundInstance - { - protected virtual Sound Sound => _sound; - public SoundInstance(AudioSystem 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(Sound, _pitch, _volume, _bus); - } - - private readonly AudioSystem _backend; - private readonly Sound _sound; - private string _bus = "Master"; - private float _pitch, _volume = 1.0f; - } -} \ No newline at end of file diff --git a/Voile/Source/Audio/StandardAudioSystem.cs b/Voile/Source/Audio/StandardAudioSystem.cs deleted file mode 100644 index e99209a..0000000 --- a/Voile/Source/Audio/StandardAudioSystem.cs +++ /dev/null @@ -1,64 +0,0 @@ -using System.Runtime.CompilerServices; -using Raylib_cs; -using SoLoud; - -namespace Voile.Audio; - -public class StandardAudioSystem : AudioSystem -{ - public StandardAudioSystem() - { - _engine = new Soloud(); - } - protected override void Initialize() - { - _engine.init(); - } - - public override void CreateBus(string busName) - { - throw new NotImplementedException(); - } - - public override float GetBusVolume(string busName) - { - throw new NotImplementedException(); - } - - public override void PlaySound(Sound sound, float pitch, float volume, string bus = "Master") - { - PlayUnsafe(sound.Buffer, sound.BufferSize, sound.SampleRate, sound.Channel); - } - - public override void SetBusVolume(string busName, float volume) - { - throw new NotImplementedException(); - } - - protected override void Shutdown() - { - _engine!.deinit(); - } - - protected override void Update() - { - - } - - private void PlayUnsafe(ReadOnlyMemory soundBuffer, long length, int sampleRate, SoundChannel channels) - { - var wav = new Wav(); - - int channelCount = channels == SoundChannel.Stereo ? 2 : 1; - - unsafe - { - nint ptr = (nint)soundBuffer.Pin().Pointer; - wav.loadRawWave16(ptr, (uint)length, sampleRate, (uint)channelCount); - } - - _engine.play(wav); - } - - private Soloud _engine; -} \ No newline at end of file