set loop on play instead of construct

pull/18/head
cosmonaut 2022-04-05 16:05:42 -07:00
parent b1b6b84809
commit 6a1fa004d6
5 changed files with 19 additions and 23 deletions

View File

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

View File

@ -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!
/// </summary>
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();

View File

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

View File

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

View File

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