1 /******************************************************************************
2  *
3  *  Copyright 2022 Google LLC
4  *
5  *  Licensed under the Apache License, Version 2.0 (the "License");
6  *  you may not use this file except in compliance with the License.
7  *  You may obtain a copy of the License at:
8  *
9  *  http://www.apache.org/licenses/LICENSE-2.0
10  *
11  *  Unless required by applicable law or agreed to in writing, software
12  *  distributed under the License is distributed on an "AS IS" BASIS,
13  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  *  See the License for the specific language governing permissions and
15  *  limitations under the License.
16  *
17  ******************************************************************************/
18 
19 /**
20  * LC3 - Temporal Noise Shaping
21  *
22  * Reference : Low Complexity Communication Codec (LC3)
23  *             Bluetooth Specification v1.0
24  */
25 
26 #ifndef __LC3_TNS_H
27 #define __LC3_TNS_H
28 
29 #include "common.h"
30 #include "bits.h"
31 
32 
33 /**
34  * Bitstream data
35  */
36 
37 typedef struct lc3_tns_data {
38     int nfilters;
39     bool lpc_weighting;
40     int rc_order[2];
41     int rc[2][8];
42 } lc3_tns_data_t;
43 
44 
45 /* ----------------------------------------------------------------------------
46  *  Encoding
47  * -------------------------------------------------------------------------- */
48 
49 /**
50  * TNS analysis
51  * dt, bw          Duration and bandwidth of the frame
52  * nn_flag         True when high energy detected near Nyquist frequency
53  * nbytes          Size in bytes of the frame
54  * data            Return bitstream data
55  * x               Spectral coefficients, filtered as output
56  */
57 void lc3_tns_analyze(enum lc3_dt dt, enum lc3_bandwidth bw,
58     bool nn_flag, int nbytes, lc3_tns_data_t *data, float *x);
59 
60 /**
61  * Return number of bits coding the data
62  * data            Bitstream data
63  * return          Bit consumption
64  */
65 int lc3_tns_get_nbits(const lc3_tns_data_t *data);
66 
67 /**
68  * Put bitstream data
69  * bits            Bitstream context
70  * data            Bitstream data
71  */
72 void lc3_tns_put_data(lc3_bits_t *bits, const lc3_tns_data_t *data);
73 
74 
75 /* ----------------------------------------------------------------------------
76  *  Decoding
77  * -------------------------------------------------------------------------- */
78 
79 /**
80  * Get bitstream data
81  * bits            Bitstream context
82  * dt, bw          Duration and bandwidth of the frame
83  * nbytes          Size in bytes of the frame
84  * data            Bitstream data
85  */
86 void lc3_tns_get_data(lc3_bits_t *bits,
87     enum lc3_dt dt, enum lc3_bandwidth bw, int nbytes, lc3_tns_data_t *data);
88 
89 /**
90  * TNS synthesis
91  * dt, bw          Duration and bandwidth of the frame
92  * data            Bitstream data
93  * x               Spectral coefficients, filtered as output
94  */
95 void lc3_tns_synthesize(enum lc3_dt dt, enum lc3_bandwidth bw,
96     const lc3_tns_data_t *data, float *x);
97 
98 
99 #endif /* __LC3_TNS_H */
100