Skip to content

Commit

Permalink
applications: nrf5340_audio: LC3 Decoder Audio Module
Browse files Browse the repository at this point in the history
    Implement the LC3 T2 decoder audio module.

Signed-off-by: Graham Wacey <[email protected]>
  • Loading branch information
gWacey committed Sep 3, 2024
1 parent ef3c723 commit 639fe4f
Show file tree
Hide file tree
Showing 19 changed files with 2,085 additions and 0 deletions.
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_ */
1 change: 1 addition & 0 deletions subsys/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ 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
1 change: 1 addition & 0 deletions subsys/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ 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
16 changes: 16 additions & 0 deletions subsys/audio_modules/lc3/t2/decoder/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#
# Copyright (c) 2023 Nordic Semiconductor
#
# SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
#

target_sources(app PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/lc3_decoder.c)

target_include_directories(app PRIVATE ${ZEPHYR_NRF_MODULE_DIR}/include/audio_module
${ZEPHYR_NRF_MODULE_DIR}/include/audio_modules)

zephyr_include_directories(
${ZEPHYR_BASE}/../nrfxlib/lc3/codec/inc
${ZEPHYR_BASE}/../nrfxlib/lc3/platform/os/inc
${ZEPHYR_BASE}/../nrfxlib/lc3/platform/os/baremetal/inc
)
146 changes: 146 additions & 0 deletions subsys/audio_modules/lc3/t2/decoder/Kconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
#
# Copyright (c) 2024 Nordic Semiconductor ASA
#
# SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
#

menu "Audio Modules"

config AUDIO_MODULE_T2_LC3_DECODER
bool "Enable the T2 LC3 decoder"
default y
help
Enable the T2 LC3 decoder audio module in test mode.

config AUDIO_MODULE_T2_LC3_DECODER_TEST
bool "Enable the T2 LC3 decoder"
default n
help
Enable the T2 LC3 decoder audio module in test mode.

config LC3_DEC_CHANNELS_MAX
int "Maximum audio channels"
default 2
help
The maximum audio channels the decoder can support.

choice LC3_DECODER_FRAME_DURATION
prompt "Select frame duration - 7.5 ms frame duration is not tested"
default LC3_DECODER_FRAME_DURATION_10_MS
help
LC3 supports frame duration of 7.5 and 10 ms.

config LC3_DECODER_FRAME_DURATION_7_5_MS
bool "7.5 ms"

config LC3_DECODER_FRAME_DURATION_10_MS
bool "10 ms"
endchoice

config LC3_DECODER_FRAME_DURATION_US
int
default 7500 if LC3_DECODER_FRAME_DURATION_7_5_MS
default 10000 if LC3_DECODER_FRAME_DURATION_10_MS
help
Audio frame duration in µs.

choice LC3_DECODER_SYSTEM_SAMPLE_RATE
prompt "System audio sample rate"
default LC3_DECODER_SAMPLE_RATE_48000_HZ
help
This configuration reflects the decoding sample rate.

config LC3_DECODER_SAMPLE_RATE_8000_HZ
bool "8 kHz"
help
Sample rate of 16kHz.

config LC3_DECODER_SAMPLE_RATE_16000_HZ
bool "16 kHz"
help
Sample rate of 16kHz.

config LC3_DECODER_SAMPLE_RATE_24000_HZ
bool "24 kHz"
help
Sample rate of 24kHz.

config LC3_DECODER_SAMPLE_RATE_32000_HZ
bool "32 kHz"
help
Sample rate of 16kHz.

config LC3_DECODER_SAMPLE_RATE_44100_HZ
bool "44.1 kHz"
help
Sample rate of 16kHz.

config LC3_DECODER_SAMPLE_RATE_48000_HZ
bool "48 kHz"
help
Sample rate of 48kHz.
endchoice

config LC3_DECODER_SAMPLE_RATE_HZ
int
default 8000 if LC3_DECODER_SAMPLE_RATE_8000_HZ
default 16000 if LC3_DECODER_SAMPLE_RATE_16000_HZ
default 24000 if LC3_DECODER_SAMPLE_RATE_24000_HZ
default 32000 if LC3_DECODER_SAMPLE_RATE_32000_HZ
default 44100 if LC3_DECODER_SAMPLE_RATE_44100_HZ
default 48000 if LC3_DECODER_SAMPLE_RATE_48000_HZ
help
I2S supports 16, 24, and 48 kHz sample rates for both input and output.
USB supports only 48 kHz for input.

choice LC3_DECODER_BIT_DEPTH
prompt "Audio bit depth"
default LC3_DECODER_BIT_DEPTH_16
help
Select the bit depth for audio.

config LC3_DECODER_BIT_DEPTH_16
bool "16 bit audio"

config LC3_DECODER_BIT_DEPTH_32
bool "32 bit audio"
endchoice

config LC3_DECODER_BIT_DEPTH_BITS
int
default 16 if LC3_DECODER_BIT_DEPTH_16
default 32 if LC3_DECODER_BIT_DEPTH_32
help
Bit depth of one sample in storage.

config LC3_DECODER_BIT_DEPTH_OCTETS
int
default 2 if LC3_DECODER_BIT_DEPTH_16
default 4 if LC3_DECODER_BIT_DEPTH_32
help
Bit depth of one sample in storage given in octets.

config LC3_DECODER_THREAD_PRIO
int "Priority for the decoder thread"
default 3
help
This is a preemptible thread.

config LC3_DECODER_STACK_SIZE
int "Stack size for the decoder thread"
default 4092 if LC3_DECODER_BIT_DEPTH_16
default 5115 if LC3_DECODER_BIT_DEPTH_32
help
The modules thread stack size.

osource "../nrfxlib/lc3/Kconfig"

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

module = AUDIO_MODULE_LC3_DECODER
module-str = t2_lc3_decoder
source "subsys/logging/Kconfig.template.log_config"

endmenu # Log levels
endmenu # Audio Modules
Loading

0 comments on commit 639fe4f

Please sign in to comment.