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