forked from nrfconnect/sdk-nrf
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpcm_mix.h
58 lines (51 loc) · 1.57 KB
/
pcm_mix.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
/*
* Copyright (c) 2022 Nordic Semiconductor ASA
*
* SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
*/
/**
* @file
* @brief PCM audio mixer library header.
*/
#ifndef _PCM_MIX_H_
#define _PCM_MIX_H_
#include <zephyr/kernel.h>
/**
* @defgroup pcm_mix Pulse Code Modulation mixer
* @brief Pulse Code Modulation audio mixer library.
*
* @{
*/
enum pcm_mix_mode {
B_STEREO_INTO_A_STEREO,
B_MONO_INTO_A_MONO,
B_MONO_INTO_A_STEREO_LR,
B_MONO_INTO_A_STEREO_L,
B_MONO_INTO_A_STEREO_R,
};
/**
* @brief 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.
*
* @param pcm_a [in/out] Pointer to the PCM data buffer A.
* @param size_a [in] Size of the PCM data buffer A (in bytes).
* @param pcm_b [in] Pointer to the PCM data buffer B.
* @param size_b [in] Size of the PCM data buffer B (in bytes).
* @param mix_mode [in] Mixing mode according to pcm_mix_mode.
*
* @retval 0 Success. Result stored in pcm_a.
* @retval -EINVAL pcm_a is NULL or size_a = 0.
* @retval -EPERM Either size_b < size_a (for stereo to stereo, mono to mono)
* or size_a/2 < size_b (for mono to stereo mix).
* @retval -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);
/**
* @}
*/
#endif /* _PCM_MIX_H_ */