Pulse Code Modulation audio mixer
The Pulse Code Modulation (PCM) audio mixer lets you mix a PCM stream into another PCM stream. It can for example be useful for mixing a tone and an audio stream together. This library is useful for developing applications that offer audio features, for example using the nRF5340 Audio DK.
The library offers the following types of mixing support:
Stereo stream into another stereo stream
Combinations of mono to mono
Mono to stereo: channel left or right or left+right
Configuration
To enable the library, set the CONFIG_PCM_MIX
Kconfig option to y
in the project configuration file prj.conf
.
API documentation
include/pcm_mix.h
lib/pcm_mix/pcm_mix.c
- group pcm_mix
Pulse Code Modulation audio mixer library.
Enums
Functions
-
int pcm_mix(void *const pcm_a, size_t size_a, void const *const pcm_b, size_t size_b, enum pcm_mix_mode mix_mode)
Mixes two buffers of PCM data.
Note
Uses simple addition with hard clip protection. Input can be mono or stereo as long as the inputs match. By selecting the mix mode, mono can also be mixed into a stereo buffer. Hard coded for the signed 16-bit PCM.
- Parameters
pcm_a – [in/out] Pointer to the PCM data buffer A.
size_a – [in] Size of the PCM data buffer A (in bytes).
pcm_b – [in] Pointer to the PCM data buffer B.
size_b – [in] Size of the PCM data buffer B (in bytes).
mix_mode – [in] Mixing mode according to pcm_mix_mode.
- Return values
0 – Success. Result stored in pcm_a.
-EINVAL – pcm_a is NULL or size_a = 0.
-EPERM – Either size_b < size_a (for stereo to stereo, mono to mono) or size_a/2 < size_b (for mono to stereo mix).
-ESRCH – Invalid mixing mode.
-
int pcm_mix(void *const pcm_a, size_t size_a, void const *const pcm_b, size_t size_b, enum pcm_mix_mode mix_mode)