22

I'm currently trying to get a clean as possible audio channel via webrtc. Via the getUserMedia mediaconstraints object, I've set the following options:

constraints: {
        audio: {
            mandatory: {
                echoCancellation: false,
                googEchoCancellation: false,
                googAutoGainControl: false,
                googAutoGainControl2: false,
                googNoiseSuppression: false,
                googHighpassFilter: false,
                googTypingNoiseDetection: false,
                //googAudioMirroring: false // For some reason setting googAudioMirroring causes a navigator.getUserMedia error:  NavigatorUserMediaError
            }
        },
        video: false
    },

This greatly improves the audio quality, but there still seems to be audio processing present which causes the mutilation of the audio in the form of high frequency noise with some of the test samples.

There is a Chrome flag --use-file-for-fake-audio-capture as described at http://peter.sh/experiments/chromium-command-line-switches/#use-file-for-fake-audio-capture which allows input via file for testing. As mentioned in the description of the flag, all audio processing has to be disabled or the audio will be distorted - so there seems to be additional options for this purpose.

I also tried the --disable-audio-track-processing --audio-buffer-size=16 --enable-exclusive-audio Chrome flags, but still there seems to be some audio processing.

Is there any way to disable the still present audio processing (preferably via JS API)?

wowpatrick
  • 5,082
  • 15
  • 55
  • 86
  • Does this happen locally or in a peer connection? It could that Chrome is changing the bitrate dynamically for Opus(this will only be the case if you are noticing this in a connection). – Benjamin Trent Apr 29 '15 at 13:37
  • Over a peer connection. I think it is some kind of voice audio optimization. Always kicks in with after x amount of time a sample has been playing. – wowpatrick Apr 29 '15 at 14:05
  • I read it so I can say for sure that the bitrate is adjusted according to available bandwith. – Robert Apr 29 '15 at 16:51
  • Did you find a solution? I am using PCMU as codec, passing these constraints does not remove processing or echo cancellation – istepaniuk May 24 '16 at 17:05
  • Beware of this open issue https://bugs.chromium.org/p/webrtc/issues/detail?id=5758 – istepaniuk May 25 '16 at 09:40
  • Make sure there are no **system** audio enhancements turned on. I am afraid we cannot control those from the browser level. Asked about it here: [how-to-disable-system-audio-enhancements-using-webrtc](https://stackoverflow.com/questions/44307432/how-to-disable-system-audio-enhancements-using-webrtc) – dankal444 Jul 24 '17 at 10:20
  • I think this link involves every answer related to `Audio_Processing` whether it is *Pre-Processing* or *Post-Processing*: [Android_Audio_Processing_Using_WebRTC](https://github.com/mail2chromium/Android-Audio-Processing-Using-WebRTC), You can also visit this reference: https://stackoverflow.com/a/58546599/10413749 – Muhammad Usman Bashir Apr 07 '20 at 08:42

2 Answers2

4

I'd wager that the variable bitrate (default) behavior of the opus codec is causing some compression or adjustment. You could manually mangle the SDP offer to use CBR (constant bitrate) instead of VBR (variable bit rate). When you get the SDP offer from the browser, change the line:

a=fmtp:111 minptime=10; useinbandfec=1

to:

a=fmtp:111 minptime=10; cbr=1

Note that I'm both adding cbr=1 and removing useinbandfec=1. I'm not positive that dropping useinbandfec is necessary, but it seems that in-band FEC (forwarding error correction) causes compression adjustment which you'd want to avoid as well.

xdumaine
  • 10,096
  • 6
  • 62
  • 103
4

This is the updated way to disable audio processing and get a clean signal:

navigator.mediaDevices.getUserMedia({
  audio: {
    autoGainControl: false,
    channelCount: 2,
    echoCancellation: false,
    latency: 0,
    noiseSuppression: false,
    sampleRate: 48000,
    sampleSize: 16,
    volume: 1.0
  }
});

If you are streaming audio via WebRTC, it defaults to radio or phone quality audio optimized for voice. So make sure your SDP has stereo and maxaveragebitrate params:

a=fmtp:111 minptime=10;useinbandfec=1; stereo=1; maxaveragebitrate=510000
Kim T
  • 5,770
  • 1
  • 52
  • 79