4

We have created a VOIP soft phone that connects the caller to a conference bridge. The conference bridge prompts, and callers on normal phones can be heard just fine, but the input from the softphone is barely audible.

We're using PJSip, AVAudioSession, Objective C and IOS 10.2

We tried setting the input gain with AVAudioSession, but the gain is not settable.

Does anyone have any ideas? Thank you

user3158212
  • 555
  • 6
  • 16
  • this issue is also happening with my app as well on iOS 9.3.5. i have posted a question http://stackoverflow.com/questions/42681265/ios-mic-captured-voice-change-volume-reprocess-on-the-fly maybe someone can hint us on the right direction on how to amplify captured data on the fly. – Hashmat Khalil Mar 09 '17 at 07:03
  • You may try this: http://stackoverflow.com/questions/10871231/how-to-control-hardware-mic-input-gain-level-on-iphone – alinoz May 09 '17 at 13:43

1 Answers1

1

You need mix of 3 iOS specific features here.

1. Audio Session Category

As per the documentation and the code, I am listing them below:

/*  Use this category for background sounds such as rain, car engine noise, etc.  
 Mixes with other music. */
public let AVAudioSessionCategoryAmbient: String

/*  Use this category for background sounds.  Other music will stop playing. */
public let AVAudioSessionCategorySoloAmbient: String

/* Use this category for music tracks.*/
public let AVAudioSessionCategoryPlayback: String

/*  Use this category when recording audio. */
public let AVAudioSessionCategoryRecord: String

/*  Use this category when recording and playing back audio. */
public let AVAudioSessionCategoryPlayAndRecord: String

/*  Use this category when using a hardware codec or signal processor while
 not playing or recording audio. */
@available(iOS, introduced: 3.0, deprecated: 10.0)
public let AVAudioSessionCategoryAudioProcessing: String

/*  Use this category to customize the usage of available audio accessories and built-in audio hardware.
 For example, this category provides an application with the ability to use an available USB output 
 and headphone output simultaneously for separate, distinct streams of audio data. Use of 
 this category by an application requires a more detailed knowledge of, and interaction with, 
 the capabilities of the available audio routes.  May be used for input, output, or both.
 Note that not all output types and output combinations are eligible for multi-route.  Input is limited
 to the last-in input port. Eligible inputs consist of the following:
    AVAudioSessionPortUSBAudio, AVAudioSessionPortHeadsetMic, and AVAudioSessionPortBuiltInMic.  
 Eligible outputs consist of the following: 
    AVAudioSessionPortUSBAudio, AVAudioSessionPortLineOut, AVAudioSessionPortHeadphones, AVAudioSessionPortHDMI, 
    and AVAudioSessionPortBuiltInSpeaker.  
 Note that AVAudioSessionPortBuiltInSpeaker is only allowed to be used when there are no other eligible 
 outputs connected.  */
@available(iOS 6.0, *)
public let AVAudioSessionCategoryMultiRoute: String

for your use case, I will pick up AVAudioSessionCategoryPlayAndRecord and set using

For swift:

AVAudioSession.sharedInstance().setCategory(AVAudioSessionCategoryPlayAndRecord)

For Obj-c

[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayAndRecord error:&err]

2. Audio Session modes

These modes help automatically set the appropriate gain, echo cancellation and other audio processing functions.

/* The default mode */
/*!
@abstract      Modes modify the audio category in order to introduce behavior that is tailored to the specific
use of audio within an application.  Available in iOS 5.0 and greater.
 */
@available(iOS 5.0, *)
public let AVAudioSessionModeDefault: String

/* Only valid with AVAudioSessionCategoryPlayAndRecord.  Appropriate for Voice over IP
(VoIP) applications.  Reduces the number of allowable audio routes to be only those
that are appropriate for VoIP applications and may engage appropriate system-supplied
signal processing.  Has the side effect of setting AVAudioSessionCategoryOptionAllowBluetooth */
@available(iOS 5.0, *)
public let AVAudioSessionModeVoiceChat: String

/* Set by Game Kit on behalf of an application that uses a GKVoiceChat object; valid
 only with the AVAudioSessionCategoryPlayAndRecord category.
 Do not set this mode directly. If you need similar behavior and are not using
 a GKVoiceChat object, use AVAudioSessionModeVoiceChat instead. */
@available(iOS 5.0, *)
public let AVAudioSessionModeGameChat: String

/* Only valid with AVAudioSessionCategoryPlayAndRecord or AVAudioSessionCategoryRecord.
 Modifies the audio routing options and may engage appropriate system-supplied signal processing. */
@available(iOS 5.0, *)
public let AVAudioSessionModeVideoRecording: String

/* Appropriate for applications that wish to minimize the effect of system-supplied signal
processing for input and/or output audio signals. */
@available(iOS 5.0, *)
public let AVAudioSessionModeMeasurement: String

/* Engages appropriate output signal processing for movie playback scenarios.  Currently
only applied during playback over built-in speaker. */
@available(iOS 6.0, *)
public let AVAudioSessionModeMoviePlayback: String

/* Only valid with kAudioSessionCategory_PlayAndRecord. Reduces the number of allowable audio
routes to be only those that are appropriate for video chat applications. May engage appropriate
system-supplied signal processing.  Has the side effect of setting
AVAudioSessionCategoryOptionAllowBluetooth and AVAudioSessionCategoryOptionDefaultToSpeaker. */
@available(iOS 7.0, *)
public let AVAudioSessionModeVideoChat: String

/* Appropriate for applications which play spoken audio and wish to be paused (via audio session interruption) rather than ducked
if another app (such as a navigation app) plays a spoken audio prompt.  Examples of apps that would use this are podcast players and
audio books.  For more information, see the related category option AVAudioSessionCategoryOptionInterruptSpokenAudioAndMixWithOthers. */
@available(iOS 9.0, *)
public let AVAudioSessionModeSpokenAudio: String

I will pick up AVAudioSessionModeVideoChat for your case and set using

Swift

AVAudioSession.sharedInstance().setMode(AVAudioSessionModeVideoChat)

Obj-c

[[AVAudioSession sharedInstance] setMode:AVAudioSessionModeVideoChat error:&err]

3. Audio Route

By default for most of the modes/categories, the audio is routed to earpiece/receiver. If you are looking at speaker mode, you have to set the same manually using

Swift

AVAudioSession.sharedInstance().overrideOutputAudioPort(AVAudioSessionPortOverride.speaker)

Obj-c

[[AVAudioSession sharedInstance] overrideOutputAudioPort:AVAudioSessionPortOverrideSpeaker error:nil];
manishg
  • 9,520
  • 1
  • 16
  • 19