forked from nrfconnect/sdk-nrf
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
applications: nrf5340_audio: Audio Module Template
Implement an audio template to allow rapid development od new audio module. Signed-off-by: Graham Wacey <[email protected]>
- Loading branch information
Showing
11 changed files
with
652 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
/* | ||
* Copyright(c) 2024 Nordic Semiconductor ASA | ||
* | ||
* SPDX-License-Identifier: LicenseRef-Nordic-5-Clause | ||
*/ | ||
#ifndef _AUDIO_MODULE_TEMPLATE_H_ | ||
#define _AUDIO_MODULE_TEMPLATE_H_ | ||
|
||
#include <stdbool.h> | ||
#include <stddef.h> | ||
#include <stdint.h> | ||
#include "audio_defines.h" | ||
#include "audio_module.h" | ||
|
||
#define AUDIO_MODULE_TEMPLATE_LAST_BYTES (10) | ||
|
||
/** | ||
* @brief Private pointer to the module's parameters. | ||
* | ||
*/ | ||
extern struct audio_module_description *audio_module_template_description; | ||
|
||
/** | ||
* @brief The module configuration structure. | ||
* | ||
*/ | ||
struct audio_module_template_configuration { | ||
/* The rate. */ | ||
uint32_t sample_rate_hz; | ||
|
||
/* the depth. */ | ||
uint32_t bit_depth; | ||
|
||
/* A string .*/ | ||
char *some_text; | ||
}; | ||
|
||
/** | ||
* @brief Private module context. | ||
* | ||
*/ | ||
struct audio_module_template_context { | ||
/* Array of data to illustrate the data process function. */ | ||
uint8_t audio_module_template_data[AUDIO_MODULE_TEMPLATE_LAST_BYTES]; | ||
|
||
/* The template configuration. */ | ||
struct audio_module_template_configuration config; | ||
}; | ||
|
||
#endif /* _AUDIO_MODULE_TEMPLATE_H_ */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
# | ||
# Copyright (c) 2023 Nordic Semiconductor | ||
# | ||
# SPDX-License-Identifier: LicenseRef-Nordic-5-Clause | ||
# | ||
|
||
target_sources(app PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/audio_module_template.c) | ||
|
||
target_include_directories(app PRIVATE ${ZEPHYR_NRF_MODULE_DIR}/include/audio_module | ||
${ZEPHYR_NRF_MODULE_DIR}/include/audio_modules) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
# | ||
# Copyright (c) 2023 Nordic Semiconductor ASA | ||
# | ||
# SPDX-License-Identifier: LicenseRef-Nordic-5-Clause | ||
# | ||
menu "Audio Modules" | ||
|
||
config AUDIO_MODULE_TEMPLATE | ||
bool "Audio module template" | ||
help | ||
Enable the audio module template, the | ||
starting point for a new audio module | ||
|
||
if AUDIO_MODULE_TEMPLATE | ||
|
||
#----------------------------------------------------------------------------# | ||
menu "Log levels" | ||
|
||
module = AUDIO_MODULE_TEMPLATE | ||
module-str = audio_module | ||
source "subsys/logging/Kconfig.template.log_config" | ||
|
||
endmenu # Log levels | ||
|
||
endif # AUDIO_MODULE_TEMPLATE | ||
|
||
endmenu # Audio Modules |
200 changes: 200 additions & 0 deletions
200
subsys/audio_modules/audio_module_template/audio_module_template.c
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,200 @@ | ||
/* | ||
* Copyright(c) 2024 Nordic Semiconductor ASA | ||
* | ||
* SPDX-License-Identifier: LicenseRef-Nordic-5-Clause | ||
*/ | ||
#include "audio_module_template.h" | ||
|
||
#include <stdlib.h> | ||
#include <stdio.h> | ||
#include <ctype.h> | ||
#include <zephyr/kernel.h> | ||
#include <zephyr/shell/shell.h> | ||
#include <errno.h> | ||
#include "audio_defines.h" | ||
#include "audio_module.h" | ||
|
||
#include <zephyr/logging/log.h> | ||
LOG_MODULE_REGISTER(audio_module_template, CONFIG_AUDIO_MODULE_TEMPLATE_LOG_LEVEL); | ||
|
||
static int audio_module_template_open(struct audio_module_handle_private *handle, | ||
struct audio_module_configuration const *const configuration) | ||
|
||
{ | ||
struct audio_module_handle *hdl = (struct audio_module_handle *)handle; | ||
struct audio_module_template_context *ctx = | ||
(struct audio_module_template_context *)hdl->context; | ||
struct audio_module_template_configuration *config = | ||
(struct audio_module_template_configuration *)configuration; | ||
|
||
/* Perform any other functions required to open the module. */ | ||
|
||
/* For example: Clear the module's context. | ||
* Save the initial configuration to the module context. | ||
*/ | ||
memset(ctx, 0, sizeof(struct audio_module_template_context)); | ||
memcpy(&ctx->config, config, sizeof(struct audio_module_template_configuration)); | ||
|
||
LOG_DBG("Open %s module", hdl->name); | ||
|
||
return 0; | ||
} | ||
|
||
static int audio_module_template_close(struct audio_module_handle_private *handle) | ||
{ | ||
struct audio_module_handle *hdl = (struct audio_module_handle *)handle; | ||
struct audio_module_template_context *ctx = | ||
(struct audio_module_template_context *)hdl->context; | ||
|
||
/* Perform any other functions required to close the module. */ | ||
|
||
/* For example: Clear the context data */ | ||
memset(ctx, 0, sizeof(struct audio_module_template_context)); | ||
|
||
LOG_DBG("Close %s module", hdl->name); | ||
|
||
return 0; | ||
} | ||
|
||
static int audio_module_template_configuration_set( | ||
struct audio_module_handle_private *handle, | ||
struct audio_module_configuration const *const configuration) | ||
{ | ||
struct audio_module_template_configuration *config = | ||
(struct audio_module_template_configuration *)configuration; | ||
struct audio_module_handle *hdl = (struct audio_module_handle *)handle; | ||
struct audio_module_template_context *ctx = | ||
(struct audio_module_template_context *)hdl->context; | ||
|
||
/* Perform any other functions to configure the module. */ | ||
|
||
/* For example: Copy the configuration into the context. */ | ||
memcpy(&ctx->config, config, sizeof(struct audio_module_template_configuration)); | ||
|
||
LOG_DBG("Set the configuration for %s module: rate = %d depth = %d string = %s", | ||
hdl->name, ctx->config.sample_rate_hz, ctx->config.bit_depth, | ||
ctx->config.some_text); | ||
|
||
return 0; | ||
} | ||
|
||
static int | ||
audio_module_template_configuration_get(struct audio_module_handle_private const *const handle, | ||
struct audio_module_configuration *configuration) | ||
{ | ||
struct audio_module_template_configuration *config = | ||
(struct audio_module_template_configuration *)configuration; | ||
struct audio_module_handle *hdl = (struct audio_module_handle *)handle; | ||
struct audio_module_template_context *ctx = | ||
(struct audio_module_template_context *)hdl->context; | ||
|
||
/* Perform any other functions to extract the configuration of the module. */ | ||
|
||
/* For example: Copy the configuration from the context into the output configuration. */ | ||
memcpy(config, &ctx->config, sizeof(struct audio_module_template_configuration)); | ||
|
||
LOG_DBG("Get the configuration for %s module: rate = %d depth = %d string = %s", | ||
hdl->name, config->sample_rate_hz, config->bit_depth, config->some_text); | ||
|
||
return 0; | ||
} | ||
|
||
static int audio_module_template_start(struct audio_module_handle_private *handle) | ||
{ | ||
struct audio_module_handle *hdl = (struct audio_module_handle *)handle; | ||
|
||
/* Perform any other functions to start the module. */ | ||
|
||
LOG_DBG("Start the %s module", hdl->name); | ||
|
||
return 0; | ||
} | ||
|
||
static int audio_module_template_stop(struct audio_module_handle_private *handle) | ||
{ | ||
struct audio_module_handle *hdl = (struct audio_module_handle *)handle; | ||
|
||
/* Perform any other functions to stop the module. */ | ||
|
||
LOG_DBG("Stop the %s module", hdl->name); | ||
|
||
return 0; | ||
} | ||
|
||
static int audio_module_template_data_process(struct audio_module_handle_private *handle, | ||
struct audio_data const *const audio_data_in, | ||
struct audio_data *audio_data_out) | ||
{ | ||
struct audio_module_handle *hdl = (struct audio_module_handle *)handle; | ||
|
||
/* Perform any other functions to process the data within the module. */ | ||
|
||
/* For example: Copy the input to the output. */ | ||
{ | ||
size_t size = audio_data_in->data_size < audio_data_out->data_size | ||
? audio_data_in->data_size | ||
: audio_data_out->data_size; | ||
|
||
memcpy(&audio_data_out->meta, &audio_data_in->meta, sizeof(struct audio_metadata)); | ||
memcpy((uint8_t *)audio_data_out->data, (uint8_t *)audio_data_in->data, size); | ||
audio_data_out->data_size = size; | ||
} | ||
|
||
LOG_DBG("Process the input audio data into the output audio data item for %s module", | ||
hdl->name); | ||
|
||
return 0; | ||
} | ||
|
||
/** | ||
* @brief Table of the dummy module functions. | ||
*/ | ||
const struct audio_module_functions audio_module_template_functions = { | ||
/** | ||
* @brief Function to an open the dummy module. | ||
*/ | ||
.open = audio_module_template_open, | ||
|
||
/** | ||
* @brief Function to close the dummy module. | ||
*/ | ||
.close = audio_module_template_close, | ||
|
||
/** | ||
* @brief Function to set the configuration of the dummy module. | ||
*/ | ||
.configuration_set = audio_module_template_configuration_set, | ||
|
||
/** | ||
* @brief Function to get the configuration of the dummy module. | ||
*/ | ||
.configuration_get = audio_module_template_configuration_get, | ||
|
||
/** | ||
* @brief Start a module processing data. | ||
*/ | ||
.start = audio_module_template_start, | ||
|
||
/** | ||
* @brief Pause a module processing data. | ||
*/ | ||
.stop = audio_module_template_stop, | ||
|
||
/** | ||
* @brief The core data processing function in the dummy module. | ||
*/ | ||
.data_process = audio_module_template_data_process, | ||
}; | ||
|
||
/** | ||
* @brief The set-up description for the LC3 decoder. | ||
*/ | ||
struct audio_module_description audio_module_template_dept = { | ||
.name = "Audio Module Temp", | ||
.type = AUDIO_MODULE_TYPE_IN_OUT, | ||
.functions = &audio_module_template_functions}; | ||
|
||
/** | ||
* @brief A private pointer to the LC3 decoder set-up parameters. | ||
*/ | ||
struct audio_module_description *audio_module_template_description = &audio_module_template_dept; |
17 changes: 17 additions & 0 deletions
17
tests/subsys/audio_modules/audio_module_template/CMakeLists.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# | ||
# Copyright (c) 20234 Nordic Semiconductor ASA | ||
# | ||
# SPDX-License-Identifier: LicenseRef-Nordic-5-Clause | ||
# | ||
|
||
cmake_minimum_required(VERSION 3.20.0) | ||
|
||
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE}) | ||
project("Audio module Template") | ||
|
||
target_sources(app PRIVATE | ||
src/main.c | ||
src/template_test.c | ||
) | ||
|
||
target_include_directories(app PRIVATE ${ZEPHYR_NRF_MODULE_DIR}/subsys/audio_modules/audio_module_template) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# | ||
# Copyright (c) 2024 Nordic Semiconductor ASA | ||
# | ||
# SPDX-License-Identifier: LicenseRef-Nordic-5-Clause | ||
# | ||
|
||
CONFIG_ZTEST=y | ||
CONFIG_ZTEST_STACK_SIZE=8196 | ||
CONFIG_IRQ_OFFLOAD=y | ||
CONFIG_DATA_FIFO=y | ||
CONFIG_AUDIO_MODULE=y | ||
CONFIG_AUDIO_MODULE_TEMPLATE=y | ||
|
||
# The large stack size can be optimized | ||
CONFIG_MAIN_STACK_SIZE=16000 | ||
|
||
CONFIG_STACK_SENTINEL=y |
11 changes: 11 additions & 0 deletions
11
tests/subsys/audio_modules/audio_module_template/src/main.c
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
/* | ||
* Copyright (c) 2024 Nordic Semiconductor ASA | ||
* | ||
* SPDX-License-Identifier: LicenseRef-Nordic-5-Clause | ||
*/ | ||
|
||
#include <zephyr/fff.h> | ||
#include <zephyr/ztest.h> | ||
#include <errno.h> | ||
|
||
ZTEST_SUITE(suite_audio_module_template, NULL, NULL, NULL, NULL, NULL); |
Oops, something went wrong.