@@ -50,6 +50,15 @@ static struct sw_codec_config sw_codec_cfg;
50
50
static int16_t test_tone_buf [CONFIG_AUDIO_SAMPLE_RATE_HZ / 1000 ];
51
51
static size_t test_tone_size ;
52
52
53
+ static bool sample_rate_valid (uint32_t sample_rate_hz )
54
+ {
55
+ if (sample_rate_hz == 16000 || sample_rate_hz == 24000 || sample_rate_hz == 48000 ) {
56
+ return true;
57
+ }
58
+
59
+ return false;
60
+ }
61
+
53
62
static void audio_gateway_configure (void )
54
63
{
55
64
if (IS_ENABLED (CONFIG_SW_CODEC_LC3 )) {
@@ -64,12 +73,6 @@ static void audio_gateway_configure(void)
64
73
sw_codec_cfg .decoder .channel_mode = SW_CODEC_MONO ;
65
74
#endif /* (CONFIG_STREAM_BIDIRECTIONAL) */
66
75
67
- if (IS_ENABLED (CONFIG_SW_CODEC_LC3 )) {
68
- sw_codec_cfg .encoder .bitrate = CONFIG_LC3_BITRATE ;
69
- } else {
70
- ERR_CHK_MSG (- EINVAL , "No codec selected" );
71
- }
72
-
73
76
if (IS_ENABLED (CONFIG_MONO_TO_ALL_RECEIVERS )) {
74
77
sw_codec_cfg .encoder .num_ch = 1 ;
75
78
} else {
@@ -93,12 +96,6 @@ static void audio_headset_configure(void)
93
96
sw_codec_cfg .encoder .enabled = true;
94
97
sw_codec_cfg .encoder .num_ch = 1 ;
95
98
sw_codec_cfg .encoder .channel_mode = SW_CODEC_MONO ;
96
-
97
- if (IS_ENABLED (CONFIG_SW_CODEC_LC3 )) {
98
- sw_codec_cfg .encoder .bitrate = CONFIG_LC3_BITRATE ;
99
- } else {
100
- ERR_CHK_MSG (- EINVAL , "No codec selected" );
101
- }
102
99
#endif /* (CONFIG_STREAM_BIDIRECTIONAL) */
103
100
104
101
sw_codec_cfg .decoder .num_ch = 1 ;
@@ -259,6 +256,30 @@ int audio_system_encode_test_tone_step(void)
259
256
return 0 ;
260
257
}
261
258
259
+ int audio_system_config_set (uint32_t encoder_sample_rate_hz , uint32_t encoder_bitrate ,
260
+ uint32_t decoder_sample_rate_hz )
261
+ {
262
+ if (sample_rate_valid (encoder_sample_rate_hz )) {
263
+ sw_codec_cfg .encoder .sample_rate_hz = encoder_sample_rate_hz ;
264
+ } else if (encoder_sample_rate_hz ) {
265
+ LOG_ERR ("%d is not a valid sample rate" , encoder_sample_rate_hz );
266
+ return - EINVAL ;
267
+ }
268
+
269
+ if (sample_rate_valid (decoder_sample_rate_hz )) {
270
+ sw_codec_cfg .decoder .sample_rate_hz = decoder_sample_rate_hz ;
271
+ } else if (decoder_sample_rate_hz ) {
272
+ LOG_ERR ("%d is not a valid sample rate" , decoder_sample_rate_hz );
273
+ return - EINVAL ;
274
+ }
275
+
276
+ if (encoder_bitrate ) {
277
+ sw_codec_cfg .encoder .bitrate = encoder_bitrate ;
278
+ }
279
+
280
+ return 0 ;
281
+ }
282
+
262
283
/* This function is only used on gateway using USB as audio source and bidirectional stream */
263
284
int audio_system_decode (void const * const encoded_data , size_t encoded_data_size , bool bad_frame )
264
285
{
0 commit comments