1*fa6e8062SMatthias Ringwald /* 2*fa6e8062SMatthias Ringwald * Copyright (C) 2018 BlueKitchen GmbH 3*fa6e8062SMatthias Ringwald * 4*fa6e8062SMatthias Ringwald * Redistribution and use in source and binary forms, with or without 5*fa6e8062SMatthias Ringwald * modification, are permitted provided that the following conditions 6*fa6e8062SMatthias Ringwald * are met: 7*fa6e8062SMatthias Ringwald * 8*fa6e8062SMatthias Ringwald * 1. Redistributions of source code must retain the above copyright 9*fa6e8062SMatthias Ringwald * notice, this list of conditions and the following disclaimer. 10*fa6e8062SMatthias Ringwald * 2. Redistributions in binary form must reproduce the above copyright 11*fa6e8062SMatthias Ringwald * notice, this list of conditions and the following disclaimer in the 12*fa6e8062SMatthias Ringwald * documentation and/or other materials provided with the distribution. 13*fa6e8062SMatthias Ringwald * 3. Neither the name of the copyright holders nor the names of 14*fa6e8062SMatthias Ringwald * contributors may be used to endorse or promote products derived 15*fa6e8062SMatthias Ringwald * from this software without specific prior written permission. 16*fa6e8062SMatthias Ringwald * 4. Any redistribution, use, or modification is done solely for 17*fa6e8062SMatthias Ringwald * personal benefit and not for any commercial purpose or for 18*fa6e8062SMatthias Ringwald * monetary gain. 19*fa6e8062SMatthias Ringwald * 20*fa6e8062SMatthias Ringwald * THIS SOFTWARE IS PROVIDED BY BLUEKITCHEN GMBH AND CONTRIBUTORS 21*fa6e8062SMatthias Ringwald * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22*fa6e8062SMatthias Ringwald * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 23*fa6e8062SMatthias Ringwald * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL MATTHIAS 24*fa6e8062SMatthias Ringwald * RINGWALD OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 25*fa6e8062SMatthias Ringwald * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 26*fa6e8062SMatthias Ringwald * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS 27*fa6e8062SMatthias Ringwald * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 28*fa6e8062SMatthias Ringwald * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 29*fa6e8062SMatthias Ringwald * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF 30*fa6e8062SMatthias Ringwald * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 31*fa6e8062SMatthias Ringwald * SUCH DAMAGE. 32*fa6e8062SMatthias Ringwald * 33*fa6e8062SMatthias Ringwald * Please inquire about commercial licensing options at 34*fa6e8062SMatthias Ringwald * [email protected] 35*fa6e8062SMatthias Ringwald * 36*fa6e8062SMatthias Ringwald */ 37*fa6e8062SMatthias Ringwald 38*fa6e8062SMatthias Ringwald #ifndef __HAL_AUDIO_H 39*fa6e8062SMatthias Ringwald #define __HAL_AUDIO_H 40*fa6e8062SMatthias Ringwald 41*fa6e8062SMatthias Ringwald #include <stdint.h> 42*fa6e8062SMatthias Ringwald 43*fa6e8062SMatthias Ringwald /* 44*fa6e8062SMatthias Ringwald * hal_audio.h 45*fa6e8062SMatthias Ringwald * 46*fa6e8062SMatthias Ringwald * Hardware abstraction layer that provides circular audio playback and recording 47*fa6e8062SMatthias Ringwald * 48*fa6e8062SMatthias Ringwald * Assumptions: 49*fa6e8062SMatthias Ringwald * - num buffers n >= 2 50*fa6e8062SMatthias Ringwald * - after start, buffers are played in sequence 0, 1, ... , n-1, 0, 1, .. , n-1, ... 51*fa6e8062SMatthias Ringwald * - after a buffer is played, the callback is called with tbe index of the played buffer 52*fa6e8062SMatthias Ringwald */ 53*fa6e8062SMatthias Ringwald 54*fa6e8062SMatthias Ringwald /** 55*fa6e8062SMatthias Ringwald * @brief Setup audio codec for specified samplerate and number channels 56*fa6e8062SMatthias Ringwald * @param Channels 57*fa6e8062SMatthias Ringwald * @param Sample rate 58*fa6e8062SMatthias Ringwald * @param Buffer played callback 59*fa6e8062SMatthias Ringwald * @param Buffer recorded callback (use NULL if no recording) 60*fa6e8062SMatthias Ringwald */ 61*fa6e8062SMatthias Ringwald void hal_audio_init(uint8_t channels, 62*fa6e8062SMatthias Ringwald uint32_t sample_rate, 63*fa6e8062SMatthias Ringwald void (*buffer_played_callback) (uint8_t buffer_index), 64*fa6e8062SMatthias Ringwald void (*buffer_recorded_callback)(const int16_t * buffer, uint16_t num_samples)); 65*fa6e8062SMatthias Ringwald 66*fa6e8062SMatthias Ringwald /** 67*fa6e8062SMatthias Ringwald * @brief Get number of output buffers in HAL 68*fa6e8062SMatthias Ringwald * @returns num buffers 69*fa6e8062SMatthias Ringwald */ 70*fa6e8062SMatthias Ringwald uint16_t hal_audio_get_num_output_buffers(void); 71*fa6e8062SMatthias Ringwald 72*fa6e8062SMatthias Ringwald /** 73*fa6e8062SMatthias Ringwald * @brief Get size of single output buffer in HAL 74*fa6e8062SMatthias Ringwald * @returns buffer size 75*fa6e8062SMatthias Ringwald */ 76*fa6e8062SMatthias Ringwald uint16_t hal_audio_get_num_output_buffer_samples(void); 77*fa6e8062SMatthias Ringwald 78*fa6e8062SMatthias Ringwald /** 79*fa6e8062SMatthias Ringwald * @brief Gey output buffer 80*fa6e8062SMatthias Ringwald * @param buffer index 81*fa6e8062SMatthias Ringwald * @returns buffer 82*fa6e8062SMatthias Ringwald */ 83*fa6e8062SMatthias Ringwald int16_t * hal_audio_get_output_buffer(uint8_t buffer_index); 84*fa6e8062SMatthias Ringwald 85*fa6e8062SMatthias Ringwald /** 86*fa6e8062SMatthias Ringwald * @brief Start stream 87*fa6e8062SMatthias Ringwald */ 88*fa6e8062SMatthias Ringwald void hal_audio_start(void); 89*fa6e8062SMatthias Ringwald 90*fa6e8062SMatthias Ringwald /** 91*fa6e8062SMatthias Ringwald * @brief Close audio codec 92*fa6e8062SMatthias Ringwald */ 93*fa6e8062SMatthias Ringwald void hal_audio_close(void); 94*fa6e8062SMatthias Ringwald 95*fa6e8062SMatthias Ringwald #endif 96