From 7d803a0211d0cc8098ae92ba34d3b3a17b41214f Mon Sep 17 00:00:00 2001 From: Christopher Snowhill Date: Tue, 11 Feb 2025 15:06:59 -0800 Subject: [PATCH] DSP: Add thread priority control DSP threads, such as the Rubber Band processing, and planned moves of other processing to buffer threads, such as the Equalizer, FreeSurround, HRTF, and Downmixing for output, because they all have small output buffers. Since these buffers drain and fill fast, they should be processed at a high priority. Hopefully, App Store doesn't complain about the use of these APIs. Signed-off-by: Christopher Snowhill --- Audio/Chain/DSPNode.h | 2 ++ Audio/Chain/DSPNode.m | 10 ++++++++++ 2 files changed, 12 insertions(+) diff --git a/Audio/Chain/DSPNode.h b/Audio/Chain/DSPNode.h index 50ac1475f..29c37db85 100644 --- a/Audio/Chain/DSPNode.h +++ b/Audio/Chain/DSPNode.h @@ -15,6 +15,8 @@ - (id _Nullable)initWithController:(id _Nonnull)c previous:(id _Nullable)p latency:(double)latency; +- (void)threadEntry:(id _Nullable)arg; + @end #endif /* DSPNode_h */ diff --git a/Audio/Chain/DSPNode.m b/Audio/Chain/DSPNode.m index 59d78313c..4eb8b239d 100644 --- a/Audio/Chain/DSPNode.m +++ b/Audio/Chain/DSPNode.m @@ -37,4 +37,14 @@ return self; } +// DSP threads buffer for low latency, and therefore should have high priority +- (void)threadEntry:(id _Nullable)arg { + @autoreleasepool { + NSThread *currentThread = [NSThread currentThread]; + [currentThread setThreadPriority:0.75]; + [currentThread setQualityOfService:NSQualityOfServiceUserInitiated]; + [self process]; + } +} + @end