1*65113a0cSMatthias Ringwald /* 2*65113a0cSMatthias Ringwald * Copyright (C) 2022 BlueKitchen GmbH 3*65113a0cSMatthias Ringwald * 4*65113a0cSMatthias Ringwald * Redistribution and use in source and binary forms, with or without 5*65113a0cSMatthias Ringwald * modification, are permitted provided that the following conditions 6*65113a0cSMatthias Ringwald * are met: 7*65113a0cSMatthias Ringwald * 8*65113a0cSMatthias Ringwald * 1. Redistributions of source code must retain the above copyright 9*65113a0cSMatthias Ringwald * notice, this list of conditions and the following disclaimer. 10*65113a0cSMatthias Ringwald * 2. Redistributions in binary form must reproduce the above copyright 11*65113a0cSMatthias Ringwald * notice, this list of conditions and the following disclaimer in the 12*65113a0cSMatthias Ringwald * documentation and/or other materials provided with the distribution. 13*65113a0cSMatthias Ringwald * 3. Neither the name of the copyright holders nor the names of 14*65113a0cSMatthias Ringwald * contributors may be used to endorse or promote products derived 15*65113a0cSMatthias Ringwald * from this software without specific prior written permission. 16*65113a0cSMatthias Ringwald * 4. Any redistribution, use, or modification is done solely for 17*65113a0cSMatthias Ringwald * personal benefit and not for any commercial purpose or for 18*65113a0cSMatthias Ringwald * monetary gain. 19*65113a0cSMatthias Ringwald * 20*65113a0cSMatthias Ringwald * THIS SOFTWARE IS PROVIDED BY BLUEKITCHEN GMBH AND CONTRIBUTORS 21*65113a0cSMatthias Ringwald * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22*65113a0cSMatthias Ringwald * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 23*65113a0cSMatthias Ringwald * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL MATTHIAS 24*65113a0cSMatthias Ringwald * RINGWALD OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 25*65113a0cSMatthias Ringwald * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 26*65113a0cSMatthias Ringwald * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS 27*65113a0cSMatthias Ringwald * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 28*65113a0cSMatthias Ringwald * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 29*65113a0cSMatthias Ringwald * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF 30*65113a0cSMatthias Ringwald * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 31*65113a0cSMatthias Ringwald * SUCH DAMAGE. 32*65113a0cSMatthias Ringwald * 33*65113a0cSMatthias Ringwald * Please inquire about commercial licensing options at 34*65113a0cSMatthias Ringwald * [email protected] 35*65113a0cSMatthias Ringwald * 36*65113a0cSMatthias Ringwald */ 37*65113a0cSMatthias Ringwald 38*65113a0cSMatthias Ringwald // ***************************************************************************** 39*65113a0cSMatthias Ringwald // 40*65113a0cSMatthias Ringwald // LC3 Interface 41*65113a0cSMatthias Ringwald // 42*65113a0cSMatthias Ringwald // ***************************************************************************** 43*65113a0cSMatthias Ringwald 44*65113a0cSMatthias Ringwald #define BTSTACK_FILE__ "btstack_lc3.c" 45*65113a0cSMatthias Ringwald 46*65113a0cSMatthias Ringwald #include "btstack_lc3.h" 47*65113a0cSMatthias Ringwald #include "btstack_debug.h" 48*65113a0cSMatthias Ringwald 49*65113a0cSMatthias Ringwald uint16_t btstack_lc3_frame_duration_in_us(btstack_lc3_frame_duration_t frame_duration){ 50*65113a0cSMatthias Ringwald switch (frame_duration){ 51*65113a0cSMatthias Ringwald case BTSTACK_LC3_FRAME_DURATION_7500US: 52*65113a0cSMatthias Ringwald return 7500; 53*65113a0cSMatthias Ringwald case BTSTACK_LC3_FRAME_DURATION_10000US: 54*65113a0cSMatthias Ringwald return 10000; 55*65113a0cSMatthias Ringwald default: 56*65113a0cSMatthias Ringwald btstack_assert(false); 57*65113a0cSMatthias Ringwald return 0; 58*65113a0cSMatthias Ringwald } 59*65113a0cSMatthias Ringwald } 60*65113a0cSMatthias Ringwald 61*65113a0cSMatthias Ringwald uint16_t btstack_lc3_samples_per_frame(uint32_t sample_rate, btstack_lc3_frame_duration_t frame_duration){ 62*65113a0cSMatthias Ringwald // 44.1 kHz uses longer iso interval and same number of samples as 48 khz 63*65113a0cSMatthias Ringwald if (sample_rate == 44100){ 64*65113a0cSMatthias Ringwald sample_rate = 48000; 65*65113a0cSMatthias Ringwald } 66*65113a0cSMatthias Ringwald // assume sample rate is x 1000 hz 67*65113a0cSMatthias Ringwald return (sample_rate / 1000) * (btstack_lc3_frame_duration_in_us(frame_duration) / 100); 68*65113a0cSMatthias Ringwald } 69