码迷,mamicode.com
首页 > 其他好文 > 详细

(提交音频太快导致崩溃)应该是SubmitSourceBuffer允许的最大buffer值XAUDIO2_MAX_QUEUED_BUFFERS的限制

时间:2016-04-29 15:48:03      阅读:481      评论:0      收藏:0      [点我收藏+]

标签:

使用IAudio2SourceVoice->SubmitSourceBuffer来提交音频数据,会有一个数据队列,可以使用XAUDIO2_VOICE_STATE来获取状态,可以看到当前待播放的等待队列中还有多少Buff,提交音频数据过快的话,会导致程序崩溃,应该是因为下面的buffer最大值限制:

// Numeric boundary values
#define XAUDIO2_MAX_BUFFER_BYTES        0x80000000    // Maximum bytes allowed in a source buffer
#define XAUDIO2_MAX_QUEUED_BUFFERS      64            // Maximum buffers allowed in a voice queue
#define XAUDIO2_MAX_BUFFERS_SYSTEM      2             // Maximum buffers allowed for system threads (Xbox 360 only)
#define XAUDIO2_MAX_AUDIO_CHANNELS      64            // Maximum channels in an audio stream
#define XAUDIO2_MIN_SAMPLE_RATE         1000          // Minimum audio sample rate supported
#define XAUDIO2_MAX_SAMPLE_RATE         200000        // Maximum audio sample rate supported
#define XAUDIO2_MAX_VOLUME_LEVEL        16777216.0f   // Maximum acceptable volume level (2^24)
#define XAUDIO2_MIN_FREQ_RATIO          (1/1024.0f)   // Minimum SetFrequencyRatio argument
#define XAUDIO2_MAX_FREQ_RATIO          1024.0f       // Maximum MaxFrequencyRatio argument
#define XAUDIO2_DEFAULT_FREQ_RATIO      2.0f          // Default MaxFrequencyRatio argument
#define XAUDIO2_MAX_FILTER_ONEOVERQ     1.5f          // Maximum XAUDIO2_FILTER_PARAMETERS.OneOverQ
#define XAUDIO2_MAX_FILTER_FREQUENCY    1.0f          // Maximum XAUDIO2_FILTER_PARAMETERS.Frequency
#define XAUDIO2_MAX_LOOP_COUNT          254           // Maximum non-infinite XAUDIO2_BUFFER.LoopCount
#define XAUDIO2_MAX_INSTANCES           8             // Maximum simultaneous XAudio2 objects on Xbox 360

IXAudio2SourceVoice::SubmitSourceBuffer method

Adds a new audio buffer to the voice queue.

Syntax

HRESULT SubmitSourceBuffer(
  [inconst XAUDIO2_BUFFER     *pBuffer,
  [inconst XAUDIO2_BUFFER_WMA *pBufferWMA = NULL
);

Parameters

pBuffer [in]

Pointer to an XAUDIO2_BUFFER structure to queue.

pBufferWMA [in]

Pointer to an additional XAUDIO2_BUFFER_WMA structure used when submitting WMA data.

Return value

Returns S_OK if successful, an error code otherwise. See XAudio2 Error Codes for descriptions of XAudio2 specific error codes.

Remarks

The voice processes and plays back the buffers in its queue in the order that they were submitted.

The XAUDIO2_BUFFER structure includes details about the audio buffer‘s location and size, the part of the buffer that should actually be played, the loop region (if any) and loop count, the context pointer to be used in any callbacks relating to this buffer, and an optional XAUDIO2_END_OF_STREAM flag that indicates that it is the last buffer of a contiguous sound.

If the voice is started and has no buffers queued, the new buffer will start playing immediately. If the voice is stopped, the buffer is added to the voice‘s queue and will be played when the voice starts.

If only part of the given buffer should be played, the PlayBegin and PlayLength fields in the XAUDIO2_BUFFER can be used to specify the region to be played. A PlayLength value of 0 means to play the entire buffer (and in this case PlayBegin must be 0 as well).

If all or part of the buffer should be played in a continuous loop, the LoopBeginLoopLength and LoopCount fields in XAUDIO2_BUFFER can be used to specify the characteristics of the loop region. A LoopBegin value of XAUDIO2_NO_LOOP_REGION means that no looping should be performed, and in this case LoopLength and LoopCount must be given as 0. If a loop region is specified, it must be non-empty (LoopLength > 0), and the loop count must be between 1 and XAUDIO2_MAX_LOOP_COUNT inclusive (or XAUDIO2_LOOP_INFINITE to specify an endless loop which will only end when IXAudio2SourceVoice::ExitLoop is called). A loop count of N means to skip backwards N times, i.e. to play the loop region N+1 times.

If an explicit play region is specified, it must begin and end within the given audio buffer (or, in the compressed case, within the set of samples that the buffer will decode to). In addition, the loop region cannot end past the end of the play region.

Xbox 360
For certain audio formats, there may be additional restrictions on the valid endpoints of any play or loop regions; e.g. for XMA buffers, the regions can only begin or end at 128-sample boundaries in the decoded audio.

 

The pBuffer pointer can be reused or freed immediately after calling this method, but the actual audio data referenced by pBuffer must remain valid until the buffer has been fully consumed by XAudio2 (which is indicated by the IXAudio2VoiceCallback::OnBufferEnd callback).

Up to XAUDIO2_MAX_QUEUED_BUFFERS buffers can be queued on a voice at any one time.

SubmitSourceBuffer takes effect immediately when called from an XAudio2 callback with an OperationSet of XAUDIO2_COMMIT_NOW.

Xbox 360
This method can be called from an Xbox system thread (most other XAudio2 methods cannot). However, a maximum of two source buffers can be submitted from a system thread at a time.

 

Platform Requirements

Windows 10 (XAudio2.9); Windows 8, Windows Phone 8 (XAudio 2.8); DirectX SDK (XAudio 2.7)

Requirements

Header

Xaudio2.h

See also

IXAudio2SourceVoice
How to: Build a Basic Audio Processing Graph
How to: Stream a Sound from Disk

 

 

社区附加资源

添加

To Colin:

The statement most likely means that the XAUDIO2_BUFFER structure can be freed immediately, but the audio data (pAudioData member of XAUDIO2_BUFFER) cannot be freed. I agree that the documentation is a bit misleading, however.
技术分享
9/27/2014

Stray debugger breakpoint in XAudio2 DLL on Windows

FYI: 

I just discovered that (at least on the Win7 PC platform w/DX11 - June 2010) if you attempt to submit more than XAUDIO2_MAX_QUEUED_BUFFERS buffers before the voice starts playing them, a debugger breakpoint is triggered IN the XAudio2 DLL! 

The upshot is that Windows will tell you your program has "stopped responding", or it will cause a crash dump to occur, as opposed to simply rejecting the submission and returning an error code.
技术分享
11/30/2011

Strange statement in the documentation...

The documentation includes the following statement:


    "The pBuffer pointer can be reused or freed immediately after calling this method, but
the actual audio
data referenced by pBuffer must remain valid until the buffer has been fully consumed by
XAudio2 (which is
indicated by the IXAudio2VoiceCallback::OnBufferEnd callback)."


If pBuffer is just a plain pointer value (as in "void * pBuffer = malloc( 200000 );"), then saying the *pointer* variable can be "reused" is obvious, and saying the the pointer variable can be "freed immediately" makes no sense.  If the statement meant that the *memory allocation* (pointed to by the pointer) could be "reused or freed immediately", then this seems to contradict the crucial second half of the statement, which warns that the data must remain valid until the "OnBufferEnd(...)" callback is called.


If "pBuffer pointer" was intended to refer to some sort of "smart pointer", or if the statement refers to some special programming context (e.g., X-Box with some particular memory management pattern), that was not at all clear in the overall description of how to use this function.


In a C++ context, "reusing or freeing" the memory allocation "immediately" would risk corrupting the source data before XAudio2 had finished consuming the audio data!  The most obvious interpretation of the statement seems to be "You can do X, but you must never do X."

(提交音频太快导致崩溃)应该是SubmitSourceBuffer允许的最大buffer值XAUDIO2_MAX_QUEUED_BUFFERS的限制

标签:

原文地址:http://blog.csdn.net/u011417605/article/details/51275764

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!