diff --git a/Audio/Chain/ConverterNode.mm b/Audio/Chain/ConverterNode.mm index e9b238a4b..3c7cffb83 100644 --- a/Audio/Chain/ConverterNode.mm +++ b/Audio/Chain/ConverterNode.mm @@ -451,9 +451,7 @@ static void convert_be_to_le(uint8_t *buffer, size_t bitsPerSample, size_t bytes usleep(500); } @autoreleasepool { - [self startWorkslice]; amountConverted = [self convert:writeBuf amount:CHUNK_SIZE]; - [self endWorkslice]; } if(!amountConverted) { if(paused) { diff --git a/Audio/Chain/InputNode.m b/Audio/Chain/InputNode.m index ae0d81bfb..90a0da2c1 100644 --- a/Audio/Chain/InputNode.m +++ b/Audio/Chain/InputNode.m @@ -189,9 +189,7 @@ static void *kInputNodeContext = &kInputNodeContext; int framesToRead = CHUNK_SIZE - amountInBuffer; int framesRead; @autoreleasepool { - [self startWorkslice]; framesRead = [decoder readAudio:((char *)inputBuffer) + bytesInBuffer frames:framesToRead]; - [self endWorkslice]; } if(framesRead > 0 && !seekError) { diff --git a/Audio/Chain/Node.h b/Audio/Chain/Node.h index 94811db0e..0e2feb2e2 100644 --- a/Audio/Chain/Node.h +++ b/Audio/Chain/Node.h @@ -29,15 +29,10 @@ BOOL shouldContinue; BOOL endOfStream; // All data is now in buffer BOOL initialBufferFilled; - BOOL isRealtime, isRealtimeError, isDeadlineError; // If was successfully set realtime, or if error AudioStreamBasicDescription nodeFormat; uint32_t nodeChannelConfig; BOOL nodeLossless; - - int64_t intervalMachLength; - os_workgroup_interval_t workgroup, wg; - os_workgroup_join_token_s wgToken; } - (id _Nullable)initWithController:(id _Nonnull)c previous:(id _Nullable)p; @@ -49,11 +44,6 @@ - (void)process; // Should be overwriten by subclass - (void)threadEntry:(id _Nullable)arg; -- (BOOL)followWorkgroup; -- (void)leaveWorkgroup; -- (void)startWorkslice; -- (void)endWorkslice; - - (void)launchThread; - (void)setShouldReset:(BOOL)s; diff --git a/Audio/Chain/Node.m b/Audio/Chain/Node.m index 9831c3eba..d9d9e64b3 100644 --- a/Audio/Chain/Node.m +++ b/Audio/Chain/Node.m @@ -131,19 +131,6 @@ BOOL SetPriorityRealtimeAudio(mach_port_t mach_thread_id) { nodeChannelConfig = 0; nodeLossless = NO; - if(@available(macOS 12, *)) { - // Get the mach time info. - struct mach_timebase_info timeBaseInfo; - mach_timebase_info(&timeBaseInfo); - - // The frequency of the clock is: (timeBaseInfo.denom / timeBaseInfo.numer) * kOneNanosecond - const double nanoSecFrequency = (double)(timeBaseInfo.denom) / (double)(timeBaseInfo.numer); - const double frequency = nanoSecFrequency * kOneNanosecond; - - // Convert the interval time in seconds to mach time length. - intervalMachLength = (int64_t)(kIOIntervalTime * frequency); - } - [self setPreviousNode:p]; } @@ -205,79 +192,7 @@ BOOL SetPriorityRealtimeAudio(mach_port_t mach_thread_id) { - (void)threadEntry:(id)arg { @autoreleasepool { - if([self followWorkgroup]) { - [self process]; - [self leaveWorkgroup]; - } - } -} - -- (BOOL)followWorkgroup { - if(@available(macOS 12, *)) { - if(!wg) { - if(!workgroup) { - workgroup = AudioWorkIntervalCreate([[NSString stringWithFormat:@"%@ Work Interval %@", [self className], self] UTF8String], clockId, &attr); - isRealtimeError = !SetPriorityRealtimeAudio(pthread_mach_thread_np(pthread_self())); - isRealtime = !isRealtimeError; - } - wg = workgroup; - if(wg && !isRealtimeError) { - int result = os_workgroup_join(wg, &wgToken); - isDeadlineError = NO; - if(result == 0) return YES; - if(result == EALREADY) { - DLog(@"Thread already in workgroup"); - return NO; - } else { - DLog(@"Cannot join workgroup, error %d", result); - isRealtimeError = YES; - return NO; - } - } - } - return wg != nil && !isRealtimeError; - } else { - if(!isRealtime && !isRealtimeError) { - isRealtimeError = SetPriorityRealtimeAudio(pthread_mach_thread_np(pthread_self())); - isRealtime = !isRealtimeError; - } - return YES; - } -} - -- (void)leaveWorkgroup { - if(@available(macOS 12, *)) { - if(wg && wgToken.sig && !isRealtimeError) { - os_workgroup_leave(wg, &wgToken); - bzero(&wgToken, sizeof(wgToken)); - wg = nil; - } - } -} - -- (void)startWorkslice { - if(@available(macOS 12, *)) { - if(wg && !isRealtimeError && !isDeadlineError) { - const uint64_t currentTime = mach_absolute_time(); - const uint64_t deadline = currentTime + intervalMachLength; - int result = os_workgroup_interval_start(wg, currentTime, deadline, nil); - if(result != 0) { - DLog(@"Deadline error = %d", result); - isDeadlineError = YES; - } - } - } -} - -- (void)endWorkslice { - if(@available(macOS 12, *)) { - if(wg && !isRealtimeError && !isDeadlineError) { - int result = os_workgroup_interval_finish(wg, nil); - if(result != 0) { - DLog(@"Deadline end error = %d", result); - isDeadlineError = YES; - } - } + [self process]; } }