From 6a1fa004d652daa7c8ad6a43955c462902d251d6 Mon Sep 17 00:00:00 2001 From: cosmonaut Date: Tue, 5 Apr 2022 16:05:42 -0700 Subject: [PATCH] set loop on play instead of construct --- src/Audio/SoundInstance.cs | 8 +++----- src/Audio/StaticSound.cs | 4 ++-- src/Audio/StaticSoundInstance.cs | 9 +++++---- src/Audio/StreamingSound.cs | 9 +++++---- src/Audio/StreamingSoundOgg.cs | 12 ++++-------- 5 files changed, 19 insertions(+), 23 deletions(-) diff --git a/src/Audio/SoundInstance.cs b/src/Audio/SoundInstance.cs index db128e85..78b5eecc 100644 --- a/src/Audio/SoundInstance.cs +++ b/src/Audio/SoundInstance.cs @@ -8,7 +8,7 @@ namespace MoonWorks.Audio { internal IntPtr Handle; internal FAudio.FAudioWaveFormatEx Format; - public bool Loop { get; } + public bool Loop { get; protected set; } = false; protected FAudio.F3DAUDIO_DSP_SETTINGS dspSettings; @@ -168,8 +168,7 @@ namespace MoonWorks.Audio ushort blockAlign, ushort channels, uint samplesPerSecond, - bool is3D, - bool loop + bool is3D ) : base(device) { var format = new FAudio.FAudioWaveFormatEx @@ -212,7 +211,6 @@ namespace MoonWorks.Audio ); */ - Loop = loop; State = SoundState.Stopped; } @@ -242,7 +240,7 @@ namespace MoonWorks.Audio ); } - public abstract void Play(); + public abstract void Play(bool loop); public abstract void Pause(); public abstract void Stop(bool immediate); diff --git a/src/Audio/StaticSound.cs b/src/Audio/StaticSound.cs index 15434d47..5f0d8511 100644 --- a/src/Audio/StaticSound.cs +++ b/src/Audio/StaticSound.cs @@ -271,11 +271,11 @@ namespace MoonWorks.Audio /// Gets a sound instance from the pool. /// NOTE: If you lose track of instances, you will create garbage collection pressure! /// - public StaticSoundInstance GetInstance(bool loop = false) + public StaticSoundInstance GetInstance() { if (Instances.Count == 0) { - Instances.Push(new StaticSoundInstance(Device, this, false, loop)); + Instances.Push(new StaticSoundInstance(Device, this, false)); } return Instances.Pop(); diff --git a/src/Audio/StaticSoundInstance.cs b/src/Audio/StaticSoundInstance.cs index bb472fc3..0ca6bd03 100644 --- a/src/Audio/StaticSoundInstance.cs +++ b/src/Audio/StaticSoundInstance.cs @@ -33,20 +33,21 @@ namespace MoonWorks.Audio internal StaticSoundInstance( AudioDevice device, StaticSound parent, - bool is3D, - bool loop - ) : base(device, parent.FormatTag, parent.BitsPerSample, parent.BlockAlign, parent.Channels, parent.SamplesPerSecond, is3D, loop) + bool is3D + ) : base(device, parent.FormatTag, parent.BitsPerSample, parent.BlockAlign, parent.Channels, parent.SamplesPerSecond, is3D) { Parent = parent; } - public override void Play() + public override void Play(bool loop = false) { if (State == SoundState.Playing) { return; } + Loop = loop; + if (Loop) { Parent.Handle.LoopCount = 255; diff --git a/src/Audio/StreamingSound.cs b/src/Audio/StreamingSound.cs index a045bc9b..81c4553c 100644 --- a/src/Audio/StreamingSound.cs +++ b/src/Audio/StreamingSound.cs @@ -23,18 +23,19 @@ namespace MoonWorks.Audio ushort blockAlign, ushort channels, uint samplesPerSecond, - bool is3D, - bool loop - ) : base(device, formatTag, bitsPerSample, blockAlign, channels, samplesPerSecond, is3D, loop) { } + bool is3D + ) : base(device, formatTag, bitsPerSample, blockAlign, channels, samplesPerSecond, is3D) { } - public override void Play() + public override void Play(bool loop = false) { if (State == SoundState.Playing) { return; } + Loop = loop; State = SoundState.Playing; + Update(); FAudio.FAudioSourceVoice_Start(Handle, 0, 0); } diff --git a/src/Audio/StreamingSoundOgg.cs b/src/Audio/StreamingSoundOgg.cs index 6d31aa64..8bad790f 100644 --- a/src/Audio/StreamingSoundOgg.cs +++ b/src/Audio/StreamingSoundOgg.cs @@ -18,8 +18,7 @@ namespace MoonWorks.Audio public static StreamingSoundOgg Load( AudioDevice device, string filePath, - bool is3D = false, - bool loop = false + bool is3D = false ) { var fileHandle = FAudio.stb_vorbis_open_filename(filePath, out var error, IntPtr.Zero); @@ -35,8 +34,7 @@ namespace MoonWorks.Audio device, fileHandle, info, - is3D, - loop + is3D ); } @@ -44,8 +42,7 @@ namespace MoonWorks.Audio AudioDevice device, IntPtr fileHandle, FAudio.stb_vorbis_info info, - bool is3D, - bool loop + bool is3D ) : base( device, 3, /* float type */ @@ -53,8 +50,7 @@ namespace MoonWorks.Audio (ushort) (4 * info.channels), (ushort) info.channels, info.sample_rate, - is3D, - loop + is3D ) { FileHandle = fileHandle;