Skip to content

Commit 7a2b37b

Browse files
gWaceyrlubos
authored andcommitted
applications: nrf5340_audio: Audio Module Template
Implement an audio template to allow rapid development od new audio module. Signed-off-by: Graham Wacey <graham.wacey@nordicsemi.no>
1 parent 811ec2d commit 7a2b37b

File tree

14 files changed

+666
-0
lines changed

14 files changed

+666
-0
lines changed

CODEOWNERS

+4
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,8 @@ CMakeLists* @nrfconnect/ncs-co-build-system
8888
/include/net/azure_* @nrfconnect/ncs-cia @coderbyheart
8989
/include/net/wifi_credentials.h @nrfconnect/ncs-cia
9090
/include/net/nrf_cloud_* @nrfconnect/ncs-nrf-cloud
91+
/include/audio/ @nrfconnect/ncs-audio
92+
/include/audio_module/ @nrfconnect/ncs-audio
9193
/include/bluetooth/ @nrfconnect/ncs-si-muffin @nrfconnect/ncs-dragoon
9294
/include/bluetooth/services/fast_pair/ @nrfconnect/ncs-si-bluebagel
9395
/include/bluetooth/adv_prov.h @nrfconnect/ncs-si-bluebagel
@@ -275,6 +277,7 @@ CMakeLists* @nrfconnect/ncs-co-build-system
275277

276278
# Subsystems
277279
/subsys/ @nrfconnect/ncs-code-owners
280+
/subsys/audio/audio_module_template/ @nrfconnect/ncs-audio
278281
/subsys/audio_module/ @nrfconnect/ncs-audio
279282
/subsys/bluetooth/ @nrfconnect/ncs-si-muffin @nrfconnect/ncs-dragoon
280283
/subsys/bluetooth/mesh/ @nrfconnect/ncs-paladin
@@ -389,6 +392,7 @@ CMakeLists* @nrfconnect/ncs-co-build-system
389392
/tests/modules/mcuboot/direct_xip/ @nrfconnect/ncs-pluto
390393
/tests/modules/mcuboot/external_flash/ @nrfconnect/ncs-pluto
391394
/tests/nrf5340_audio/ @nrfconnect/ncs-audio @nordic-auko
395+
/tests/subsys/audio/audio_module_template/ @nrfconnect/ncs-audio
392396
/tests/subsys/audio_module/ @nrfconnect/ncs-audio
393397
/tests/subsys/bluetooth/gatt_dm/ @nrfconnect/ncs-si-muffin
394398
/tests/subsys/bluetooth/mesh/ @nrfconnect/ncs-paladin

include/audio/audio_module_template.h

+51
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/*
2+
* Copyright(c) 2024 Nordic Semiconductor ASA
3+
*
4+
* SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
5+
*/
6+
#ifndef _AUDIO_MODULE_TEMPLATE_H_
7+
#define _AUDIO_MODULE_TEMPLATE_H_
8+
9+
#include <stdbool.h>
10+
#include <stddef.h>
11+
#include <stdint.h>
12+
#include "audio_defines.h"
13+
#include "audio_module.h"
14+
15+
/* @brief Size of the data block within the template context, for testing. */
16+
#define AUDIO_MODULE_TEMPLATE_DATA_BYTES (10)
17+
18+
/**
19+
* @brief Private pointer to the module's parameters.
20+
*
21+
*/
22+
extern struct audio_module_description *audio_module_template_description;
23+
24+
/**
25+
* @brief The module configuration structure.
26+
*
27+
*/
28+
struct audio_module_template_configuration {
29+
/* The sample rate, for testing. */
30+
uint32_t sample_rate_hz;
31+
32+
/* The bit depth, for testing. */
33+
uint8_t bit_depth;
34+
35+
/* A string for testing.*/
36+
char *module_description;
37+
};
38+
39+
/**
40+
* @brief Private module context.
41+
*
42+
*/
43+
struct audio_module_template_context {
44+
/* Array of data to illustrate the data process function. */
45+
uint8_t audio_module_template_data[AUDIO_MODULE_TEMPLATE_DATA_BYTES];
46+
47+
/* The template configuration. */
48+
struct audio_module_template_configuration config;
49+
};
50+
51+
#endif /* _AUDIO_MODULE_TEMPLATE_H_ */

scripts/ci/tags.yaml

+2
Original file line numberDiff line numberDiff line change
@@ -920,6 +920,8 @@ ci_tests_subsys_audio_module:
920920
files:
921921
- nrf/subsys/audio_module/
922922
- nrf/tests/subsys/audio_module/
923+
- nrf/subsys/audio/
924+
- nrf/tests/subsys/audio/
923925

924926
ci_tests_subsys_mpsl:
925927
files:

subsys/CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ add_subdirectory_ifdef(CONFIG_NRF_DM dm)
7070
add_subdirectory_ifdef(CONFIG_EMDS emds)
7171
add_subdirectory_ifdef(CONFIG_NET_CORE_MONITOR net_core_monitor)
7272
add_subdirectory_ifdef(CONFIG_AUDIO_MODULE audio_module)
73+
add_subdirectory_ifdef(CONFIG_AUDIO_MODULE_TEMPLATE audio/audio_module_template)
7374
add_subdirectory_ifdef(CONFIG_UART_ASYNC_ADAPTER uart_async_adapter)
7475
add_subdirectory_ifdef(CONFIG_SDFW_SERVICES_ENABLED sdfw_services)
7576
add_subdirectory(suit)

subsys/Kconfig

+1
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ rsource "dm/Kconfig"
3434
rsource "nrf_security/Kconfig"
3535
rsource "net_core_monitor/Kconfig"
3636
rsource "audio_module/Kconfig"
37+
rsource "audio/audio_module_template/Kconfig"
3738
rsource "uart_async_adapter/Kconfig"
3839
rsource "trusted_storage/Kconfig"
3940
rsource "logging/Kconfig"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#
2+
# Copyright (c) 2024 Nordic Semiconductor
3+
#
4+
# SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
5+
#
6+
7+
target_sources(app PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/audio_module_template.c)
8+
9+
target_include_directories(app PRIVATE ${ZEPHYR_NRF_MODULE_DIR}/include/audio_module
10+
${ZEPHYR_NRF_MODULE_DIR}/include/audio)
+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#
2+
# Copyright (c) 2024 Nordic Semiconductor ASA
3+
#
4+
# SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
5+
#
6+
menu "Audio Modules"
7+
8+
config AUDIO_MODULE_TEMPLATE
9+
bool "Audio module template"
10+
help
11+
Enable the audio module template, the
12+
starting point for a new audio module
13+
14+
if AUDIO_MODULE_TEMPLATE
15+
16+
#----------------------------------------------------------------------------#
17+
menu "Log levels"
18+
19+
module = AUDIO_MODULE_TEMPLATE
20+
module-str = audio_module
21+
source "subsys/logging/Kconfig.template.log_config"
22+
23+
endmenu # Log levels
24+
25+
endif # AUDIO_MODULE_TEMPLATE
26+
27+
endmenu # Audio Modules
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,201 @@
1+
/*
2+
* Copyright(c) 2024 Nordic Semiconductor ASA
3+
*
4+
* SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
5+
*/
6+
#include "audio_module_template.h"
7+
8+
#include <stdlib.h>
9+
#include <stdio.h>
10+
#include <ctype.h>
11+
#include <zephyr/kernel.h>
12+
#include <errno.h>
13+
#include "audio_defines.h"
14+
#include "audio_module.h"
15+
16+
#include <zephyr/logging/log.h>
17+
LOG_MODULE_REGISTER(audio_module_template, CONFIG_AUDIO_MODULE_TEMPLATE_LOG_LEVEL);
18+
19+
static int audio_module_template_open(struct audio_module_handle_private *handle,
20+
struct audio_module_configuration const *const configuration)
21+
22+
{
23+
struct audio_module_handle *hdl = (struct audio_module_handle *)handle;
24+
struct audio_module_template_context *ctx =
25+
(struct audio_module_template_context *)hdl->context;
26+
struct audio_module_template_configuration *config =
27+
(struct audio_module_template_configuration *)configuration;
28+
29+
/* Perform any other functions required to open the module. */
30+
31+
/* For example: Clear the module's context.
32+
* Save the initial configuration to the module context.
33+
*/
34+
memset(ctx, 0, sizeof(struct audio_module_template_context));
35+
memcpy(&ctx->config, config, sizeof(struct audio_module_template_configuration));
36+
37+
LOG_DBG("Open %s module", hdl->name);
38+
39+
return 0;
40+
}
41+
42+
static int audio_module_template_close(struct audio_module_handle_private *handle)
43+
{
44+
struct audio_module_handle *hdl = (struct audio_module_handle *)handle;
45+
struct audio_module_template_context *ctx =
46+
(struct audio_module_template_context *)hdl->context;
47+
48+
/* Perform any other functions required to close the module. */
49+
50+
/* For example: Clear the context data */
51+
memset(ctx, 0, sizeof(struct audio_module_template_context));
52+
53+
LOG_DBG("Close %s module", hdl->name);
54+
55+
return 0;
56+
}
57+
58+
static int audio_module_template_configuration_set(
59+
struct audio_module_handle_private *handle,
60+
struct audio_module_configuration const *const configuration)
61+
{
62+
struct audio_module_template_configuration *config =
63+
(struct audio_module_template_configuration *)configuration;
64+
struct audio_module_handle *hdl = (struct audio_module_handle *)handle;
65+
struct audio_module_template_context *ctx =
66+
(struct audio_module_template_context *)hdl->context;
67+
68+
/* Perform any other functions to configure the module. */
69+
70+
/* For example: Copy the configuration into the context. */
71+
memcpy(&ctx->config, config, sizeof(struct audio_module_template_configuration));
72+
73+
LOG_DBG("Set the configuration for %s module: sample rate = %d bit depth = %d string = "
74+
"%s",
75+
hdl->name, ctx->config.sample_rate_hz, ctx->config.bit_depth,
76+
ctx->config.module_description);
77+
78+
return 0;
79+
}
80+
81+
static int
82+
audio_module_template_configuration_get(struct audio_module_handle_private const *const handle,
83+
struct audio_module_configuration *configuration)
84+
{
85+
struct audio_module_template_configuration *config =
86+
(struct audio_module_template_configuration *)configuration;
87+
struct audio_module_handle *hdl = (struct audio_module_handle *)handle;
88+
struct audio_module_template_context *ctx =
89+
(struct audio_module_template_context *)hdl->context;
90+
91+
/* Perform any other functions to extract the configuration of the module. */
92+
93+
/* For example: Copy the configuration from the context into the output configuration. */
94+
memcpy(config, &ctx->config, sizeof(struct audio_module_template_configuration));
95+
96+
LOG_DBG("Get the configuration for %s module: sample rate = %d bit depth = %d string = "
97+
"%s",
98+
hdl->name, config->sample_rate_hz, config->bit_depth, config->module_description);
99+
100+
return 0;
101+
}
102+
103+
static int audio_module_template_start(struct audio_module_handle_private *handle)
104+
{
105+
struct audio_module_handle *hdl = (struct audio_module_handle *)handle;
106+
107+
/* Perform any other functions to start the module. */
108+
109+
LOG_DBG("Start the %s module", hdl->name);
110+
111+
return 0;
112+
}
113+
114+
static int audio_module_template_stop(struct audio_module_handle_private *handle)
115+
{
116+
struct audio_module_handle *hdl = (struct audio_module_handle *)handle;
117+
118+
/* Perform any other functions to stop the module. */
119+
120+
LOG_DBG("Stop the %s module", hdl->name);
121+
122+
return 0;
123+
}
124+
125+
static int audio_module_template_data_process(struct audio_module_handle_private *handle,
126+
struct audio_data const *const audio_data_in,
127+
struct audio_data *audio_data_out)
128+
{
129+
struct audio_module_handle *hdl = (struct audio_module_handle *)handle;
130+
131+
/* Perform any other functions to process the data within the module. */
132+
133+
/* For example: Copy the input to the output. */
134+
{
135+
size_t size = audio_data_in->data_size < audio_data_out->data_size
136+
? audio_data_in->data_size
137+
: audio_data_out->data_size;
138+
139+
memcpy(&audio_data_out->meta, &audio_data_in->meta, sizeof(struct audio_metadata));
140+
memcpy(audio_data_out->data, audio_data_in->data, size);
141+
audio_data_out->data_size = size;
142+
}
143+
144+
LOG_DBG("Process the input audio data into the output audio data item for %s module",
145+
hdl->name);
146+
147+
return 0;
148+
}
149+
150+
/**
151+
* @brief Table of the dummy module functions.
152+
*/
153+
const struct audio_module_functions audio_module_template_functions = {
154+
/**
155+
* @brief Function to an open the dummy module.
156+
*/
157+
.open = audio_module_template_open,
158+
159+
/**
160+
* @brief Function to close the dummy module.
161+
*/
162+
.close = audio_module_template_close,
163+
164+
/**
165+
* @brief Function to set the configuration of the dummy module.
166+
*/
167+
.configuration_set = audio_module_template_configuration_set,
168+
169+
/**
170+
* @brief Function to get the configuration of the dummy module.
171+
*/
172+
.configuration_get = audio_module_template_configuration_get,
173+
174+
/**
175+
* @brief Start a module processing data.
176+
*/
177+
.start = audio_module_template_start,
178+
179+
/**
180+
* @brief Pause a module processing data.
181+
*/
182+
.stop = audio_module_template_stop,
183+
184+
/**
185+
* @brief The core data processing function in the dummy module.
186+
*/
187+
.data_process = audio_module_template_data_process,
188+
};
189+
190+
/**
191+
* @brief The set-up description for the LC3 decoder.
192+
*/
193+
struct audio_module_description audio_module_template_dept = {
194+
.name = "Audio Module Temp",
195+
.type = AUDIO_MODULE_TYPE_IN_OUT,
196+
.functions = &audio_module_template_functions};
197+
198+
/**
199+
* @brief A private pointer to the template set-up parameters.
200+
*/
201+
struct audio_module_description *audio_module_template_description = &audio_module_template_dept;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#
2+
# Copyright (c) 2024 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("Audio module Template")
11+
12+
target_sources(app PRIVATE
13+
src/main.c
14+
src/template_test.c
15+
)
16+
17+
target_include_directories(app PRIVATE ${ZEPHYR_NRF_MODULE_DIR}/subsys/audio/audio_module_template)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#
2+
# Copyright (c) 2024 Nordic Semiconductor ASA
3+
#
4+
# SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
5+
#
6+
7+
CONFIG_ZTEST=y
8+
CONFIG_ZTEST_STACK_SIZE=8196
9+
CONFIG_IRQ_OFFLOAD=y
10+
CONFIG_DATA_FIFO=y
11+
CONFIG_AUDIO_MODULE=y
12+
CONFIG_AUDIO_MODULE_TEMPLATE=y
13+
14+
# The large stack size can be optimized
15+
CONFIG_MAIN_STACK_SIZE=16000
16+
17+
CONFIG_STACK_SENTINEL=y
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
/*
2+
* Copyright (c) 2024 Nordic Semiconductor ASA
3+
*
4+
* SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
5+
*/
6+
7+
#include <zephyr/fff.h>
8+
#include <zephyr/ztest.h>
9+
#include <errno.h>
10+
11+
ZTEST_SUITE(suite_audio_module_template, NULL, NULL, NULL, NULL, NULL);

0 commit comments

Comments
 (0)