question

BrettHoyle-4914 avatar image
0 Votes"
BrettHoyle-4914 asked BrettHoyle-4914 commented

XAudio 2.9 SubmitSourceBuffer() returns XAUDIO2_E_INVALID_CALL if AudioBytes = 0

I want to tell XAudio 2.9 to finish up my stream with Flags = XAUDIO2_END_OF_STREAM

If AudioBytes is less than 8 bytes SubmitSourceBuffer() fails with XAUDIO2_E_INVALID_CALL.
There is no data I want to add to the buffer, I just want to flag XAUDIO2_END_OF_STREAM with AudioBytes = 0

I want to set XAUDIO2_END_OF_STREAM so that the callback for OnStreamEnd() occurs when the buffer is exhausted.

AudioBytes=0 works perfectly fine for XAudio 2.7 and below.
XAudio 2.8 is untested.

Example of attempt to set XAUDIO2_END_OF_STREAM that returns XAUDIO2_E_INVALID_CALL
XAUDIO2_BUFFER buf = {0};
buf.AudioBytes = 0; // if this is set to 8 bytes XAudio 2.9 accepts
buf.pAudioData = (BYTE*)pOffset;
buf.Flags = XAUDIO2_END_OF_STREAM;

m_pSourceVoice->SubmitSourceBuffer( &buf );

windows-apic++
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

XiaopoYang-MSFT avatar image
0 Votes"
XiaopoYang-MSFT answered BrettHoyle-4914 commented

Hello,

Welcome to Microsoft Q&A!

Perhaps you can submit a silent source buffer instead of 0 byte source buffer or Mark last buffer in the stream as XAUDIO2_END_OF_STREAM. But Both XAUDIO2_BUFFER and DirectXTK do not show AudioBytes can be 0.

Thank you.


If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Thanks for the comments.
A silent buffer adds incorrect data to the stream that will be played and alters the stream length.
I already had implemented adding 8 silent bytes to the buffer but I think it is a hack solution.
I certainly preferred the behaviour in XAudio 2.7 and below of allowing AudioBytes = 0.

0 Votes 0 ·