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 Jul 17, 2024
1 parent 8cbfd47 commit 998308d
Show file tree
Hide file tree
Showing 17 changed files with 1,978 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 @@ -69,6 +69,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 "sdfw_services/Kconfig"
Expand Down
8 changes: 8 additions & 0 deletions subsys/audio_modules/lc3/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#
# Copyright (c) 2018 Nordic Semiconductor
#
# SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
#

add_subdirectory_ifdef(CONFIG_AUDIO_MODULE_LC3_DECODER_T2 t2/decoder)
add_subdirectory_ifdef(CONFIG_SW_LC3_ENCODER_T2 t2/encoder)
132 changes: 132 additions & 0 deletions subsys/audio_modules/lc3/Kconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
#
# Copyright (c) 2023 Nordic Semiconductor ASA
#
# SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
#

menu "Audio Modules"

config AUDIO_MODULE_LC3_DECODER_T2
bool "Select the T2 software LC3 Decoder"
depends on AUDIO_MODULE

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

module = AUDIO_MODULE_LC3_DECODER_T2
module-str = lc3_decoder_t2
source "subsys/logging/Kconfig.template.log_config"

endmenu # Log levels
#----------------------------------------------------------------------------#

menu "LC3"
visible if SW_CODEC_LC3

config SW_LC3_PLC_DISABLED
bool "Skip PLC on a bad frame and fill the output buffer(s) with zeros instead"
default n
select LC3_PLC_DISABLED

config SW_LC3_BITRATE_MAX
int "Max bitrate"
default 124000

config SW_LC3_BITRATE_MIN
int "Min bitrate"
default 32000

config SW_LC3_BITRATE
int
range SW_LC3_BITRATE_MIN SW_LC3_BITRATE_MAX
default 96000

choice SW_LC3_FRAME_DURATION
prompt "Select frame duration - 7.5 ms frame duration is not tested"
default SW_LC3_FRAME_DURATION_10_MS
help
LC3 supports frame duration of 7.5 and 10 ms.
If USB is selected as audio source, we should
have a frame duration of 10 ms since USB sends 1ms at a time.

config SW_LC3_FRAME_DURATION_7_5_MS
bool "7.5 ms"

config SW_LC3_FRAME_DURATION_10_MS
bool "10 ms"
endchoice

config SW_LC3_FRAME_DURATION_US
int
default 7500 if SW_LC3_FRAME_DURATION_7_5_MS
default 10000 if SW_LC3_FRAME_DURATION_10_MS
help
Audio frame duration in µs.

choice SW_LC3_SAMPLE_RATE
prompt "Audio sample rate"
default SW_LC3_SAMPLE_RATE_16000_HZ if BT_BAP_BROADCAST_16_2_1 || BT_BAP_BROADCAST_16_2_2 || BT_BAP_UNICAST_16_2_1
default SW_LC3_SAMPLE_RATE_24000_HZ if BT_BAP_BROADCAST_24_2_1 || BT_BAP_BROADCAST_24_2_2 || BT_BAP_UNICAST_24_2_1
default SW_LC3_SAMPLE_RATE_48000_HZ
help
This will be selected based on the BAP settings.

config SW_LC3_SAMPLE_RATE_16000_HZ
bool "16 kHz"
help
Sample rate of 16kHz is currently only valid for I2S/line-in.

config SW_LC3_SAMPLE_RATE_24000_HZ
bool "24 kHz"
help
Sample rate of 24kHz is currently only valid for I2S/line-in.

config SW_LC3_SAMPLE_RATE_48000_HZ
bool "48 kHz"
help
Sample rate of 48kHz is valid for both I2S/line-in and USB.
endchoice

config SW_LC3_SAMPLE_RATE_HZ
int
default 16000 if SW_LC3_SAMPLE_RATE_16000_HZ
default 24000 if SW_LC3_SAMPLE_RATE_24000_HZ
default 48000 if SW_LC3_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 SW_LC3_BIT_DEPTH
prompt "Audio bit depth"
default SW_LC3_BIT_DEPTH_16
help
Select the bit depth for audio.

config SW_LC3_BIT_DEPTH_16
bool "16 bit audio"

config SW_LC3_BIT_DEPTH_32
bool "32 bit audio"
endchoice

config SW_LC3_BIT_DEPTH_BITS
int
default 16 if SW_LC3_BIT_DEPTH_16
default 32 if SW_LC3_BIT_DEPTH_32
help
Bit depth of one sample in storage.

config SW_LC3_BIT_DEPTH_OCTETS
int
default 2 if SW_LC3_BIT_DEPTH_16
default 4 if SW_LC3_BIT_DEPTH_32
help
Bit depth of one sample in storage given in octets.

#----------------------------------------------------------------------------#

osource "../nrfxlib/lc3/Kconfig"

endmenu # LC3
endmenu # SW Codec
endmenu # Audio
9 changes: 9 additions & 0 deletions subsys/audio_modules/lc3/t2/decoder/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#
# Copyright (c) 2023 Nordic Semiconductor
#
# SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
#

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

0 comments on commit 998308d

Please sign in to comment.