comparison libfaad2/rvlc.c @ 12527:4a370c80fe5c

update to the 2.0 release of faad, patch by adland
author diego
date Wed, 02 Jun 2004 22:59:04 +0000
parents 3185f64f6350
children d81145997036
comparison
equal deleted inserted replaced
12526:e183ad37d24c 12527:4a370c80fe5c
1 /* 1 /*
2 ** FAAD2 - Freeware Advanced Audio (AAC) Decoder including SBR decoding 2 ** FAAD2 - Freeware Advanced Audio (AAC) Decoder including SBR decoding
3 ** Copyright (C) 2003 M. Bakker, Ahead Software AG, http://www.nero.com 3 ** Copyright (C) 2003-2004 M. Bakker, Ahead Software AG, http://www.nero.com
4 ** 4 **
5 ** This program is free software; you can redistribute it and/or modify 5 ** This program is free software; you can redistribute it and/or modify
6 ** it under the terms of the GNU General Public License as published by 6 ** it under the terms of the GNU General Public License as published by
7 ** the Free Software Foundation; either version 2 of the License, or 7 ** the Free Software Foundation; either version 2 of the License, or
8 ** (at your option) any later version. 8 ** (at your option) any later version.
20 ** forbidden. 20 ** forbidden.
21 ** 21 **
22 ** Commercial non-GPL licensing of this software is possible. 22 ** Commercial non-GPL licensing of this software is possible.
23 ** For more info contact Ahead Software through Mpeg4AAClicense@nero.com. 23 ** For more info contact Ahead Software through Mpeg4AAClicense@nero.com.
24 ** 24 **
25 ** $Id: rvlc.c,v 1.6 2003/09/09 18:09:52 menno Exp $ 25 ** $Id: rvlc.c,v 1.2 2003/10/03 22:22:27 alex Exp $
26 **/ 26 **/
27 27
28 /* RVLC scalefactor decoding 28 /* RVLC scalefactor decoding
29 * 29 *
30 * RVLC works like this: 30 * RVLC works like this:
50 50
51 #ifdef ERROR_RESILIENCE 51 #ifdef ERROR_RESILIENCE
52 52
53 //#define PRINT_RVLC 53 //#define PRINT_RVLC
54 54
55 /* static function declarations */
56 static uint8_t rvlc_decode_sf_forward(ic_stream *ics,
57 bitfile *ld_sf,
58 bitfile *ld_esc,
59 uint8_t *is_used);
60 #if 0
61 static uint8_t rvlc_decode_sf_reverse(ic_stream *ics,
62 bitfile *ld_sf,
63 bitfile *ld_esc,
64 uint8_t is_used);
65 #endif
66 static int8_t rvlc_huffman_sf(bitfile *ld_sf, bitfile *ld_esc,
67 int8_t direction);
68 static int8_t rvlc_huffman_esc(bitfile *ld_esc, int8_t direction);
69
70
55 uint8_t rvlc_scale_factor_data(ic_stream *ics, bitfile *ld) 71 uint8_t rvlc_scale_factor_data(ic_stream *ics, bitfile *ld)
56 { 72 {
57 uint8_t bits = 9; 73 uint8_t bits = 9;
58 74
59 ics->sf_concealment = faad_get1bit(ld 75 ics->sf_concealment = faad_get1bit(ld
60 DEBUGVAR(1,149,"rvlc_scale_factor_data(): sf_concealment")); 76 DEBUGVAR(1,149,"rvlc_scale_factor_data(): sf_concealment"));
61 ics->rev_global_gain = faad_getbits(ld, 8 77 ics->rev_global_gain = (uint8_t)faad_getbits(ld, 8
62 DEBUGVAR(1,150,"rvlc_scale_factor_data(): rev_global_gain")); 78 DEBUGVAR(1,150,"rvlc_scale_factor_data(): rev_global_gain"));
63 79
64 if (ics->window_sequence == EIGHT_SHORT_SEQUENCE) 80 if (ics->window_sequence == EIGHT_SHORT_SEQUENCE)
65 bits = 11; 81 bits = 11;
66 82
67 /* the number of bits used for the huffman codewords */ 83 /* the number of bits used for the huffman codewords */
68 ics->length_of_rvlc_sf = faad_getbits(ld, bits 84 ics->length_of_rvlc_sf = (uint16_t)faad_getbits(ld, bits
69 DEBUGVAR(1,151,"rvlc_scale_factor_data(): length_of_rvlc_sf")); 85 DEBUGVAR(1,151,"rvlc_scale_factor_data(): length_of_rvlc_sf"));
70 86
71 if (ics->noise_used) 87 if (ics->noise_used)
72 { 88 {
73 ics->dpcm_noise_nrg = faad_getbits(ld, 9 89 ics->dpcm_noise_nrg = (uint16_t)faad_getbits(ld, 9
74 DEBUGVAR(1,152,"rvlc_scale_factor_data(): dpcm_noise_nrg")); 90 DEBUGVAR(1,152,"rvlc_scale_factor_data(): dpcm_noise_nrg"));
75 91
76 ics->length_of_rvlc_sf -= 9; 92 ics->length_of_rvlc_sf -= 9;
77 } 93 }
78 94
79 ics->sf_escapes_present = faad_get1bit(ld 95 ics->sf_escapes_present = faad_get1bit(ld
80 DEBUGVAR(1,153,"rvlc_scale_factor_data(): sf_escapes_present")); 96 DEBUGVAR(1,153,"rvlc_scale_factor_data(): sf_escapes_present"));
81 97
82 if (ics->sf_escapes_present) 98 if (ics->sf_escapes_present)
83 { 99 {
84 ics->length_of_rvlc_escapes = faad_getbits(ld, 8 100 ics->length_of_rvlc_escapes = (uint8_t)faad_getbits(ld, 8
85 DEBUGVAR(1,154,"rvlc_scale_factor_data(): length_of_rvlc_escapes")); 101 DEBUGVAR(1,154,"rvlc_scale_factor_data(): length_of_rvlc_escapes"));
86 } 102 }
87 103
88 if (ics->noise_used) 104 if (ics->noise_used)
89 { 105 {
90 ics->dpcm_noise_last_position = faad_getbits(ld, 9 106 ics->dpcm_noise_last_position = (uint16_t)faad_getbits(ld, 9
91 DEBUGVAR(1,155,"rvlc_scale_factor_data(): dpcm_noise_last_position")); 107 DEBUGVAR(1,155,"rvlc_scale_factor_data(): dpcm_noise_last_position"));
92 } 108 }
93 109
94 return 0; 110 return 0;
95 } 111 }
134 &ld_rvlc_esc, &intensity_used); 150 &ld_rvlc_esc, &intensity_used);
135 // result = rvlc_decode_sf_reverse(ics, &ld_rvlc_sf_rev, 151 // result = rvlc_decode_sf_reverse(ics, &ld_rvlc_sf_rev,
136 // &ld_rvlc_esc_rev, intensity_used); 152 // &ld_rvlc_esc_rev, intensity_used);
137 153
138 154
139 if (rvlc_esc_buffer) free(rvlc_esc_buffer); 155 if (rvlc_esc_buffer) faad_free(rvlc_esc_buffer);
140 if (rvlc_sf_buffer) free(rvlc_sf_buffer); 156 if (rvlc_sf_buffer) faad_free(rvlc_sf_buffer);
141 157
142 if (ics->length_of_rvlc_sf > 0) 158 if (ics->length_of_rvlc_sf > 0)
143 faad_endbits(&ld_rvlc_sf); 159 faad_endbits(&ld_rvlc_sf);
144 if (ics->sf_escapes_present) 160 if (ics->sf_escapes_present)
145 faad_endbits(&ld_rvlc_esc); 161 faad_endbits(&ld_rvlc_esc);
233 #endif 249 #endif
234 250
235 return 0; 251 return 0;
236 } 252 }
237 253
254 #if 0 // not used right now, doesn't work correctly yet
238 static uint8_t rvlc_decode_sf_reverse(ic_stream *ics, bitfile *ld_sf, bitfile *ld_esc, 255 static uint8_t rvlc_decode_sf_reverse(ic_stream *ics, bitfile *ld_sf, bitfile *ld_esc,
239 uint8_t intensity_used) 256 uint8_t intensity_used)
240 { 257 {
241 int8_t g, sfb; 258 int8_t g, sfb;
242 int8_t t = 0; 259 int8_t t = 0;
281 ics->scale_factors[g][sfb] = is_position; 298 ics->scale_factors[g][sfb] = is_position;
282 } else { 299 } else {
283 t = rvlc_huffman_sf(ld_sf, ld_esc, -1); 300 t = rvlc_huffman_sf(ld_sf, ld_esc, -1);
284 is_position -= t; 301 is_position -= t;
285 302
286 ics->scale_factors[g][sfb] = is_position; 303 ics->scale_factors[g][sfb] = (uint8_t)is_position;
287 } 304 }
288
289 break; 305 break;
290 case NOISE_HCB: /* noise books */ 306 case NOISE_HCB: /* noise books */
291 307
292 /* decode noise energy */ 308 /* decode noise energy */
293 if (noise_pcm_flag) 309 if (noise_pcm_flag)
297 } else { 313 } else {
298 t = rvlc_huffman_sf(ld_sf, ld_esc, -1); 314 t = rvlc_huffman_sf(ld_sf, ld_esc, -1);
299 noise_energy -= t; 315 noise_energy -= t;
300 } 316 }
301 317
302 ics->scale_factors[g][sfb] = noise_energy; 318 ics->scale_factors[g][sfb] = (uint8_t)noise_energy;
303
304 break; 319 break;
305 default: /* spectral books */ 320 default: /* spectral books */
306 321
307 if (sf_pcm_flag || (sfb == 0)) 322 if (sf_pcm_flag || (sfb == 0))
308 { 323 {
313 /* decode scale factor */ 328 /* decode scale factor */
314 t = rvlc_huffman_sf(ld_sf, ld_esc, -1); 329 t = rvlc_huffman_sf(ld_sf, ld_esc, -1);
315 scale_factor -= t; 330 scale_factor -= t;
316 } 331 }
317 332
318 ics->scale_factors[g][sfb] = scale_factor;
319
320 if (scale_factor < 0) 333 if (scale_factor < 0)
321 return 4; 334 return 4;
322 335
336 ics->scale_factors[g][sfb] = (uint8_t)scale_factor;
323 break; 337 break;
324 } 338 }
325 #ifdef PRINT_RVLC 339 #ifdef PRINT_RVLC
326 printf("%3d:%4d%4d\n", sfb, ics->sfb_cb[g][sfb], 340 printf("%3d:%4d%4d\n", sfb, ics->sfb_cb[g][sfb],
327 ics->scale_factors[g][sfb]); 341 ics->scale_factors[g][sfb]);
338 printf("\n\n"); 352 printf("\n\n");
339 #endif 353 #endif
340 354
341 return 0; 355 return 0;
342 } 356 }
357 #endif
343 358
344 /* index == 99 means not allowed codeword */ 359 /* index == 99 means not allowed codeword */
345 static rvlc_huff_table book_rvlc[] = { 360 static rvlc_huff_table book_rvlc[] = {
346 /*index length codeword */ 361 /*index length codeword */
347 { 0, 1, 0 }, /* 0 */ 362 { 0, 1, 0 }, /* 0 */
510 525
511 return h->index; 526 return h->index;
512 } 527 }
513 528
514 #endif 529 #endif
530