xref: /btstack/src/btstack_audio.h (revision e39d945b26cebddb2e28a3ae932371da73f658f1)
123a1bbc3SMatthias Ringwald /*
223a1bbc3SMatthias Ringwald  * Copyright (C) 2017 BlueKitchen GmbH
323a1bbc3SMatthias Ringwald  *
423a1bbc3SMatthias Ringwald  * Redistribution and use in source and binary forms, with or without
523a1bbc3SMatthias Ringwald  * modification, are permitted provided that the following conditions
623a1bbc3SMatthias Ringwald  * are met:
723a1bbc3SMatthias Ringwald  *
823a1bbc3SMatthias Ringwald  * 1. Redistributions of source code must retain the above copyright
923a1bbc3SMatthias Ringwald  *    notice, this list of conditions and the following disclaimer.
1023a1bbc3SMatthias Ringwald  * 2. Redistributions in binary form must reproduce the above copyright
1123a1bbc3SMatthias Ringwald  *    notice, this list of conditions and the following disclaimer in the
1223a1bbc3SMatthias Ringwald  *    documentation and/or other materials provided with the distribution.
1323a1bbc3SMatthias Ringwald  * 3. Neither the name of the copyright holders nor the names of
1423a1bbc3SMatthias Ringwald  *    contributors may be used to endorse or promote products derived
1523a1bbc3SMatthias Ringwald  *    from this software without specific prior written permission.
1623a1bbc3SMatthias Ringwald  * 4. Any redistribution, use, or modification is done solely for
1723a1bbc3SMatthias Ringwald  *    personal benefit and not for any commercial purpose or for
1823a1bbc3SMatthias Ringwald  *    monetary gain.
1923a1bbc3SMatthias Ringwald  *
2023a1bbc3SMatthias Ringwald  * THIS SOFTWARE IS PROVIDED BY BLUEKITCHEN GMBH AND CONTRIBUTORS
2123a1bbc3SMatthias Ringwald  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
2223a1bbc3SMatthias Ringwald  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
2323a1bbc3SMatthias Ringwald  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL MATTHIAS
2423a1bbc3SMatthias Ringwald  * RINGWALD OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
2523a1bbc3SMatthias Ringwald  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
2623a1bbc3SMatthias Ringwald  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
2723a1bbc3SMatthias Ringwald  * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
2823a1bbc3SMatthias Ringwald  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
2923a1bbc3SMatthias Ringwald  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
3023a1bbc3SMatthias Ringwald  * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
3123a1bbc3SMatthias Ringwald  * SUCH DAMAGE.
3223a1bbc3SMatthias Ringwald  *
3323a1bbc3SMatthias Ringwald  * Please inquire about commercial licensing options at
3423a1bbc3SMatthias Ringwald  * [email protected]
3523a1bbc3SMatthias Ringwald  *
3623a1bbc3SMatthias Ringwald  */
3723a1bbc3SMatthias Ringwald 
3823a1bbc3SMatthias Ringwald #ifndef __BTSTACK_AUDIO_DMA_H
3923a1bbc3SMatthias Ringwald #define __BTSTACK_AUDIO_DMA_H
4023a1bbc3SMatthias Ringwald 
4123a1bbc3SMatthias Ringwald #include <stdint.h>
4223a1bbc3SMatthias Ringwald 
4323a1bbc3SMatthias Ringwald #if defined __cplusplus
4423a1bbc3SMatthias Ringwald extern "C" {
4523a1bbc3SMatthias Ringwald #endif
4623a1bbc3SMatthias Ringwald 
4723a1bbc3SMatthias Ringwald /*
4823a1bbc3SMatthias Ringwald  *  btstack_audio.h
4923a1bbc3SMatthias Ringwald  *
5023a1bbc3SMatthias Ringwald  *  Abstraction layer for 16-bit audio playback and recording within BTstack
5123a1bbc3SMatthias Ringwald  */
5223a1bbc3SMatthias Ringwald 
5323a1bbc3SMatthias Ringwald typedef struct {
5423a1bbc3SMatthias Ringwald 
5523a1bbc3SMatthias Ringwald     /**
5623a1bbc3SMatthias Ringwald 	 * @brief Setup audio codec for specified samplerate and number of channels
5723a1bbc3SMatthias Ringwald 	 * @param Channels (1=mono, 2=stereo)
5823a1bbc3SMatthias Ringwald 	 * @param Sample rate
5923a1bbc3SMatthias Ringwald 	 * @param Playback callback
60*e39d945bSDirk Helbig 	 * @return 1 on success
61*e39d945bSDirk Helbig 	 */
62*e39d945bSDirk Helbig 	int (*init)(uint8_t channels,
63*e39d945bSDirk Helbig 				uint32_t samplerate,
64*e39d945bSDirk Helbig 				void (*playback) (      int16_t * buffer, uint16_t num_samples));
65*e39d945bSDirk Helbig 
66*e39d945bSDirk Helbig     /**
67*e39d945bSDirk Helbig 	 * @brief Start stream
68*e39d945bSDirk Helbig 	 */
69*e39d945bSDirk Helbig 	void (*start_stream)(void);
70*e39d945bSDirk Helbig 
71*e39d945bSDirk Helbig     /**
72*e39d945bSDirk Helbig 	 * @brief Stop stream
73*e39d945bSDirk Helbig 	 */
74*e39d945bSDirk Helbig 	void (*stop_stream)(void);
75*e39d945bSDirk Helbig 
76*e39d945bSDirk Helbig     /**
77*e39d945bSDirk Helbig 	 * @brief Close audio codec
78*e39d945bSDirk Helbig 	 */
79*e39d945bSDirk Helbig 	void (*close)(void);
80*e39d945bSDirk Helbig 
81*e39d945bSDirk Helbig } btstack_audio_sink_t;
82*e39d945bSDirk Helbig 
83*e39d945bSDirk Helbig 
84*e39d945bSDirk Helbig typedef struct {
85*e39d945bSDirk Helbig 
86*e39d945bSDirk Helbig     /**
87*e39d945bSDirk Helbig      * @brief Setup audio codec for specified samplerate and number of channels
88*e39d945bSDirk Helbig      * @param Channels (1=mono, 2=stereo)
89*e39d945bSDirk Helbig      * @param Sample rate
9023a1bbc3SMatthias Ringwald      * @param Recording callback
9123a1bbc3SMatthias Ringwald      * @return 1 on success
9223a1bbc3SMatthias Ringwald      */
9323a1bbc3SMatthias Ringwald 	int (*init)(uint8_t channels,
9423a1bbc3SMatthias Ringwald 				uint32_t samplerate,
9523a1bbc3SMatthias Ringwald 				void (*recording)(const int16_t * buffer, uint16_t num_samples));
9623a1bbc3SMatthias Ringwald 
9723a1bbc3SMatthias Ringwald     /**
9823a1bbc3SMatthias Ringwald      * @brief Start stream
9923a1bbc3SMatthias Ringwald      */
10023a1bbc3SMatthias Ringwald 	void (*start_stream)(void);
10123a1bbc3SMatthias Ringwald 
10223a1bbc3SMatthias Ringwald     /**
103*e39d945bSDirk Helbig      * @brief Stop stream
104*e39d945bSDirk Helbig      */
105*e39d945bSDirk Helbig     void (*stop_stream)(void);
106*e39d945bSDirk Helbig 
107*e39d945bSDirk Helbig     /**
10823a1bbc3SMatthias Ringwald      * @brief Close audio codec
10923a1bbc3SMatthias Ringwald      */
11023a1bbc3SMatthias Ringwald     void (*close)(void);
11123a1bbc3SMatthias Ringwald 
112*e39d945bSDirk Helbig } btstack_audio_source_t;
113*e39d945bSDirk Helbig 
11423a1bbc3SMatthias Ringwald 
11523a1bbc3SMatthias Ringwald /**
116*e39d945bSDirk Helbig  * @brief Get BTstack Audio Sink Instance
117*e39d945bSDirk Helbig  * @returns btstack_audio_sink implementation
11823a1bbc3SMatthias Ringwald  */
119*e39d945bSDirk Helbig const btstack_audio_sink_t * btstack_audio_sink_get_instance(void);
12023a1bbc3SMatthias Ringwald 
12123a1bbc3SMatthias Ringwald /**
122*e39d945bSDirk Helbig  * @brief Get BTstack Audio Source Instance
123*e39d945bSDirk Helbig  * @returns btstack_audio_source implementation
12423a1bbc3SMatthias Ringwald  */
125*e39d945bSDirk Helbig const btstack_audio_source_t * btstack_audio_source_get_instance(void);
126*e39d945bSDirk Helbig 
127*e39d945bSDirk Helbig 
128*e39d945bSDirk Helbig /**
129*e39d945bSDirk Helbig  * @brief Get BTstack Audio Sink Instance
130*e39d945bSDirk Helbig  * @param btstack_audio_sink implementation
131*e39d945bSDirk Helbig  */
132*e39d945bSDirk Helbig void btstack_audio_sink_set_instance(const btstack_audio_sink_t * audio_sink_impl);
133*e39d945bSDirk Helbig 
134*e39d945bSDirk Helbig /**
135*e39d945bSDirk Helbig  * @brief Get BTstack Audio Source Instance
136*e39d945bSDirk Helbig  * @param btstack_audio_source implementation
137*e39d945bSDirk Helbig  */
138*e39d945bSDirk Helbig void btstack_audio_source_set_instance(const btstack_audio_source_t * audio_source_impl);
13923a1bbc3SMatthias Ringwald 
14023a1bbc3SMatthias Ringwald 
14123a1bbc3SMatthias Ringwald // common implementations
142*e39d945bSDirk Helbig const btstack_audio_sink_t * btstack_audio_portaudio_sink_get_instance(void);
143*e39d945bSDirk Helbig const btstack_audio_source_t * btstack_audio_portaudio_source_get_instance(void);
144*e39d945bSDirk Helbig 
145*e39d945bSDirk Helbig //const btstack_audio_t * btstack_audio_embedded_get_instance(void);
146*e39d945bSDirk Helbig //const btstack_audio_t * btstack_audio_esp32_get_instance(void);
14723a1bbc3SMatthias Ringwald 
14823a1bbc3SMatthias Ringwald #if defined __cplusplus
14923a1bbc3SMatthias Ringwald }
15023a1bbc3SMatthias Ringwald #endif
15123a1bbc3SMatthias Ringwald 
15223a1bbc3SMatthias Ringwald #endif
153