Mercurial > libavcodec.hg
comparison mace.c @ 8000:5ef823d919d5 libavcodec
Use a for() instead of triplicating code.
author | vitor |
---|---|
date | Sun, 05 Oct 2008 16:33:43 +0000 |
parents | 2dbed1c6a963 |
children | 038bb3b45b34 |
comparison
equal
deleted
inserted
replaced
7999:582e4aae5d16 | 8000:5ef823d919d5 |
---|---|
136 { 10278, 32767}, { 10737, 32767}, { 11216, 32767}, { 11717, 32767}, | 136 { 10278, 32767}, { 10737, 32767}, { 11216, 32767}, { 11717, 32767}, |
137 { 12240, 32767}, { 12786, 32767}, { 13356, 32767}, { 13953, 32767}, | 137 { 12240, 32767}, { 12786, 32767}, { 13356, 32767}, { 13953, 32767}, |
138 { 14576, 32767}, { 15226, 32767}, { 15906, 32767}, { 16615, 32767} | 138 { 14576, 32767}, { 15226, 32767}, { 15906, 32767}, { 16615, 32767} |
139 }; | 139 }; |
140 | 140 |
141 static const struct { | |
142 const int16_t *tab1; const int16_t *tab2; int stride; | |
143 } tabs[] = { | |
144 {MACEtab1, &MACEtab2[0][0], 4}, | |
145 {MACEtab3, &MACEtab4[0][0], 2}, | |
146 {MACEtab1, &MACEtab2[0][0], 4} | |
147 }; | |
148 | |
141 #define QT_8S_2_16S(x) (((x) & 0xFF00) | (((x) >> 8) & 0xFF)) | 149 #define QT_8S_2_16S(x) (((x) & 0xFF00) | (((x) >> 8) & 0xFF)) |
142 | 150 |
143 typedef struct ChannelData { | 151 typedef struct ChannelData { |
144 int16_t index, factor, prev2, previous, level; | 152 int16_t index, factor, prev2, previous, level; |
145 } ChannelData; | 153 } ChannelData; |
160 return -32767; | 168 return -32767; |
161 else | 169 else |
162 return n; | 170 return n; |
163 } | 171 } |
164 | 172 |
165 static int16_t read_table(ChannelData *chd, uint8_t val, const int16_t tab1[], | 173 static int16_t read_table(ChannelData *chd, uint8_t val, int tab_idx) |
166 const int16_t *tab2, int tab2_stride) | |
167 { | 174 { |
168 int16_t current; | 175 int16_t current; |
169 | 176 |
170 if (val < tab2_stride) | 177 if (val < tabs[tab_idx].stride) |
171 current = tab2[((chd->index & 0x7f0) >> 4)*tab2_stride + val]; | 178 current = tabs[tab_idx].tab2[((chd->index & 0x7f0) >> 4) * tabs[tab_idx].stride + val]; |
172 else | 179 else |
173 current = - 1 - tab2[((chd->index & 0x7f0) >> 4)*tab2_stride + 2*tab2_stride-val-1]; | 180 current = - 1 - tabs[tab_idx].tab2[((chd->index & 0x7f0) >> 4)*tabs[tab_idx].stride + 2*tabs[tab_idx].stride-val-1]; |
174 | 181 |
175 if (( chd->index += tab1[val]-(chd->index >> 5) ) < 0) | 182 if (( chd->index += tabs[tab_idx].tab1[val]-(chd->index >> 5) ) < 0) |
176 chd->index = 0; | 183 chd->index = 0; |
177 | 184 |
178 return current; | 185 return current; |
179 } | 186 } |
180 | 187 |
181 static void chomp3(ChannelData *chd, int16_t *output, uint8_t val, | 188 static void chomp3(ChannelData *chd, int16_t *output, uint8_t val, |
182 const int16_t tab1[], | 189 int tab_idx, |
183 const int16_t *tab2, int tab2_stride, | |
184 uint32_t numChannels) | 190 uint32_t numChannels) |
185 { | 191 { |
186 | 192 |
187 int16_t current = read_table(chd, val, tab1, tab2, tab2_stride); | 193 int16_t current = read_table(chd, val, tab_idx); |
188 | 194 |
189 current = mace_broken_clip_int16(current + chd->level); | 195 current = mace_broken_clip_int16(current + chd->level); |
190 | 196 |
191 chd->level = current - (current >> 3); | 197 chd->level = current - (current >> 3); |
192 *output = QT_8S_2_16S(current); | 198 *output = QT_8S_2_16S(current); |
193 } | 199 } |
194 | 200 |
195 static void chomp6(ChannelData *chd, int16_t *output, uint8_t val, | 201 static void chomp6(ChannelData *chd, int16_t *output, uint8_t val, |
196 const int16_t tab1[], | 202 int tab_idx, |
197 const int16_t *tab2, int tab2_stride, | |
198 uint32_t numChannels) | 203 uint32_t numChannels) |
199 { | 204 { |
200 int16_t current = read_table(chd, val, tab1, tab2, tab2_stride); | 205 int16_t current = read_table(chd, val, tab_idx); |
201 | 206 |
202 if ((chd->previous ^ current) >= 0) { | 207 if ((chd->previous ^ current) >= 0) { |
203 chd->factor = FFMIN(chd->factor + 506, 32767); | 208 chd->factor = FFMIN(chd->factor + 506, 32767); |
204 } else { | 209 } else { |
205 if (chd->factor - 314 < -32768) | 210 if (chd->factor - 314 < -32768) |
233 void *data, int *data_size, | 238 void *data, int *data_size, |
234 const uint8_t *buf, int buf_size) | 239 const uint8_t *buf, int buf_size) |
235 { | 240 { |
236 int16_t *samples = data; | 241 int16_t *samples = data; |
237 MACEContext *ctx = avctx->priv_data; | 242 MACEContext *ctx = avctx->priv_data; |
238 int i, j, k; | 243 int i, j, k, l; |
239 | 244 |
240 if (*data_size < 2 * 3 * buf_size) { | 245 if (*data_size < 2 * 3 * buf_size) { |
241 av_log(avctx, AV_LOG_ERROR, "Output buffer too small!\n"); | 246 av_log(avctx, AV_LOG_ERROR, "Output buffer too small!\n"); |
242 return -1; | 247 return -1; |
243 } | 248 } |
246 int16_t *output = samples + i; | 251 int16_t *output = samples + i; |
247 | 252 |
248 for (j=0; j < buf_size / 2 / avctx->channels; j++) | 253 for (j=0; j < buf_size / 2 / avctx->channels; j++) |
249 for (k=0; k < 2; k++) { | 254 for (k=0; k < 2; k++) { |
250 uint8_t pkt = buf[i*2 + j*2*avctx->channels + k]; | 255 uint8_t pkt = buf[i*2 + j*2*avctx->channels + k]; |
251 chomp3(&ctx->chd[i], output, pkt &7, MACEtab1, MACEtab2, | 256 uint8_t val[3] = {pkt & 7, (pkt >> 3) & 3, pkt >> 5}; |
252 4, avctx->channels); | 257 |
253 output += avctx->channels; | 258 for (l=0; l < 3; l++) { |
254 chomp3(&ctx->chd[i], output,(pkt >> 3) &3, MACEtab3, MACEtab4, | 259 chomp3(&ctx->chd[i], output, val[l], l, avctx->channels); |
255 2, avctx->channels); | 260 output += avctx->channels; |
256 output += avctx->channels; | 261 } |
257 chomp3(&ctx->chd[i], output, pkt >> 5 , MACEtab1, MACEtab2, | |
258 4, avctx->channels); | |
259 output += avctx->channels; | |
260 } | 262 } |
261 } | 263 } |
262 | 264 |
263 *data_size = 2 * 3 * buf_size; | 265 *data_size = 2 * 3 * buf_size; |
264 | 266 |
269 void *data, int *data_size, | 271 void *data, int *data_size, |
270 const uint8_t *buf, int buf_size) | 272 const uint8_t *buf, int buf_size) |
271 { | 273 { |
272 int16_t *samples = data; | 274 int16_t *samples = data; |
273 MACEContext *ctx = avctx->priv_data; | 275 MACEContext *ctx = avctx->priv_data; |
274 int i, j; | 276 int i, j, l; |
275 | 277 |
276 if (*data_size < 2 * 6 * buf_size) { | 278 if (*data_size < 2 * 6 * buf_size) { |
277 av_log(avctx, AV_LOG_ERROR, "Output buffer too small!\n"); | 279 av_log(avctx, AV_LOG_ERROR, "Output buffer too small!\n"); |
278 return -1; | 280 return -1; |
279 } | 281 } |
281 for(i = 0; i < avctx->channels; i++) { | 283 for(i = 0; i < avctx->channels; i++) { |
282 int16_t *output = samples + i; | 284 int16_t *output = samples + i; |
283 | 285 |
284 for (j = 0; j < buf_size / avctx->channels; j++) { | 286 for (j = 0; j < buf_size / avctx->channels; j++) { |
285 uint8_t pkt = buf[i + j*avctx->channels]; | 287 uint8_t pkt = buf[i + j*avctx->channels]; |
286 | 288 uint8_t val[3] = {pkt >> 5, (pkt >> 3) & 3, pkt & 7}; |
287 chomp6(&ctx->chd[i], output, pkt >> 5 , MACEtab1, MACEtab2, | 289 |
288 4, avctx->channels); | 290 for (l=0; l < 3; l++) { |
289 output += avctx->channels << 1; | 291 chomp6(&ctx->chd[i], output, val[l], l, avctx->channels); |
290 chomp6(&ctx->chd[i], output,(pkt >> 3) & 3, MACEtab3, MACEtab4, | 292 output += avctx->channels << 1; |
291 2, avctx->channels); | 293 } |
292 output += avctx->channels << 1; | |
293 chomp6(&ctx->chd[i], output, pkt & 7, MACEtab1, MACEtab2, | |
294 4, avctx->channels); | |
295 output += avctx->channels << 1; | |
296 } | 294 } |
297 } | 295 } |
298 | 296 |
299 *data_size = 2 * 6 * buf_size; | 297 *data_size = 2 * 6 * buf_size; |
300 | 298 |