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 float *xs, *xf, s[0]; 107 }; 108 109 #define LC3_ENCODER_BUFFER_COUNT(dt_us, sr_hz) \ 110 ( 2*__LC3_NS(dt_us, sr_hz) + __LC3_ND(dt_us, sr_hz) ) 111 112 #define LC3_ENCODER_MEM_T(dt_us, sr_hz) \ 113 struct { \ 114 struct lc3_encoder __e; \ 115 float __s[LC3_ENCODER_BUFFER_COUNT(dt_us, sr_hz)]; \ 116 } 117 118 119 /** 120 * Decoder state and memory 121 */ 122 123 typedef struct lc3_ltpf_synthesis { 124 bool active; 125 int pitch; 126 float c[12][2], x[12]; 127 } lc3_ltpf_synthesis_t; 128 129 typedef struct lc3_plc_state { 130 uint16_t seed; 131 int count; 132 float alpha; 133 } lc3_plc_state_t; 134 135 struct lc3_decoder { 136 enum lc3_dt dt; 137 enum lc3_srate sr, sr_pcm; 138 139 lc3_ltpf_synthesis_t ltpf; 140 lc3_plc_state_t plc; 141 142 float *xs, *xd, *xg, s[0]; 143 }; 144 145 #define LC3_DECODER_BUFFER_COUNT(dt_us, sr_hz) \ 146 ( __LC3_NH(sr_hz) + __LC3_NS(dt_us, sr_hz) + \ 147 __LC3_ND(dt_us, sr_hz) + __LC3_NS(dt_us, sr_hz) ) 148 149 #define LC3_DECODER_MEM_T(dt_us, sr_hz) \ 150 struct { \ 151 struct lc3_decoder __d; \ 152 float __s[LC3_DECODER_BUFFER_COUNT(dt_us, sr_hz)]; \ 153 } 154 155 156 #endif /* __LC3_PRIVATE_H */ 157