| 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_TABLES_H |
| 20 |
#define __LC3_TABLES_H |
| 21 |
|
| 22 |
#include "common.h" |
| 23 |
#include "bits.h" |
| 24 |
|
| 25 |
|
| 26 |
/** |
| 27 |
* Characteristics |
| 28 |
* |
| 29 |
* ns Number of temporal samples / frequency coefficients within a frame |
| 30 |
* |
| 31 |
* ne Number of encoded frequency coefficients |
| 32 |
* |
| 33 |
* nd Number of MDCT delayed samples, sum of half a frame and an ovelap |
| 34 |
* of future by 1.25 ms (2.5ms, 5ms and 10ms frame durations), |
| 35 |
* or 2 ms (7.5ms frame duration). |
| 36 |
* |
| 37 |
* nh Number of 18 ms samples of the history buffer, aligned on a frame |
| 38 |
* |
| 39 |
* nt Number of 1.25 ms previous samples |
| 40 |
*/ |
| 41 |
|
| 42 |
extern const int lc3_ns_2m5[LC3_NUM_SRATE]; |
| 43 |
extern const int lc3_ne_2m5[LC3_NUM_SRATE]; |
| 44 |
extern const int lc3_ns_4m [LC3_NUM_SRATE]; |
| 45 |
|
| 46 |
static inline int lc3_ns(enum lc3_dt dt, enum lc3_srate sr) { |
| 47 |
return lc3_ns_2m5[sr] * (1 + dt); |
| 48 |
} |
| 49 |
|
| 50 |
static inline int lc3_ne(enum lc3_dt dt, enum lc3_srate sr) { |
| 51 |
return lc3_ne_2m5[sr] * (1 + dt); |
| 52 |
} |
| 53 |
|
| 54 |
static inline int lc3_nd(enum lc3_dt dt, enum lc3_srate sr) { |
| 55 |
return ( lc3_ns(dt, sr) + |
| 56 |
(dt == LC3_DT_7M5 ? lc3_ns_4m[sr] : lc3_ns_2m5[sr]) ) >> 1; |
| 57 |
} |
| 58 |
|
| 59 |
static inline int lc3_nh(enum lc3_dt dt, enum lc3_srate sr) { |
| 60 |
return sr > LC3_SRATE_48K_HR ? 0 : |
| 61 |
(8 + (dt == LC3_DT_7M5)) * lc3_ns_2m5[sr]; |
| 62 |
} |
| 63 |
|
| 64 |
static inline int lc3_nt(enum lc3_srate sr) { |
| 65 |
return lc3_ns_2m5[sr] >> 1; |
| 66 |
} |
| 67 |
|
| 68 |
#define LC3_MAX_SRATE_HZ ( LC3_PLUS_HR ? 96000 : 48000 ) |
| 69 |
|
| 70 |
#define LC3_MAX_NS ( LC3_NS(10000, LC3_MAX_SRATE_HZ) ) |
| 71 |
#define LC3_MAX_NE ( LC3_PLUS_HR ? LC3_MAX_NS : LC3_NS(10000, 40000) ) |
| 72 |
|
| 73 |
|
| 74 |
/** |
| 75 |
* Limits on size of frame |
| 76 |
*/ |
| 77 |
|
| 78 |
extern const int lc3_frame_bytes_hr_lim |
| 79 |
[LC3_NUM_DT][LC3_NUM_SRATE - LC3_SRATE_48K_HR][2]; |
| 80 |
|
| 81 |
static inline int lc3_min_frame_bytes(enum lc3_dt dt, enum lc3_srate sr) { |
| 82 |
return !lc3_hr(sr) ? LC3_MIN_FRAME_BYTES : |
| 83 |
lc3_frame_bytes_hr_lim[dt][sr - LC3_SRATE_48K_HR][0]; |
| 84 |
} |
| 85 |
|
| 86 |
static inline int lc3_max_frame_bytes(enum lc3_dt dt, enum lc3_srate sr) { |
| 87 |
return !lc3_hr(sr) ? LC3_MAX_FRAME_BYTES : |
| 88 |
lc3_frame_bytes_hr_lim[dt][sr - LC3_SRATE_48K_HR][1]; |
| 89 |
} |
| 90 |
|
| 91 |
|
| 92 |
/** |
| 93 |
* MDCT Twiddles and window coefficients |
| 94 |
*/ |
| 95 |
|
| 96 |
struct lc3_fft_bf3_twiddles { int n3; const struct lc3_complex (*t)[2]; }; |
| 97 |
struct lc3_fft_bf2_twiddles { int n2; const struct lc3_complex *t; }; |
| 98 |
struct lc3_mdct_rot_def { int n4; const struct lc3_complex *w; }; |
| 99 |
|
| 100 |
extern const struct lc3_fft_bf3_twiddles *lc3_fft_twiddles_bf3[]; |
| 101 |
extern const struct lc3_fft_bf2_twiddles *lc3_fft_twiddles_bf2[][3]; |
| 102 |
extern const struct lc3_mdct_rot_def *lc3_mdct_rot[LC3_NUM_DT][LC3_NUM_SRATE]; |
| 103 |
|
| 104 |
extern const float *lc3_mdct_win[LC3_NUM_DT][LC3_NUM_SRATE]; |
| 105 |
|
| 106 |
|
| 107 |
/** |
| 108 |
* Limits of bands |
| 109 |
*/ |
| 110 |
|
| 111 |
#define LC3_MAX_BANDS 64 |
| 112 |
|
| 113 |
extern const int lc3_num_bands[LC3_NUM_DT][LC3_NUM_SRATE]; |
| 114 |
extern const int *lc3_band_lim[LC3_NUM_DT][LC3_NUM_SRATE]; |
| 115 |
|
| 116 |
|
| 117 |
/** |
| 118 |
* SNS Quantization |
| 119 |
*/ |
| 120 |
|
| 121 |
extern const float lc3_sns_lfcb[32][8]; |
| 122 |
extern const float lc3_sns_hfcb[32][8]; |
| 123 |
|
| 124 |
struct lc3_sns_vq_gains { |
| 125 |
int count; const float *v; |
| 126 |
}; |
| 127 |
|
| 128 |
extern const struct lc3_sns_vq_gains lc3_sns_vq_gains[4]; |
| 129 |
|
| 130 |
extern const int32_t lc3_sns_mpvq_offsets[][11]; |
| 131 |
|
| 132 |
|
| 133 |
/** |
| 134 |
* TNS Arithmetic Coding |
| 135 |
*/ |
| 136 |
|
| 137 |
extern const struct lc3_ac_model lc3_tns_order_models[]; |
| 138 |
extern const uint16_t lc3_tns_order_bits[][8]; |
| 139 |
|
| 140 |
extern const struct lc3_ac_model lc3_tns_coeffs_models[]; |
| 141 |
extern const uint16_t lc3_tns_coeffs_bits[][17]; |
| 142 |
|
| 143 |
|
| 144 |
/** |
| 145 |
* Long Term Postfilter |
| 146 |
*/ |
| 147 |
|
| 148 |
extern const float *lc3_ltpf_cnum[LC3_NUM_SRATE][4]; |
| 149 |
extern const float *lc3_ltpf_cden[LC3_NUM_SRATE][4]; |
| 150 |
|
| 151 |
|
| 152 |
/** |
| 153 |
* Spectral Data Arithmetic Coding |
| 154 |
*/ |
| 155 |
|
| 156 |
extern const uint8_t lc3_spectrum_lookup[2][2][256][4]; |
| 157 |
extern const struct lc3_ac_model lc3_spectrum_models[]; |
| 158 |
extern const uint16_t lc3_spectrum_bits[][17]; |
| 159 |
|
| 160 |
|
| 161 |
#endif /* __LC3_TABLES_H */ |