1 /* 2 * Copyright (C) 2022 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 9 * notice, this list of conditions and the following disclaimer. 10 * 2. Redistributions in binary form must reproduce the above copyright 11 * notice, this list of conditions and the following disclaimer in the 12 * documentation and/or other materials provided with the distribution. 13 * 3. Neither the name of the copyright holders nor the names of 14 * contributors may be used to endorse or promote products derived 15 * from this software without specific prior written permission. 16 * 17 * THIS SOFTWARE IS PROVIDED BY BLUEKITCHEN GMBH AND CONTRIBUTORS 18 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 19 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 20 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BLUEKITCHEN 21 * GMBH OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 22 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 23 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS 24 * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 25 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 26 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF 27 * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 28 * SUCH DAMAGE. 29 * 30 */ 31 32 /** 33 * @title LC3 Interface 34 * 35 * Interface for LC3 implementations 36 * 37 */ 38 39 #ifndef BTSTACK_LC3_H 40 #define BTSTACK_LC3_H 41 42 #include <stdint.h> 43 44 #if defined __cplusplus 45 extern "C" { 46 #endif 47 48 /* API_START */ 49 50 typedef enum { 51 BTSTACK_LC3_FRAME_DURATION_10000US, 52 BTSTACK_LC3_FRAME_DURATION_7500US 53 } btstack_lc3_frame_duration_t; 54 55 typedef struct { 56 57 /** 58 * Configure Decoder 59 * @param context 60 * @param sample_rate 61 * @param frame_duration 62 * @param octets_per_frame 63 * @return status 64 */ 65 uint8_t (*configure)(void * context, uint32_t sample_rate, btstack_lc3_frame_duration_t frame_duration, uint16_t octets_per_frame); 66 67 /** 68 * Decode LC3 Frame into signed 16-bit samples 69 * @param context 70 * @param bytes 71 * @param BFI Bad Frame Indication flags 72 * @param pcm_out buffer for decoded PCM samples 73 * @param stride count between two consecutive samples 74 * @param BEC_detect Bit Error Detected flag 75 * @return status 76 */ 77 uint8_t (*decode_signed_16)(void * context, const uint8_t *bytes, uint8_t BFI, 78 int16_t* pcm_out, uint16_t stride, uint8_t * BEC_detect); 79 80 /** 81 * Decode LC3 Frame into signed 24-bit samples, sign-extended to 32-bit 82 * @param context 83 * @param bytes 84 * @param BFI Bad Frame Indication flags 85 * @param pcm_out buffer for decoded PCM samples 86 * @param stride count between two consecutive samples 87 * @param BEC_detect Bit Error Detected flag 88 * @return status 89 */ 90 uint8_t (*decode_signed_24)(void * context, const uint8_t *bytes, uint8_t BFI, 91 int32_t* pcm_out, uint16_t stride, uint8_t * BEC_detect); 92 93 } btstack_lc3_decoder_t; 94 95 typedef struct { 96 /** 97 * Configure Decoder 98 * @param context 99 * @param sample_rate 100 * @param frame_duration 101 * @param octets_per_frame 102 * @return status 103 */ 104 uint8_t (*configure)(void * context, uint32_t sample_rate, btstack_lc3_frame_duration_t frame_duration, uint16_t octets_per_frame); 105 106 /** 107 * Encode LC3 Frame with 16-bit signed PCM samples 108 * @param context 109 * @param pcm_in buffer for decoded PCM samples 110 * @param stride count between two consecutive samples 111 * @param bytes 112 * @return status 113 */ 114 uint8_t (*encode_signed_16)(void * context, const int16_t* pcm_in, uint16_t stride, uint8_t *bytes); 115 116 /** 117 * Encode LC3 Frame with 24-bit signed PCM samples, sign-extended to 32 bit 118 * @param context 119 * @param pcm_in buffer for decoded PCM samples 120 * @param stride count between two consecutive samples 121 * @param bytes 122 * @return status 123 */ 124 uint8_t (*encode_signed_24)(void * context, const int32_t* pcm_in, uint16_t stride, uint8_t *bytes); 125 126 } btstack_lc3_encoder_t; 127 128 /** 129 * @brief Map enum to ISO Interval in us 130 * @param frame_duration enum 131 * @return frame_duratoin in us or 0 for invalid frame_duration enum 132 */ 133 uint16_t btstack_lc3_frame_duration_in_us(btstack_lc3_frame_duration_t frame_duration); 134 135 /** 136 * @bbrief Calculate number of samples per ISO Interval 137 * @param sample_rate 138 * @param frame_duration 139 * @return 140 */ 141 uint16_t btstack_lc3_samples_per_frame(uint32_t sample_rate, btstack_lc3_frame_duration_t frame_duration); 142 143 /* API_END */ 144 145 #if defined __cplusplus 146 } 147 #endif 148 #endif // LC3_H 149