From d3d3bde6579c376f6f08894c0c92a320c4de42e0 Mon Sep 17 00:00:00 2001 From: Stevo John Date: Fri, 16 Aug 2024 18:46:18 +0100 Subject: [PATCH] WIP --- .../Modules/Audio/Engines/Bass/BassException.cs | 8 ++++++++ .../Modules/Audio/Engines/BassAudioEngine.cs | 14 +++++++++++--- src/Zen.System/Modules/AyAudio.cs | 2 +- 3 files changed, 20 insertions(+), 4 deletions(-) create mode 100644 src/Zen.System/Modules/Audio/Engines/Bass/BassException.cs diff --git a/src/Zen.System/Modules/Audio/Engines/Bass/BassException.cs b/src/Zen.System/Modules/Audio/Engines/Bass/BassException.cs new file mode 100644 index 00000000..121ef0ab --- /dev/null +++ b/src/Zen.System/Modules/Audio/Engines/Bass/BassException.cs @@ -0,0 +1,8 @@ +namespace Zen.System.Modules.Audio.Engines.Bass; + +public class BassException : Exception +{ + public BassException(string message) : base(message) + { + } +} \ No newline at end of file diff --git a/src/Zen.System/Modules/Audio/Engines/BassAudioEngine.cs b/src/Zen.System/Modules/Audio/Engines/BassAudioEngine.cs index 335d29a7..71e8ecbf 100644 --- a/src/Zen.System/Modules/Audio/Engines/BassAudioEngine.cs +++ b/src/Zen.System/Modules/Audio/Engines/BassAudioEngine.cs @@ -55,7 +55,7 @@ public void Send(float[] data) _channel = ManagedBass.BASS_SampleGetChannel(_sampleHandle, BassFlag.BASS_SAMCHAN_STREAM); - ManagedBass.BASS_ChannelSetSync(_channel, BassSync.BASS_SYNC_END | BassSync.BASS_SYNC_ONETIME, Constants.DefaultBufferSize * 4, PlayComplete, IntPtr.Zero); + Logger.LogException(ManagedBass.BASS_ChannelSetSync(_channel, BassSync.BASS_SYNC_END | BassSync.BASS_SYNC_ONETIME, Constants.DefaultBufferSize * 4, PlayComplete, IntPtr.Zero).ToString(), new Exception()); ManagedBass.BASS_ChannelPlay(_channel, false); } @@ -79,9 +79,17 @@ private void Initialise() { try { - ManagedBass.BASS_Init(-1, Constants.SampleRate, BassInit.BASS_DEVICE_MONO, IntPtr.Zero); - + if (! ManagedBass.BASS_Init(-1, Constants.SampleRate, BassInit.BASS_DEVICE_MONO, IntPtr.Zero)) + { + throw new BassException("Error initialising BASS library."); + } + _sampleHandle = ManagedBass.BASS_SampleCreate(Constants.DefaultBufferSize * 4, Constants.SampleRate, 1, 1, BassFlag.BASS_SAMPLE_FLOAT); + + if (_sampleHandle == 0) + { + throw new BassException("Error creating BASS sample."); + } } catch (Exception exception) { diff --git a/src/Zen.System/Modules/AyAudio.cs b/src/Zen.System/Modules/AyAudio.cs index 26efbc62..38183b5d 100644 --- a/src/Zen.System/Modules/AyAudio.cs +++ b/src/Zen.System/Modules/AyAudio.cs @@ -286,7 +286,7 @@ private void RunFrame() try { _resetEvent.WaitOne(); - + _resetEvent.Reset(); for (var i = 0; i < Constants.DefaultBufferSize; i++)