add audio Seek functionality
parent
985e096a7b
commit
83eb268a4a
|
@ -241,6 +241,8 @@ namespace MoonWorks.Audio
|
||||||
public abstract void Play(bool loop);
|
public abstract void Play(bool loop);
|
||||||
public abstract void Pause();
|
public abstract void Pause();
|
||||||
public abstract void Stop(bool immediate);
|
public abstract void Stop(bool immediate);
|
||||||
|
public abstract void Seek(float seconds);
|
||||||
|
public abstract void Seek(uint sampleFrame);
|
||||||
|
|
||||||
private void InitDSPSettings(uint srcChannels)
|
private void InitDSPSettings(uint srcChannels)
|
||||||
{
|
{
|
||||||
|
|
|
@ -93,6 +93,31 @@ namespace MoonWorks.Audio
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void PerformSeek(uint sampleFrame)
|
||||||
|
{
|
||||||
|
if (State == SoundState.Playing)
|
||||||
|
{
|
||||||
|
FAudio.FAudioSourceVoice_Stop(Handle, 0, 0);
|
||||||
|
FAudio.FAudioSourceVoice_FlushSourceBuffers(Handle);
|
||||||
|
}
|
||||||
|
|
||||||
|
Parent.Handle.PlayBegin = sampleFrame;
|
||||||
|
Play();
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void Seek(float seconds)
|
||||||
|
{
|
||||||
|
uint sampleFrame =
|
||||||
|
(uint) (Parent.SamplesPerSecond * seconds);
|
||||||
|
|
||||||
|
PerformSeek(sampleFrame);
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void Seek(uint sampleFrame)
|
||||||
|
{
|
||||||
|
PerformSeek(sampleFrame);
|
||||||
|
}
|
||||||
|
|
||||||
public void Free()
|
public void Free()
|
||||||
{
|
{
|
||||||
Parent.FreeInstance(this);
|
Parent.FreeInstance(this);
|
||||||
|
|
|
@ -62,6 +62,35 @@ namespace MoonWorks.Audio
|
||||||
device.AddDynamicSoundInstance(this);
|
device.AddDynamicSoundInstance(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void PerformSeek(uint sampleFrame)
|
||||||
|
{
|
||||||
|
if (State == SoundState.Playing)
|
||||||
|
{
|
||||||
|
FAudio.FAudioSourceVoice_Stop(Handle, 0, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
FAudio.FAudioSourceVoice_FlushSourceBuffers(Handle);
|
||||||
|
ClearBuffers();
|
||||||
|
FAudio.stb_vorbis_seek(VorbisHandle, sampleFrame);
|
||||||
|
QueueBuffers();
|
||||||
|
|
||||||
|
if (State == SoundState.Playing)
|
||||||
|
{
|
||||||
|
Play();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void Seek(float seconds)
|
||||||
|
{
|
||||||
|
uint sampleFrame = (uint) (Info.sample_rate * seconds);
|
||||||
|
PerformSeek(sampleFrame);
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void Seek(uint sampleFrame)
|
||||||
|
{
|
||||||
|
PerformSeek(sampleFrame);
|
||||||
|
}
|
||||||
|
|
||||||
protected override void AddBuffer(
|
protected override void AddBuffer(
|
||||||
out float[] buffer,
|
out float[] buffer,
|
||||||
out uint bufferOffset,
|
out uint bufferOffset,
|
||||||
|
|
Loading…
Reference in New Issue