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