Add synchronized audio playback mechanism

pull/47/head
cosmonaut 2023-02-16 15:12:35 -08:00
parent 5baa1d7b40
commit e9aacb44da
4 changed files with 28 additions and 2 deletions

View File

@ -224,6 +224,11 @@ namespace MoonWorks.Audio
}
}
public void SyncPlay()
{
FAudio.FAudio_CommitChanges(Handle, 1);
}
internal void AddDynamicSoundInstance(StreamingSound instance)
{
streamingSounds.Add(new WeakReference<StreamingSound>(instance));

View File

@ -253,6 +253,7 @@ namespace MoonWorks.Audio
}
public abstract void Play();
public abstract void QueueSyncPlay();
public abstract void Pause();
public abstract void Stop();
public abstract void StopImmediate();

View File

@ -41,6 +41,16 @@ namespace MoonWorks.Audio
}
public override void Play()
{
PlayUsingOperationSet(0);
}
public override void QueueSyncPlay()
{
PlayUsingOperationSet(1);
}
private void PlayUsingOperationSet(uint operationSet)
{
if (State == SoundState.Playing)
{
@ -66,7 +76,7 @@ namespace MoonWorks.Audio
IntPtr.Zero
);
FAudio.FAudioSourceVoice_Start(Handle, 0, 0);
FAudio.FAudioSourceVoice_Start(Handle, 0, operationSet);
State = SoundState.Playing;
}

View File

@ -35,6 +35,16 @@ namespace MoonWorks.Audio
}
public override void Play()
{
PlayUsingOperationSet(0);
}
public override void QueueSyncPlay()
{
PlayUsingOperationSet(1);
}
private void PlayUsingOperationSet(uint operationSet)
{
if (State == SoundState.Playing)
{
@ -44,7 +54,7 @@ namespace MoonWorks.Audio
State = SoundState.Playing;
Update();
FAudio.FAudioSourceVoice_Start(Handle, 0, 0);
FAudio.FAudioSourceVoice_Start(Handle, 0, operationSet);
}
public override void Pause()