Initialize the new audio unit before disposing the old one

This commit is contained in:
Chris Robinson 2021-03-09 02:55:01 -08:00
parent 1d57db6836
commit e6c7cdc1ba

View File

@ -123,6 +123,12 @@ void CoreAudioPlayback::open(const char *name)
if(err != noErr)
throw al::backend_exception{al::backend_error::NoDevice,
"Could not create component instance: %u", err};
err = AudioUnitInitialize(audioUnit);
if(err != noErr)
throw al::backend_exception{al::backend_error::DeviceError,
"Could not initialize audio unit: %u", err};
/* WARNING: I don't know if "valid" audio unit values are guaranteed to be
* non-0. If not, this logic is broken.
*/
@ -133,12 +139,6 @@ void CoreAudioPlayback::open(const char *name)
}
mAudioUnit = audioUnit;
/* init and start the default audio unit... */
err = AudioUnitInitialize(mAudioUnit);
if(err != noErr)
throw al::backend_exception{al::backend_error::DeviceError,
"Could not initialize audio unit: %u", err};
mDevice->DeviceName = name;
}