summaryrefslogtreecommitdiff
path: root/apps/codecs/libfaad/huffman.c
diff options
context:
space:
mode:
Diffstat (limited to 'apps/codecs/libfaad/huffman.c')
-rw-r--r--apps/codecs/libfaad/huffman.c69
1 files changed, 36 insertions, 33 deletions
diff --git a/apps/codecs/libfaad/huffman.c b/apps/codecs/libfaad/huffman.c
index c142ad7ac7..bea0dd7bf2 100644
--- a/apps/codecs/libfaad/huffman.c
+++ b/apps/codecs/libfaad/huffman.c
@@ -39,17 +39,18 @@
39 39
40 40
41/* static function declarations */ 41/* static function declarations */
42static INLINE void huffman_sign_bits(bitfile *ld, int16_t *sp, uint8_t len); 42static INLINE void huffman_sign_bits_pair(bitfile *ld, int16_t *sp);
43static INLINE void huffman_sign_bits_quad(bitfile *ld, int16_t *sp);
43static INLINE int16_t huffman_getescape(bitfile *ld, int16_t sp); 44static INLINE int16_t huffman_getescape(bitfile *ld, int16_t sp);
44static uint8_t huffman_2step_quad(uint8_t cb, bitfile *ld, int16_t *sp); 45static uint8_t huffman_2step_quad(uint8_t cb, bitfile *ld, int16_t *sp);
45static uint8_t huffman_2step_quad_sign(uint8_t cb, bitfile *ld, int16_t *sp); 46static uint8_t huffman_2step_quad_sign(uint8_t cb, bitfile *ld, int16_t *sp);
46static uint8_t huffman_2step_pair(uint8_t cb, bitfile *ld, int16_t *sp); 47static INLINE uint8_t huffman_2step_pair(uint8_t cb, bitfile *ld, int16_t *sp);
47static uint8_t huffman_2step_pair_sign(uint8_t cb, bitfile *ld, int16_t *sp); 48static INLINE uint8_t huffman_2step_pair_sign(uint8_t cb, bitfile *ld, int16_t *sp);
48static uint8_t huffman_binary_quad(uint8_t cb, bitfile *ld, int16_t *sp); 49static uint8_t huffman_binary_quad(uint8_t cb, bitfile *ld, int16_t *sp);
49static uint8_t huffman_binary_quad_sign(uint8_t cb, bitfile *ld, int16_t *sp); 50static uint8_t huffman_binary_quad_sign(uint8_t cb, bitfile *ld, int16_t *sp);
50static uint8_t huffman_binary_pair(uint8_t cb, bitfile *ld, int16_t *sp); 51static uint8_t huffman_binary_pair(uint8_t cb, bitfile *ld, int16_t *sp);
51static uint8_t huffman_binary_pair_sign(uint8_t cb, bitfile *ld, int16_t *sp); 52static uint8_t huffman_binary_pair_sign(uint8_t cb, bitfile *ld, int16_t *sp);
52static int16_t huffman_codebook(uint8_t i); 53static int16_t huffman_codebook(uint8_t i) ICODE_ATTR_FAAD_LARGE_IRAM;
53#ifdef ERROR_RESILIENCE 54#ifdef ERROR_RESILIENCE
54static void vcb11_check_LAV(uint8_t cb, int16_t *sp); 55static void vcb11_check_LAV(uint8_t cb, int16_t *sp);
55#endif 56#endif
@@ -75,49 +76,51 @@ int8_t huffman_scale_factor(bitfile *ld)
75} 76}
76 77
77 78
78hcb *hcb_table[] = { 79hcb *hcb_table[] ICONST_ATTR = {
79 0, hcb1_1, hcb2_1, 0, hcb4_1, 0, hcb6_1, 0, hcb8_1, 0, hcb10_1, hcb11_1 80 0, hcb1_1, hcb2_1, 0, hcb4_1, 0, hcb6_1, 0, hcb8_1, 0, hcb10_1, hcb11_1
80}; 81};
81 82
82hcb_2_quad *hcb_2_quad_table[] = { 83hcb_2_quad *hcb_2_quad_table[] ICONST_ATTR = {
83 0, hcb1_2, hcb2_2, 0, hcb4_2, 0, 0, 0, 0, 0, 0, 0 84 0, hcb1_2, hcb2_2, 0, hcb4_2, 0, 0, 0, 0, 0, 0, 0
84}; 85};
85 86
86hcb_2_pair *hcb_2_pair_table[] = { 87hcb_2_pair *hcb_2_pair_table[] ICONST_ATTR = {
87 0, 0, 0, 0, 0, 0, hcb6_2, 0, hcb8_2, 0, hcb10_2, hcb11_2 88 0, 0, 0, 0, 0, 0, hcb6_2, 0, hcb8_2, 0, hcb10_2, hcb11_2
88}; 89};
89 90
90hcb_bin_pair *hcb_bin_table[] = { 91hcb_bin_pair *hcb_bin_table[] ICONST_ATTR = {
91 0, 0, 0, 0, 0, hcb5, 0, hcb7, 0, hcb9, 0, 0 92 0, 0, 0, 0, 0, hcb5, 0, hcb7, 0, hcb9, 0, 0
92}; 93};
93 94
94uint8_t hcbN[] = { 0, 5, 5, 0, 5, 0, 5, 0, 5, 0, 6, 5 }; 95uint8_t hcbN[] ICONST_ATTR = { 0, 5, 5, 0, 5, 0, 5, 0, 5, 0, 6, 5 };
95 96
96/* defines whether a huffman codebook is unsigned or not */ 97/* defines whether a huffman codebook is unsigned or not */
97/* Table 4.6.2 */ 98/* Table 4.6.2 */
98uint8_t unsigned_cb[] = { 0, 0, 0, 1, 1, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 99uint8_t unsigned_cb[] ICONST_ATTR = { 0, 0, 0, 1, 1, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0,
99 /* codebook 16 to 31 */ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 100 /* codebook 16 to 31 */ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1
100}; 101};
101 102
102int hcb_2_quad_table_size[] = { 0, 114, 86, 0, 185, 0, 0, 0, 0, 0, 0, 0 }; 103int hcb_2_quad_table_size[] ICONST_ATTR = { 0, 114, 86, 0, 185, 0, 0, 0, 0, 0, 0, 0 };
103int hcb_2_pair_table_size[] = { 0, 0, 0, 0, 0, 0, 126, 0, 83, 0, 210, 373 }; 104int hcb_2_pair_table_size[] ICONST_ATTR = { 0, 0, 0, 0, 0, 0, 126, 0, 83, 0, 210, 373 };
104int hcb_bin_table_size[] = { 0, 0, 0, 161, 0, 161, 0, 127, 0, 337, 0, 0 }; 105int hcb_bin_table_size[] ICONST_ATTR = { 0, 0, 0, 161, 0, 161, 0, 127, 0, 337, 0, 0 };
105 106
106static INLINE void huffman_sign_bits(bitfile *ld, int16_t *sp, uint8_t len) 107#define FAAD_GET_SIGN(idx) \
108 if (sp[idx]) \
109 if (faad_get1bit(ld)&1) \
110 sp[idx] = -sp[idx]; \
111
112static INLINE void huffman_sign_bits_pair(bitfile *ld, int16_t *sp)
107{ 113{
108 uint8_t i; 114 FAAD_GET_SIGN(0)
115 FAAD_GET_SIGN(1)
116}
109 117
110 for (i = 0; i < len; i++) 118static INLINE void huffman_sign_bits_quad(bitfile *ld, int16_t *sp)
111 { 119{
112 if(sp[i]) 120 FAAD_GET_SIGN(0)
113 { 121 FAAD_GET_SIGN(1)
114 if(faad_get1bit(ld 122 FAAD_GET_SIGN(2)
115 DEBUGVAR(1,5,"huffman_sign_bits(): sign bit")) & 1) 123 FAAD_GET_SIGN(3)
116 {
117 sp[i] = -sp[i];
118 }
119 }
120 }
121} 124}
122 125
123static INLINE int16_t huffman_getescape(bitfile *ld, int16_t sp) 126static INLINE int16_t huffman_getescape(bitfile *ld, int16_t sp)
@@ -194,12 +197,12 @@ static uint8_t huffman_2step_quad(uint8_t cb, bitfile *ld, int16_t *sp)
194static uint8_t huffman_2step_quad_sign(uint8_t cb, bitfile *ld, int16_t *sp) 197static uint8_t huffman_2step_quad_sign(uint8_t cb, bitfile *ld, int16_t *sp)
195{ 198{
196 uint8_t err = huffman_2step_quad(cb, ld, sp); 199 uint8_t err = huffman_2step_quad(cb, ld, sp);
197 huffman_sign_bits(ld, sp, QUAD_LEN); 200 huffman_sign_bits_quad(ld, sp);
198 201
199 return err; 202 return err;
200} 203}
201 204
202static uint8_t huffman_2step_pair(uint8_t cb, bitfile *ld, int16_t *sp) 205static INLINE uint8_t huffman_2step_pair(uint8_t cb, bitfile *ld, int16_t *sp)
203{ 206{
204 uint32_t cw; 207 uint32_t cw;
205 uint16_t offset = 0; 208 uint16_t offset = 0;
@@ -232,10 +235,10 @@ static uint8_t huffman_2step_pair(uint8_t cb, bitfile *ld, int16_t *sp)
232 return 0; 235 return 0;
233} 236}
234 237
235static uint8_t huffman_2step_pair_sign(uint8_t cb, bitfile *ld, int16_t *sp) 238static INLINE uint8_t huffman_2step_pair_sign(uint8_t cb, bitfile *ld, int16_t *sp)
236{ 239{
237 uint8_t err = huffman_2step_pair(cb, ld, sp); 240 uint8_t err = huffman_2step_pair(cb, ld, sp);
238 huffman_sign_bits(ld, sp, PAIR_LEN); 241 huffman_sign_bits_pair(ld, sp);
239 242
240 return err; 243 return err;
241} 244}
@@ -269,7 +272,7 @@ static uint8_t huffman_binary_quad(uint8_t cb, bitfile *ld, int16_t *sp)
269static uint8_t huffman_binary_quad_sign(uint8_t cb, bitfile *ld, int16_t *sp) 272static uint8_t huffman_binary_quad_sign(uint8_t cb, bitfile *ld, int16_t *sp)
270{ 273{
271 uint8_t err = huffman_binary_quad(cb, ld, sp); 274 uint8_t err = huffman_binary_quad(cb, ld, sp);
272 huffman_sign_bits(ld, sp, QUAD_LEN); 275 huffman_sign_bits_quad(ld, sp);
273 276
274 return err; 277 return err;
275} 278}
@@ -301,7 +304,7 @@ static uint8_t huffman_binary_pair(uint8_t cb, bitfile *ld, int16_t *sp)
301static uint8_t huffman_binary_pair_sign(uint8_t cb, bitfile *ld, int16_t *sp) 304static uint8_t huffman_binary_pair_sign(uint8_t cb, bitfile *ld, int16_t *sp)
302{ 305{
303 uint8_t err = huffman_binary_pair(cb, ld, sp); 306 uint8_t err = huffman_binary_pair(cb, ld, sp);
304 huffman_sign_bits(ld, sp, PAIR_LEN); 307 huffman_sign_bits_pair(ld, sp);
305 308
306 return err; 309 return err;
307} 310}