函数说明
用此函数来暂停播放音频,或播放音频。根据参数来决定, 0是播放音频 ,非0是暂停播放音频切记,并不是停止播放音频!
函数声明
/**
* \name Pause audio functions
*
* These functions pause and unpause the audio callback processing.
* They should be called with a parameter of 0 after opening the audio
* device to start playing sound. This is so you can safely initialize
* data for your callback function after opening the audio device.
* Silence will be written to the audio device during the pause.
*/
/* @{ */
extern DECLSPEC void SDLCALL SDL_PauseAudio(int pause_on);
extern DECLSPEC void SDLCALL SDL_PauseAudioDevice(SDL_AudioDeviceID dev,
int pause_on);
/* @} *//* Pause audio functions */
函数具体实现
void
SDL_PauseAudioDevice(SDL_AudioDeviceID devid, int pause_on)
{
SDL_AudioDevice *device = get_audio_device(devid);
if (device) {
current_audio.impl.LockDevice(device);
SDL_AtomicSet(&device->paused, pause_on ? 1 : 0);
current_audio.impl.UnlockDevice(device);
}
}
void
SDL_PauseAudio(int pause_on)
{
SDL_PauseAudioDevice(1, pause_on);
}
代码剖析
关键是设置设备的paused状态,因此,该函数只是做了一个标志位的设置,SDL底层的线程会判断该标志,通过回调函数取音频数据进行播放
标签:pause,音频,播放,剖析,device,SDL,audio,PauseAudio From: https://blog.51cto.com/fengyuzaitu/6159298