hfp_codec.c (759481344a7bcec120864fddd1e20ef1ccb99ff1) | hfp_codec.c (f0d1308510b802e387477715d74ec3ad1f42180a) |
---|---|
1/* 2 * Copyright (C) 2023 BlueKitchen GmbH 3 * 4 * Redistribution and use in source and binary forms, with or without 5 * modification, are permitted provided that the following conditions 6 * are met: 7 * 8 * 1. Redistributions of source code must retain the above copyright --- 99 unchanged lines hidden (view full) --- 108 memset(hfp_codec, 0, sizeof(hfp_codec_t)); 109 hfp_h2_framing_init(&hfp_codec->h2_framing); 110 hfp_codec_reset_sco_buffer(hfp_codec); 111 hfp_codec->samples_per_frame = 240; 112 hfp_codec->encode = &hfp_codec_encode_lc3swb; 113 // init lc3 encoder 114 hfp_codec->lc3_encoder = lc3_encoder; 115 hfp_codec->lc3_encoder_context = lc3_encoder_context; | 1/* 2 * Copyright (C) 2023 BlueKitchen GmbH 3 * 4 * Redistribution and use in source and binary forms, with or without 5 * modification, are permitted provided that the following conditions 6 * are met: 7 * 8 * 1. Redistributions of source code must retain the above copyright --- 99 unchanged lines hidden (view full) --- 108 memset(hfp_codec, 0, sizeof(hfp_codec_t)); 109 hfp_h2_framing_init(&hfp_codec->h2_framing); 110 hfp_codec_reset_sco_buffer(hfp_codec); 111 hfp_codec->samples_per_frame = 240; 112 hfp_codec->encode = &hfp_codec_encode_lc3swb; 113 // init lc3 encoder 114 hfp_codec->lc3_encoder = lc3_encoder; 115 hfp_codec->lc3_encoder_context = lc3_encoder_context; |
116 hfp_codec->lc3_encoder->configure(&hfp_codec->lc3_encoder_context, 32000, BTSTACK_LC3_FRAME_DURATION_7500US, LC3_SWB_OCTETS_PER_FRAME); | 116 hfp_codec->lc3_encoder->configure(hfp_codec->lc3_encoder_context, 32000, BTSTACK_LC3_FRAME_DURATION_7500US, LC3_SWB_OCTETS_PER_FRAME); |
117} 118#endif 119 120bool hfp_codec_can_encode_audio_frame_now(const hfp_codec_t * hfp_codec){ 121 return hfp_codec->write_pos <= SCO_FRAME_SIZE; 122} 123 124uint16_t hfp_codec_num_audio_samples_per_frame(const hfp_codec_t * hfp_codec){ --- 9 unchanged lines hidden (view full) --- 134 // Final padding to use SCO_FRAME_SIZE bytes 135 hfp_codec->sco_packet[hfp_codec->write_pos++] = 0; 136} 137#endif 138 139#ifdef ENABLE_HFP_SUPER_WIDE_BAND_SPEECH 140static void hfp_codec_encode_lc3swb(hfp_codec_t * hfp_codec, int16_t * pcm_samples){ 141 // Encode LC3 Frame | 117} 118#endif 119 120bool hfp_codec_can_encode_audio_frame_now(const hfp_codec_t * hfp_codec){ 121 return hfp_codec->write_pos <= SCO_FRAME_SIZE; 122} 123 124uint16_t hfp_codec_num_audio_samples_per_frame(const hfp_codec_t * hfp_codec){ --- 9 unchanged lines hidden (view full) --- 134 // Final padding to use SCO_FRAME_SIZE bytes 135 hfp_codec->sco_packet[hfp_codec->write_pos++] = 0; 136} 137#endif 138 139#ifdef ENABLE_HFP_SUPER_WIDE_BAND_SPEECH 140static void hfp_codec_encode_lc3swb(hfp_codec_t * hfp_codec, int16_t * pcm_samples){ 141 // Encode LC3 Frame |
142 hfp_codec->lc3_encoder->encode_signed_16(&hfp_codec->lc3_encoder_context, pcm_samples, 1, &hfp_codec->sco_packet[hfp_codec->write_pos]); | 142 hfp_codec->lc3_encoder->encode_signed_16(hfp_codec->lc3_encoder_context, pcm_samples, 1, &hfp_codec->sco_packet[hfp_codec->write_pos]); |
143 hfp_codec->write_pos += LC3_SWB_OCTETS_PER_FRAME; 144} 145#endif 146 147void hfp_codec_encode_audio_frame(hfp_codec_t * hfp_codec, int16_t * pcm_samples){ 148 btstack_assert(hfp_codec_can_encode_audio_frame_now(hfp_codec)); 149 // Synchronization Header H2 150 hfp_h2_framing_add_header(&hfp_codec->h2_framing, &hfp_codec->sco_packet[hfp_codec->write_pos]); --- 41 unchanged lines hidden --- | 143 hfp_codec->write_pos += LC3_SWB_OCTETS_PER_FRAME; 144} 145#endif 146 147void hfp_codec_encode_audio_frame(hfp_codec_t * hfp_codec, int16_t * pcm_samples){ 148 btstack_assert(hfp_codec_can_encode_audio_frame_now(hfp_codec)); 149 // Synchronization Header H2 150 hfp_h2_framing_add_header(&hfp_codec->h2_framing, &hfp_codec->sco_packet[hfp_codec->write_pos]); --- 41 unchanged lines hidden --- |