xref: /btstack/3rd-party/lc3-google/src/tns.h (revision 6897da5c53aac5b1f90f41b5b15d0bd43d61dfff)
19a19cd78SMatthias Ringwald /******************************************************************************
29a19cd78SMatthias Ringwald  *
34930cef6SMatthias Ringwald  *  Copyright 2022 Google LLC
49a19cd78SMatthias Ringwald  *
59a19cd78SMatthias Ringwald  *  Licensed under the Apache License, Version 2.0 (the "License");
69a19cd78SMatthias Ringwald  *  you may not use this file except in compliance with the License.
79a19cd78SMatthias Ringwald  *  You may obtain a copy of the License at:
89a19cd78SMatthias Ringwald  *
99a19cd78SMatthias Ringwald  *  http://www.apache.org/licenses/LICENSE-2.0
109a19cd78SMatthias Ringwald  *
119a19cd78SMatthias Ringwald  *  Unless required by applicable law or agreed to in writing, software
129a19cd78SMatthias Ringwald  *  distributed under the License is distributed on an "AS IS" BASIS,
139a19cd78SMatthias Ringwald  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
149a19cd78SMatthias Ringwald  *  See the License for the specific language governing permissions and
159a19cd78SMatthias Ringwald  *  limitations under the License.
169a19cd78SMatthias Ringwald  *
179a19cd78SMatthias Ringwald  ******************************************************************************/
189a19cd78SMatthias Ringwald 
199a19cd78SMatthias Ringwald #ifndef __LC3_TNS_H
209a19cd78SMatthias Ringwald #define __LC3_TNS_H
219a19cd78SMatthias Ringwald 
229a19cd78SMatthias Ringwald #include "common.h"
239a19cd78SMatthias Ringwald #include "bits.h"
249a19cd78SMatthias Ringwald 
259a19cd78SMatthias Ringwald 
269a19cd78SMatthias Ringwald /**
279a19cd78SMatthias Ringwald  * Bitstream data
289a19cd78SMatthias Ringwald  */
299a19cd78SMatthias Ringwald 
309a19cd78SMatthias Ringwald typedef struct lc3_tns_data {
319a19cd78SMatthias Ringwald     int nfilters;
329a19cd78SMatthias Ringwald     bool lpc_weighting;
339a19cd78SMatthias Ringwald     int rc_order[2];
349a19cd78SMatthias Ringwald     int rc[2][8];
359a19cd78SMatthias Ringwald } lc3_tns_data_t;
369a19cd78SMatthias Ringwald 
379a19cd78SMatthias Ringwald 
389a19cd78SMatthias Ringwald /* ----------------------------------------------------------------------------
399a19cd78SMatthias Ringwald  *  Encoding
409a19cd78SMatthias Ringwald  * -------------------------------------------------------------------------- */
419a19cd78SMatthias Ringwald 
429a19cd78SMatthias Ringwald /**
439a19cd78SMatthias Ringwald  * TNS analysis
449a19cd78SMatthias Ringwald  * dt, bw          Duration and bandwidth of the frame
459a19cd78SMatthias Ringwald  * nn_flag         True when high energy detected near Nyquist frequency
469a19cd78SMatthias Ringwald  * nbytes          Size in bytes of the frame
479a19cd78SMatthias Ringwald  * data            Return bitstream data
489a19cd78SMatthias Ringwald  * x               Spectral coefficients, filtered as output
499a19cd78SMatthias Ringwald  */
509a19cd78SMatthias Ringwald void lc3_tns_analyze(enum lc3_dt dt, enum lc3_bandwidth bw,
519a19cd78SMatthias Ringwald     bool nn_flag, int nbytes, lc3_tns_data_t *data, float *x);
529a19cd78SMatthias Ringwald 
539a19cd78SMatthias Ringwald /**
549a19cd78SMatthias Ringwald  * Return number of bits coding the data
559a19cd78SMatthias Ringwald  * data            Bitstream data
569a19cd78SMatthias Ringwald  * return          Bit consumption
579a19cd78SMatthias Ringwald  */
589a19cd78SMatthias Ringwald int lc3_tns_get_nbits(const lc3_tns_data_t *data);
599a19cd78SMatthias Ringwald 
609a19cd78SMatthias Ringwald /**
619a19cd78SMatthias Ringwald  * Put bitstream data
629a19cd78SMatthias Ringwald  * bits            Bitstream context
639a19cd78SMatthias Ringwald  * data            Bitstream data
649a19cd78SMatthias Ringwald  */
659a19cd78SMatthias Ringwald void lc3_tns_put_data(lc3_bits_t *bits, const lc3_tns_data_t *data);
669a19cd78SMatthias Ringwald 
679a19cd78SMatthias Ringwald 
689a19cd78SMatthias Ringwald /* ----------------------------------------------------------------------------
699a19cd78SMatthias Ringwald  *  Decoding
709a19cd78SMatthias Ringwald  * -------------------------------------------------------------------------- */
719a19cd78SMatthias Ringwald 
729a19cd78SMatthias Ringwald /**
739a19cd78SMatthias Ringwald  * Get bitstream data
749a19cd78SMatthias Ringwald  * bits            Bitstream context
759a19cd78SMatthias Ringwald  * dt, bw          Duration and bandwidth of the frame
769a19cd78SMatthias Ringwald  * nbytes          Size in bytes of the frame
779a19cd78SMatthias Ringwald  * data            Bitstream data
78*6897da5cSDirk Helbig  * return          0: Ok  -1: Invalid bitstream data
799a19cd78SMatthias Ringwald  */
80*6897da5cSDirk Helbig int lc3_tns_get_data(lc3_bits_t *bits,
819a19cd78SMatthias Ringwald     enum lc3_dt dt, enum lc3_bandwidth bw, int nbytes, lc3_tns_data_t *data);
829a19cd78SMatthias Ringwald 
839a19cd78SMatthias Ringwald /**
849a19cd78SMatthias Ringwald  * TNS synthesis
859a19cd78SMatthias Ringwald  * dt, bw          Duration and bandwidth of the frame
869a19cd78SMatthias Ringwald  * data            Bitstream data
879a19cd78SMatthias Ringwald  * x               Spectral coefficients, filtered as output
889a19cd78SMatthias Ringwald  */
899a19cd78SMatthias Ringwald void lc3_tns_synthesize(enum lc3_dt dt, enum lc3_bandwidth bw,
909a19cd78SMatthias Ringwald     const lc3_tns_data_t *data, float *x);
919a19cd78SMatthias Ringwald 
929a19cd78SMatthias Ringwald 
939a19cd78SMatthias Ringwald #endif /* __LC3_TNS_H */
94