xref: /btstack/3rd-party/lc3-google/src/ltpf.h (revision 4930cef6e21e6da2d7571b9259c7f0fb8bed3d01)
19a19cd78SMatthias Ringwald /******************************************************************************
29a19cd78SMatthias Ringwald  *
3*4930cef6SMatthias 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 /**
209a19cd78SMatthias Ringwald  * LC3 - Long Term Postfilter
219a19cd78SMatthias Ringwald  *
229a19cd78SMatthias Ringwald  * Reference : Low Complexity Communication Codec (LC3)
239a19cd78SMatthias Ringwald  *             Bluetooth Specification v1.0
249a19cd78SMatthias Ringwald  */
259a19cd78SMatthias Ringwald 
269a19cd78SMatthias Ringwald #ifndef __LC3_LTPF_H
279a19cd78SMatthias Ringwald #define __LC3_LTPF_H
289a19cd78SMatthias Ringwald 
299a19cd78SMatthias Ringwald #include "common.h"
309a19cd78SMatthias Ringwald #include "bits.h"
319a19cd78SMatthias Ringwald 
329a19cd78SMatthias Ringwald 
339a19cd78SMatthias Ringwald /**
349a19cd78SMatthias Ringwald  * LTPF data
359a19cd78SMatthias Ringwald  */
369a19cd78SMatthias Ringwald 
379a19cd78SMatthias Ringwald typedef struct lc3_ltpf_data {
389a19cd78SMatthias Ringwald     bool active;
399a19cd78SMatthias Ringwald     int pitch_index;
409a19cd78SMatthias Ringwald } lc3_ltpf_data_t;
419a19cd78SMatthias Ringwald 
429a19cd78SMatthias Ringwald 
439a19cd78SMatthias Ringwald /* ----------------------------------------------------------------------------
449a19cd78SMatthias Ringwald  *  Encoding
459a19cd78SMatthias Ringwald  * -------------------------------------------------------------------------- */
469a19cd78SMatthias Ringwald 
479a19cd78SMatthias Ringwald /**
489a19cd78SMatthias Ringwald  * LTPF analysis
499a19cd78SMatthias Ringwald  * dt, sr          Duration and samplerate of the frame
509a19cd78SMatthias Ringwald  * ltpf            Context of analysis
519a19cd78SMatthias Ringwald  * allowed         True when activation of LTPF is allowed
529a19cd78SMatthias Ringwald  * x               [-d..-1] Previous, [0..ns-1] Current samples
539a19cd78SMatthias Ringwald  * data            Return bitstream data
549a19cd78SMatthias Ringwald  * return          True when pitch present, False otherwise
559a19cd78SMatthias Ringwald  *
56*4930cef6SMatthias Ringwald  * The `x` vector is aligned on 32 bits
579a19cd78SMatthias Ringwald  * The number of previous samples `d` accessed on `x` is :
589a19cd78SMatthias Ringwald  *   d: { 10, 20, 30, 40, 60 } - 1 for samplerates from 8KHz to 48KHz
599a19cd78SMatthias Ringwald  */
609a19cd78SMatthias Ringwald bool lc3_ltpf_analyse(enum lc3_dt dt, enum lc3_srate sr,
61*4930cef6SMatthias Ringwald     lc3_ltpf_analysis_t *ltpf, const int16_t *x, lc3_ltpf_data_t *data);
629a19cd78SMatthias Ringwald 
639a19cd78SMatthias Ringwald /**
649a19cd78SMatthias Ringwald  * LTPF disable
659a19cd78SMatthias Ringwald  * data            LTPF data, disabled activation on return
669a19cd78SMatthias Ringwald  */
679a19cd78SMatthias Ringwald void lc3_ltpf_disable(lc3_ltpf_data_t *data);
689a19cd78SMatthias Ringwald 
699a19cd78SMatthias Ringwald /**
709a19cd78SMatthias Ringwald  * Return number of bits coding the bitstream data
719a19cd78SMatthias Ringwald  * pitch           True when pitch present, False otherwise
729a19cd78SMatthias Ringwald  * return          Bit consumption, including the pitch present flag
739a19cd78SMatthias Ringwald  */
749a19cd78SMatthias Ringwald int lc3_ltpf_get_nbits(bool pitch);
759a19cd78SMatthias Ringwald 
769a19cd78SMatthias Ringwald /**
779a19cd78SMatthias Ringwald  * Put bitstream data
789a19cd78SMatthias Ringwald  * bits            Bitstream context
799a19cd78SMatthias Ringwald  * data            LTPF data
809a19cd78SMatthias Ringwald  */
819a19cd78SMatthias Ringwald void lc3_ltpf_put_data(lc3_bits_t *bits, const lc3_ltpf_data_t *data);
829a19cd78SMatthias Ringwald 
839a19cd78SMatthias Ringwald 
849a19cd78SMatthias Ringwald /* ----------------------------------------------------------------------------
859a19cd78SMatthias Ringwald  *  Decoding
869a19cd78SMatthias Ringwald  * -------------------------------------------------------------------------- */
879a19cd78SMatthias Ringwald /**
889a19cd78SMatthias Ringwald  * Get bitstream data
899a19cd78SMatthias Ringwald  * bits            Bitstream context
909a19cd78SMatthias Ringwald  * data            Return bitstream data
919a19cd78SMatthias Ringwald  */
929a19cd78SMatthias Ringwald void lc3_ltpf_get_data(lc3_bits_t *bits, lc3_ltpf_data_t *data);
939a19cd78SMatthias Ringwald 
949a19cd78SMatthias Ringwald /**
959a19cd78SMatthias Ringwald  * LTPF synthesis
969a19cd78SMatthias Ringwald  * dt, sr          Duration and samplerate of the frame
979a19cd78SMatthias Ringwald  * nbytes          Size in bytes of the frame
989a19cd78SMatthias Ringwald  * ltpf            Context of synthesis
999a19cd78SMatthias Ringwald  * data            Bitstream data, NULL when pitch not present
100*4930cef6SMatthias Ringwald  * xr              Base address of ring buffer of decoded samples
101*4930cef6SMatthias Ringwald  * x               Samples to proceed in the ring buffer, filtered as output
1029a19cd78SMatthias Ringwald  *
103*4930cef6SMatthias Ringwald  * The size of the ring buffer is `nh + ns`.
104*4930cef6SMatthias Ringwald  * The filtering needs an history of at least 18 ms.
1059a19cd78SMatthias Ringwald  */
1069a19cd78SMatthias Ringwald void lc3_ltpf_synthesize(enum lc3_dt dt, enum lc3_srate sr, int nbytes,
107*4930cef6SMatthias Ringwald     lc3_ltpf_synthesis_t *ltpf, const lc3_ltpf_data_t *data,
108*4930cef6SMatthias Ringwald     const float *xr, float *x);
1099a19cd78SMatthias Ringwald 
1109a19cd78SMatthias Ringwald 
1119a19cd78SMatthias Ringwald #endif /* __LC3_LTPF_H */
112