xref: /btstack/src/classic/btstack_cvsd_plc.h (revision 7e6b1e83d2aaaacbcb5e04ae26e1c08d6d0bb297)
1*7e6b1e83SMilanka Ringwald /*
2*7e6b1e83SMilanka Ringwald  * Copyright (C) 2016 BlueKitchen GmbH
3*7e6b1e83SMilanka Ringwald  *
4*7e6b1e83SMilanka Ringwald  * Redistribution and use in source and binary forms, with or without
5*7e6b1e83SMilanka Ringwald  * modification, are permitted provided that the following conditions
6*7e6b1e83SMilanka Ringwald  * are met:
7*7e6b1e83SMilanka Ringwald  *
8*7e6b1e83SMilanka Ringwald  * 1. Redistributions of source code must retain the above copyright
9*7e6b1e83SMilanka Ringwald  *    notice, this list of conditions and the following disclaimer.
10*7e6b1e83SMilanka Ringwald  * 2. Redistributions in binary form must reproduce the above copyright
11*7e6b1e83SMilanka Ringwald  *    notice, this list of conditions and the following disclaimer in the
12*7e6b1e83SMilanka Ringwald  *    documentation and/or other materials provided with the distribution.
13*7e6b1e83SMilanka Ringwald  * 3. Neither the name of the copyright holders nor the names of
14*7e6b1e83SMilanka Ringwald  *    contributors may be used to endorse or promote products derived
15*7e6b1e83SMilanka Ringwald  *    from this software without specific prior written permission.
16*7e6b1e83SMilanka Ringwald  * 4. Any redistribution, use, or modification is done solely for
17*7e6b1e83SMilanka Ringwald  *    personal benefit and not for any commercial purpose or for
18*7e6b1e83SMilanka Ringwald  *    monetary gain.
19*7e6b1e83SMilanka Ringwald  *
20*7e6b1e83SMilanka Ringwald  * THIS SOFTWARE IS PROVIDED BY BLUEKITCHEN GMBH AND CONTRIBUTORS
21*7e6b1e83SMilanka Ringwald  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22*7e6b1e83SMilanka Ringwald  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
23*7e6b1e83SMilanka Ringwald  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL MATTHIAS
24*7e6b1e83SMilanka Ringwald  * RINGWALD OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
25*7e6b1e83SMilanka Ringwald  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
26*7e6b1e83SMilanka Ringwald  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
27*7e6b1e83SMilanka Ringwald  * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
28*7e6b1e83SMilanka Ringwald  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
29*7e6b1e83SMilanka Ringwald  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
30*7e6b1e83SMilanka Ringwald  * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31*7e6b1e83SMilanka Ringwald  * SUCH DAMAGE.
32*7e6b1e83SMilanka Ringwald  *
33*7e6b1e83SMilanka Ringwald  * Please inquire about commercial licensing options at
34*7e6b1e83SMilanka Ringwald  * [email protected]
35*7e6b1e83SMilanka Ringwald  *
36*7e6b1e83SMilanka Ringwald  */
37*7e6b1e83SMilanka Ringwald 
38*7e6b1e83SMilanka Ringwald /*
39*7e6b1e83SMilanka Ringwald  * btstack_cvsd_plc.h
40*7e6b1e83SMilanka Ringwald  *
41*7e6b1e83SMilanka Ringwald  */
42*7e6b1e83SMilanka Ringwald 
43*7e6b1e83SMilanka Ringwald #ifndef __BTSTACK_CVSD_PLC_H
44*7e6b1e83SMilanka Ringwald #define __BTSTACK_CVSD_PLC_H
45*7e6b1e83SMilanka Ringwald 
46*7e6b1e83SMilanka Ringwald #include <stdint.h>
47*7e6b1e83SMilanka Ringwald 
48*7e6b1e83SMilanka Ringwald #if defined __cplusplus
49*7e6b1e83SMilanka Ringwald extern "C" {
50*7e6b1e83SMilanka Ringwald #endif
51*7e6b1e83SMilanka Ringwald 
52*7e6b1e83SMilanka Ringwald #define CVSD_FS 24           /* CVSD Frame Size */
53*7e6b1e83SMilanka Ringwald #define CVSD_N 128           /* 16ms - Window Length for pattern matching */
54*7e6b1e83SMilanka Ringwald #define CVSD_M 10            /* Template for matching */
55*7e6b1e83SMilanka Ringwald #define CVSD_LHIST (CVSD_N+CVSD_FS-1)  /* Length of history buffer required */
56*7e6b1e83SMilanka Ringwald #define CVSD_RT 5        /*  Reconvergence Time (samples) */
57*7e6b1e83SMilanka Ringwald #define CVSD_OLAL 16         /* OverLap-Add Length (samples) */
58*7e6b1e83SMilanka Ringwald 
59*7e6b1e83SMilanka Ringwald /* PLC State Information */
60*7e6b1e83SMilanka Ringwald typedef struct cvsd_plc_state {
61*7e6b1e83SMilanka Ringwald     int8_t hist[CVSD_LHIST+CVSD_FS+CVSD_RT+CVSD_OLAL];
62*7e6b1e83SMilanka Ringwald     int16_t bestlag;
63*7e6b1e83SMilanka Ringwald     int     nbf;
64*7e6b1e83SMilanka Ringwald } btstack_cvsd_plc_state_t;
65*7e6b1e83SMilanka Ringwald 
66*7e6b1e83SMilanka Ringwald void btstack_cvsd_plc_init(btstack_cvsd_plc_state_t *plc_state);
67*7e6b1e83SMilanka Ringwald void btstack_cvsd_plc_bad_frame(btstack_cvsd_plc_state_t *plc_state, int8_t *out);
68*7e6b1e83SMilanka Ringwald void btstack_cvsd_plc_good_frame(btstack_cvsd_plc_state_t *plc_state, int8_t *in, int8_t *out);
69*7e6b1e83SMilanka Ringwald uint8_t * btstack_cvsd_plc_zero_signal_frame(void);
70*7e6b1e83SMilanka Ringwald 
71*7e6b1e83SMilanka Ringwald #if defined __cplusplus
72*7e6b1e83SMilanka Ringwald }
73*7e6b1e83SMilanka Ringwald #endif
74*7e6b1e83SMilanka Ringwald 
75*7e6b1e83SMilanka Ringwald #endif // __BTSTACK_CVSD_PLC_H