我正在使用SDL 音频播放声音。
SDL_LockAudio告诉这个:
不要从回调函数中调用它,否则会导致死锁。
但是,SDL_PauseAudio并没有这么说,而是告诉:
该函数暂停和取消暂停音频回调处理
我的混音器回调如下所示:
void AudioPlaybackCallback( void *, core::bty::UInt8 *stream, int len )
{
// number of bytes left to play in the current sample
const int thisSampleLeft = currentSample.dataLength - currentSample.dataPos;
// number of bytes that will be sent to the audio stream
const int amountToPlay = std::min( thisSampleLeft, len );
if ( amountToPlay > 0 )
{
SDL_MixAudio( stream,
currentSample.data + currentSample.dataPos,
amountToPlay,
currentSample.volume );
// update the current sample
currentSample.dataPos += amountToPlay;
}
else
{
if ( PlayingQueue::QueueHasElements() )
{
// update the current sample
currentSample = PlayingQueue::QueuePop();
}
else
{
// since the current sample finished, and there are no more samples to
// play, pause the playback
SDL_PauseAudio( 1 );
}
}
}
PlayingQueue
是一个提供对静态std::queue
对象的访问的类。没有什么花哨。
这很好,直到我们决定更新 SDL 和 alsa 库(现在没有回头路了)。从那以后,我在日志中看到了这一点:
ALSA lib pcm.c:7316:(snd_pcm_recover) 发生欠载
如果我假设 SDL 或 alsa 库中没有错误(这很可能是错误的,在谷歌搜索此消息后),我想应该可以更改我的代码来修复,或者至少避免欠载。
所以,问题是:我可以暂停自己的回调吗?它会导致我看到的欠载吗?