Skip to content

Commit d4bbb84

Browse files
Bluetooth: Audio: Shell: Add SBC encoded audio
Add code to use shell application to test A2DP profile with option to use SBC encoded audio. Add sine tone audio file which will be used to render to encoded audio A2DP sink device. There is an kconfig option to enable/disable encoded audio support Signed-off-by: Vinit Mehta <vinit.mehta@nxp.com>
1 parent 0ffef90 commit d4bbb84

File tree

11 files changed

+790
-27
lines changed

11 files changed

+790
-27
lines changed

include/zephyr/bluetooth/classic/a2dp_codec_sbc.h

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,14 @@ struct bt_a2dp_codec_sbc_params {
111111
*/
112112
uint8_t bt_a2dp_sbc_get_channel_num(struct bt_a2dp_codec_sbc_params *sbc_codec);
113113

114+
/** @brief get channel mode of a2dp sbc config.
115+
*
116+
* @param sbc_codec The a2dp sbc parameter.
117+
*
118+
* @return the channel mode.
119+
*/
120+
enum sbc_ch_mode bt_a2dp_sbc_get_channel_mode(struct bt_a2dp_codec_sbc_params *sbc_codec);
121+
114122
/** @brief get sample rate of a2dp sbc config.
115123
*
116124
* @param sbc_codec The a2dp sbc parameter.
@@ -119,6 +127,30 @@ uint8_t bt_a2dp_sbc_get_channel_num(struct bt_a2dp_codec_sbc_params *sbc_codec);
119127
*/
120128
uint32_t bt_a2dp_sbc_get_sampling_frequency(struct bt_a2dp_codec_sbc_params *sbc_codec);
121129

130+
/** @brief get subband num of a2dp sbc config.
131+
*
132+
* @param sbc_codec The a2dp sbc parameter.
133+
*
134+
* @return the subband num.
135+
*/
136+
uint8_t bt_a2dp_sbc_get_subband_num(struct bt_a2dp_codec_sbc_params *sbc_codec);
137+
138+
/** @brief get block length of a2dp sbc config.
139+
*
140+
* @param sbc_codec The a2dp sbc parameter.
141+
*
142+
* @return the block length.
143+
*/
144+
uint8_t bt_a2dp_sbc_get_block_length(struct bt_a2dp_codec_sbc_params *sbc_codec);
145+
146+
/** @brief get allocation method of a2dp sbc config.
147+
*
148+
* @param sbc_codec The a2dp sbc parameter.
149+
*
150+
* @return the allocation method.
151+
*/
152+
enum sbc_alloc_mthd bt_a2dp_sbc_get_allocation_method(struct bt_a2dp_codec_sbc_params *sbc_codec);
153+
122154
#ifdef __cplusplus
123155
}
124156
#endif

include/zephyr/libsbc/sbc.h renamed to include/zephyr/bluetooth/sbc.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include <stdint.h>
1111
#include <stdbool.h>
1212
#include <string.h>
13+
#include <zephyr/toolchain.h>
1314
#include "sbc_encoder.h"
1415
#include "oi_codec_sbc.h"
1516
#include "oi_status.h"

modules/libsbc/CMakeLists.txt

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
1-
if(CONFIG_LIBSBC_ENCODER OR CONFIG_LIBSBC_DECODER)
1+
if(CONFIG_LIBSBC)
22

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

66
zephyr_compile_definitions(SBC_FOR_EMBEDDED_LINUX)
77
zephyr_compile_definitions(SBC_NO_PCM_CPY_OPTION)
8-
zephyr_library_sources(sbc.c)
98

109
zephyr_include_directories(
1110
${ZEPHYR_LIBSBC_MODULE_DIR}/encoder/include
@@ -16,7 +15,6 @@ zephyr_include_directories(
1615
${ZEPHYR_LIBSBC_MODULE_DIR}/decoder/srce
1716
)
1817

19-
if(CONFIG_LIBSBC_ENCODER)
2018
zephyr_library_sources(
2119
${ZEPHYR_LIBSBC_MODULE_DIR}/encoder/srce/sbc_analysis.c
2220
${ZEPHYR_LIBSBC_MODULE_DIR}/encoder/srce/sbc_dct.c
@@ -27,9 +25,7 @@ zephyr_library_sources(
2725
${ZEPHYR_LIBSBC_MODULE_DIR}/encoder/srce/sbc_encoder.c
2826
${ZEPHYR_LIBSBC_MODULE_DIR}/encoder/srce/sbc_packing.c
2927
)
30-
endif()
3128

32-
if(CONFIG_LIBSBC_DECODER)
3329
zephyr_library_sources(
3430
${ZEPHYR_LIBSBC_MODULE_DIR}/decoder/srce/alloc.c
3531
${ZEPHYR_LIBSBC_MODULE_DIR}/decoder/srce/bitalloc.c
@@ -47,5 +43,4 @@ zephyr_library_sources(
4743
${ZEPHYR_LIBSBC_MODULE_DIR}/decoder/srce/synthesis-dct8.c
4844
${ZEPHYR_LIBSBC_MODULE_DIR}/decoder/srce/synthesis-sbc.c
4945
)
50-
endif()
51-
endif()
46+
endif()

modules/libsbc/Kconfig

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,7 @@
44
config ZEPHYR_LIBSBC_MODULE
55
bool
66

7-
config LIBSBC_ENCODER
8-
bool "libsbc encoder Support"
7+
config LIBSBC
8+
bool "libsbc Support"
99
help
10-
This option enables the Android SBC encoder library for Bluetooth A2DP
11-
12-
config LIBSBC_DECODER
13-
bool "libsbc decoder Support"
14-
help
15-
This option enables the Android SBC decoder library for Bluetooth A2DP
10+
This option enables Low Complexity Subband Codec (SBC)

subsys/bluetooth/host/classic/Kconfig

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -444,6 +444,7 @@ config BT_AVDTP
444444
config BT_A2DP
445445
bool "Bluetooth A2DP Profile [EXPERIMENTAL]"
446446
select BT_AVDTP
447+
imply LIBSBC
447448
select EXPERIMENTAL
448449
help
449450
This option enables the A2DP profile
@@ -478,6 +479,26 @@ config BT_A2DP_SINK
478479
help
479480
This option enables the A2DP profile sink function
480481

482+
config BT_A2DP_SOURCE_DISCOVER_RESULT_COUNT
483+
int "Maximum result count per device discovery"
484+
default 10
485+
486+
config BT_A2DP_SOURCE_EPS_DISCOVER_COUNT
487+
int "Maximum result count per a2dp endpoint discovery"
488+
default 10
489+
490+
config BT_A2DP_SOURCE_SBC_BIT_RATE_DEFAULT
491+
int "default sbc bit rate"
492+
default 229
493+
494+
config BT_A2DP_SOURCE_DATA_SEND_INTERVAL
495+
int "data send interval (ms)"
496+
default 20
497+
498+
config BT_A2DP_SOURCE_DATA_BUF_SIZE
499+
int "data buffer size (bytes)"
500+
default 1000
501+
481502
endif # BT_A2DP
482503

483504
config BT_AVCTP
@@ -617,6 +638,15 @@ config BT_OEBX_RSP_CODE_TO_STR
617638

618639
endif # BT_GOEP
619640

641+
config BT_A2DP_SOURCE_SBC_AUDIO_SHELL
642+
bool "A2DP Source SBC Audio Shell Support"
643+
depends on BT_A2DP_SOURCE && SHELL
644+
default n
645+
help
646+
Enable A2DP source SBC audio encoding and playback functionality
647+
in the shell. This includes SBC encoder support, audio streaming,
648+
and related shell commands for testing A2DP source functionality.
649+
620650
endif # BT_CLASSIC
621651

622652
endmenu

subsys/bluetooth/host/classic/a2dp_codec_sbc.c

Lines changed: 59 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
#include <zephyr/bluetooth/classic/a2dp_codec_sbc.h>
1616
#include <zephyr/bluetooth/classic/a2dp.h>
17-
17+
#include <zephyr/bluetooth/sbc.h>
1818

1919
uint8_t bt_a2dp_sbc_get_channel_num(struct bt_a2dp_codec_sbc_params *sbc_codec)
2020
{
@@ -33,6 +33,23 @@ uint8_t bt_a2dp_sbc_get_channel_num(struct bt_a2dp_codec_sbc_params *sbc_codec)
3333
}
3434
}
3535

36+
enum sbc_ch_mode bt_a2dp_sbc_get_channel_mode(struct bt_a2dp_codec_sbc_params *sbc_codec)
37+
{
38+
__ASSERT_NO_MSG(sbc_codec != NULL);
39+
40+
if (sbc_codec->config[0] & A2DP_SBC_CH_MODE_MONO) {
41+
return SBC_CH_MODE_MONO;
42+
} else if (sbc_codec->config[0] & A2DP_SBC_CH_MODE_DUAL) {
43+
return SBC_CH_MODE_DUAL_CHANNEL;
44+
} else if (sbc_codec->config[0] & A2DP_SBC_CH_MODE_STEREO) {
45+
return SBC_CH_MODE_STEREO;
46+
} else if (sbc_codec->config[0] & A2DP_SBC_CH_MODE_JOINT) {
47+
return SBC_CH_MODE_JOINT_STEREO;
48+
} else {
49+
return SBC_CH_MODE_MONO;
50+
}
51+
}
52+
3653
uint32_t bt_a2dp_sbc_get_sampling_frequency(struct bt_a2dp_codec_sbc_params *sbc_codec)
3754
{
3855
__ASSERT_NO_MSG(sbc_codec != NULL);
@@ -49,3 +66,44 @@ uint32_t bt_a2dp_sbc_get_sampling_frequency(struct bt_a2dp_codec_sbc_params *sbc
4966
return 0U;
5067
}
5168
}
69+
70+
uint8_t bt_a2dp_sbc_get_subband_num(struct bt_a2dp_codec_sbc_params *sbc_codec)
71+
{
72+
__ASSERT_NO_MSG(sbc_codec != NULL);
73+
74+
if (sbc_codec->config[1] & A2DP_SBC_SUBBAND_4) {
75+
return 4U;
76+
} else if (sbc_codec->config[1] & A2DP_SBC_SUBBAND_8) {
77+
return 8U;
78+
} else {
79+
return 0U;
80+
}
81+
}
82+
83+
uint8_t bt_a2dp_sbc_get_block_length(struct bt_a2dp_codec_sbc_params *sbc_codec)
84+
{
85+
__ASSERT_NO_MSG(sbc_codec != NULL);
86+
87+
if (sbc_codec->config[1] & A2DP_SBC_BLK_LEN_4) {
88+
return 4U;
89+
} else if (sbc_codec->config[1] & A2DP_SBC_BLK_LEN_8) {
90+
return 8U;
91+
} else if (sbc_codec->config[1] & A2DP_SBC_BLK_LEN_12) {
92+
return 12U;
93+
} else if (sbc_codec->config[1] & A2DP_SBC_BLK_LEN_16) {
94+
return 16U;
95+
} else {
96+
return 0U;
97+
}
98+
}
99+
100+
enum sbc_alloc_mthd bt_a2dp_sbc_get_allocation_method(struct bt_a2dp_codec_sbc_params *sbc_codec)
101+
{
102+
__ASSERT_NO_MSG(sbc_codec != NULL);
103+
104+
if (sbc_codec->config[1] & A2DP_SBC_ALLOC_MTHD_SNR) {
105+
return SBC_ALLOC_MTHD_SNR;
106+
} else {
107+
return SBC_ALLOC_MTHD_LOUDNESS;
108+
}
109+
}

0 commit comments

Comments
 (0)