Unable to work on the gain of the microphone in a native iOs app (using swift)

555 views
Skip to first unread message

Philippe Bourez

unread,
Mar 18, 2015, 4:41:02 PM3/18/15
to discuss...@googlegroups.com
Hello guys,

I'm actually working on an native iOs application using webrtc. The sound is live streamed to a Ruby on Rails server. It's all working great, but I get quite quickly a Larsen problem.

I would like to work on the "volume" / gain of the iPhone microphone, but I find nothing helpful on the internet. Does someone here already worked with the gain of the microphone?
I have taken inspiration of the PhoneRTC project (https://github.com/alongubkin/phonertc).

Here is where I create my stream, and add it to my peerConnection. 

     var peerConnection: RTCPeerConnection?
     
var pcObserver: RTCPeerConnectionObserver!
     
var queuedRemoteCandidates: [RTCICECandidate]?
     
var stream: RTCMediaStream?
     
var streams: StreamsConfig
     
var localAudioTrack: RTCAudioTrack?

     func createOrUpdateStream
() {
       
if self.stream != nil {
           
self.peerConnection!.removeStream(self.stream)
           
self.stream = nil
       
}
       
self.stream = peerConnectionFactory!.mediaStreamWithLabel("ARDAMS")

       
if self.streams.audio {
           
if self.localAudioTrack == nil {
               
self.initLocalAudioTrack()
           
}
           
self.stream!.addAudioTrack(self.localAudioTrack!)
       
}

       
self.peerConnection!.addStream(self.stream)
   
}

    func initLocalAudioTrack
() {
       
self.localAudioTrack = peerConnectionFactory!.audioTrackWithID("ARDAMSa0")
   
}



I don't know if it's possible in a way or another to get the RTCAudioTrack microphone input device, and then change it's gain? If it is possible, I sadly didn't find where.

Thanks for taking time reading my problem,

Philippe

Philippe Bourez

unread,
Mar 20, 2015, 10:54:24 AM3/20/15
to discuss...@googlegroups.com
I'm now trying to modify webRTC source got from "http://webrtc.googlecode.com/svn/trunk" thanks to this blog (http://ninjanetic.com/how-to-get-started-with-webrtc-and-ios-without-wasting-10-hours-of-your-life/)

Is there any way to work on the audio_device.mm class found in the source code of webRTC, in order to change the input sound?

Lars Bork

unread,
Nov 23, 2016, 6:56:25 PM11/23/16
to discuss-webrtc
Hey Philippe,

have you been able to find a solution for this problem? I am trying to do something similar right now and would love to hear you opinion!

Thanks a lot and have a nice day!

Michaël Albert

unread,
Nov 25, 2016, 10:26:39 AM11/25/16
to discuss-webrtc
Hi Lars,

I've done such a thing in modifying the file audio_device_ios.mm.

AudioDeviceIOS::RecordProcessImpl(AudioUnitRenderActionFlags *ioActionFlags,
                                      const AudioTimeStamp *inTimeStamp,
                                      uint32_t inBusNumber,
                                      uint32_t inNumberFrames) {
    // Setup some basic stuff
    // Use temp buffer not to lock up recording buffer more than necessary
    // todo: Make dataTmp a member variable with static size that holds
    //       max possible frames?
    int16_t* dataTmp = new int16_t[inNumberFrames];
    memset(dataTmp, 0, 2*inNumberFrames);

    AudioBufferList abList;
    abList.mNumberBuffers = 1;
    //abList.mBuffers[0].mData = dataTmp;
    // HERE - insert gain modificator
    abList.mBuffers[0].mData = dataTmp * 0.3;
    abList.mBuffers[0].mDataByteSize = 2*inNumberFrames;  // 2 bytes/sample
    abList.mBuffers[0].mNumberChannels = 1;

    // Get data from mic
    OSStatus res = AudioUnitRender(_auVoiceProcessing,
                                   ioActionFlags, inTimeStamp,
                                   inBusNumber, inNumberFrames, &abList);
    if (res != 0) {
        WEBRTC_TRACE(kTraceWarning, kTraceAudioDevice, _id,
                     "  Error getting rec data, error = %d", res);

        if (_recWarning > 0) {
            WEBRTC_TRACE(kTraceWarning, kTraceAudioDevice, _id,
                         "  Pending rec warning exists");
        }
        _recWarning = 1;

        delete [] dataTmp;
        return 0;
    }



As you can see you have just to multiply the value in the buffer. you can do a binary division but this code is working.

It is an older version of WebRTC, check with the latest version.

Let me know if it helped you.

Cheers,

Michael
Reply all
Reply to author
Forward
0 new messages