[Audio Output] Make toggling DSPs safe

The DSPs should not be deinitialized from another thread, possibly while
they are currently processing.

Signed-off-by: Christopher Snowhill <kode54@gmail.com>
main
Christopher Snowhill 2022-07-14 03:16:21 -07:00
parent dd58a540a8
commit d417d245f4
2 changed files with 12 additions and 5 deletions

View File

@ -113,6 +113,8 @@ using std::atomic_long;
BOOL enableFSurround; BOOL enableFSurround;
FSurroundFilter *fsurround; FSurroundFilter *fsurround;
BOOL resetStreamFormat;
float *samplePtr; float *samplePtr;
float tempBuffer[512 * 32]; float tempBuffer[512 * 32];
float inputBuffer[4096 * 32]; // 4096 samples times maximum supported channel count float inputBuffer[4096 * 32]; // 4096 samples times maximum supported channel count

View File

@ -304,12 +304,10 @@ current_device_listener(AudioObjectID inObjectID, UInt32 inNumberAddresses, cons
eqPreamp = pow(10.0, preamp / 20.0); eqPreamp = pow(10.0, preamp / 20.0);
} else if([keyPath isEqualToString:@"values.enableHrtf"]) { } else if([keyPath isEqualToString:@"values.enableHrtf"]) {
enableHrtf = [[[NSUserDefaultsController sharedUserDefaultsController] defaults] boolForKey:@"enableHrtf"]; enableHrtf = [[[NSUserDefaultsController sharedUserDefaultsController] defaults] boolForKey:@"enableHrtf"];
if(streamFormatStarted) resetStreamFormat = YES;
[self updateStreamFormat];
} else if([keyPath isEqualToString:@"values.enableFSurround"]) { } else if([keyPath isEqualToString:@"values.enableFSurround"]) {
enableFSurround = [[[NSUserDefaultsController sharedUserDefaultsController] defaults] boolForKey:@"enableFSurround"]; enableFSurround = [[[NSUserDefaultsController sharedUserDefaultsController] defaults] boolForKey:@"enableFSurround"];
if(streamFormatStarted) resetStreamFormat = YES;
[self updateStreamFormat];
} }
} }
@ -606,6 +604,7 @@ current_device_listener(AudioObjectID inObjectID, UInt32 inNumberAddresses, cons
- (void)updateStreamFormat { - (void)updateStreamFormat {
/* Set the channel layout for the audio queue */ /* Set the channel layout for the audio queue */
streamFormatChanged = YES; streamFormatChanged = YES;
resetStreamFormat = NO;
uint32_t channels = realStreamFormat.mChannelsPerFrame; uint32_t channels = realStreamFormat.mChannelsPerFrame;
uint32_t channelConfig = realStreamChannelConfig; uint32_t channelConfig = realStreamChannelConfig;
@ -746,6 +745,10 @@ current_device_listener(AudioObjectID inObjectID, UInt32 inNumberAddresses, cons
status = CMBlockBufferCreateEmpty(kCFAllocatorDefault, 0, 0, &blockListBuffer); status = CMBlockBufferCreateEmpty(kCFAllocatorDefault, 0, 0, &blockListBuffer);
if(status != noErr || !blockListBuffer) return 0; if(status != noErr || !blockListBuffer) return 0;
if(resetStreamFormat) {
[self updateStreamFormat];
}
int inputRendered = 0; int inputRendered = 0;
int bytesRendered = 0; int bytesRendered = 0;
do { do {
@ -898,7 +901,9 @@ current_device_listener(AudioObjectID inObjectID, UInt32 inNumberAddresses, cons
commandStop = NO; commandStop = NO;
audioFormatDescription = NULL; audioFormatDescription = NULL;
resetStreamFormat = NO;
running = NO; running = NO;
stopping = NO; stopping = NO;
stopped = NO; stopped = NO;