1 // Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 #ifndef _SBC_PLC_H 16 #define _SBC_PLC_H 17 18 #include <stdint.h> 19 20 #if defined __cplusplus 21 extern "C" { 22 #endif 23 24 /* Paramter for PLC (16 kHZ)*/ 25 #define SBC_FS 120 /* SBC Frame Size */ 26 #define SBC_N 256 /* 16ms - Window Length for pattern matching */ 27 #define SBC_M 64 /* 4ms - Template for matching */ 28 #define SBC_LHIST (SBC_N + SBC_FS - 1) /* Length of history buffer required */ 29 #define SBC_RT 36 /* SBC Reconvergence Time (samples) */ 30 #define SBC_OLAL 16 /* OverLap-Add Length (samples) */ 31 32 /* PLC State Information */ 33 typedef struct sbc_plc_state { 34 int16_t hist[SBC_LHIST + SBC_FS + SBC_RT + SBC_OLAL]; 35 int16_t bestlag; 36 int nbf; 37 } sbc_plc_state_t; 38 39 /* Prototypes */ 40 /** 41 * Perform PLC initialization of memory vectors. 42 * 43 * @param plc_state pointer to PLC state memory 44 */ 45 void sbc_plc_init(sbc_plc_state_t *plc_state); 46 47 /** 48 * Perform PLC deinitialization of memory vectors. 49 * 50 * @param plc_state pointer to PLC state memory 51 */ 52 void sbc_plc_deinit(sbc_plc_state_t *plc_state); 53 54 /** 55 * Perform bad frame processing. 56 * 57 * @param plc_state pointer to PLC state memory 58 * @param ZIRbuf pointer to the ZIR response of the SBC decoder 59 * @param out pointer to the output samples 60 */ 61 void sbc_plc_bad_frame(sbc_plc_state_t *plc_state, int16_t *ZIRbuf, int16_t *out); 62 63 /** 64 * Perform good frame processing. Most of the time, this function 65 * just updates history buffers and passes the input to the output, 66 * but in the first good frame after frame loss, it must conceal the 67 * received signal as it reconverges with the true output. 68 * 69 * @param plc_state pointer to PLC state memory 70 * @param in pointer to the input vector 71 * @param out pointer to the output samples 72 */ 73 void sbc_plc_good_frame(sbc_plc_state_t *plc_state, int16_t *in, int16_t *out); 74 75 /** 76 * Get a zero signal eSCO frame 77 * @return pointer to data buffer 78 */ 79 uint8_t * sbc_plc_zero_signal_frame(void); 80 81 /** 82 * Get a zero signal eSCO pcm frame 83 * @return pointer to data buffer 84 */ 85 int16_t * sbc_plc_zero_signal_frame_pcm(void); 86 87 #if defined __cplusplus 88 } 89 #endif 90 91 #endif /// _SBC_PLC_H 92