diff options
author | Jens Arnold <amiconn@rockbox.org> | 2008-11-16 12:58:15 +0000 |
---|---|---|
committer | Jens Arnold <amiconn@rockbox.org> | 2008-11-16 12:58:15 +0000 |
commit | b5c0afc4423727cd790a970781cc4ece76211391 (patch) | |
tree | 0d0bf3d0c1df6bb96de15befa28e3bf7dccd958e /apps/codecs/demac | |
parent | a0584aec74379f43ee6f0a26c6a70be18ff32803 (diff) | |
download | rockbox-b5c0afc4423727cd790a970781cc4ece76211391.tar.gz rockbox-b5c0afc4423727cd790a970781cc4ece76211391.zip |
Move the contents of rangecoding.h into entropy.c, and remove the former. It was only used there, and defined some variables in the .h
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@19116 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'apps/codecs/demac')
-rw-r--r-- | apps/codecs/demac/Makefile | 3 | ||||
-rw-r--r-- | apps/codecs/demac/libdemac/entropy.c | 155 | ||||
-rw-r--r-- | apps/codecs/demac/libdemac/rangecoding.h | 178 |
3 files changed, 155 insertions, 181 deletions
diff --git a/apps/codecs/demac/Makefile b/apps/codecs/demac/Makefile index e0ed4ad341..f1886b2a32 100644 --- a/apps/codecs/demac/Makefile +++ b/apps/codecs/demac/Makefile | |||
@@ -1,4 +1,4 @@ | |||
1 | # $Id:$ | 1 | # $Id$ |
2 | 2 | ||
3 | FILTERS = libdemac/filter_16_11.o libdemac/filter_64_11.o libdemac/filter_256_13.o libdemac/filter_32_10.o libdemac/filter_1280_15.o | 3 | FILTERS = libdemac/filter_16_11.o libdemac/filter_64_11.o libdemac/filter_256_13.o libdemac/filter_32_10.o libdemac/filter_1280_15.o |
4 | LIBOBJS = libdemac/parser.o libdemac/decoder.o libdemac/entropy.o libdemac/predictor.o libdemac/crc.o $(FILTERS) | 4 | LIBOBJS = libdemac/parser.o libdemac/decoder.o libdemac/entropy.o libdemac/predictor.o libdemac/crc.o $(FILTERS) |
@@ -37,7 +37,6 @@ libdemac/filter_64_11.o: libdemac/filter.c | |||
37 | libdemac/filter_256_13.o: libdemac/filter.c | 37 | libdemac/filter_256_13.o: libdemac/filter.c |
38 | libdemac/filter_1280_15.o: libdemac/filter.c | 38 | libdemac/filter_1280_15.o: libdemac/filter.c |
39 | libdemac/filter_32_10.o: libdemac/filter.c | 39 | libdemac/filter_32_10.o: libdemac/filter.c |
40 | libdemac/entropy.o: libdemac/rangecoding.h | ||
41 | 40 | ||
42 | clean: | 41 | clean: |
43 | rm -f $(OUTPUT) $(OBJS) *~ */*~ | 42 | rm -f $(OUTPUT) $(OBJS) *~ */*~ |
diff --git a/apps/codecs/demac/libdemac/entropy.c b/apps/codecs/demac/libdemac/entropy.c index 86ea06d389..baddce07be 100644 --- a/apps/codecs/demac/libdemac/entropy.c +++ b/apps/codecs/demac/libdemac/entropy.c | |||
@@ -27,7 +27,6 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA | |||
27 | 27 | ||
28 | #include "parser.h" | 28 | #include "parser.h" |
29 | #include "entropy.h" | 29 | #include "entropy.h" |
30 | #include "rangecoding.h" /* Range-coding (static inline) functions */ | ||
31 | #include "demac_iram.h" | 30 | #include "demac_iram.h" |
32 | 31 | ||
33 | #define MODEL_ELEMENTS 64 | 32 | #define MODEL_ELEMENTS 64 |
@@ -91,6 +90,160 @@ static const int counts_diff_3980[64] ICONST_ATTR = | |||
91 | }; | 90 | }; |
92 | 91 | ||
93 | /* | 92 | /* |
93 | |||
94 | Range decoder adapted from rangecod.c included in: | ||
95 | |||
96 | http://www.compressconsult.com/rangecoder/rngcod13.zip | ||
97 | |||
98 | rangecod.c range encoding | ||
99 | |||
100 | (c) Michael Schindler | ||
101 | 1997, 1998, 1999, 2000 | ||
102 | http://www.compressconsult.com/ | ||
103 | michael@compressconsult.com | ||
104 | |||
105 | This program is free software; you can redistribute it and/or modify | ||
106 | it under the terms of the GNU General Public License as published by | ||
107 | the Free Software Foundation; either version 2 of the License, or | ||
108 | (at your option) any later version. | ||
109 | |||
110 | |||
111 | The encoding functions were removed, and functions turned into "static | ||
112 | inline" functions. Some minor cosmetic changes were made (e.g. turning | ||
113 | pre-processor symbols into upper-case, removing the rc parameter from | ||
114 | each function (and the RNGC macro)). | ||
115 | |||
116 | */ | ||
117 | |||
118 | #ifdef ROCKBOX | ||
119 | #include "../lib/codeclib.h" | ||
120 | /* for UDIV32() */ | ||
121 | #endif | ||
122 | |||
123 | #ifndef UDIV32 | ||
124 | #define UDIV32(a, b) (a / b) | ||
125 | #endif | ||
126 | |||
127 | /* BITSTREAM READING FUNCTIONS */ | ||
128 | |||
129 | /* We deal with the input data one byte at a time - to ensure | ||
130 | functionality on CPUs of any endianness regardless of any requirements | ||
131 | for aligned reads. | ||
132 | */ | ||
133 | |||
134 | static unsigned char* bytebuffer IBSS_ATTR; | ||
135 | static int bytebufferoffset IBSS_ATTR; | ||
136 | |||
137 | static inline void skip_byte(void) | ||
138 | { | ||
139 | bytebufferoffset--; | ||
140 | bytebuffer += bytebufferoffset & 4; | ||
141 | bytebufferoffset &= 3; | ||
142 | } | ||
143 | |||
144 | static inline int read_byte(void) | ||
145 | { | ||
146 | int ch = bytebuffer[bytebufferoffset]; | ||
147 | |||
148 | skip_byte(); | ||
149 | |||
150 | return ch; | ||
151 | } | ||
152 | |||
153 | /* RANGE DECODING FUNCTIONS */ | ||
154 | |||
155 | /* SIZE OF RANGE ENCODING CODE VALUES. */ | ||
156 | |||
157 | #define CODE_BITS 32 | ||
158 | #define TOP_VALUE ((unsigned int)1 << (CODE_BITS-1)) | ||
159 | #define SHIFT_BITS (CODE_BITS - 9) | ||
160 | #define EXTRA_BITS ((CODE_BITS-2) % 8 + 1) | ||
161 | #define BOTTOM_VALUE (TOP_VALUE >> 8) | ||
162 | |||
163 | struct rangecoder_t | ||
164 | { | ||
165 | uint32_t low; /* low end of interval */ | ||
166 | uint32_t range; /* length of interval */ | ||
167 | uint32_t help; /* bytes_to_follow resp. intermediate value */ | ||
168 | unsigned int buffer; /* buffer for input/output */ | ||
169 | }; | ||
170 | |||
171 | static struct rangecoder_t rc IBSS_ATTR; | ||
172 | |||
173 | /* Start the decoder */ | ||
174 | static inline void range_start_decoding(void) | ||
175 | { | ||
176 | rc.buffer = read_byte(); | ||
177 | rc.low = rc.buffer >> (8 - EXTRA_BITS); | ||
178 | rc.range = (uint32_t) 1 << EXTRA_BITS; | ||
179 | } | ||
180 | |||
181 | static inline void range_dec_normalize(void) | ||
182 | { | ||
183 | while (rc.range <= BOTTOM_VALUE) | ||
184 | { | ||
185 | rc.buffer = (rc.buffer << 8) | read_byte(); | ||
186 | rc.low = (rc.low << 8) | ((rc.buffer >> 1) & 0xff); | ||
187 | rc.range <<= 8; | ||
188 | } | ||
189 | } | ||
190 | |||
191 | /* Calculate culmulative frequency for next symbol. Does NO update!*/ | ||
192 | /* tot_f is the total frequency */ | ||
193 | /* or: totf is (code_value)1<<shift */ | ||
194 | /* returns the culmulative frequency */ | ||
195 | static inline int range_decode_culfreq(int tot_f) | ||
196 | { | ||
197 | range_dec_normalize(); | ||
198 | rc.help = UDIV32(rc.range, tot_f); | ||
199 | return UDIV32(rc.low, rc.help); | ||
200 | } | ||
201 | |||
202 | static inline int range_decode_culshift(int shift) | ||
203 | { | ||
204 | range_dec_normalize(); | ||
205 | rc.help = rc.range >> shift; | ||
206 | return UDIV32(rc.low, rc.help); | ||
207 | } | ||
208 | |||
209 | |||
210 | /* Update decoding state */ | ||
211 | /* sy_f is the interval length (frequency of the symbol) */ | ||
212 | /* lt_f is the lower end (frequency sum of < symbols) */ | ||
213 | static inline void range_decode_update(int sy_f, int lt_f) | ||
214 | { | ||
215 | rc.low -= rc.help * lt_f; | ||
216 | rc.range = rc.help * sy_f; | ||
217 | } | ||
218 | |||
219 | |||
220 | /* Decode a byte/short without modelling */ | ||
221 | static inline unsigned char decode_byte(void) | ||
222 | { int tmp = range_decode_culshift(8); | ||
223 | range_decode_update( 1,tmp); | ||
224 | return tmp; | ||
225 | } | ||
226 | |||
227 | static inline int short range_decode_short(void) | ||
228 | { int tmp = range_decode_culshift(16); | ||
229 | range_decode_update( 1,tmp); | ||
230 | return tmp; | ||
231 | } | ||
232 | |||
233 | /* Decode n bits (n <= 16) without modelling - based on range_decode_short */ | ||
234 | static inline int range_decode_bits(int n) | ||
235 | { int tmp = range_decode_culshift(n); | ||
236 | range_decode_update( 1,tmp); | ||
237 | return tmp; | ||
238 | } | ||
239 | |||
240 | |||
241 | /* Finish decoding */ | ||
242 | static inline void range_done_decoding(void) | ||
243 | { range_dec_normalize(); /* normalize to use up all bytes */ | ||
244 | } | ||
245 | |||
246 | /* | ||
94 | range_get_symbol_* functions based on main decoding loop in simple_d.c from | 247 | range_get_symbol_* functions based on main decoding loop in simple_d.c from |
95 | http://www.compressconsult.com/rangecoder/rngcod13.zip | 248 | http://www.compressconsult.com/rangecoder/rngcod13.zip |
96 | (c) Michael Schindler | 249 | (c) Michael Schindler |
diff --git a/apps/codecs/demac/libdemac/rangecoding.h b/apps/codecs/demac/libdemac/rangecoding.h deleted file mode 100644 index 645fd1ad92..0000000000 --- a/apps/codecs/demac/libdemac/rangecoding.h +++ /dev/null | |||
@@ -1,178 +0,0 @@ | |||
1 | /* | ||
2 | |||
3 | libdemac - A Monkey's Audio decoder | ||
4 | |||
5 | $Id$ | ||
6 | |||
7 | Copyright (C) Dave Chapman 2007 | ||
8 | |||
9 | This program is free software; you can redistribute it and/or modify | ||
10 | it under the terms of the GNU General Public License as published by | ||
11 | the Free Software Foundation; either version 2 of the License, or | ||
12 | (at your option) any later version. | ||
13 | |||
14 | This program is distributed in the hope that it will be useful, | ||
15 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
17 | GNU General Public License for more details. | ||
18 | |||
19 | You should have received a copy of the GNU General Public License | ||
20 | along with this program; if not, write to the Free Software | ||
21 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA | ||
22 | |||
23 | */ | ||
24 | |||
25 | /* | ||
26 | |||
27 | Range decoder adapted from rangecod.c included in: | ||
28 | |||
29 | http://www.compressconsult.com/rangecoder/rngcod13.zip | ||
30 | |||
31 | rangecod.c range encoding | ||
32 | |||
33 | (c) Michael Schindler | ||
34 | 1997, 1998, 1999, 2000 | ||
35 | http://www.compressconsult.com/ | ||
36 | michael@compressconsult.com | ||
37 | |||
38 | This program is free software; you can redistribute it and/or modify | ||
39 | it under the terms of the GNU General Public License as published by | ||
40 | the Free Software Foundation; either version 2 of the License, or | ||
41 | (at your option) any later version. | ||
42 | |||
43 | |||
44 | The encoding functions were removed, and functions turned into "static | ||
45 | inline" functions and moved to a .h file. Some minor cosmetic changes | ||
46 | were made (e.g. turning pre-processor symbols into upper-case, | ||
47 | removing the rc parameter from each function (and the RNGC macro)). | ||
48 | |||
49 | |||
50 | */ | ||
51 | |||
52 | #ifdef ROCKBOX | ||
53 | #include "../lib/codeclib.h" | ||
54 | /* for UDIV32() */ | ||
55 | #endif | ||
56 | |||
57 | #ifndef UDIV32 | ||
58 | #define UDIV32(a, b) (a / b) | ||
59 | #endif | ||
60 | |||
61 | /* BITSTREAM READING FUNCTIONS */ | ||
62 | |||
63 | /* We deal with the input data one byte at a time - to ensure | ||
64 | functionality on CPUs of any endianness regardless of any requirements | ||
65 | for aligned reads. | ||
66 | */ | ||
67 | |||
68 | static unsigned char* bytebuffer IBSS_ATTR; | ||
69 | static int bytebufferoffset IBSS_ATTR; | ||
70 | |||
71 | static inline void skip_byte(void) | ||
72 | { | ||
73 | bytebufferoffset--; | ||
74 | bytebuffer += bytebufferoffset & 4; | ||
75 | bytebufferoffset &= 3; | ||
76 | } | ||
77 | |||
78 | static inline int read_byte(void) | ||
79 | { | ||
80 | int ch = bytebuffer[bytebufferoffset]; | ||
81 | |||
82 | skip_byte(); | ||
83 | |||
84 | return ch; | ||
85 | } | ||
86 | |||
87 | /* RANGE DECODING FUNCTIONS */ | ||
88 | |||
89 | /* SIZE OF RANGE ENCODING CODE VALUES. */ | ||
90 | |||
91 | #define CODE_BITS 32 | ||
92 | #define TOP_VALUE ((unsigned int)1 << (CODE_BITS-1)) | ||
93 | #define SHIFT_BITS (CODE_BITS - 9) | ||
94 | #define EXTRA_BITS ((CODE_BITS-2) % 8 + 1) | ||
95 | #define BOTTOM_VALUE (TOP_VALUE >> 8) | ||
96 | |||
97 | struct rangecoder_t | ||
98 | { | ||
99 | uint32_t low; /* low end of interval */ | ||
100 | uint32_t range; /* length of interval */ | ||
101 | uint32_t help; /* bytes_to_follow resp. intermediate value */ | ||
102 | unsigned int buffer; /* buffer for input/output */ | ||
103 | }; | ||
104 | |||
105 | static struct rangecoder_t rc IBSS_ATTR; | ||
106 | |||
107 | /* Start the decoder */ | ||
108 | static inline void range_start_decoding(void) | ||
109 | { | ||
110 | rc.buffer = read_byte(); | ||
111 | rc.low = rc.buffer >> (8 - EXTRA_BITS); | ||
112 | rc.range = (uint32_t) 1 << EXTRA_BITS; | ||
113 | } | ||
114 | |||
115 | static inline void range_dec_normalize(void) | ||
116 | { | ||
117 | while (rc.range <= BOTTOM_VALUE) | ||
118 | { | ||
119 | rc.buffer = (rc.buffer << 8) | read_byte(); | ||
120 | rc.low = (rc.low << 8) | ((rc.buffer >> 1) & 0xff); | ||
121 | rc.range <<= 8; | ||
122 | } | ||
123 | } | ||
124 | |||
125 | /* Calculate culmulative frequency for next symbol. Does NO update!*/ | ||
126 | /* tot_f is the total frequency */ | ||
127 | /* or: totf is (code_value)1<<shift */ | ||
128 | /* returns the culmulative frequency */ | ||
129 | static inline int range_decode_culfreq(int tot_f) | ||
130 | { | ||
131 | range_dec_normalize(); | ||
132 | rc.help = UDIV32(rc.range, tot_f); | ||
133 | return UDIV32(rc.low, rc.help); | ||
134 | } | ||
135 | |||
136 | static inline int range_decode_culshift(int shift) | ||
137 | { | ||
138 | range_dec_normalize(); | ||
139 | rc.help = rc.range >> shift; | ||
140 | return UDIV32(rc.low, rc.help); | ||
141 | } | ||
142 | |||
143 | |||
144 | /* Update decoding state */ | ||
145 | /* sy_f is the interval length (frequency of the symbol) */ | ||
146 | /* lt_f is the lower end (frequency sum of < symbols) */ | ||
147 | static inline void range_decode_update(int sy_f, int lt_f) | ||
148 | { | ||
149 | rc.low -= rc.help * lt_f; | ||
150 | rc.range = rc.help * sy_f; | ||
151 | } | ||
152 | |||
153 | |||
154 | /* Decode a byte/short without modelling */ | ||
155 | static inline unsigned char decode_byte(void) | ||
156 | { int tmp = range_decode_culshift(8); | ||
157 | range_decode_update( 1,tmp); | ||
158 | return tmp; | ||
159 | } | ||
160 | |||
161 | static inline int short range_decode_short(void) | ||
162 | { int tmp = range_decode_culshift(16); | ||
163 | range_decode_update( 1,tmp); | ||
164 | return tmp; | ||
165 | } | ||
166 | |||
167 | /* Decode n bits (n <= 16) without modelling - based on range_decode_short */ | ||
168 | static inline int range_decode_bits(int n) | ||
169 | { int tmp = range_decode_culshift(n); | ||
170 | range_decode_update( 1,tmp); | ||
171 | return tmp; | ||
172 | } | ||
173 | |||
174 | |||
175 | /* Finish decoding */ | ||
176 | static inline void range_done_decoding(void) | ||
177 | { range_dec_normalize(); /* normalize to use up all bytes */ | ||
178 | } | ||