Use this function to pause audio playback on a specified device.
int SDL_PauseAudioDevice(SDL_AudioDeviceID dev);
dev | a device opened by SDL_OpenAudioDevice() |
Returns 0 on success or a negative error code on failure; call SDL_GetError() for more information.
This function pauses the audio callback processing for a given device. Silence will be written to the audio device while paused, and the audio callback is guaranteed to not be called. Pausing one device does not prevent other unpaused devices from running their callbacks.
If you just need to protect a few variables from race conditions vs your callback, you shouldn't pause the audio device, as it will lead to dropouts in the audio playback. Instead, you should use SDL_LockAudioDevice().
This function is available since SDL 3.0.0.
extern SDL_AudioDeviceID devid;
1); // audio callback is stopped when this returns.
SDL_PauseAudioDevice(devid, 5000); // audio device plays silence for 5 seconds
SDL_Delay(0); // audio callback starts running again. SDL_PauseAudioDevice(devid,