1 /*
2  * SPDX-FileCopyrightText: 2015-2021 Espressif Systems (Shanghai) CO LTD
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  */
6 
7 #ifndef _SBC_PLC_H
8 #define _SBC_PLC_H
9 
10 #include <stdint.h>
11 
12 #if defined __cplusplus
13 extern "C" {
14 #endif
15 
16 /* Paramter for PLC (16 kHZ)*/
17 #define SBC_FS          120                     /* SBC Frame Size */
18 #define SBC_N           256                     /* 16ms - Window Length for pattern matching */
19 #define SBC_M           64                      /* 4ms - Template for matching */
20 #define SBC_LHIST       (SBC_N + SBC_FS - 1)    /* Length of history buffer required */
21 #define SBC_RT          36                      /* SBC Reconvergence Time (samples) */
22 #define SBC_OLAL        16                      /* OverLap-Add Length (samples) */
23 
24 /* PLC State Information */
25 typedef struct sbc_plc_state {
26     int16_t hist[SBC_LHIST + SBC_FS + SBC_RT + SBC_OLAL];
27     int16_t bestlag;
28     int     nbf;
29 } sbc_plc_state_t;
30 
31 /* Prototypes */
32 /**
33  * Perform PLC initialization of memory vectors.
34  *
35  * @param plc_state pointer to PLC state memory
36  */
37 void sbc_plc_init(sbc_plc_state_t *plc_state);
38 
39 /**
40  * Perform PLC deinitialization of memory vectors.
41  *
42  * @param plc_state pointer to PLC state memory
43  */
44 void sbc_plc_deinit(sbc_plc_state_t *plc_state);
45 
46 /**
47  * Perform bad frame processing.
48  *
49  * @param plc_state pointer to PLC state memory
50  * @param ZIRbuf    pointer to the ZIR response of the SBC decoder
51  * @param out       pointer to the output samples
52  */
53 void sbc_plc_bad_frame(sbc_plc_state_t *plc_state, int16_t *ZIRbuf, int16_t *out);
54 
55 /**
56  * Perform good frame processing. Most of the time, this function
57  * just updates history buffers and passes the input to the output,
58  * but in the first good frame after frame loss, it must conceal the
59  * received signal as it reconverges with the true output.
60  *
61  * @param plc_state pointer to PLC state memory
62  * @param in        pointer to the input vector
63  * @param out       pointer to the output samples
64  */
65 void sbc_plc_good_frame(sbc_plc_state_t *plc_state, int16_t *in, int16_t *out);
66 
67 /**
68  * Get a zero signal eSCO frame
69  * @return  pointer to data buffer
70  */
71 uint8_t * sbc_plc_zero_signal_frame(void);
72 
73 /**
74  * Get a zero signal eSCO pcm frame
75  * @return  pointer to data buffer
76  */
77 int16_t * sbc_plc_zero_signal_frame_pcm(void);
78 
79 #if defined __cplusplus
80 }
81 #endif
82 
83 #endif /// _SBC_PLC_H
84