[Core Audio] Conditionally uninitialize equalizer

Only uninitialize the equalizer if sound output was successfully started
and the equalizer AudioUnit was successfully ininitialized.

Signed-off-by: Christopher Snowhill <kode54@gmail.com>
swiftingly
Christopher Snowhill 2022-06-10 18:43:56 -07:00
parent d390febe72
commit 10f0644407
2 changed files with 7 additions and 1 deletions

View File

@ -51,6 +51,7 @@ using std::atomic_long;
BOOL restarted; BOOL restarted;
BOOL eqEnabled; BOOL eqEnabled;
BOOL eqInitialized;
BOOL streamFormatStarted; BOOL streamFormatStarted;

View File

@ -764,6 +764,8 @@ default_device_changed(AudioObjectID inObjectID, UInt32 inNumberAddresses, const
if(_err) if(_err)
return NO; return NO;
eqInitialized = YES;
[self setEqualizerEnabled:[[[[NSUserDefaultsController sharedUserDefaultsController] defaults] objectForKey:@"GraphicEQenable"] boolValue]]; [self setEqualizerEnabled:[[[[NSUserDefaultsController sharedUserDefaultsController] defaults] objectForKey:@"GraphicEQenable"] boolValue]];
[outputController beginEqualizer:_eq]; [outputController beginEqualizer:_eq];
@ -851,7 +853,10 @@ default_device_changed(AudioObjectID inObjectID, UInt32 inNumberAddresses, const
} }
if(_eq) { if(_eq) {
[outputController endEqualizer:_eq]; [outputController endEqualizer:_eq];
AudioUnitUninitialize(_eq); if(eqInitialized) {
AudioUnitUninitialize(_eq);
eqInitialized = NO;
}
AudioComponentInstanceDispose(_eq); AudioComponentInstanceDispose(_eq);
_eq = NULL; _eq = NULL;
} }