xref: /btstack/3rd-party/lc3-google/src/spec.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_SPEC_H
209a19cd78SMatthias Ringwald #define __LC3_SPEC_H
219a19cd78SMatthias Ringwald 
229a19cd78SMatthias Ringwald #include "common.h"
239a19cd78SMatthias Ringwald #include "tables.h"
249a19cd78SMatthias Ringwald #include "bwdet.h"
259a19cd78SMatthias Ringwald #include "ltpf.h"
269a19cd78SMatthias Ringwald #include "tns.h"
279a19cd78SMatthias Ringwald #include "sns.h"
289a19cd78SMatthias Ringwald 
299a19cd78SMatthias Ringwald 
309a19cd78SMatthias Ringwald /**
319a19cd78SMatthias Ringwald  * Spectral quantization side data
329a19cd78SMatthias Ringwald  */
339a19cd78SMatthias Ringwald typedef struct lc3_spec_side {
349a19cd78SMatthias Ringwald     int g_idx, nq;
359a19cd78SMatthias Ringwald     bool lsb_mode;
369a19cd78SMatthias Ringwald } lc3_spec_side_t;
379a19cd78SMatthias Ringwald 
389a19cd78SMatthias Ringwald 
399a19cd78SMatthias Ringwald /* ----------------------------------------------------------------------------
409a19cd78SMatthias Ringwald  *  Encoding
419a19cd78SMatthias Ringwald  * -------------------------------------------------------------------------- */
429a19cd78SMatthias Ringwald 
439a19cd78SMatthias Ringwald /**
449a19cd78SMatthias Ringwald  * Spectrum analysis
459a19cd78SMatthias Ringwald  * dt, sr, nbytes  Duration, samplerate and size of the frame
469a19cd78SMatthias Ringwald  * pitch, tns      Pitch present indication and TNS bistream data
479a19cd78SMatthias Ringwald  * spec            Context of analysis
489a19cd78SMatthias Ringwald  * x               Spectral coefficients, scaled as output
49*6897da5cSDirk Helbig  * side            Return quantization data
509a19cd78SMatthias Ringwald  */
51*6897da5cSDirk Helbig void lc3_spec_analyze(
52*6897da5cSDirk Helbig     enum lc3_dt dt, enum lc3_srate sr, int nbytes,
53*6897da5cSDirk Helbig     bool pitch, const lc3_tns_data_t *tns, lc3_spec_analysis_t *spec,
54*6897da5cSDirk Helbig     float *x, lc3_spec_side_t *side);
559a19cd78SMatthias Ringwald 
569a19cd78SMatthias Ringwald /**
579a19cd78SMatthias Ringwald  * Put spectral quantization side data
589a19cd78SMatthias Ringwald  * bits            Bitstream context
599a19cd78SMatthias Ringwald  * dt, sr          Duration and samplerate of the frame
609a19cd78SMatthias Ringwald  * side            Spectral quantization side data
619a19cd78SMatthias Ringwald  */
629a19cd78SMatthias Ringwald void lc3_spec_put_side(lc3_bits_t *bits,
639a19cd78SMatthias Ringwald     enum lc3_dt dt, enum lc3_srate sr, const lc3_spec_side_t *side);
649a19cd78SMatthias Ringwald 
659a19cd78SMatthias Ringwald /**
669a19cd78SMatthias Ringwald  * Encode spectral coefficients
679a19cd78SMatthias Ringwald  * bits            Bitstream context
689a19cd78SMatthias Ringwald  * dt, sr, bw      Duration, samplerate, bandwidth
699a19cd78SMatthias Ringwald  * nbytes          and size of the frame
70*6897da5cSDirk Helbig  * side, x         Quantization data, and scaled coefficients
719a19cd78SMatthias Ringwald  */
729a19cd78SMatthias Ringwald void lc3_spec_encode(lc3_bits_t *bits,
73*6897da5cSDirk Helbig     enum lc3_dt dt, enum lc3_srate sr, enum lc3_bandwidth bw,
74*6897da5cSDirk Helbig     int nbytes, const lc3_spec_side_t *side, float *x);
759a19cd78SMatthias Ringwald 
769a19cd78SMatthias Ringwald 
779a19cd78SMatthias Ringwald /* ----------------------------------------------------------------------------
789a19cd78SMatthias Ringwald  *  Decoding
799a19cd78SMatthias Ringwald  * -------------------------------------------------------------------------- */
809a19cd78SMatthias Ringwald 
819a19cd78SMatthias Ringwald /**
829a19cd78SMatthias Ringwald  * Get spectral quantization side data
839a19cd78SMatthias Ringwald  * bits            Bitstream context
849a19cd78SMatthias Ringwald  * dt, sr          Duration and samplerate of the frame
859a19cd78SMatthias Ringwald  * side            Return quantization side data
869a19cd78SMatthias Ringwald  * return          0: Ok  -1: Invalid bandwidth indication
879a19cd78SMatthias Ringwald  */
889a19cd78SMatthias Ringwald int lc3_spec_get_side(lc3_bits_t *bits,
899a19cd78SMatthias Ringwald     enum lc3_dt dt, enum lc3_srate sr, lc3_spec_side_t *side);
909a19cd78SMatthias Ringwald 
919a19cd78SMatthias Ringwald /**
929a19cd78SMatthias Ringwald  * Decode spectral coefficients
939a19cd78SMatthias Ringwald  * bits            Bitstream context
949a19cd78SMatthias Ringwald  * dt, sr, bw      Duration, samplerate, bandwidth
959a19cd78SMatthias Ringwald  * nbytes          and size of the frame
969a19cd78SMatthias Ringwald  * side            Quantization side data
979a19cd78SMatthias Ringwald  * x               Spectral coefficients
989a19cd78SMatthias Ringwald  * return          0: Ok  -1: Invalid bitstream data
999a19cd78SMatthias Ringwald  */
100*6897da5cSDirk Helbig int lc3_spec_decode(lc3_bits_t *bits,
101*6897da5cSDirk Helbig     enum lc3_dt dt, enum lc3_srate sr, enum lc3_bandwidth bw,
102*6897da5cSDirk Helbig     int nbytes, const lc3_spec_side_t *side, float *x);
1039a19cd78SMatthias Ringwald 
1049a19cd78SMatthias Ringwald 
1059a19cd78SMatthias Ringwald #endif /* __LC3_SPEC_H */
106