How do I retrieve the current sample play position from an XAudio2 source voice?

827 Views Asked by At

I have an IXAudio2SourceVoice that is playing a submitted XAUDIO2_BUFFER. How do I retrieve from these the play position within the currently-playing buffer, in samples?

Thanks for your help!

1

There are 1 best solutions below

2
On BEST ANSWER

Just use IXAudio2SourceVoice::GetState:

    XAUDIO2_VOICE_STATE xstate;
#if (_WIN32_WINNT >= _WIN32_WINNT_WIN8)
    voice->GetState( &xstate, 0 );
#else
    voice->GetState( &xstate );
#endif
if ( xstate.BuffersQueued > 0 )
{
    // xstate.SamplesPlayed
}

The reason GetState takes a flag in XAudio 2.8 or later is specifically so you can use XAUDIO2_VOICE_NOSAMPLESPLAYED to save the overhead of filling out the current SamplesPlayed value.