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 38*65ec5d42SMatthias Ringwald #ifndef __BTSTACK_AUDIO_H 39*65ec5d42SMatthias Ringwald #define __BTSTACK_AUDIO_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 60e39d945bSDirk Helbig * @return 1 on success 61e39d945bSDirk Helbig */ 62e39d945bSDirk Helbig int (*init)(uint8_t channels, 63e39d945bSDirk Helbig uint32_t samplerate, 64e39d945bSDirk Helbig void (*playback) (int16_t * buffer, uint16_t num_samples)); 65e39d945bSDirk Helbig 66e39d945bSDirk Helbig /** 67e39d945bSDirk Helbig * @brief Start stream 68e39d945bSDirk Helbig */ 69e39d945bSDirk Helbig void (*start_stream)(void); 70e39d945bSDirk Helbig 71e39d945bSDirk Helbig /** 72e39d945bSDirk Helbig * @brief Stop stream 73e39d945bSDirk Helbig */ 74e39d945bSDirk Helbig void (*stop_stream)(void); 75e39d945bSDirk Helbig 76e39d945bSDirk Helbig /** 77e39d945bSDirk Helbig * @brief Close audio codec 78e39d945bSDirk Helbig */ 79e39d945bSDirk Helbig void (*close)(void); 80e39d945bSDirk Helbig 81e39d945bSDirk Helbig } btstack_audio_sink_t; 82e39d945bSDirk Helbig 83e39d945bSDirk Helbig 84e39d945bSDirk Helbig typedef struct { 85e39d945bSDirk Helbig 86e39d945bSDirk Helbig /** 87e39d945bSDirk Helbig * @brief Setup audio codec for specified samplerate and number of channels 88e39d945bSDirk Helbig * @param Channels (1=mono, 2=stereo) 89e39d945bSDirk 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 /** 103e39d945bSDirk Helbig * @brief Stop stream 104e39d945bSDirk Helbig */ 105e39d945bSDirk Helbig void (*stop_stream)(void); 106e39d945bSDirk Helbig 107e39d945bSDirk Helbig /** 10823a1bbc3SMatthias Ringwald * @brief Close audio codec 10923a1bbc3SMatthias Ringwald */ 11023a1bbc3SMatthias Ringwald void (*close)(void); 11123a1bbc3SMatthias Ringwald 112e39d945bSDirk Helbig } btstack_audio_source_t; 113e39d945bSDirk Helbig 11423a1bbc3SMatthias Ringwald 11523a1bbc3SMatthias Ringwald /** 116e39d945bSDirk Helbig * @brief Get BTstack Audio Sink Instance 117e39d945bSDirk Helbig * @returns btstack_audio_sink implementation 11823a1bbc3SMatthias Ringwald */ 119e39d945bSDirk Helbig const btstack_audio_sink_t * btstack_audio_sink_get_instance(void); 12023a1bbc3SMatthias Ringwald 12123a1bbc3SMatthias Ringwald /** 122e39d945bSDirk Helbig * @brief Get BTstack Audio Source Instance 123e39d945bSDirk Helbig * @returns btstack_audio_source implementation 12423a1bbc3SMatthias Ringwald */ 125e39d945bSDirk Helbig const btstack_audio_source_t * btstack_audio_source_get_instance(void); 126e39d945bSDirk Helbig 127e39d945bSDirk Helbig 128e39d945bSDirk Helbig /** 129e39d945bSDirk Helbig * @brief Get BTstack Audio Sink Instance 130e39d945bSDirk Helbig * @param btstack_audio_sink implementation 131e39d945bSDirk Helbig */ 132e39d945bSDirk Helbig void btstack_audio_sink_set_instance(const btstack_audio_sink_t * audio_sink_impl); 133e39d945bSDirk Helbig 134e39d945bSDirk Helbig /** 135e39d945bSDirk Helbig * @brief Get BTstack Audio Source Instance 136e39d945bSDirk Helbig * @param btstack_audio_source implementation 137e39d945bSDirk Helbig */ 138e39d945bSDirk Helbig void btstack_audio_source_set_instance(const btstack_audio_source_t * audio_source_impl); 13923a1bbc3SMatthias Ringwald 14023a1bbc3SMatthias Ringwald 14123a1bbc3SMatthias Ringwald // common implementations 142e39d945bSDirk Helbig const btstack_audio_sink_t * btstack_audio_portaudio_sink_get_instance(void); 143e39d945bSDirk Helbig const btstack_audio_source_t * btstack_audio_portaudio_source_get_instance(void); 144e39d945bSDirk Helbig 145*65ec5d42SMatthias Ringwald const btstack_audio_sink_t * btstack_audio_embedded_sink_get_instance(void); 146*65ec5d42SMatthias Ringwald const btstack_audio_source_t * btstack_audio_embedded_source_get_instance(void); 147*65ec5d42SMatthias Ringwald 148*65ec5d42SMatthias Ringwald const btstack_audio_sink_t * btstack_audio_esp32_sink_get_instance(void); 149*65ec5d42SMatthias Ringwald // const btstack_audio_source_t * btstack_audio_esp32_source_get_instance(void); 15023a1bbc3SMatthias Ringwald 15123a1bbc3SMatthias Ringwald #if defined __cplusplus 15223a1bbc3SMatthias Ringwald } 15323a1bbc3SMatthias Ringwald #endif 15423a1bbc3SMatthias Ringwald 15523a1bbc3SMatthias Ringwald #endif 156