1*9a19cd78SMatthias Ringwald /****************************************************************************** 2*9a19cd78SMatthias Ringwald * 3*9a19cd78SMatthias Ringwald * Copyright 2021 Google, Inc. 4*9a19cd78SMatthias Ringwald * 5*9a19cd78SMatthias Ringwald * Licensed under the Apache License, Version 2.0 (the "License"); 6*9a19cd78SMatthias Ringwald * you may not use this file except in compliance with the License. 7*9a19cd78SMatthias Ringwald * You may obtain a copy of the License at: 8*9a19cd78SMatthias Ringwald * 9*9a19cd78SMatthias Ringwald * http://www.apache.org/licenses/LICENSE-2.0 10*9a19cd78SMatthias Ringwald * 11*9a19cd78SMatthias Ringwald * Unless required by applicable law or agreed to in writing, software 12*9a19cd78SMatthias Ringwald * distributed under the License is distributed on an "AS IS" BASIS, 13*9a19cd78SMatthias Ringwald * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14*9a19cd78SMatthias Ringwald * See the License for the specific language governing permissions and 15*9a19cd78SMatthias Ringwald * limitations under the License. 16*9a19cd78SMatthias Ringwald * 17*9a19cd78SMatthias Ringwald ******************************************************************************/ 18*9a19cd78SMatthias Ringwald 19*9a19cd78SMatthias Ringwald /** 20*9a19cd78SMatthias Ringwald * LC3 - Spectral coefficients encoding/decoding 21*9a19cd78SMatthias Ringwald * 22*9a19cd78SMatthias Ringwald * Reference : Low Complexity Communication Codec (LC3) 23*9a19cd78SMatthias Ringwald * Bluetooth Specification v1.0 24*9a19cd78SMatthias Ringwald */ 25*9a19cd78SMatthias Ringwald 26*9a19cd78SMatthias Ringwald #ifndef __LC3_SPEC_H 27*9a19cd78SMatthias Ringwald #define __LC3_SPEC_H 28*9a19cd78SMatthias Ringwald 29*9a19cd78SMatthias Ringwald #include "common.h" 30*9a19cd78SMatthias Ringwald #include "tables.h" 31*9a19cd78SMatthias Ringwald #include "bwdet.h" 32*9a19cd78SMatthias Ringwald #include "ltpf.h" 33*9a19cd78SMatthias Ringwald #include "tns.h" 34*9a19cd78SMatthias Ringwald #include "sns.h" 35*9a19cd78SMatthias Ringwald 36*9a19cd78SMatthias Ringwald 37*9a19cd78SMatthias Ringwald /** 38*9a19cd78SMatthias Ringwald * Spectral quantization side data 39*9a19cd78SMatthias Ringwald */ 40*9a19cd78SMatthias Ringwald typedef struct lc3_spec_side { 41*9a19cd78SMatthias Ringwald int g_idx, nq; 42*9a19cd78SMatthias Ringwald bool lsb_mode; 43*9a19cd78SMatthias Ringwald } lc3_spec_side_t; 44*9a19cd78SMatthias Ringwald 45*9a19cd78SMatthias Ringwald 46*9a19cd78SMatthias Ringwald /* ---------------------------------------------------------------------------- 47*9a19cd78SMatthias Ringwald * Encoding 48*9a19cd78SMatthias Ringwald * -------------------------------------------------------------------------- */ 49*9a19cd78SMatthias Ringwald 50*9a19cd78SMatthias Ringwald /** 51*9a19cd78SMatthias Ringwald * Spectrum analysis 52*9a19cd78SMatthias Ringwald * dt, sr, nbytes Duration, samplerate and size of the frame 53*9a19cd78SMatthias Ringwald * pitch, tns Pitch present indication and TNS bistream data 54*9a19cd78SMatthias Ringwald * spec Context of analysis 55*9a19cd78SMatthias Ringwald * x Spectral coefficients, scaled as output 56*9a19cd78SMatthias Ringwald * xq, side Return quantization data 57*9a19cd78SMatthias Ringwald */ 58*9a19cd78SMatthias Ringwald void lc3_spec_analyze(enum lc3_dt dt, enum lc3_srate sr, 59*9a19cd78SMatthias Ringwald int nbytes, bool pitch, const lc3_tns_data_t *tns, 60*9a19cd78SMatthias Ringwald lc3_spec_analysis_t *spec, float *x, int16_t *xq, lc3_spec_side_t *side); 61*9a19cd78SMatthias Ringwald 62*9a19cd78SMatthias Ringwald /** 63*9a19cd78SMatthias Ringwald * Put spectral quantization side data 64*9a19cd78SMatthias Ringwald * bits Bitstream context 65*9a19cd78SMatthias Ringwald * dt, sr Duration and samplerate of the frame 66*9a19cd78SMatthias Ringwald * side Spectral quantization side data 67*9a19cd78SMatthias Ringwald */ 68*9a19cd78SMatthias Ringwald void lc3_spec_put_side(lc3_bits_t *bits, 69*9a19cd78SMatthias Ringwald enum lc3_dt dt, enum lc3_srate sr, const lc3_spec_side_t *side); 70*9a19cd78SMatthias Ringwald 71*9a19cd78SMatthias Ringwald /** 72*9a19cd78SMatthias Ringwald * Encode spectral coefficients 73*9a19cd78SMatthias Ringwald * bits Bitstream context 74*9a19cd78SMatthias Ringwald * dt, sr, bw Duration, samplerate, bandwidth 75*9a19cd78SMatthias Ringwald * nbytes and size of the frame 76*9a19cd78SMatthias Ringwald * xq, side Quantization data 77*9a19cd78SMatthias Ringwald * x Scaled spectral coefficients 78*9a19cd78SMatthias Ringwald */ 79*9a19cd78SMatthias Ringwald void lc3_spec_encode(lc3_bits_t *bits, 80*9a19cd78SMatthias Ringwald enum lc3_dt dt, enum lc3_srate sr, enum lc3_bandwidth bw, int nbytes, 81*9a19cd78SMatthias Ringwald const int16_t *xq, const lc3_spec_side_t *side, const float *x); 82*9a19cd78SMatthias Ringwald 83*9a19cd78SMatthias Ringwald 84*9a19cd78SMatthias Ringwald /* ---------------------------------------------------------------------------- 85*9a19cd78SMatthias Ringwald * Decoding 86*9a19cd78SMatthias Ringwald * -------------------------------------------------------------------------- */ 87*9a19cd78SMatthias Ringwald 88*9a19cd78SMatthias Ringwald /** 89*9a19cd78SMatthias Ringwald * Get spectral quantization side data 90*9a19cd78SMatthias Ringwald * bits Bitstream context 91*9a19cd78SMatthias Ringwald * dt, sr Duration and samplerate of the frame 92*9a19cd78SMatthias Ringwald * side Return quantization side data 93*9a19cd78SMatthias Ringwald * return 0: Ok -1: Invalid bandwidth indication 94*9a19cd78SMatthias Ringwald */ 95*9a19cd78SMatthias Ringwald int lc3_spec_get_side(lc3_bits_t *bits, 96*9a19cd78SMatthias Ringwald enum lc3_dt dt, enum lc3_srate sr, lc3_spec_side_t *side); 97*9a19cd78SMatthias Ringwald 98*9a19cd78SMatthias Ringwald /** 99*9a19cd78SMatthias Ringwald * Decode spectral coefficients 100*9a19cd78SMatthias Ringwald * bits Bitstream context 101*9a19cd78SMatthias Ringwald * dt, sr, bw Duration, samplerate, bandwidth 102*9a19cd78SMatthias Ringwald * nbytes and size of the frame 103*9a19cd78SMatthias Ringwald * side Quantization side data 104*9a19cd78SMatthias Ringwald * x Spectral coefficients 105*9a19cd78SMatthias Ringwald * return 0: Ok -1: Invalid bitstream data 106*9a19cd78SMatthias Ringwald */ 107*9a19cd78SMatthias Ringwald int lc3_spec_decode(lc3_bits_t *bits, enum lc3_dt dt, enum lc3_srate sr, 108*9a19cd78SMatthias Ringwald enum lc3_bandwidth bw, int nbytes, const lc3_spec_side_t *side, float *x); 109*9a19cd78SMatthias Ringwald 110*9a19cd78SMatthias Ringwald 111*9a19cd78SMatthias Ringwald #endif /* __LC3_SPEC_H */ 112