使用SDL_OpenAudioDevice接口打开音频设备 (#2489)

修复SDL_OpenAudio()接口可能打开失败问题
This commit is contained in:
PioLing 2023-05-26 17:02:21 +08:00 committed by GitHub
parent 936babf459
commit 3f447246c2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -33,8 +33,8 @@ SDLAudioDevice::SDLAudioDevice() {
SDLAudioDevice *_this = (SDLAudioDevice *) userdata;
_this->onReqPCM((char *) stream, len);
};
if (SDL_OpenAudio(&wanted_spec, &_audio_config) < 0) {
throw std::runtime_error("SDL_OpenAudio failed");
if (SDL_OpenAudioDevice(NULL, 0, &wanted_spec, &_audio_config, SDL_AUDIO_ALLOW_ANY_CHANGE) < 0) {
throw std::runtime_error("SDL_OpenAudioDevice failed");
}
InfoL << "actual audioSpec, " << "freq:" << _audio_config.freq