1 /****************************************************************************** 2 * 3 * Copyright 2021 Google, Inc. 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 - Spectral coefficients encoding/decoding 21 * 22 * Reference : Low Complexity Communication Codec (LC3) 23 * Bluetooth Specification v1.0 24 */ 25 26 #ifndef __LC3_SPEC_H 27 #define __LC3_SPEC_H 28 29 #include "common.h" 30 #include "tables.h" 31 #include "bwdet.h" 32 #include "ltpf.h" 33 #include "tns.h" 34 #include "sns.h" 35 36 37 /** 38 * Spectral quantization side data 39 */ 40 typedef struct lc3_spec_side { 41 int g_idx, nq; 42 bool lsb_mode; 43 } lc3_spec_side_t; 44 45 46 /* ---------------------------------------------------------------------------- 47 * Encoding 48 * -------------------------------------------------------------------------- */ 49 50 /** 51 * Spectrum analysis 52 * dt, sr, nbytes Duration, samplerate and size of the frame 53 * pitch, tns Pitch present indication and TNS bistream data 54 * spec Context of analysis 55 * x Spectral coefficients, scaled as output 56 * xq, side Return quantization data 57 */ 58 void lc3_spec_analyze(enum lc3_dt dt, enum lc3_srate sr, 59 int nbytes, bool pitch, const lc3_tns_data_t *tns, 60 lc3_spec_analysis_t *spec, float *x, int16_t *xq, lc3_spec_side_t *side); 61 62 /** 63 * Put spectral quantization side data 64 * bits Bitstream context 65 * dt, sr Duration and samplerate of the frame 66 * side Spectral quantization side data 67 */ 68 void lc3_spec_put_side(lc3_bits_t *bits, 69 enum lc3_dt dt, enum lc3_srate sr, const lc3_spec_side_t *side); 70 71 /** 72 * Encode spectral coefficients 73 * bits Bitstream context 74 * dt, sr, bw Duration, samplerate, bandwidth 75 * nbytes and size of the frame 76 * xq, side Quantization data 77 * x Scaled spectral coefficients 78 */ 79 void lc3_spec_encode(lc3_bits_t *bits, 80 enum lc3_dt dt, enum lc3_srate sr, enum lc3_bandwidth bw, int nbytes, 81 const int16_t *xq, const lc3_spec_side_t *side, const float *x); 82 83 84 /* ---------------------------------------------------------------------------- 85 * Decoding 86 * -------------------------------------------------------------------------- */ 87 88 /** 89 * Get spectral quantization side data 90 * bits Bitstream context 91 * dt, sr Duration and samplerate of the frame 92 * side Return quantization side data 93 * return 0: Ok -1: Invalid bandwidth indication 94 */ 95 int lc3_spec_get_side(lc3_bits_t *bits, 96 enum lc3_dt dt, enum lc3_srate sr, lc3_spec_side_t *side); 97 98 /** 99 * Decode spectral coefficients 100 * bits Bitstream context 101 * dt, sr, bw Duration, samplerate, bandwidth 102 * nbytes and size of the frame 103 * side Quantization side data 104 * x Spectral coefficients 105 * return 0: Ok -1: Invalid bitstream data 106 */ 107 int lc3_spec_decode(lc3_bits_t *bits, enum lc3_dt dt, enum lc3_srate sr, 108 enum lc3_bandwidth bw, int nbytes, const lc3_spec_side_t *side, float *x); 109 110 111 #endif /* __LC3_SPEC_H */ 112