@@ -187,6 +187,17 @@ int sw_codec_lc3_dec_uninit_all(void)
187187 return 0 ;
188188}
189189
190+ int sw_codec_lc3_uninit (void )
191+ {
192+ int ret ;
193+ ret = LC3Deinitialize ();
194+ if (ret ) {
195+ LOG_ERR ("Failed to uninitialize LC3 Codec: %d" , ret );
196+ return - EIO ;
197+ }
198+ return 0 ;
199+ }
200+
190201int sw_codec_lc3_init (uint8_t * sw_codec_lc3_buffer , uint32_t * sw_codec_lc3_buffer_size ,
191202 uint16_t framesize_us )
192203{
@@ -260,6 +271,93 @@ int sw_codec_lc3_init(uint8_t *sw_codec_lc3_buffer, uint32_t *sw_codec_lc3_buffe
260271 return ret ;
261272}
262273
274+ static uint8_t enc_sample_rate_hz_to_bit (uint16_t sample_rate )
275+ {
276+ switch (sample_rate ) {
277+ case 8000 :
278+ return IS_ENABLED (CONFIG_LC3_ENC_SAMPLE_RATE_8KHZ_SUPPORT ) ? LC3_SAMPLE_RATE_8_KHZ : 0 ;
279+ case 16000 :
280+ return IS_ENABLED (CONFIG_LC3_ENC_SAMPLE_RATE_16KHZ_SUPPORT ) ? LC3_SAMPLE_RATE_16_KHZ : 0 ;
281+ case 24000 :
282+ return IS_ENABLED (CONFIG_LC3_ENC_SAMPLE_RATE_24KHZ_SUPPORT ) ? LC3_SAMPLE_RATE_24_KHZ : 0 ;
283+ case 32000 :
284+ return IS_ENABLED (CONFIG_LC3_ENC_SAMPLE_RATE_32KHZ_SUPPORT ) ? LC3_SAMPLE_RATE_32_KHZ : 0 ;
285+ case 44100 :
286+ return IS_ENABLED (CONFIG_LC3_ENC_SAMPLE_RATE_441KHZ_SUPPORT ) ? LC3_SAMPLE_RATE_441_KHZ : 0 ;
287+ case 48000 :
288+ return IS_ENABLED (CONFIG_LC3_ENC_SAMPLE_RATE_48KHZ_SUPPORT ) ? LC3_SAMPLE_RATE_48_KHZ : 0 ;
289+ default :
290+ return 0 ;
291+ }
292+ }
293+
294+ static uint8_t dec_sample_rate_hz_to_bit (uint16_t sample_rate )
295+ {
296+ switch (sample_rate ) {
297+ case 8000 :
298+ return IS_ENABLED (CONFIG_LC3_DEC_SAMPLE_RATE_8KHZ_SUPPORT ) ? LC3_SAMPLE_RATE_8_KHZ : 0 ;
299+ case 16000 :
300+ return IS_ENABLED (CONFIG_LC3_DEC_SAMPLE_RATE_16KHZ_SUPPORT ) ? LC3_SAMPLE_RATE_16_KHZ : 0 ;
301+ case 24000 :
302+ return IS_ENABLED (CONFIG_LC3_DEC_SAMPLE_RATE_24KHZ_SUPPORT ) ? LC3_SAMPLE_RATE_24_KHZ : 0 ;
303+ case 32000 :
304+ return IS_ENABLED (CONFIG_LC3_DEC_SAMPLE_RATE_32KHZ_SUPPORT ) ? LC3_SAMPLE_RATE_32_KHZ : 0 ;
305+ case 44100 :
306+ return IS_ENABLED (CONFIG_LC3_DEC_SAMPLE_RATE_441KHZ_SUPPORT ) ? LC3_SAMPLE_RATE_441_KHZ : 0 ;
307+ case 48000 :
308+ return IS_ENABLED (CONFIG_LC3_DEC_SAMPLE_RATE_48KHZ_SUPPORT ) ? LC3_SAMPLE_RATE_48_KHZ : 0 ;
309+ default :
310+ return 0 ;
311+ }
312+ }
313+
314+ int sw_codec_lc3_single_rate_init (uint16_t encoder_sample_rate , uint16_t decoder_sample_rate ,
315+ uint8_t * sw_codec_lc3_buffer ,
316+ uint32_t * sw_codec_lc3_buffer_size ,
317+ uint16_t framesize_us )
318+ {
319+ int ret ;
320+ uint8_t enc_sample_rate_bit ;
321+ uint8_t dec_sample_rate_bit ;
322+
323+ /* Set unique session to 0 for using the default sharing memory setting.
324+ *
325+ * This could lead to higher heap consumption, but is able to manipulate
326+ * different sample rate setting between encoder/decoder.
327+ */
328+ uint8_t unique_session = 0 ;
329+
330+ enc_sample_rate_bit = enc_sample_rate_hz_to_bit (encoder_sample_rate );
331+ if (enc_sample_rate_bit == 0 && encoder_sample_rate != 0 ) {
332+ LOG_ERR ("Unsupported encoder sample rate: %d" , encoder_sample_rate );
333+ return - EINVAL ;
334+ }
335+
336+ dec_sample_rate_bit = dec_sample_rate_hz_to_bit (decoder_sample_rate );
337+ if (dec_sample_rate_bit == 0 && decoder_sample_rate != 0 ) {
338+ LOG_ERR ("Unsupported decoder sample rate: %d" , decoder_sample_rate );
339+ return - EINVAL ;
340+ }
341+
342+ LC3FrameSizeConfig_t framesize ;
343+
344+ switch (framesize_us ) {
345+ case 7500 :
346+ framesize = LC3FrameSize7_5MsConfig ;
347+ break ;
348+ case 10000 :
349+ framesize = LC3FrameSize10MsConfig ;
350+ break ;
351+ default :
352+ LOG_ERR ("Unsupported framesize: %d" , framesize_us );
353+ return - EINVAL ;
354+ }
355+
356+ ret = LC3Initialize (enc_sample_rate_bit , dec_sample_rate_bit , framesize , unique_session ,
357+ sw_codec_lc3_buffer , sw_codec_lc3_buffer_size );
358+ return ret ;
359+ }
360+
263361int sw_codec_lc3_enc_init (uint16_t pcm_sample_rate , uint8_t pcm_bit_depth , uint16_t framesize_us ,
264362 uint32_t enc_bitrate , uint8_t num_channels , uint16_t * const pcm_bytes_req )
265363{
0 commit comments