XAUDIO2: WARNING: Glitch at output sample 35412960 问题追踪

播放视频同时也播放音频,期间做着同步。之后偶然的时候,会有以下的输出:
“XAUDIO2: WARNING: Spent 251.13ms in OnProcessingPassStart callbacks
XAUDIO2: WARNING: Glitch at output sample 15522240

视频采用的是微软的media player api(CWMPPlayer4),音频采用的是 xaudio2。

google值到了https://msdn.microsoft.com/zh-cn/library/windows/desktop/ee415765

*If the audio thread runs for too long, XAudio2 shows a message in this form.
XAudio2: WARNING: Spent Xms in audio thread; XAudio2 possibly overloaded
Typically, this message occurs with the next message.

*If the audio driver can’t be fed new audio data on time, XAudio2 shows a message in this form.
XAudio2: WARNING: Glitch at output sample X

*Calling IXAudio2::GetPerformanceData provides XAudio2 performance data, including the total number of glitches since the XAudio2 engine started.
总的原因是音频线程运行时间太长,或者音频数据不能及时被提供。

解决办法:
Reduce the number of active voices and effects in the graph, especially expensive effects like reverb.
减少激活的声音数量和音效,尤其是让cpu费力的音效,如混响。
Disable voices and effects you’re not using.
在你不用时,禁用声音和音效。
Use the XAUDIO2_VOICE_NOSRC and XAUDIO2_VOICE_NOPITCH flags in IXAudio2::CreateSourceVoice, whenever possible. Sample rate conversion is costly.
尽可能的在CreateSourceVoice时使用 XAUDIO2_VOICE_NOSRC and XAUDIO2_VOICE_NOPITCH两个标记。采样率转换也很“昂贵”
Reduce the sample rate of individual voices. For example, a submix voice hosting a reverb effect can have a lower sample rate than the source voice sending to it. Sounds such as explosions and gunshots that don’t need high fidelity can also be recorded at lower sample rates.
降低个别声音的采样率。例如托管混响效果的子混音语音的采样率可能比发送给它的源语音的采样率低。不需要高保真度的声音,如爆炸和枪声也可以以较低的采样率。
Ensure that callback implementations do as little work as possible and never block.
确保回调实现尽可能少的工作,并且不会阻塞
Make fewer calls to XAudio2. Audio parameters usually don’t need to be updated for every video frame. Every 30 ms or so is sufficient. You should eliminate redundant calls, such as setting volume several times in quick succession.
尽量少调用XAudio2。音频参数通草不会在每一帧都需要更新。每30毫秒左右就足够了。您应该消除多余的调用,例如快速连续多次设置音量。
Reduce the game’s overall CPU usage.
减少游戏的整体CPU使用率。

采用方案:减少调用!

你可能感兴趣的:(c++)