Skip to content
Draft
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
32 changes: 32 additions & 0 deletions include/zephyr/bluetooth/classic/a2dp_codec_sbc.h
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,14 @@ struct bt_a2dp_codec_sbc_params {
*/
uint8_t bt_a2dp_sbc_get_channel_num(struct bt_a2dp_codec_sbc_params *sbc_codec);

/** @brief get channel mode of a2dp sbc config.
*
* @param sbc_codec The a2dp sbc parameter.
*
* @return the channel mode.
*/
enum sbc_ch_mode bt_a2dp_sbc_get_channel_mode(struct bt_a2dp_codec_sbc_params *sbc_codec);

/** @brief get sample rate of a2dp sbc config.
*
* @param sbc_codec The a2dp sbc parameter.
Expand All @@ -119,6 +127,30 @@ uint8_t bt_a2dp_sbc_get_channel_num(struct bt_a2dp_codec_sbc_params *sbc_codec);
*/
uint32_t bt_a2dp_sbc_get_sampling_frequency(struct bt_a2dp_codec_sbc_params *sbc_codec);

/** @brief get subband num of a2dp sbc config.
*
* @param sbc_codec The a2dp sbc parameter.
*
* @return the subband num.
*/
uint8_t bt_a2dp_sbc_get_subband_num(struct bt_a2dp_codec_sbc_params *sbc_codec);

/** @brief get block length of a2dp sbc config.
*
* @param sbc_codec The a2dp sbc parameter.
*
* @return the block length.
*/
uint8_t bt_a2dp_sbc_get_block_length(struct bt_a2dp_codec_sbc_params *sbc_codec);

/** @brief get allocation method of a2dp sbc config.
*
* @param sbc_codec The a2dp sbc parameter.
*
* @return the allocation method.
*/
enum sbc_alloc_mthd bt_a2dp_sbc_get_allocation_method(struct bt_a2dp_codec_sbc_params *sbc_codec);

#ifdef __cplusplus
}
#endif
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include <stdint.h>
#include <stdbool.h>
#include <string.h>
#include <zephyr/toolchain.h>
#include "sbc_encoder.h"
#include "oi_codec_sbc.h"
#include "oi_status.h"
Expand Down
9 changes: 2 additions & 7 deletions modules/libsbc/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
if(CONFIG_LIBSBC_ENCODER OR CONFIG_LIBSBC_DECODER)
if(CONFIG_LIBSBC)

zephyr_library_named(libsbc)
zephyr_library_compile_options(-O3 -std=c11 -ffast-math -Wno-array-bounds)
zephyr_library_compile_options(-O3 -std=c11 -ffast-math -Wno-stringop-overflow)

zephyr_compile_definitions(SBC_FOR_EMBEDDED_LINUX)
zephyr_compile_definitions(SBC_NO_PCM_CPY_OPTION)
zephyr_library_sources(sbc.c)

zephyr_include_directories(
${ZEPHYR_LIBSBC_MODULE_DIR}/encoder/include
Expand All @@ -16,7 +15,6 @@ zephyr_include_directories(
${ZEPHYR_LIBSBC_MODULE_DIR}/decoder/srce
)

if(CONFIG_LIBSBC_ENCODER)
zephyr_library_sources(
${ZEPHYR_LIBSBC_MODULE_DIR}/encoder/srce/sbc_analysis.c
${ZEPHYR_LIBSBC_MODULE_DIR}/encoder/srce/sbc_dct.c
Expand All @@ -27,9 +25,7 @@ zephyr_library_sources(
${ZEPHYR_LIBSBC_MODULE_DIR}/encoder/srce/sbc_encoder.c
${ZEPHYR_LIBSBC_MODULE_DIR}/encoder/srce/sbc_packing.c
)
endif()

if(CONFIG_LIBSBC_DECODER)
zephyr_library_sources(
${ZEPHYR_LIBSBC_MODULE_DIR}/decoder/srce/alloc.c
${ZEPHYR_LIBSBC_MODULE_DIR}/decoder/srce/bitalloc.c
Expand All @@ -48,4 +44,3 @@ zephyr_library_sources(
${ZEPHYR_LIBSBC_MODULE_DIR}/decoder/srce/synthesis-sbc.c
)
endif()
endif()
11 changes: 3 additions & 8 deletions modules/libsbc/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,7 @@
config ZEPHYR_LIBSBC_MODULE
bool

config LIBSBC_ENCODER
bool "libsbc encoder Support"
config LIBSBC
bool "libsbc Support"
help
This option enables the Android SBC encoder library for Bluetooth A2DP

config LIBSBC_DECODER
bool "libsbc decoder Support"
help
This option enables the Android SBC decoder library for Bluetooth A2DP
This option enables Low Complexity Subband Codec (SBC)
30 changes: 30 additions & 0 deletions subsys/bluetooth/host/classic/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -444,6 +444,7 @@ config BT_AVDTP
config BT_A2DP
bool "Bluetooth A2DP Profile [EXPERIMENTAL]"
select BT_AVDTP
imply LIBSBC
select EXPERIMENTAL
help
This option enables the A2DP profile
Expand Down Expand Up @@ -478,6 +479,26 @@ config BT_A2DP_SINK
help
This option enables the A2DP profile sink function

config BT_A2DP_SOURCE_DISCOVER_RESULT_COUNT
int "Maximum result count per device discovery"
default 10

config BT_A2DP_SOURCE_EPS_DISCOVER_COUNT
int "Maximum result count per a2dp endpoint discovery"
default 10

config BT_A2DP_SOURCE_SBC_BIT_RATE_DEFAULT
int "default sbc bit rate"
default 229

config BT_A2DP_SOURCE_DATA_SEND_INTERVAL
int "data send interval (ms)"
default 20

config BT_A2DP_SOURCE_DATA_BUF_SIZE
int "data buffer size (bytes)"
default 1000

endif # BT_A2DP

config BT_AVCTP
Expand Down Expand Up @@ -617,6 +638,15 @@ config BT_OEBX_RSP_CODE_TO_STR

endif # BT_GOEP

config BT_A2DP_SOURCE_SBC_AUDIO_SHELL
bool "A2DP Source SBC Audio Shell Support"
depends on BT_A2DP_SOURCE && SHELL
default n
help
Enable A2DP source SBC audio encoding and playback functionality
in the shell. This includes SBC encoder support, audio streaming,
and related shell commands for testing A2DP source functionality.

endif # BT_CLASSIC

endmenu
60 changes: 59 additions & 1 deletion subsys/bluetooth/host/classic/a2dp_codec_sbc.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

#include <zephyr/bluetooth/classic/a2dp_codec_sbc.h>
#include <zephyr/bluetooth/classic/a2dp.h>

#include <zephyr/bluetooth/sbc.h>

uint8_t bt_a2dp_sbc_get_channel_num(struct bt_a2dp_codec_sbc_params *sbc_codec)
{
Expand All @@ -33,6 +33,23 @@ uint8_t bt_a2dp_sbc_get_channel_num(struct bt_a2dp_codec_sbc_params *sbc_codec)
}
}

enum sbc_ch_mode bt_a2dp_sbc_get_channel_mode(struct bt_a2dp_codec_sbc_params *sbc_codec)
{
__ASSERT_NO_MSG(sbc_codec != NULL);

if (sbc_codec->config[0] & A2DP_SBC_CH_MODE_MONO) {
return SBC_CH_MODE_MONO;
} else if (sbc_codec->config[0] & A2DP_SBC_CH_MODE_DUAL) {
return SBC_CH_MODE_DUAL_CHANNEL;
} else if (sbc_codec->config[0] & A2DP_SBC_CH_MODE_STEREO) {
return SBC_CH_MODE_STEREO;
} else if (sbc_codec->config[0] & A2DP_SBC_CH_MODE_JOINT) {
return SBC_CH_MODE_JOINT_STEREO;
} else {
return SBC_CH_MODE_MONO;
}
}

uint32_t bt_a2dp_sbc_get_sampling_frequency(struct bt_a2dp_codec_sbc_params *sbc_codec)
{
__ASSERT_NO_MSG(sbc_codec != NULL);
Expand All @@ -49,3 +66,44 @@ uint32_t bt_a2dp_sbc_get_sampling_frequency(struct bt_a2dp_codec_sbc_params *sbc
return 0U;
}
}

uint8_t bt_a2dp_sbc_get_subband_num(struct bt_a2dp_codec_sbc_params *sbc_codec)
{
__ASSERT_NO_MSG(sbc_codec != NULL);

if (sbc_codec->config[1] & A2DP_SBC_SUBBAND_4) {
return 4U;
} else if (sbc_codec->config[1] & A2DP_SBC_SUBBAND_8) {
return 8U;
} else {
return 0U;
}
}

uint8_t bt_a2dp_sbc_get_block_length(struct bt_a2dp_codec_sbc_params *sbc_codec)
{
__ASSERT_NO_MSG(sbc_codec != NULL);

if (sbc_codec->config[1] & A2DP_SBC_BLK_LEN_4) {
return 4U;
} else if (sbc_codec->config[1] & A2DP_SBC_BLK_LEN_8) {
return 8U;
} else if (sbc_codec->config[1] & A2DP_SBC_BLK_LEN_12) {
return 12U;
} else if (sbc_codec->config[1] & A2DP_SBC_BLK_LEN_16) {
return 16U;
} else {
return 0U;
}
}

enum sbc_alloc_mthd bt_a2dp_sbc_get_allocation_method(struct bt_a2dp_codec_sbc_params *sbc_codec)
{
__ASSERT_NO_MSG(sbc_codec != NULL);

if (sbc_codec->config[1] & A2DP_SBC_ALLOC_MTHD_SNR) {
return SBC_ALLOC_MTHD_SNR;
} else {
return SBC_ALLOC_MTHD_LOUDNESS;
}
}
Loading