Remove audio, will make it as separate packages instead.

This commit is contained in:
2024-10-29 01:17:55 +01:00
parent e51d28ce89
commit a806e3b764
5 changed files with 0 additions and 186 deletions

View File

@@ -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();
}

View File

@@ -1,43 +0,0 @@
namespace Voile.Audio
{
/// <summary>
/// Dummy audio system.
/// </summary>
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;
}
}
}

View File

@@ -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;
}
}

View File

@@ -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<short> 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;
}