Skip to content

Commit d75b95e

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 d75b95e

File tree

6 files changed

+776
-5
lines changed

6 files changed

+776
-5
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

subsys/bluetooth/host/classic/Kconfig

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -478,6 +478,25 @@ config BT_A2DP_SINK
478478
help
479479
This option enables the A2DP profile sink function
480480

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

483502
config BT_AVCTP
@@ -617,6 +636,15 @@ config BT_OEBX_RSP_CODE_TO_STR
617636

618637
endif # BT_GOEP
619638

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

622650
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/libsbc/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)