Permalink
Browse files

MKAudio, MKAudioInput: only enable echo cancellation for built-in mic.

  • Loading branch information...
1 parent a949200 commit 1c356d811300bf9a4afca95bca0e45fd22f6faed @mkrautz mkrautz committed Mar 31, 2012
Showing with 35 additions and 2 deletions.
  1. +22 −0 src/MKAudio.m
  2. +7 −2 src/MKAudioInput.m
  3. +6 −0 src/MumbleKit/MKAudio.h
View
@@ -289,4 +289,26 @@ - (void) setMuted:(BOOL)muted {
[_audioInput setMuted:muted];
}
+- (BOOL) echoCancellationAvailable {
+ NSDictionary *dict = nil;
+ UInt32 valSize = sizeof(NSDictionary *);
+ OSStatus err = AudioSessionGetProperty(kAudioSessionProperty_AudioRouteDescription, &valSize, &dict);
+ if (err != kAudioSessionNoError) {
+ return NO;
+ }
+
+ NSArray *inputs = [dict objectForKey:(id)kAudioSession_AudioRouteKey_Inputs];
+ if ([inputs count] == 0) {
+ return NO;
+ }
+
+ NSDictionary *input = [inputs objectAtIndex:0];
+ NSString *inputKind = [input objectForKey:(id)kAudioSession_AudioRouteKey_Type];
+
+ if ([inputKind isEqualToString:(NSString *)kAudioSessionInputRoute_BuiltInMic])
+ return YES;
+
+ return NO;
+}
+
@end
View
@@ -377,8 +377,13 @@ - (BOOL) setupiOSDevice {
AudioComponentDescription desc;
AudioStreamBasicDescription fmt;
+ BOOL shouldCancelEcho = NO;
+ if ([[MKAudio sharedAudio] echoCancellationAvailable]) {
+ shouldCancelEcho = _settings.enableEchoCancellation;
+ }
+
desc.componentType = kAudioUnitType_Output;
- if (_settings.enableEchoCancellation)
+ if (shouldCancelEcho)
desc.componentSubType = kAudioUnitSubType_VoiceProcessingIO;
else
desc.componentSubType = kAudioUnitSubType_RemoteIO;
@@ -455,7 +460,7 @@ - (BOOL) setupiOSDevice {
return NO;
}
- if (_settings.enableEchoCancellation) {
+ if (shouldCancelEcho) {
val = 0;
len = sizeof(UInt32);
err = AudioUnitSetProperty(audioUnit, kAUVoiceIOProperty_BypassVoiceProcessing, kAudioUnitScope_Global, 0, &val, len);
View
@@ -125,6 +125,12 @@ typedef struct _MKAudioSettings {
*/
- (void) setForceTransmit:(BOOL)enableForceTransmit;
+/**
+ * Returns whether or not the system's current audio route is
+ * suitable for echo cancellation.
+ */
+- (BOOL) echoCancellationAvailable;
+
- (float) speechProbablity;
- (float) peakCleanMic;

0 comments on commit 1c356d8

Please sign in to comment.