From 1aeb3e9f6c698ef41660f6b3a42ceaffdfa1b7c2 Mon Sep 17 00:00:00 2001 From: cosmonaut Date: Mon, 1 Aug 2022 23:14:45 -0700 Subject: [PATCH] revise Stop to Stop and StopImmediate --- src/Audio/SoundInstance.cs | 8 ++++---- src/Audio/StaticSoundInstance.cs | 23 +++++++++++------------ src/Audio/StreamingSound.cs | 20 +++++++++++--------- src/Audio/StreamingSoundOgg.cs | 2 -- src/Audio/StreamingSoundSeekable.cs | 2 +- src/Video/StreamingSoundTheora.cs | 4 +--- src/Video/Video.cs | 2 +- 7 files changed, 29 insertions(+), 32 deletions(-) diff --git a/src/Audio/SoundInstance.cs b/src/Audio/SoundInstance.cs index 8210d2a..caba229 100644 --- a/src/Audio/SoundInstance.cs +++ b/src/Audio/SoundInstance.cs @@ -12,7 +12,7 @@ namespace MoonWorks.Audio public bool Is3D { get; protected set; } - public abstract SoundState State { get; protected set; } + public virtual SoundState State { get; protected set; } private float _pan = 0; public float Pan @@ -238,7 +238,8 @@ namespace MoonWorks.Audio public abstract void Play(); public abstract void Pause(); - public abstract void Stop(bool immediate); + public abstract void Stop(); + public abstract void StopImmediate(); private void InitDSPSettings(uint srcChannels) { @@ -341,8 +342,7 @@ namespace MoonWorks.Audio protected override void Destroy() { - Stop(true); - + StopImmediate(); FAudio.FAudioVoice_DestroyVoice(Handle); Marshal.FreeHGlobal(dspSettings.pMatrixCoefficients); } diff --git a/src/Audio/StaticSoundInstance.cs b/src/Audio/StaticSoundInstance.cs index 685e350..7f52a97 100644 --- a/src/Audio/StaticSoundInstance.cs +++ b/src/Audio/StaticSoundInstance.cs @@ -20,7 +20,7 @@ namespace MoonWorks.Audio ); if (state.BuffersQueued == 0) { - Stop(true); + StopImmediate(); } return _state; @@ -79,18 +79,17 @@ namespace MoonWorks.Audio } } - public override void Stop(bool immediate = true) + public override void Stop() { - if (immediate) - { - FAudio.FAudioSourceVoice_Stop(Handle, 0, 0); - FAudio.FAudioSourceVoice_FlushSourceBuffers(Handle); - State = SoundState.Stopped; - } - else - { - FAudio.FAudioSourceVoice_ExitLoop(Handle, 0); - } + FAudio.FAudioSourceVoice_ExitLoop(Handle, 0); + State = SoundState.Stopped; + } + + public override void StopImmediate() + { + FAudio.FAudioSourceVoice_Stop(Handle, 0, 0); + FAudio.FAudioSourceVoice_FlushSourceBuffers(Handle); + State = SoundState.Stopped; } public void Seek(uint sampleFrame) diff --git a/src/Audio/StreamingSound.cs b/src/Audio/StreamingSound.cs index 9dd954d..d3d75eb 100644 --- a/src/Audio/StreamingSound.cs +++ b/src/Audio/StreamingSound.cs @@ -51,14 +51,16 @@ namespace MoonWorks.Audio } } - public override void Stop(bool immediate = true) + public override void Stop() { - if (immediate) - { - FAudio.FAudioSourceVoice_Stop(Handle, 0, 0); - FAudio.FAudioSourceVoice_FlushSourceBuffers(Handle); - ClearBuffers(); - } + State = SoundState.Stopped; + } + + public override void StopImmediate() + { + FAudio.FAudioSourceVoice_Stop(Handle, 0, 0); + FAudio.FAudioSourceVoice_FlushSourceBuffers(Handle); + ClearBuffers(); State = SoundState.Stopped; } @@ -157,7 +159,7 @@ namespace MoonWorks.Audio protected virtual void OnReachedEnd() { - Stop(false); + Stop(); } protected unsafe abstract void AddBuffer( @@ -169,7 +171,7 @@ namespace MoonWorks.Audio protected override void Destroy() { - Stop(true); + StopImmediate(); } } } diff --git a/src/Audio/StreamingSoundOgg.cs b/src/Audio/StreamingSoundOgg.cs index 0c3bb7f..31ba8c5 100644 --- a/src/Audio/StreamingSoundOgg.cs +++ b/src/Audio/StreamingSoundOgg.cs @@ -16,8 +16,6 @@ namespace MoonWorks.Audio private readonly float[] buffer; // currently decoded bytes - public override SoundState State { get; protected set; } - public unsafe static StreamingSoundOgg Load(AudioDevice device, string filePath) { var fileData = File.ReadAllBytes(filePath); diff --git a/src/Audio/StreamingSoundSeekable.cs b/src/Audio/StreamingSoundSeekable.cs index ad159c1..7ca563b 100644 --- a/src/Audio/StreamingSoundSeekable.cs +++ b/src/Audio/StreamingSoundSeekable.cs @@ -18,7 +18,7 @@ namespace MoonWorks.Audio } else { - Stop(false); + Stop(); } } } diff --git a/src/Video/StreamingSoundTheora.cs b/src/Video/StreamingSoundTheora.cs index aeab3e1..311ed9d 100644 --- a/src/Video/StreamingSoundTheora.cs +++ b/src/Video/StreamingSoundTheora.cs @@ -5,9 +5,7 @@ namespace MoonWorks.Video { public unsafe class StreamingSoundTheora : StreamingSound { - public IntPtr VideoHandle; - - public override SoundState State { get => throw new System.NotImplementedException(); protected set => throw new System.NotImplementedException(); } + private IntPtr VideoHandle; public override int BUFFER_SIZE => 4096 * 2; diff --git a/src/Video/Video.cs b/src/Video/Video.cs index 679c603..bdcc66e 100644 --- a/src/Video/Video.cs +++ b/src/Video/Video.cs @@ -195,7 +195,7 @@ namespace MoonWorks.Video if (audioStream != null) { - audioStream.Stop(true); + audioStream.StopImmediate(); audioStream.Dispose(); audioStream = null; }