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