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