Skip to content

Commit 841a780

Browse files
koffesgreg-fer
authored andcommitted
lib: pcm_mix: Moved PCM mix from application
Tests and code moved from applications: nrf5340_audio Signed-off-by: Kristoffer Rist Skøien <kristoffer.skoien@nordicsemi.no> Co-authored-by: Grzegorz Ferenc <Grzegorz.Ferenc@nordicsemi.no>
1 parent 28a10f9 commit 841a780

File tree

21 files changed

+148
-74
lines changed

21 files changed

+148
-74
lines changed

.github/test-spec.yml

+1
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
- "boards/arm/nrf5340_audio_dk_nrf5340/**/*"
4545
- "tests/nrf5340_audio/**/*"
4646
- "tests/lib/contin_array/**/*"
47+
- "tests/lib/pcm_mix/**/*"
4748

4849
"CI-iot-samples-test":
4950
- "include/modem/at_monitor.h"

CODEOWNERS

+1
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ Kconfig* @tejlmand
116116
/lib/modem_jwt/ @jayteemo @SeppoTakalo
117117
/lib/modem_attest_token/ @jayteemo
118118
/lib/qos/ @simensrostad
119+
/lib/pcm_mix/ @koffes @alexsven @erikrobstad @rick1082 @gWacey
119120
/lib/contin_array/ @koffes @alexsven @erikrobstad @rick1082 @gWacey
120121
/modules/ @tejlmand
121122
/modules/mcuboot/ @de-nordic @nordicjm

applications/nrf5340_audio/Kconfig.defaults

+4-1
Original file line numberDiff line numberDiff line change
@@ -69,11 +69,14 @@ config CONTIN_ARRAY
6969
bool
7070
default y
7171

72-
# I2S
7372
config NRFX_I2S
7473
bool
7574
default y
7675

76+
config PCM_MIX
77+
bool
78+
default y
79+
7780
# Enable NRFX_CLOCK for ACLK control
7881
config NRFX_CLOCK
7982
bool

applications/nrf5340_audio/src/utils/CMakeLists.txt

-1
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,4 @@ target_sources(app PRIVATE
1212
${CMAKE_CURRENT_SOURCE_DIR}/pcm_stream_channel_modifier.c
1313
${CMAKE_CURRENT_SOURCE_DIR}/tone.c
1414
${CMAKE_CURRENT_SOURCE_DIR}/uicr.c
15-
${CMAKE_CURRENT_SOURCE_DIR}/pcm_mix.c
1615
)

applications/nrf5340_audio/src/utils/Kconfig

-4
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,6 @@ module = FW_INFO
6060
module-str = fw-info
6161
source "subsys/logging/Kconfig.template.log_config"
6262

63-
module = PCM_MIX
64-
module-str = pcm-mix
65-
source "subsys/logging/Kconfig.template.log_config"
66-
6763
module = PSCM
6864
module-str = pscm
6965
source "subsys/logging/Kconfig.template.log_config"

applications/nrf5340_audio/src/utils/pcm_mix.h

-43
This file was deleted.

doc/nrf/libraries/others/pcm_mix.rst

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
.. _lib_pcm_mix:
2+
3+
Pulse Code Modulation audio mixer
4+
#################################
5+
6+
.. contents::
7+
:local:
8+
:depth: 2
9+
10+
The Pulse Code Modulation (PCM) audio mixer lets you mix a PCM stream into another PCM stream.
11+
It can for example be useful for mixing a tone and an audio stream together.
12+
This library is useful for developing applications that offer audio features, for example using the nRF5340 Audio DK.
13+
14+
15+
The library offers the following types of mixing support:
16+
17+
* Stereo stream into another stereo stream
18+
* Combinations of mono to mono
19+
* Mono to stereo: channel left or right or left+right
20+
21+
Configuration
22+
*************
23+
24+
To enable the library, set the :kconfig:option:`CONFIG_PCM_MIX` Kconfig option to ``y`` in the project configuration file :file:`prj.conf`.
25+
26+
API documentation
27+
*****************
28+
29+
| Header file: :file:`include/pcm_mix.h`
30+
| Source file: :file:`lib/pcm_mix/pcm_mix.c`
31+
32+
.. doxygengroup:: pcm_mix
33+
:project: nrf
34+
:members:

doc/nrf/releases/release-notes-changelog.rst

+5
Original file line numberDiff line numberDiff line change
@@ -378,6 +378,11 @@ Other libraries
378378
It is replaced by the Trusted Firmware-M (TF-M) as the supported trusted execution solution.
379379
See :ref:`Trusted Firmware-M (TF-M) <ug_tfm>` for more information about the TF-M.
380380

381+
* PCM Mix:
382+
383+
* PCM mix (Pulse Code Modulation) audio mixer has been moved out of the nRF5340 Audio
384+
application, and into lib/pcm_mix.
385+
381386
Common Application Framework (CAF)
382387
----------------------------------
383388

include/pcm_mix.h

+58
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
/*
2+
* Copyright (c) 2022 Nordic Semiconductor ASA
3+
*
4+
* SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
5+
*/
6+
7+
/**
8+
* @file
9+
* @brief PCM audio mixer library header.
10+
*/
11+
12+
#ifndef _PCM_MIX_H_
13+
#define _PCM_MIX_H_
14+
15+
#include <zephyr/kernel.h>
16+
17+
/**
18+
* @defgroup pcm_mix Pulse Code Modulation mixer
19+
* @brief Pulse Code Modulation audio mixer library.
20+
*
21+
* @{
22+
*/
23+
24+
enum pcm_mix_mode {
25+
B_STEREO_INTO_A_STEREO,
26+
B_MONO_INTO_A_MONO,
27+
B_MONO_INTO_A_STEREO_LR,
28+
B_MONO_INTO_A_STEREO_L,
29+
B_MONO_INTO_A_STEREO_R,
30+
};
31+
32+
/**
33+
* @brief Mixes two buffers of PCM data.
34+
*
35+
* @note Uses simple addition with hard clip protection.
36+
* Input can be mono or stereo as long as the inputs match.
37+
* By selecting the mix mode, mono can also be mixed into a stereo buffer.
38+
* Hard coded for the signed 16-bit PCM.
39+
*
40+
* @param pcm_a [in/out] Pointer to the PCM data buffer A.
41+
* @param size_a [in] Size of the PCM data buffer A (in bytes).
42+
* @param pcm_b [in] Pointer to the PCM data buffer B.
43+
* @param size_b [in] Size of the PCM data buffer B (in bytes).
44+
* @param mix_mode [in] Mixing mode according to pcm_mix_mode.
45+
*
46+
* @retval 0 Success. Result stored in pcm_a.
47+
* @retval -EINVAL pcm_a is NULL or size_a = 0.
48+
* @retval -EPERM Either size_b < size_a (for stereo to stereo, mono to mono)
49+
* or size_a/2 < size_b (for mono to stereo mix).
50+
* @retval -ESRCH Invalid mixing mode.
51+
*/
52+
int pcm_mix(void *const pcm_a, size_t size_a, void const *const pcm_b, size_t size_b,
53+
enum pcm_mix_mode mix_mode);
54+
55+
/**
56+
* @}
57+
*/
58+
#endif /* _PCM_MIX_H_ */

lib/CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -41,3 +41,4 @@ add_subdirectory_ifdef(CONFIG_QOS qos)
4141
add_subdirectory_ifdef(CONFIG_IDENTITY_KEY identity_key)
4242
add_subdirectory_ifdef(CONFIG_SFLOAT sfloat)
4343
add_subdirectory_ifdef(CONFIG_CONTIN_ARRAY contin_array)
44+
add_subdirectory_ifdef(CONFIG_PCM_MIX pcm_mix)

lib/Kconfig

+1
Original file line numberDiff line numberDiff line change
@@ -42,5 +42,6 @@ rsource "qos/Kconfig"
4242
rsource "identity_key/Kconfig"
4343
rsource "sfloat/Kconfig"
4444
rsource "contin_array/Kconfig"
45+
rsource "pcm_mix/Kconfig"
4546

4647
endmenu

lib/pcm_mix/CMakeLists.txt

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#
2+
# Copyright (c) 2022 Nordic Semiconductor
3+
#
4+
# SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
5+
#
6+
7+
zephyr_library()
8+
zephyr_library_sources(
9+
pcm_mix.c
10+
)
11+
12+
zephyr_include_directories(.)

lib/pcm_mix/Kconfig

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Copyright (c) 2022 Nordic Semiconductor
2+
#
3+
# SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
4+
#
5+
6+
menuconfig PCM_MIX
7+
bool "PCM - Pulse Code Modulation mix library"
8+
help
9+
Library for mixing multiple audio streams
10+
11+
if PCM_MIX
12+
13+
module = PCM_MIX
14+
module-str = pcm-mix
15+
source "${ZEPHYR_BASE}/subsys/logging/Kconfig.template.log_config"
16+
17+
endif #PCM_MIX
File renamed without changes.

tests/lib/pcm_mix/CMakeLists.txt

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#
2+
# Copyright (c) 2020 Nordic Semiconductor ASA
3+
#
4+
# SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
5+
#
6+
7+
cmake_minimum_required(VERSION 3.20.0)
8+
9+
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
10+
project(pcm_mix)
11+
12+
FILE(GLOB app_sources src/*.c)
13+
target_sources(app PRIVATE ${app_sources})
File renamed without changes.
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
CONFIG_ZTEST=y
22
CONFIG_IRQ_OFFLOAD=y
3+
CONFIG_PCM_MIX=y
File renamed without changes.
File renamed without changes.

tests/nrf5340_audio/pcm_mix/CMakeLists.txt

-21
This file was deleted.

tests/nrf5340_audio/pcm_stream_channel_modifier/Kconfig

-4
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
11
# Copyright (c) 2022 Nordic Semiconductor ASA
22
# SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
33

4-
module = PCM_MIX
5-
module-str = pcm-mix
6-
source "subsys/logging/Kconfig.template.log_config"
7-
84
module = PSCM
95
module-str = pscm
106
source "subsys/logging/Kconfig.template.log_config"

0 commit comments

Comments
 (0)