Mercurial > mplayer.hg
comparison libfaad2/huffman.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: huffman.c,v 1.4 2003/09/09 18:12:00 menno Exp $ | 25 ** $Id: huffman.c,v 1.1 2003/10/03 22:23:26 alex Exp $ |
26 **/ | 26 **/ |
27 | 27 |
28 #include "common.h" | 28 #include "common.h" |
29 #include "structs.h" | 29 #include "structs.h" |
30 | 30 |
35 | 35 |
36 #include "bits.h" | 36 #include "bits.h" |
37 #include "huffman.h" | 37 #include "huffman.h" |
38 #include "codebook/hcb.h" | 38 #include "codebook/hcb.h" |
39 | 39 |
40 | |
41 /* static function declarations */ | |
42 static INLINE void huffman_sign_bits(bitfile *ld, int16_t *sp, uint8_t len); | |
43 static INLINE int16_t huffman_getescape(bitfile *ld, int16_t sp); | |
44 static uint8_t huffman_2step_quad(uint8_t cb, bitfile *ld, int16_t *sp); | |
45 static uint8_t huffman_2step_quad_sign(uint8_t cb, bitfile *ld, int16_t *sp); | |
46 static uint8_t huffman_2step_pair(uint8_t cb, bitfile *ld, int16_t *sp); | |
47 static uint8_t huffman_2step_pair_sign(uint8_t cb, bitfile *ld, int16_t *sp); | |
48 static uint8_t huffman_binary_quad(uint8_t cb, bitfile *ld, int16_t *sp); | |
49 static uint8_t huffman_binary_quad_sign(uint8_t cb, bitfile *ld, int16_t *sp); | |
50 static uint8_t huffman_binary_pair(uint8_t cb, bitfile *ld, int16_t *sp); | |
51 static uint8_t huffman_binary_pair_sign(uint8_t cb, bitfile *ld, int16_t *sp); | |
52 static int16_t huffman_codebook(uint8_t i); | |
40 | 53 |
41 int8_t huffman_scale_factor(bitfile *ld) | 54 int8_t huffman_scale_factor(bitfile *ld) |
42 { | 55 { |
43 uint16_t offset = 0; | 56 uint16_t offset = 0; |
44 | 57 |
105 } | 118 } |
106 | 119 |
107 static INLINE int16_t huffman_getescape(bitfile *ld, int16_t sp) | 120 static INLINE int16_t huffman_getescape(bitfile *ld, int16_t sp) |
108 { | 121 { |
109 uint8_t neg, i; | 122 uint8_t neg, i; |
110 int16_t j; | 123 int32_t j; |
111 int32_t off; | 124 int32_t off; |
112 | 125 |
113 if (sp < 0) | 126 if (sp < 0) |
114 { | 127 { |
115 if (sp != -16) | 128 if (sp != -16) |
116 return sp; | 129 return sp; |
117 neg = 1; | 130 neg = 1; |
118 } else { | 131 } else { |
119 if(sp != 16) | 132 if (sp != 16) |
120 return sp; | 133 return sp; |
121 neg = 0; | 134 neg = 0; |
122 } | 135 } |
123 | 136 |
124 for (i = 4; ; i++) | 137 for (i = 4; ; i++) |
131 } | 144 } |
132 | 145 |
133 off = faad_getbits(ld, i | 146 off = faad_getbits(ld, i |
134 DEBUGVAR(1,9,"huffman_getescape(): escape")); | 147 DEBUGVAR(1,9,"huffman_getescape(): escape")); |
135 | 148 |
136 j = off + (1<<i); | 149 j = off | (1<<i); |
137 if (neg) | 150 if (neg) |
138 j = -j; | 151 j = -j; |
139 | 152 |
140 return j; | 153 return j; |
141 } | 154 } |
214 sp[1] = hcb_2_pair_table[cb][offset].y; | 227 sp[1] = hcb_2_pair_table[cb][offset].y; |
215 | 228 |
216 return 0; | 229 return 0; |
217 } | 230 } |
218 | 231 |
219 static huffman_2step_pair_sign(uint8_t cb, bitfile *ld, int16_t *sp) | 232 static uint8_t huffman_2step_pair_sign(uint8_t cb, bitfile *ld, int16_t *sp) |
220 { | 233 { |
221 uint8_t err = huffman_2step_pair(cb, ld, sp); | 234 uint8_t err = huffman_2step_pair(cb, ld, sp); |
222 huffman_sign_bits(ld, sp, PAIR_LEN); | 235 huffman_sign_bits(ld, sp, PAIR_LEN); |
223 | 236 |
224 return err; | 237 return err; |
317 return huffman_binary_pair_sign(cb, ld, sp); | 330 return huffman_binary_pair_sign(cb, ld, sp); |
318 case 8: /* 2-step method for data pairs */ | 331 case 8: /* 2-step method for data pairs */ |
319 case 10: | 332 case 10: |
320 return huffman_2step_pair_sign(cb, ld, sp); | 333 return huffman_2step_pair_sign(cb, ld, sp); |
321 case 12: { | 334 case 12: { |
322 uint8_t err = huffman_2step_quad(1, ld, sp); | 335 uint8_t err = huffman_2step_pair(11, ld, sp); |
323 sp[0] = huffman_codebook(0); sp[1] = huffman_codebook(1); | 336 sp[0] = huffman_codebook(0); sp[1] = huffman_codebook(1); |
324 return err; } | 337 return err; } |
325 case 11: | 338 case 11: |
326 #ifdef ERROR_RESILIENCE | 339 #ifdef ERROR_RESILIENCE |
327 /* VCB11 uses codebook 11 */ | 340 /* VCB11 uses codebook 11 */ |
355 { | 368 { |
356 uint32_t cw; | 369 uint32_t cw; |
357 uint16_t offset = 0; | 370 uint16_t offset = 0; |
358 uint8_t extra_bits; | 371 uint8_t extra_bits; |
359 uint8_t i; | 372 uint8_t i; |
360 uint8_t save_cb = cb; | |
361 | 373 |
362 | 374 |
363 switch (cb) | 375 switch (cb) |
364 { | 376 { |
365 case 1: /* 2-step method for data quadruples */ | 377 case 1: /* 2-step method for data quadruples */ |