From 246f69ab5dbd5719cf894f0a645807d8d1399528 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 --- SoundInstance.cs | 8 +++----- StaticSound.cs | 4 ++-- StaticSoundInstance.cs | 9 +++++---- StreamingSound.cs | 9 +++++---- StreamingSoundOgg.cs | 12 ++++-------- 5 files changed, 19 insertions(+), 23 deletions(-) diff --git a/SoundInstance.cs b/SoundInstance.cs index db128e8..78b5eec 100644 --- a/SoundInstance.cs +++ b/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/StaticSound.cs b/StaticSound.cs index 15434d4..5f0d851 100644 --- a/StaticSound.cs +++ b/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/StaticSoundInstance.cs b/StaticSoundInstance.cs index bb472fc..0ca6bd0 100644 --- a/StaticSoundInstance.cs +++ b/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/StreamingSound.cs b/StreamingSound.cs index a045bc9..81c4553 100644 --- a/StreamingSound.cs +++ b/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/StreamingSoundOgg.cs b/StreamingSoundOgg.cs index 6d31aa6..8bad790 100644 --- a/StreamingSoundOgg.cs +++ b/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;