fix StaticSoundInstance race condition and state

pull/49/head
cosmonaut 2023-05-11 18:59:26 -07:00
parent 5df08727c1
commit c037b4cb69
3 changed files with 10 additions and 11 deletions

@ -1 +1 @@
Subproject commit 63071f2c309f6fc2193de1c6b85da0e31df80040
Subproject commit 590cc3537f64d3b118f0001a2f2c111fcbd2b23f

View File

@ -274,10 +274,11 @@ namespace MoonWorks.Audio
{
if (AvailableInstances.Count == 0)
{
AvailableInstances.Push(new StaticSoundInstance(Device, this, autoFree));
AvailableInstances.Push(new StaticSoundInstance(Device, this));
}
var instance = AvailableInstances.Pop();
instance.AutoFree = autoFree;
UsedInstances.Add(instance);
return instance;
}

View File

@ -32,21 +32,14 @@ namespace MoonWorks.Audio
}
}
public bool AutoFree { get; }
public bool AutoFree { get; internal set; }
internal StaticSoundInstance(
AudioDevice device,
StaticSound parent,
bool autoFree
StaticSound parent
) : base(device, parent.FormatTag, parent.BitsPerSample, parent.BlockAlign, parent.Channels, parent.SamplesPerSecond)
{
Parent = parent;
AutoFree = autoFree;
if (AutoFree)
{
device.AddAutoFreeStaticSoundInstance(this);
}
}
public override void Play()
@ -87,6 +80,11 @@ namespace MoonWorks.Audio
FAudio.FAudioSourceVoice_Start(Voice, 0, operationSet);
State = SoundState.Playing;
if (AutoFree)
{
Device.AddAutoFreeStaticSoundInstance(this);
}
}
public override void Pause()