1 /****************************************************************************** 2 * 3 * Copyright 2015 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 #ifndef __LC3_PRIVATE_H 20 #define __LC3_PRIVATE_H 21 22 #include <stdint.h> 23 #include <stdbool.h> 24 25 26 /** 27 * Return number of samples, delayed samples and 28 * encoded spectrum coefficients within a frame 29 * For decoding, add number of samples of 18 ms history 30 */ 31 32 #define __LC3_NS(dt_us, sr_hz) \ 33 ((dt_us * sr_hz) / 1000 / 1000) 34 35 #define __LC3_ND(dt_us, sr_hz) \ 36 ( (dt_us) == 7500 ? 23 * __LC3_NS(dt_us, sr_hz) / 30 \ 37 : 5 * __LC3_NS(dt_us, sr_hz) / 8 ) 38 39 #define __LC3_NH(sr_hz) \ 40 ( (18 * sr_hz) / 1000 ) 41 42 43 /** 44 * Frame duration 7.5ms or 10ms 45 */ 46 47 enum lc3_dt { 48 LC3_DT_7M5, 49 LC3_DT_10M, 50 51 LC3_NUM_DT 52 }; 53 54 /** 55 * Sampling frequency 56 */ 57 58 enum lc3_srate { 59 LC3_SRATE_8K, 60 LC3_SRATE_16K, 61 LC3_SRATE_24K, 62 LC3_SRATE_32K, 63 LC3_SRATE_48K, 64 65 LC3_NUM_SRATE, 66 }; 67 68 69 /** 70 * Encoder state and memory 71 */ 72 73 typedef struct lc3_attdet_analysis { 74 float en1, an1; 75 int p_att; 76 } lc3_attdet_analysis_t; 77 78 struct lc3_ltpf_hp50_state { 79 float s1, s2; 80 }; 81 82 typedef struct lc3_ltpf_analysis { 83 bool active; 84 int pitch; 85 float nc[2]; 86 87 struct lc3_ltpf_hp50_state hp50; 88 float x_12k8[384]; 89 float x_6k4[178]; 90 int tc; 91 } lc3_ltpf_analysis_t; 92 93 typedef struct lc3_spec_analysis { 94 float nbits_off; 95 int nbits_spare; 96 } lc3_spec_analysis_t; 97 98 struct lc3_encoder { 99 enum lc3_dt dt; 100 enum lc3_srate sr, sr_pcm; 101 102 lc3_attdet_analysis_t attdet; 103 lc3_ltpf_analysis_t ltpf; 104 lc3_spec_analysis_t spec; 105 106 // BK: s[0] -> s[1] to avoid compiler warning for zero sized warning 107 float *xs, *xf, s[1]; 108 }; 109 110 #define LC3_ENCODER_BUFFER_COUNT(dt_us, sr_hz) \ 111 ( 2*__LC3_NS(dt_us, sr_hz) + __LC3_ND(dt_us, sr_hz) ) 112 113 #define LC3_ENCODER_MEM_T(dt_us, sr_hz) \ 114 struct { \ 115 struct lc3_encoder __e; \ 116 float __s[LC3_ENCODER_BUFFER_COUNT(dt_us, sr_hz)]; \ 117 } 118 119 120 /** 121 * Decoder state and memory 122 */ 123 124 typedef struct lc3_ltpf_synthesis { 125 bool active; 126 int pitch; 127 float c[12][2], x[12]; 128 } lc3_ltpf_synthesis_t; 129 130 typedef struct lc3_plc_state { 131 uint16_t seed; 132 int count; 133 float alpha; 134 } lc3_plc_state_t; 135 136 struct lc3_decoder { 137 enum lc3_dt dt; 138 enum lc3_srate sr, sr_pcm; 139 140 lc3_ltpf_synthesis_t ltpf; 141 lc3_plc_state_t plc; 142 143 // BK: s[0] -> s[1] to avoid compiler warning for zero sized warning 144 float *xs, *xd, *xg, s[1]; 145 }; 146 147 #define LC3_DECODER_BUFFER_COUNT(dt_us, sr_hz) \ 148 ( __LC3_NH(sr_hz) + __LC3_NS(dt_us, sr_hz) + \ 149 __LC3_ND(dt_us, sr_hz) + __LC3_NS(dt_us, sr_hz) ) 150 151 #define LC3_DECODER_MEM_T(dt_us, sr_hz) \ 152 struct { \ 153 struct lc3_decoder __d; \ 154 float __s[LC3_DECODER_BUFFER_COUNT(dt_us, sr_hz)]; \ 155 } 156 157 158 #endif /* __LC3_PRIVATE_H */ 159