Open Bug 2090426 Opened 16 days ago Updated 7 days ago

Opening a mic input stream with echoCancellation:true makes WebAudio output sound terrible on macOS

Categories

(Core :: Audio/Video: cubeb, defect, P2)

All
macOS
defect

Tracking

()

People

(Reporter: mstange, Unassigned, NeedInfo)

References

Details

Attachments

(1 file)

Attached file testcase —

In the attached testcase, audio becomes mono and tinny once you click the button to enable mic input with echoCancellation:true.

Profile with logs: https://share.firefox.dev/4j32tII

It sounds fine in Chrome and Safari.


I noticed this in a singing practice app I am building.

Thanks for the testcase and the profile with logs.

Analysis

The profile shows why the output becomes mono. With echoCancellation: true, the graph opens one duplex cubeb stream with the VOICE preference ("using VOICE and requesting input processing params AEC"). cubeb then plays the page output through the macOS VoiceProcessingIO (VPIO) unit. Before the mic opens, the output is a normal stereo stream at 48000 Hz.

On the VPIO output, cubeb reads a format of 1 channel at 44100 Hz. VPIO rejects the stereo layout (kAudioUnitProperty_AudioChannelLayout rv=-10851), and get_output_channel_layout returns MONO for VPIO. A mixer then downmixes 2 channels to 1, and the output is resampled to 44100 Hz. The downmix explains why the chord stops moving and plays in the middle. The mono 44100 Hz VPIO path is the probable cause of the thin sound, but no test proves it yet.

In this testcase, the VPIO unit also does no processing. cubeb rejects AEC without NS ("couldn't set input processing params ECHO_CANCELLATION. AEC != NS."). Gecko then uses the libwebrtc AEC and sets the platform params to NONE, so cubeb puts VPIO in bypass. IsVoiceInput stays true because the software AEC is on, so the stream stays on the mono VPIO unit. With echoCancellation: false, the profile shows an aggregate device with stereo output at 48000 Hz.

Affected code

  • GraphDriver.cpp selects CUBEB_DEVICE_PREF_VOICE when IsVoiceInput in MediaEngineWebRTCAudio.h is true.
  • mod.rs selects VPIO for input and output when the input has VOICE.
  • The same file tries the stereo layout on the VPIO output (mod.rs) and hard-codes MONO in get_output_channel_layout (mod.rs).

Fix direction

  • In cubeb-coreaudio, try a 2-channel stream format on the VPIO output bus, and use mono only when VPIO rejects it. Nobody has tested yet whether VPIO on macOS 14 and 15 accepts it.
  • When the platform processing params are NONE, VPIO gives no benefit for the output. Note that the non-VPIO duplex path has its own open problems (bug 2090431, bug 2073800).

No regressor is known. Bug 1869526 limited VPIO to VOICE input streams, and its description already says that VPIO makes the output mono.

The code at fault is in cubeb, so this bug moves to Audio/Video: cubeb. Matthew, could you please look at the VPIO output format in cubeb-coreaudio?


If you'd like to provide feedback on this comment, please use the 👍 or 👎 reaction.

Severity: -- → S3
Component: Audio/Video: Playback → Audio/Video: cubeb
Flags: needinfo?(kinetik)
Priority: -- → P2
See Also: → 1869526, 2090431, 2073800

If you do echoCancellation: true, noiseSuppression: true, autoGainControl: true does it improve? That should make us match Safari with echoCancellation: true, noiseSuppression: false, autoGainControl: false I think.

Flags: needinfo?(mstange.moz)

I can reproduce a closely related issue on macOS 27 (Apple Silicon) with Soundcore AeroClip 2 Bluetooth earbuds in Google Meet, using both Firefox and Zen Browser.

Symptoms and observations:

  • Severe intermittent crackling, stuttering and distorted audio, including the built-in Google Meet "Test speakers" function.
  • The issue persists when using the MacBook Pro's built-in microphone with AeroClip 2 selected only as the audio output.
  • Switching output to the MacBook's built-in speakers resolves the issue, even when the AeroClip 2 microphone remains selected.
  • Sony WH-1000XM6 Bluetooth headphones work correctly in the same Firefox/Meet setup.
  • AeroClip 2 work correctly with YouTube in Firefox, as well as audio in Safari and Zoom.
  • Keeping Firefox in the foreground and opening about:support do not change the behavior.

Confirmed workaround:

Setting media.getusermedia.audio.processing.platform.enabled to false in about:config and fully restarting Firefox completely resolves the audio distortion.

This strongly suggests an interaction between Firefox's platform audio processing (potentially VPIO) and the AeroClip 2 Bluetooth output path.

I haven't verified the actual audio format negotiation, so I cannot confirm that the underlying cause is identical to the one described in this bug.

You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: