Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions Custom-Audio-Driver/External-Audio-Device/OTDefaultAudioDevice.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<OTAudioBus>)audioBus;

- (OTAudioFormat*)captureFormat;
Expand Down
34 changes: 34 additions & 0 deletions Custom-Audio-Driver/External-Audio-Device/OTDefaultAudioDevice.m
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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
{
Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down
4 changes: 3 additions & 1 deletion Custom-Audio-Driver/External-Audio-Device/ViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 5 additions & 1 deletion Custom-Audio-Driver/README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Custom Audio Drvier
Custom Audio Driver
================================

This project implements a controller nearly identical to the hello world sample.
Expand All @@ -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
Expand Down