summaryrefslogtreecommitdiff
path: root/core/multimedia/opieplayer/libmad/huffman.c
Unidiff
Diffstat (limited to 'core/multimedia/opieplayer/libmad/huffman.c') (more/less context) (ignore whitespace changes)
-rw-r--r--core/multimedia/opieplayer/libmad/huffman.c31
1 files changed, 21 insertions, 10 deletions
diff --git a/core/multimedia/opieplayer/libmad/huffman.c b/core/multimedia/opieplayer/libmad/huffman.c
index 5ea6547..684409e 100644
--- a/core/multimedia/opieplayer/libmad/huffman.c
+++ b/core/multimedia/opieplayer/libmad/huffman.c
@@ -1,67 +1,73 @@
1/* 1/*
2 * libmad - MPEG audio decoder library 2 * libmad - MPEG audio decoder library
3 * Copyright (C) 2000-2001 Robert Leslie 3 * Copyright (C) 2000-2004 Underbit Technologies, Inc.
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.
9 * 9 *
10 * This program is distributed in the hope that it will be useful, 10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details. 13 * GNU General Public License for more details.
14 * 14 *
15 * You should have received a copy of the GNU General Public License 15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software 16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 * 18 *
19 * $Id$ 19 * $Id$
20 */ 20 */
21 21
22# ifdef HAVE_CONFIG_H 22# ifdef HAVE_CONFIG_H
23# include "libmad_config.h" 23# include "libmad_config.h"
24# endif 24# endif
25 25
26# include "libmad_global.h" 26# include "libmad_global.h"
27 27
28# include "huffman.h" 28# include "huffman.h"
29 29
30/* 30/*
31 * These are the Huffman code words for Layer III. 31 * These are the Huffman code words for Layer III.
32 * The data for these tables are derived from Table B.7 of ISO/IEC 11172-3. 32 * The data for these tables are derived from Table B.7 of ISO/IEC 11172-3.
33 * 33 *
34 * These tables support decoding up to 4 Huffman code bits at a time. 34 * These tables support decoding up to 4 Huffman code bits at a time.
35 */ 35 */
36 36
37# if defined(__GNUC__) 37# if defined(__GNUC__) || \
38 # define PTR(offs, bits){ ptr: { 0, bits, offs } } 38 (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901)
39 # define V(v, w, x, y, hlen){ value: { 1, hlen, v, w, x, y } } 39 # define PTR(offs, bits){ .ptr = { 0, bits, offs } }
40 # define V(v, w, x, y, hlen){ .value = { 1, hlen, v, w, x, y } }
40# else 41# else
41 # define PTR(offs, bits){ { 0, bits, offs } } 42 # define PTR(offs, bits){ { 0, bits, offs } }
42 # define V(v, w, x, y, hlen){ { 1, hlen, (v << 0) | (w << 1) | \ 43# if defined(WORDS_BIGENDIAN)
43 (x << 2) | (y << 3) } } 44 # define V(v, w, x, y, hlen){ { 1, hlen, (v << 11) | (w << 10) | \
45 (x << 9) | (y << 8) } }
46# else
47 # define V(v, w, x, y, hlen){ { 1, hlen, (v << 0) | (w << 1) | \
48 (x << 2) | (y << 3) } }
49# endif
44# endif 50# endif
45 51
46static 52static
47union huffquad const hufftabA[] = { 53union huffquad const hufftabA[] = {
48 /* 0000 */ PTR(16, 2), 54 /* 0000 */ PTR(16, 2),
49 /* 0001 */ PTR(20, 2), 55 /* 0001 */ PTR(20, 2),
50 /* 0010 */ PTR(24, 1), 56 /* 0010 */ PTR(24, 1),
51 /* 0011 */ PTR(26, 1), 57 /* 0011 */ PTR(26, 1),
52 /* 0100 */ V(0, 0, 1, 0, 4), 58 /* 0100 */ V(0, 0, 1, 0, 4),
53 /* 0101 */ V(0, 0, 0, 1, 4), 59 /* 0101 */ V(0, 0, 0, 1, 4),
54 /* 0110 */ V(0, 1, 0, 0, 4), 60 /* 0110 */ V(0, 1, 0, 0, 4),
55 /* 0111 */ V(1, 0, 0, 0, 4), 61 /* 0111 */ V(1, 0, 0, 0, 4),
56 /* 1000 */ V(0, 0, 0, 0, 1), 62 /* 1000 */ V(0, 0, 0, 0, 1),
57 /* 1001 */ V(0, 0, 0, 0, 1), 63 /* 1001 */ V(0, 0, 0, 0, 1),
58 /* 1010 */ V(0, 0, 0, 0, 1), 64 /* 1010 */ V(0, 0, 0, 0, 1),
59 /* 1011 */ V(0, 0, 0, 0, 1), 65 /* 1011 */ V(0, 0, 0, 0, 1),
60 /* 1100 */ V(0, 0, 0, 0, 1), 66 /* 1100 */ V(0, 0, 0, 0, 1),
61 /* 1101 */ V(0, 0, 0, 0, 1), 67 /* 1101 */ V(0, 0, 0, 0, 1),
62 /* 1110 */ V(0, 0, 0, 0, 1), 68 /* 1110 */ V(0, 0, 0, 0, 1),
63 /* 1111 */ V(0, 0, 0, 0, 1), 69 /* 1111 */ V(0, 0, 0, 0, 1),
64 70
65 /* 0000 ... */ 71 /* 0000 ... */
66 /* 00 */ V(1, 0, 1, 1, 2),/* 16 */ 72 /* 00 */ V(1, 0, 1, 1, 2),/* 16 */
67 /* 01 */ V(1, 1, 1, 1, 2), 73 /* 01 */ V(1, 1, 1, 1, 2),
@@ -85,54 +91,59 @@ union huffquad const hufftabA[] = {
85 91
86static 92static
87union huffquad const hufftabB[] = { 93union huffquad const hufftabB[] = {
88 /* 0000 */ V(1, 1, 1, 1, 4), 94 /* 0000 */ V(1, 1, 1, 1, 4),
89 /* 0001 */ V(1, 1, 1, 0, 4), 95 /* 0001 */ V(1, 1, 1, 0, 4),
90 /* 0010 */ V(1, 1, 0, 1, 4), 96 /* 0010 */ V(1, 1, 0, 1, 4),
91 /* 0011 */ V(1, 1, 0, 0, 4), 97 /* 0011 */ V(1, 1, 0, 0, 4),
92 /* 0100 */ V(1, 0, 1, 1, 4), 98 /* 0100 */ V(1, 0, 1, 1, 4),
93 /* 0101 */ V(1, 0, 1, 0, 4), 99 /* 0101 */ V(1, 0, 1, 0, 4),
94 /* 0110 */ V(1, 0, 0, 1, 4), 100 /* 0110 */ V(1, 0, 0, 1, 4),
95 /* 0111 */ V(1, 0, 0, 0, 4), 101 /* 0111 */ V(1, 0, 0, 0, 4),
96 /* 1000 */ V(0, 1, 1, 1, 4), 102 /* 1000 */ V(0, 1, 1, 1, 4),
97 /* 1001 */ V(0, 1, 1, 0, 4), 103 /* 1001 */ V(0, 1, 1, 0, 4),
98 /* 1010 */ V(0, 1, 0, 1, 4), 104 /* 1010 */ V(0, 1, 0, 1, 4),
99 /* 1011 */ V(0, 1, 0, 0, 4), 105 /* 1011 */ V(0, 1, 0, 0, 4),
100 /* 1100 */ V(0, 0, 1, 1, 4), 106 /* 1100 */ V(0, 0, 1, 1, 4),
101 /* 1101 */ V(0, 0, 1, 0, 4), 107 /* 1101 */ V(0, 0, 1, 0, 4),
102 /* 1110 */ V(0, 0, 0, 1, 4), 108 /* 1110 */ V(0, 0, 0, 1, 4),
103 /* 1111 */ V(0, 0, 0, 0, 4) 109 /* 1111 */ V(0, 0, 0, 0, 4)
104}; 110};
105 111
106# undef V 112# undef V
107# undef PTR 113# undef PTR
108 114
109# if defined(__GNUC__) 115# if defined(__GNUC__) || \
110 # define PTR(offs, bits){ ptr: { 0, bits, offs } } 116 (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901)
111 # define V(x, y, hlen) { value: { 1, hlen, x, y } } 117 # define PTR(offs, bits){ .ptr = { 0, bits, offs } }
118 # define V(x, y, hlen) { .value = { 1, hlen, x, y } }
112# else 119# else
113 # define PTR(offs, bits){ { 0, bits, offs } } 120 # define PTR(offs, bits){ { 0, bits, offs } }
114 # define V(x, y, hlen) { { 1, hlen, (x << 0) | (y << 4) } } 121# if defined(WORDS_BIGENDIAN)
122 # define V(x, y, hlen){ { 1, hlen, (x << 8) | (y << 4) } }
123# else
124 # define V(x, y, hlen){ { 1, hlen, (x << 0) | (y << 4) } }
125# endif
115# endif 126# endif
116 127
117static 128static
118union huffpair const hufftab0[] = { 129union huffpair const hufftab0[] = {
119 /* */ V(0, 0, 0) 130 /* */ V(0, 0, 0)
120}; 131};
121 132
122static 133static
123union huffpair const hufftab1[] = { 134union huffpair const hufftab1[] = {
124 /* 000 */ V(1, 1, 3), 135 /* 000 */ V(1, 1, 3),
125 /* 001 */ V(0, 1, 3), 136 /* 001 */ V(0, 1, 3),
126 /* 010 */ V(1, 0, 2), 137 /* 010 */ V(1, 0, 2),
127 /* 011 */ V(1, 0, 2), 138 /* 011 */ V(1, 0, 2),
128 /* 100 */ V(0, 0, 1), 139 /* 100 */ V(0, 0, 1),
129 /* 101 */ V(0, 0, 1), 140 /* 101 */ V(0, 0, 1),
130 /* 110 */ V(0, 0, 1), 141 /* 110 */ V(0, 0, 1),
131 /* 111 */ V(0, 0, 1) 142 /* 111 */ V(0, 0, 1)
132}; 143};
133 144
134static 145static
135union huffpair const hufftab2[] = { 146union huffpair const hufftab2[] = {
136 /* 000 */ PTR(8, 3), 147 /* 000 */ PTR(8, 3),
137 /* 001 */ V(1, 1, 3), 148 /* 001 */ V(1, 1, 3),
138 /* 010 */ V(0, 1, 3), 149 /* 010 */ V(0, 1, 3),