From 39d3f7edfe9337fc9d5c060909866ff0e91ba5ed Mon Sep 17 00:00:00 2001 From: Christopher Snowhill Date: Sat, 9 Jul 2022 18:42:03 -0700 Subject: [PATCH] [HRTF] Force filtering of odd channel formats Apparently, Apple's Spatial Audio processor doesn't really support weird configurations like this. So we need to filter them down to stereo. Signed-off-by: Christopher Snowhill --- Audio/Output/OutputAVFoundation.m | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Audio/Output/OutputAVFoundation.m b/Audio/Output/OutputAVFoundation.m index 030699d66..1d9f6f97d 100644 --- a/Audio/Output/OutputAVFoundation.m +++ b/Audio/Output/OutputAVFoundation.m @@ -600,7 +600,8 @@ current_device_listener(AudioObjectID inObjectID, UInt32 inNumberAddresses, cons - (void)updateStreamFormat { /* Set the channel layout for the audio queue */ - if(enableHrtf) { + /* Apple's audio processor really only supports common 1-8 channel formats */ + if(enableHrtf || realStreamFormat.mChannelsPerFrame > 8 || ((realStreamChannelConfig & ~(AudioConfig6Point1|AudioConfig7Point1)) != 0)) { NSURL *presetUrl = [[NSBundle mainBundle] URLForResource:@"SADIE_D02-96000" withExtension:@"mhr"]; hrtf = [[HeadphoneFilter alloc] initWithImpulseFile:presetUrl forSampleRate:realStreamFormat.mSampleRate withInputChannels:realStreamFormat.mChannelsPerFrame withConfig:realStreamChannelConfig]; @@ -769,7 +770,7 @@ current_device_listener(AudioObjectID inObjectID, UInt32 inNumberAddresses, cons } if(samplesRendered) { - if(enableHrtf && hrtf) { + if(hrtf) { [hrtf process:samplePtr sampleCount:samplesRendered toBuffer:&hrtfBuffer[0]]; samplePtr = &hrtfBuffer[0]; }