diff options
Diffstat (limited to 'apps')
-rw-r--r-- | apps/codecs/Tremor/bitwise.c | 62 | ||||
-rw-r--r-- | apps/codecs/Tremor/ogg.h | 67 |
2 files changed, 70 insertions, 59 deletions
diff --git a/apps/codecs/Tremor/bitwise.c b/apps/codecs/Tremor/bitwise.c index 41941f2506..7b6682720a 100644 --- a/apps/codecs/Tremor/bitwise.c +++ b/apps/codecs/Tremor/bitwise.c | |||
@@ -22,45 +22,6 @@ | |||
22 | #include <string.h> | 22 | #include <string.h> |
23 | #include "ogg.h" | 23 | #include "ogg.h" |
24 | 24 | ||
25 | static const unsigned long mask[] ICONST_ATTR = | ||
26 | {0x00000000,0x00000001,0x00000003,0x00000007,0x0000000f, | ||
27 | 0x0000001f,0x0000003f,0x0000007f,0x000000ff,0x000001ff, | ||
28 | 0x000003ff,0x000007ff,0x00000fff,0x00001fff,0x00003fff, | ||
29 | 0x00007fff,0x0000ffff,0x0001ffff,0x0003ffff,0x0007ffff, | ||
30 | 0x000fffff,0x001fffff,0x003fffff,0x007fffff,0x00ffffff, | ||
31 | 0x01ffffff,0x03ffffff,0x07ffffff,0x0fffffff,0x1fffffff, | ||
32 | 0x3fffffff,0x7fffffff,0xffffffff }; | ||
33 | |||
34 | /* mark read process as having run off the end */ | ||
35 | static void _adv_halt(oggpack_buffer *b){ | ||
36 | b->headptr=b->head->buffer->data+b->head->begin+b->head->length; | ||
37 | b->headend=-1; | ||
38 | b->headbit=0; | ||
39 | } | ||
40 | |||
41 | /* spans forward, skipping as many bytes as headend is negative; if | ||
42 | headend is zero, simply finds next byte. If we're up to the end | ||
43 | of the buffer, leaves headend at zero. If we've read past the end, | ||
44 | halt the decode process. */ | ||
45 | static void _span(oggpack_buffer *b){ | ||
46 | while(b->headend<1){ | ||
47 | if(b->head->next){ | ||
48 | b->count+=b->head->length; | ||
49 | b->head=b->head->next; | ||
50 | b->headptr=b->head->buffer->data+b->head->begin-b->headend; | ||
51 | b->headend+=b->head->length; | ||
52 | }else{ | ||
53 | /* we've either met the end of decode, or gone past it. halt | ||
54 | only if we're past */ | ||
55 | if(b->headend<0 || b->headbit) | ||
56 | /* read has fallen off the end */ | ||
57 | _adv_halt(b); | ||
58 | |||
59 | break; | ||
60 | } | ||
61 | } | ||
62 | } | ||
63 | |||
64 | void oggpack_readinit(oggpack_buffer *b,ogg_reference *r){ | 25 | void oggpack_readinit(oggpack_buffer *b,ogg_reference *r){ |
65 | memset(b,0,sizeof(*b)); | 26 | memset(b,0,sizeof(*b)); |
66 | 27 | ||
@@ -79,9 +40,9 @@ void oggpack_readinit(oggpack_buffer *b,ogg_reference *r){ | |||
79 | } | 40 | } |
80 | 41 | ||
81 | /* Read in bits without advancing the bitptr; bits <= 32 */ | 42 | /* Read in bits without advancing the bitptr; bits <= 32 */ |
82 | long oggpack_look(oggpack_buffer *b,int bits) ICODE_ATTR; | 43 | long oggpack_look_full(oggpack_buffer *b,int bits) ICODE_ATTR; |
83 | long oggpack_look(oggpack_buffer *b,int bits){ | 44 | long oggpack_look_full(oggpack_buffer *b,int bits){ |
84 | unsigned long m=mask[bits]; | 45 | unsigned long m=(1<<bits)-1; |
85 | unsigned long ret=0; | 46 | unsigned long ret=0; |
86 | 47 | ||
87 | bits+=b->headbit; | 48 | bits+=b->headbit; |
@@ -139,19 +100,6 @@ long oggpack_look(oggpack_buffer *b,int bits){ | |||
139 | return ret; | 100 | return ret; |
140 | } | 101 | } |
141 | 102 | ||
142 | /* limited to 32 at a time */ | ||
143 | #if CONFIG_CPU!=PP5020 | ||
144 | /* TODO: This function (and this function only) causes a "relocation | ||
145 | truncated to fit: R_ARM_PC24" error when in IRAM on ARM targets */ | ||
146 | void oggpack_adv(oggpack_buffer *b,int bits) ICODE_ATTR; | ||
147 | #endif | ||
148 | void oggpack_adv(oggpack_buffer *b,int bits){ | ||
149 | bits+=b->headbit; | ||
150 | b->headbit=bits&7; | ||
151 | b->headptr+=bits/8; | ||
152 | if((b->headend-=bits/8)<1)_span(b); | ||
153 | } | ||
154 | |||
155 | /* spans forward and finds next byte. Never halts */ | 103 | /* spans forward and finds next byte. Never halts */ |
156 | static void _span_one(oggpack_buffer *b){ | 104 | static void _span_one(oggpack_buffer *b){ |
157 | while(b->headend<1){ | 105 | while(b->headend<1){ |
@@ -180,7 +128,7 @@ int oggpack_eop(oggpack_buffer *b){ | |||
180 | 128 | ||
181 | /* bits <= 32 */ | 129 | /* bits <= 32 */ |
182 | long oggpack_read(oggpack_buffer *b,int bits){ | 130 | long oggpack_read(oggpack_buffer *b,int bits){ |
183 | unsigned long m=mask[bits]; | 131 | unsigned long m=(1<<bits)-1; |
184 | ogg_uint32_t ret=0; | 132 | ogg_uint32_t ret=0; |
185 | 133 | ||
186 | bits+=b->headbit; | 134 | bits+=b->headbit; |
@@ -235,7 +183,7 @@ long oggpack_read(oggpack_buffer *b,int bits){ | |||
235 | } | 183 | } |
236 | } | 184 | } |
237 | }else{ | 185 | }else{ |
238 | 186 | ||
239 | ret=b->headptr[0]>>b->headbit; | 187 | ret=b->headptr[0]>>b->headbit; |
240 | if(bits>8){ | 188 | if(bits>8){ |
241 | ret|=b->headptr[1]<<(8-b->headbit); | 189 | ret|=b->headptr[1]<<(8-b->headbit); |
diff --git a/apps/codecs/Tremor/ogg.h b/apps/codecs/Tremor/ogg.h index 85cb41b64a..08d15788c0 100644 --- a/apps/codecs/Tremor/ogg.h +++ b/apps/codecs/Tremor/ogg.h | |||
@@ -141,13 +141,76 @@ typedef struct { | |||
141 | /* Ogg BITSTREAM PRIMITIVES: bitstream ************************/ | 141 | /* Ogg BITSTREAM PRIMITIVES: bitstream ************************/ |
142 | 142 | ||
143 | extern void oggpack_readinit(oggpack_buffer *b,ogg_reference *r); | 143 | extern void oggpack_readinit(oggpack_buffer *b,ogg_reference *r); |
144 | extern long oggpack_look(oggpack_buffer *b,int bits); | 144 | extern long oggpack_look_full(oggpack_buffer *b,int bits); |
145 | extern void oggpack_adv(oggpack_buffer *b,int bits); | ||
146 | extern long oggpack_read(oggpack_buffer *b,int bits); | 145 | extern long oggpack_read(oggpack_buffer *b,int bits); |
147 | extern long oggpack_bytes(oggpack_buffer *b); | 146 | extern long oggpack_bytes(oggpack_buffer *b); |
148 | extern long oggpack_bits(oggpack_buffer *b); | 147 | extern long oggpack_bits(oggpack_buffer *b); |
149 | extern int oggpack_eop(oggpack_buffer *b); | 148 | extern int oggpack_eop(oggpack_buffer *b); |
150 | 149 | ||
150 | /* Inline a few, often called functions */ | ||
151 | |||
152 | /* mark read process as having run off the end */ | ||
153 | static inline void _adv_halt(oggpack_buffer *b){ | ||
154 | b->headptr=b->head->buffer->data+b->head->begin+b->head->length; | ||
155 | b->headend=-1; | ||
156 | b->headbit=0; | ||
157 | } | ||
158 | |||
159 | /* spans forward, skipping as many bytes as headend is negative; if | ||
160 | headend is zero, simply finds next byte. If we're up to the end | ||
161 | of the buffer, leaves headend at zero. If we've read past the end, | ||
162 | halt the decode process. */ | ||
163 | static inline void _span(oggpack_buffer *b){ | ||
164 | while(b->headend<1){ | ||
165 | if(b->head->next){ | ||
166 | b->count+=b->head->length; | ||
167 | b->head=b->head->next; | ||
168 | b->headptr=b->head->buffer->data+b->head->begin-b->headend; | ||
169 | b->headend+=b->head->length; | ||
170 | }else{ | ||
171 | /* we've either met the end of decode, or gone past it. halt | ||
172 | only if we're past */ | ||
173 | if(b->headend<0 || b->headbit) | ||
174 | /* read has fallen off the end */ | ||
175 | _adv_halt(b); | ||
176 | |||
177 | break; | ||
178 | } | ||
179 | } | ||
180 | } | ||
181 | |||
182 | /* limited to 32 at a time */ | ||
183 | static inline void oggpack_adv(oggpack_buffer *b,int bits){ | ||
184 | bits+=b->headbit; | ||
185 | b->headbit=bits&7; | ||
186 | b->headptr+=bits/8; | ||
187 | if((b->headend-=bits/8)<1)_span(b); | ||
188 | } | ||
189 | |||
190 | static inline long oggpack_look(oggpack_buffer *b, int bits){ | ||
191 | if(bits+b->headbit < b->headend<<3){ | ||
192 | unsigned long m=(1<<bits)-1; | ||
193 | unsigned long ret=0; | ||
194 | |||
195 | bits+=b->headbit; | ||
196 | ret=b->headptr[0]>>b->headbit; | ||
197 | if(bits>8){ | ||
198 | ret|=b->headptr[1]<<(8-b->headbit); | ||
199 | if(bits>16){ | ||
200 | ret|=b->headptr[2]<<(16-b->headbit); | ||
201 | if(bits>24){ | ||
202 | ret|=b->headptr[3]<<(24-b->headbit); | ||
203 | if(bits>32 && b->headbit) | ||
204 | ret|=b->headptr[4]<<(32-b->headbit); | ||
205 | } | ||
206 | } | ||
207 | } | ||
208 | return ret&m; | ||
209 | }else{ | ||
210 | return oggpack_look_full(b, bits); | ||
211 | } | ||
212 | } | ||
213 | |||
151 | /* Ogg BITSTREAM PRIMITIVES: decoding **************************/ | 214 | /* Ogg BITSTREAM PRIMITIVES: decoding **************************/ |
152 | 215 | ||
153 | extern ogg_sync_state *ogg_sync_create(void); | 216 | extern ogg_sync_state *ogg_sync_create(void); |