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 context 63 * @return status 64 */ 65 uint8_t (*configure)(void * context, uint32_t sample_rate, btstack_lc3_frame_duration_t frame_duration); 66 67 /** 68 * Get number of octets per LC3 frame for bitrate 69 * @param context 70 * @param bitrate 71 * @return octets_per_frame 72 */ 73 uint16_t (*get_number_octets_for_bitrate)(void * context, uint32_t bitrate); 74 75 /** 76 * Get number of samples per LC3 frame 77 * @param context 78 * @return number of samples 79 */ 80 uint16_t (*get_number_samples_per_frame)(void * context); 81 82 /** 83 * Decode LC3 Frame 84 * @param context 85 * @param bytes 86 * @param byte_count 87 * @param BFI Bad Frame Indication flags 88 * @param pcm_out buffer for decoded PCM samples 89 * @param stride count between two consecutive samples 90 * @param BEC_detect Bit Error Detected flag 91 * @return status 92 */ 93 uint8_t (*decode)(void * context, const uint8_t *bytes, uint16_t byte_count, uint8_t BFI, 94 int16_t* pcm_out, uint16_t stride, uint8_t * BEC_detect); 95 96 } btstack_lc3_decoder_t; 97 98 typedef struct { 99 /** 100 * Configure Decoder 101 * @param context 102 * @param sample_rate 103 * @param frame_duration 104 * @param context 105 * @return status 106 */ 107 uint8_t (*configure)(void * context, uint32_t sample_rate, btstack_lc3_frame_duration_t frame_duration); 108 109 /** 110 * Get bitrate from number of octets per LC3 frame 111 * @param context 112 * @param number_of_octets 113 * @return bitrate 114 */ 115 uint32_t (*get_bitrate_for_number_of_octets)(void * context, uint16_t number_of_octets); 116 117 /** 118 * Get number of samples per LC3 frame 119 * @param context 120 * @return number of samples 121 */ 122 uint16_t (*get_number_samples_per_frame)(void * context); 123 124 /** 125 * Encode LC3 Frame 126 * @param context 127 * @param pcm_in buffer for decoded PCM samples 128 * @param stride count between two consecutive samples 129 * @param bytes 130 * @param byte_count 131 * @return status 132 */ 133 uint8_t (*encode)(void * context, const int16_t* pcm_in, uint16_t stride, uint8_t *bytes, uint16_t byte_count); 134 135 } btstack_lc3_encoder_t; 136 137 /* API_END */ 138 139 #if defined __cplusplus 140 } 141 #endif 142 #endif // LC3_H 143