Question

I am using the SharpDX wrapper for the DirectX XAudio2 api. http://sharpdx.org/

I need to be able to seek a WAV file loaded into a SourceVoice to a given position in the track. I am struggling to work out what I should be setting PlayBegin to in order to skip a set amount of milliseconds, or a proportional amount of the track.

public void onMetronome(int bar)
{
   if (voice != null) voice.DestroyVoice();
   voice = new SourceVoice(Player.XAudio, buffer.WaveFormat, true);
   buffer.PlayBegin = (int)(bar * buffer.Stream.Length / 4);
   voice.SubmitSourceBuffer(buffer, buffer.DecodedPacketsInfo);
   voice.Start();
}

Can anyone tell me what value I should be setting play begin to?

I can see from the documentation that this value is the sample number and that it may need to be a multiple of 128 but think I am still doing something wrong.

http://msdn.microsoft.com/en-us/library/windows/desktop/microsoft.directx_sdk.ixaudio2sourcevoice.ixaudio2sourcevoice.submitsourcebuffer(v=vs.85).aspx

http://msdn.microsoft.com/en-us/library/windows/desktop/microsoft.directx_sdk.xaudio2.xaudio2_buffer(v=vs.85).aspx

Was it helpful?

Solution

Figured it out, think I have been multiplying by 1000 when I shouldn't have, the following works

var offset = (int)Math.Floor(buffer.WaveFormat.SampleRate * barDuration / 128) * 128 * bar;
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top