xref: /aosp_15_r20/external/webrtc/modules/audio_mixer/g3doc/index.md (revision d9f758449e529ab9291ac668be2861e7a55c2422)
1<?% config.freshness.owner = 'alessiob' %?>
2<?% config.freshness.reviewed = '2021-04-21' %?>
3
4# The WebRTC Audio Mixer Module
5
6The WebRTC audio mixer module is responsible for mixing multiple incoming audio
7streams (sources) into a single audio stream (mix). It works with 10 ms frames,
8it supports sample rates up to 48 kHz and up to 8 audio channels. The API is
9defined in
10[`api/audio/audio_mixer.h`](https://source.chromium.org/chromium/chromium/src/+/main:third_party/webrtc/api/audio/audio_mixer.h)
11and it includes the definition of
12[`AudioMixer::Source`](https://source.chromium.org/search?q=symbol:AudioMixer::Source%20file:third_party%2Fwebrtc%2Fapi%2Faudio%2Faudio_mixer.h),
13which describes an incoming audio stream, and the definition of
14[`AudioMixer`](https://source.chromium.org/search?q=symbol:AudioMixer%20file:third_party%2Fwebrtc%2Fapi%2Faudio%2Faudio_mixer.h),
15which operates on a collection of
16[`AudioMixer::Source`](https://source.chromium.org/search?q=symbol:AudioMixer::Source%20file:third_party%2Fwebrtc%2Fapi%2Faudio%2Faudio_mixer.h)
17objects to produce a mix.
18
19## AudioMixer::Source
20
21A source has different characteristic (e.g., sample rate, number of channels,
22muted state) and it is identified by an SSRC[^1].
23[`AudioMixer::Source::GetAudioFrameWithInfo()`](https://source.chromium.org/search?q=symbol:AudioMixer::Source::GetAudioFrameWithInfo%20file:third_party%2Fwebrtc%2Fapi%2Faudio%2Faudio_mixer.h)
24is used to retrieve the next 10 ms chunk of audio to be mixed.
25
26[^1]: A synchronization source (SSRC) is the source of a stream of RTP packets,
27    identified by a 32-bit numeric SSRC identifier carried in the RTP header
28    so as not to be dependent upon the network address (see
29    [RFC 3550](https://tools.ietf.org/html/rfc3550#section-3)).
30
31## AudioMixer
32
33The interface allows to add and remove sources and the
34[`AudioMixer::Mix()`](https://source.chromium.org/search?q=symbol:AudioMixer::Mix%20file:third_party%2Fwebrtc%2Fapi%2Faudio%2Faudio_mixer.h)
35method allows to generates a mix with the desired number of channels.
36
37## WebRTC implementation
38
39The interface is implemented in different parts of WebRTC:
40
41*   [`AudioMixer::Source`](https://source.chromium.org/search?q=symbol:AudioMixer::Source%20file:third_party%2Fwebrtc%2Fapi%2Faudio%2Faudio_mixer.h):
42    [`audio/audio_receive_stream.h`](https://source.chromium.org/chromium/chromium/src/+/main:third_party/webrtc/audio/audio_receive_stream.h)
43*   [`AudioMixer`](https://source.chromium.org/search?q=symbol:AudioMixer%20file:third_party%2Fwebrtc%2Fapi%2Faudio%2Faudio_mixer.h):
44    [`modules/audio_mixer/audio_mixer_impl.h`](https://source.chromium.org/chromium/chromium/src/+/main:third_party/webrtc/modules/audio_mixer/audio_mixer_impl.h)
45
46[`AudioMixer`](https://source.chromium.org/search?q=symbol:AudioMixer%20file:third_party%2Fwebrtc%2Fapi%2Faudio%2Faudio_mixer.h)
47is thread-safe. The output sample rate of the generated mix is automatically
48assigned depending on the sample rate of the sources; whereas the number of
49output channels is defined by the caller[^2]. Samples from the non-muted sources
50are summed up and then a limiter is used to apply soft-clipping when needed.
51
52[^2]: [`audio/utility/channel_mixer.h`](https://source.chromium.org/chromium/chromium/src/+/main:third_party/webrtc/audio/utility/channel_mixer.h)
53    is used to mix channels in the non-trivial cases - i.e., if the number of
54    channels for a source or the mix is greater than 3.
55