From f81b57318a3c6a102519c68813643bb1ecf04c79 Mon Sep 17 00:00:00 2001 From: Jaideep Date: Thu, 30 May 2024 12:58:11 -0700 Subject: [PATCH 1/3] AGC and (AEC,NS) support at Audio Unit level --- .../OTDefaultAudioDevice.h | 10 ++++++ .../OTDefaultAudioDevice.m | 34 +++++++++++++++++++ .../OTDefaultAudioDeviceWithVolumeControl.h | 6 ++++ .../OTDefaultAudioDeviceWithVolumeControl.m | 9 +++++ .../External-Audio-Device/ViewController.m | 4 ++- 5 files changed, 62 insertions(+), 1 deletion(-) diff --git a/Custom-Audio-Driver/External-Audio-Device/OTDefaultAudioDevice.h b/Custom-Audio-Driver/External-Audio-Device/OTDefaultAudioDevice.h index ba90f0e7..ca0c9663 100644 --- a/Custom-Audio-Driver/External-Audio-Device/OTDefaultAudioDevice.h +++ b/Custom-Audio-Driver/External-Audio-Device/OTDefaultAudioDevice.h @@ -30,6 +30,16 @@ */ @property (nonatomic, readonly) BOOL bluetoothDeviceAvailable; +/** + AEC and NS are disabled together. No separate disabling is allowed by Apple AU API's. .Default is FALSE. + */ +@property (nonatomic) BOOL disableAudioProcessing; + +/** + Enable Automatic Gain Control. Default is TRUE. + */ +@property (nonatomic) BOOL enableAGC; + - (BOOL)setAudioBus:(id)audioBus; - (OTAudioFormat*)captureFormat; diff --git a/Custom-Audio-Driver/External-Audio-Device/OTDefaultAudioDevice.m b/Custom-Audio-Driver/External-Audio-Device/OTDefaultAudioDevice.m index 56c1c2d9..d45e44ff 100644 --- a/Custom-Audio-Driver/External-Audio-Device/OTDefaultAudioDevice.m +++ b/Custom-Audio-Driver/External-Audio-Device/OTDefaultAudioDevice.m @@ -121,6 +121,8 @@ - (instancetype)init _safetyQueue = dispatch_queue_create("ot-audio-driver", DISPATCH_QUEUE_SERIAL); _restartRetryCount = 0; + self.disableAudioProcessing = FALSE; + self.enableAGC = TRUE; } return self; } @@ -1086,6 +1088,22 @@ - (BOOL)setupAudioUnit:(AudioUnit *)voice_unit playout:(BOOL)isPlayout; AudioUnitSetProperty(*voice_unit, kAudioOutputUnitProperty_EnableIO, kAudioUnitScope_Output, kOutputBus, &enable_output, sizeof(enable_output)); + UInt32 bypassVoiceProcessing = self.disableAudioProcessing; + CheckError(AudioUnitSetProperty(*voice_unit, + kAUVoiceIOProperty_BypassVoiceProcessing, + kAudioUnitScope_Global, + kInputBus, + &bypassVoiceProcessing, + sizeof(bypassVoiceProcessing)), + @"kAUVoiceIOProperty_BypassVoiceProcessing failed"); + UInt32 enableAGC = self.enableAGC; + CheckError(AudioUnitSetProperty(*voice_unit, + kAUVoiceIOProperty_VoiceProcessingEnableAGC, + kAudioUnitScope_Global, + kInputBus, + &enableAGC, + sizeof(enableAGC)), + @"kAUVoiceIOProperty_VoiceProcessingEnableAGC failed"); } else { @@ -1102,6 +1120,22 @@ - (BOOL)setupAudioUnit:(AudioUnit *)voice_unit playout:(BOOL)isPlayout; kAudioUnitScope_Input, kInputBus, &enable_input, sizeof(enable_input)); [self setPlayOutRenderCallback:*voice_unit]; + UInt32 bypassVoiceProcessing = self.disableAudioProcessing; + CheckError(AudioUnitSetProperty(*voice_unit, + kAUVoiceIOProperty_BypassVoiceProcessing, + kAudioUnitScope_Global, + kInputBus, + &bypassVoiceProcessing, + sizeof(bypassVoiceProcessing)), + @"kAUVoiceIOProperty_BypassVoiceProcessing failed"); + UInt32 enableAGC = self.enableAGC; + CheckError(AudioUnitSetProperty(*voice_unit, + kAUVoiceIOProperty_VoiceProcessingEnableAGC, + kAudioUnitScope_Global, + kInputBus, + &enableAGC, + sizeof(enableAGC)), + @"kAUVoiceIOProperty_VoiceProcessingEnableAGC failed"); } Float64 f64 = 0; diff --git a/Custom-Audio-Driver/External-Audio-Device/OTDefaultAudioDeviceWithVolumeControl.h b/Custom-Audio-Driver/External-Audio-Device/OTDefaultAudioDeviceWithVolumeControl.h index b639db70..0369915b 100644 --- a/Custom-Audio-Driver/External-Audio-Device/OTDefaultAudioDeviceWithVolumeControl.h +++ b/Custom-Audio-Driver/External-Audio-Device/OTDefaultAudioDeviceWithVolumeControl.h @@ -12,4 +12,10 @@ // value range - 0 (min) and 1 (max) -(void)setPlayoutVolume:(float)value; + +/** + * Initializes an audio device with options to enable AGC and bypassing other default audio processing. + */ +- (instancetype)initWithAGC:(BOOL)agc disableAudioProcessing:(BOOL) disbaleAudioProcessing; + @end diff --git a/Custom-Audio-Driver/External-Audio-Device/OTDefaultAudioDeviceWithVolumeControl.m b/Custom-Audio-Driver/External-Audio-Device/OTDefaultAudioDeviceWithVolumeControl.m index 45a1bf75..02631421 100644 --- a/Custom-Audio-Driver/External-Audio-Device/OTDefaultAudioDeviceWithVolumeControl.m +++ b/Custom-Audio-Driver/External-Audio-Device/OTDefaultAudioDeviceWithVolumeControl.m @@ -23,6 +23,15 @@ @implementation OTDefaultAudioDeviceWithVolumeControl AudioUnit mixerUnit; } +- (instancetype)initWithAGC:(BOOL)agc disableAudioProcessing:(BOOL) disbaleAudioProcessing { + self = [super init]; + if (self) { + self.enableAGC = agc; + self.disableAudioProcessing = disbaleAudioProcessing; + } + return self; + +} - (BOOL)setupAudioUnit:(AudioUnit *)voice_unit playout:(BOOL)isPlayout { BOOL result = [super setupAudioUnit:voice_unit playout:isPlayout]; diff --git a/Custom-Audio-Driver/External-Audio-Device/ViewController.m b/Custom-Audio-Driver/External-Audio-Device/ViewController.m index 54744ca4..30fbab5d 100644 --- a/Custom-Audio-Driver/External-Audio-Device/ViewController.m +++ b/Custom-Audio-Driver/External-Audio-Device/ViewController.m @@ -34,8 +34,10 @@ - (void)viewDidLoad { [super viewDidLoad]; +// OTDefaultAudioDeviceWithVolumeControl* audioDevice = +// [OTDefaultAudioDeviceWithVolumeControl new]; OTDefaultAudioDeviceWithVolumeControl* audioDevice = - [OTDefaultAudioDeviceWithVolumeControl new]; + [[OTDefaultAudioDeviceWithVolumeControl alloc] initWithAGC:YES disableAudioProcessing:NO]; [OTAudioDeviceManager setAudioDevice:audioDevice]; // Step 1: As the view comes into the foreground, initialize a new instance From 784c183dabc534e9daef34bc9118fb563b010380 Mon Sep 17 00:00:00 2001 From: Jaideep Date: Fri, 31 May 2024 13:50:17 -0700 Subject: [PATCH 2/3] new init doc in Readme --- Custom-Audio-Driver/README.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Custom-Audio-Driver/README.md b/Custom-Audio-Driver/README.md index 19989b18..41e93984 100644 --- a/Custom-Audio-Driver/README.md +++ b/Custom-Audio-Driver/README.md @@ -10,6 +10,10 @@ instance of OTSession or OTPublisher is initialized: _myAudioDevice = [[OTDefaultAudioDevice alloc] init]; [OTAudioDeviceManager setAudioDevice:_myAudioDevice]; ``` +If you want to test or use audio processing controls like automatic gain control or bypassing audio processing then initialize the audio device with the initializer: +``` +- (instancetype)initWithAGC:(BOOL)agcEnabled disableAudioProcessing:(BOOL)audioProcessingDisabled; +``` `OTDefaultAudioDevice` is a copy of the default device driver used in the OpenTok iOS SDK. If no audio device is set prior to the first instantiation From c3a074add5585e7bddbaa55341d90ba09a89a96e Mon Sep 17 00:00:00 2001 From: Jaideep Date: Fri, 31 May 2024 13:51:22 -0700 Subject: [PATCH 3/3] typo --- Custom-Audio-Driver/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Custom-Audio-Driver/README.md b/Custom-Audio-Driver/README.md index 41e93984..07cf78ed 100644 --- a/Custom-Audio-Driver/README.md +++ b/Custom-Audio-Driver/README.md @@ -1,4 +1,4 @@ -Custom Audio Drvier +Custom Audio Driver ================================ This project implements a controller nearly identical to the hello world sample.