Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

applications: nrf5340_audio: LC3 Decoder Audio Module #13

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion include/audio_defines.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ struct audio_metadata {
* bits_per_sample = 24
* carrier_size = 32
*/
uint8_t carried_bits_pr_sample;
uint8_t carried_bits_per_sample;

/* A 32 bit mask indicating which channel(s)/locations are active within
* the data. A bit set indicates the location is active and
Expand Down
25 changes: 25 additions & 0 deletions include/audio_module/audio_module.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,19 @@ extern "C" {

#include "audio_defines.h"

/**
* @brief Helper macro to configure the modules parameters.
*/
#define AUDIO_MODULE_PARAMETERS(p, dest, stk, stk_size, pri, fifo_rx, fifo_tx, slab, slab_size) \
(p).description = (dest); \
(p).thread.stack = (stk); \
(p).thread.stack_size = (stk_size); \
(p).thread.priority = (pri); \
(p).thread.msg_rx = (fifo_rx); \
(p).thread.msg_tx = (fifo_tx); \
(p).thread.data_slab = (slab); \
(p).thread.data_size = (slab_size);

/**
* @brief Number of valid location bits.
*/
Expand Down Expand Up @@ -409,6 +422,10 @@ int audio_module_stop(struct audio_module_handle *handle);
/**
* @brief Send an audio data item to an audio module, all data is consumed by the module.
*
* @note: The data pointer and its associated size that are passed via the audio data
* pointer, can be NULL and/or 0. It is the responsibility of the low level module functions
* to handle this correctly.
*
* @param handle [in/out] The handle for the receiving module instance.
* @param audio_data [in] Pointer to the audio data to send to the module.
* @param response_cb [in] Pointer to a callback to run when the buffer is
Expand All @@ -423,6 +440,10 @@ int audio_module_data_tx(struct audio_module_handle *handle,
/**
* @brief Retrieve an audio data item from an audio module.
*
* @note: The data pointer and its associated size that are passed via the audio data
* pointer, can be NULL and/or 0. It is the responsibility of the low level module functions
* to handle this correctly.
*
* @param handle [in/out] The handle to the module instance.
* @param audio_data [out] Pointer to the audio data from the module.
* @param timeout [in] Non-negative waiting period to wait for operation to complete
Expand All @@ -441,6 +462,10 @@ int audio_module_data_rx(struct audio_module_handle *handle, struct audio_data *
* returned via the module or final module's output FIFO. All the input data is consumed
* within the call and thus the input data buffer maybe released once the function returns.
*
* @note: The data I/O pointers and their associated sizes that are passed via the audio data
* pointers, can be NULL and/or 0. It is the responsibility of the low level module functions
* to handle this correctly.
*
* @param handle_tx [in/out] The handle to the module to send the input audio data to.
* @param handle_rx [in/out] The handle to the module to receive audio data from.
* @param audio_data_tx [in] Pointer to the audio data to send.
Expand Down
50 changes: 50 additions & 0 deletions include/audio_modules/audio_module_template.h
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_ */
83 changes: 83 additions & 0 deletions include/audio_modules/lc3_decoder.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
/*
* Copyright(c) 2024 Nordic Semiconductor ASA
*
* SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
*/
#ifndef _LC3_DECODER_H_
#define _LC3_DECODER_H_

#include "audio_defines.h"
#include "audio_module.h"

#define LC3_DECODER_PCM_NUM_BYTES_MONO \
((CONFIG_LC3_DECODER_SAMPLE_RATE_HZ * CONFIG_LC3_DECODER_BIT_DEPTH_OCTETS * \
CONFIG_LC3_DECODER_FRAME_DURATION_US) / \
1000000)

/**
* @brief Private pointer to the module's parameters.
*/
extern struct audio_module_description *lc3_decoder_description;

/**
* @brief Private pointer to the decoders handle.
*/
struct lc3_decoder_handle;

/**
* @brief The module configuration structure.
*/
struct lc3_decoder_configuration {
/* Sample rate for the decoder instance. */
uint32_t sample_rate_hz;

/* Number of valid bits for a sample (bit depth).
* Typically 16 or 24.
*/
uint8_t bits_per_sample;

/* Number of bits used to carry a sample of size bits_per_sample.
* For example, say we have a 24 bit sample stored in a 32 bit
* word (int32_t), then:
* bits_per_sample = 24
* carrier_size = 32
*/
uint32_t carried_bits_per_sample;

/* Frame duration for this decoder instance. */
uint32_t data_len_us;

/* A flag indicating if the decoded buffer is sample interleaved or not. */
bool interleaved;

/* Channel locations for this decoder instance. */
uint32_t locations;

/* Maximum bitrate supported by the decoder. */
uint32_t bitrate_bps_max;
};

/**
* @brief Private module context.
*/
struct lc3_decoder_context {
/* Array of decoder channel handles. */
struct lc3_decoder_handle *lc3_dec_channel[CONFIG_LC3_DEC_CHANNELS_MAX];

/* Number of decoder channel handles. */
uint32_t dec_handles_count;

/* The decoder configuration. */
struct lc3_decoder_configuration config;

/* Minimum coded bytes required for this decoder instance. */
uint16_t coded_bytes_req;

/* Audio sample bytes per frame. */
size_t sample_frame_bytes;

/* Number of successive frames to which PLC has been applied. */
uint16_t plc_count;
};

#endif /* _LC3_DECODER_H_ */
20 changes: 15 additions & 5 deletions include/data_fifo.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,10 @@ struct data_fifo {
};

#define DATA_FIFO_DEFINE(name, elements_max_in, block_size_max_in) \
char __aligned(WB_UP(1)) \
_msgq_buffer_##name[(elements_max_in) * sizeof(struct data_fifo_msgq)] = {0}; \
char __aligned(WB_UP(1)) \
_slab_buffer_##name[(elements_max_in) * (block_size_max_in)] = {0}; \
char __aligned(WB_UP( \
1)) _msgq_buffer_##name[(elements_max_in) * sizeof(struct data_fifo_msgq)] = {0}; \
char __aligned(WB_UP(1)) _slab_buffer_##name[(elements_max_in) * (block_size_max_in)] = { \
0}; \
struct data_fifo name = {.msgq_buffer = _msgq_buffer_##name, \
.slab_buffer = _slab_buffer_##name, \
.block_size_max = block_size_max_in, \
Expand Down Expand Up @@ -163,7 +163,7 @@ int data_fifo_empty(struct data_fifo *data_fifo);
int data_fifo_uninit(struct data_fifo *data_fifo);

/**
* @brief Initialise the data_fifo.
* @brief Initialize the data_fifo.
*
* @param data_fifo Pointer to the data_fifo structure.
*
Expand All @@ -172,6 +172,16 @@ int data_fifo_uninit(struct data_fifo *data_fifo);
*/
int data_fifo_init(struct data_fifo *data_fifo);

/**
* @brief Test if the data_fifo state.
*
* @param data_fifo Pointer to the data_fifo structure.
*
* @retval false Uninitialized.
* @retval true Initialized.
*/
bool data_fifo_state(struct data_fifo *data_fifo);

/**
* @}
*/
Expand Down
10 changes: 10 additions & 0 deletions lib/data_fifo/data_fifo.c
Original file line number Diff line number Diff line change
Expand Up @@ -206,3 +206,13 @@ int data_fifo_init(struct data_fifo *data_fifo)

return ret;
}

bool data_fifo_state(struct data_fifo *data_fifo)
{
__ASSERT_NO_MSG(data_fifo != NULL);
__ASSERT_NO_MSG(data_fifo->elements_max != 0);
__ASSERT_NO_MSG(data_fifo->block_size_max != 0);
__ASSERT_NO_MSG((data_fifo->block_size_max % WB_UP(1)) == 0);

return data_fifo->initialized;
}
2 changes: 2 additions & 0 deletions subsys/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ add_subdirectory_ifdef(CONFIG_NRF_DM dm)
add_subdirectory_ifdef(CONFIG_EMDS emds)
add_subdirectory_ifdef(CONFIG_NET_CORE_MONITOR net_core_monitor)
add_subdirectory_ifdef(CONFIG_AUDIO_MODULE audio_module)
add_subdirectory_ifdef(CONFIG_AUDIO_MODULE_TEMPLATE audio_modules/audio_module_template)
add_subdirectory_ifdef(CONFIG_AUDIO_MODULE_T2_LC3_DECODER audio_modules/lc3/t2/decoder)
add_subdirectory_ifdef(CONFIG_UART_ASYNC_ADAPTER uart_async_adapter)
add_subdirectory_ifdef(CONFIG_SDFW_SERVICES_ENABLED sdfw_services)
add_subdirectory(suit)
Expand Down
2 changes: 2 additions & 0 deletions subsys/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ rsource "dm/Kconfig"
rsource "nrf_security/Kconfig"
rsource "net_core_monitor/Kconfig"
rsource "audio_module/Kconfig"
rsource "audio_modules/audio_module_template/Kconfig"
rsource "audio_modules/lc3/t2/decoder/Kconfig"
rsource "uart_async_adapter/Kconfig"
rsource "trusted_storage/Kconfig"
rsource "logging/Kconfig"
Expand Down
2 changes: 1 addition & 1 deletion subsys/audio_module/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@
# SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
#

target_sources(app PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/audio_module.c)
zephyr_sources_ifdef(CONFIG_AUDIO_MODULE audio_module.c)
9 changes: 6 additions & 3 deletions subsys/audio_module/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
#
# SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
#

menu "Audio Module"
menu "Audio Modules"

config AUDIO_MODULE
tristate "Enable the audio module"
Expand All @@ -20,8 +19,12 @@ config AUDIO_MODULE_NAME_SIZE
int "Maximum size for module naming in characters"
default 20

#----------------------------------------------------------------------------#
menu "Log levels"

module = AUDIO_MODULE
module-str = audio_module
source "subsys/logging/Kconfig.template.log_config"

endmenu # Audio Module
endmenu # Log levels
endmenu # Audio Modules
Loading
Loading