summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPedro Vasconcelos <pbv@rockbox.org>2005-06-08 13:09:30 +0000
committerPedro Vasconcelos <pbv@rockbox.org>2005-06-08 13:09:30 +0000
commit0a3f8e0924aff1da89cd8e2d594fe76474da8524 (patch)
tree323f33057877419d80609b4748a0c38b7632e940
parentead61c1d18281b025696d8851763d9d8f13997e0 (diff)
downloadrockbox-0a3f8e0924aff1da89cd8e2d594fe76474da8524.tar.gz
rockbox-0a3f8e0924aff1da89cd8e2d594fe76474da8524.zip
Vorbis opts: keep floor1 lookup table in IRAM.
Slightly faster 16-bit clipping function. Misc: changed tabs for spaces to conform with Rockbox coding standards. git-svn-id: svn://svn.rockbox.org/rockbox/trunk@6608 a1c6a512-1295-4272-9138-f99709370657
-rw-r--r--apps/codecs/Tremor/asm_mcf5249.h360
-rw-r--r--apps/codecs/Tremor/floor1.c99
-rw-r--r--apps/codecs/Tremor/mapping0.c62
-rw-r--r--apps/codecs/Tremor/mdct.c314
-rw-r--r--apps/codecs/Tremor/mdct_lookup.h3
-rw-r--r--apps/codecs/Tremor/misc.h2
-rw-r--r--apps/codecs/Tremor/res012.c88
-rw-r--r--apps/codecs/Tremor/synthesis.c8
-rw-r--r--apps/codecs/Tremor/vorbisfile.c800
-rw-r--r--apps/codecs/Tremor/window.c6
-rw-r--r--apps/codecs/Tremor/window_lookup.h10
11 files changed, 890 insertions, 862 deletions
diff --git a/apps/codecs/Tremor/asm_mcf5249.h b/apps/codecs/Tremor/asm_mcf5249.h
index 933d6bb1fc..b930ce1f5f 100644
--- a/apps/codecs/Tremor/asm_mcf5249.h
+++ b/apps/codecs/Tremor/asm_mcf5249.h
@@ -24,102 +24,118 @@
24#ifndef _V_WIDE_MATH 24#ifndef _V_WIDE_MATH
25#define _V_WIDE_MATH 25#define _V_WIDE_MATH
26 26
27//#define MB() asm volatile ("" : : : "memory")
28#define MB() 27#define MB()
29 28
30static inline void mcf5249_init_mac(void) { 29static inline void mcf5249_init_mac(void) {
31 int r; 30 int r;
32 asm volatile ("move.l #0x20, %%macsr;" // frac, truncate, no saturation 31 asm volatile ("move.l #0x20, %%macsr;" /* frac, truncate, no saturation */
33 "movclr.l %%acc0, %[r];" // clear accumulators 32 "movclr.l %%acc0, %[r];" /* clear accumulators */
34 "move.l %%acc0, %%acc1;" 33 "move.l %%acc0, %%acc1;"
35 "move.l %%acc0, %%acc2;" 34 "move.l %%acc0, %%acc2;"
36 "move.l %%acc0, %%acc3;" 35 "move.l %%acc0, %%acc3;"
37 : [r] "=r" (r)); 36 : [r] "=r" (r));
38} 37}
39 38
40static inline ogg_int32_t MULT32(ogg_int32_t x, ogg_int32_t y) { 39static inline ogg_int32_t MULT32(ogg_int32_t x, ogg_int32_t y) {
41 ogg_int32_t r; 40 asm volatile ("mac.l %[x], %[y], %%acc0;" /* multiply & shift */
42 asm volatile ("mac.l %[x], %[y], %%acc0;" // multiply into acc 41 "movclr.l %%acc0, %[x];" /* move & clear acc */
43 "movclr.l %%acc0, %[r];" // move & clear acc 42 "asr.l #1, %[x];" /* no overflow test */
44 "asr.l #1, %[r];" // no overflow test 43 : [x] "+&d" (x)
45 : [r] "=d" (r) 44 : [y] "r" (y)
46 : [x] "r" (x), [y] "r" (y) 45 : "cc");
47 : "cc"); 46 return x;
48 return r;
49} 47}
50 48
51static inline ogg_int32_t MULT31(ogg_int32_t x, ogg_int32_t y) { 49static inline ogg_int32_t MULT31(ogg_int32_t x, ogg_int32_t y) {
52 asm volatile ("mac.l %[x], %[y], %%acc0;" // multiply 50 asm volatile ("mac.l %[x], %[y], %%acc0;" /* multiply */
53 "movclr.l %%acc0, %[x];" // move and clear 51 "movclr.l %%acc0, %[x];" /* move and clear */
54 : [x] "+&r" (x) 52 : [x] "+&r" (x)
55 : [y] "r" (y) 53 : [y] "r" (y)
56 : "cc"); 54 : "cc");
57 return x; 55 return x;
58} 56}
59 57
60 58
61static inline ogg_int32_t MULT31_SHIFT15(ogg_int32_t x, ogg_int32_t y) { 59static inline ogg_int32_t MULT31_SHIFT15(ogg_int32_t x, ogg_int32_t y) {
62 ogg_int32_t r; 60 ogg_int32_t r;
63 asm volatile ("mac.l %[x], %[y], %%acc0;" // multiply 61 asm volatile ("mac.l %[x], %[y], %%acc0;" /* multiply */
64 "movclr.l %%acc0, %[r];" // get higher half 62 "movclr.l %%acc0, %[r];" /* get higher half */
65 "mulu.l %[y], %[x];" // get lower half 63 "mulu.l %[y], %[x];" /* get lower half */
66 "asl.l #8, %[r];" // hi << 17 64 "asl.l #8, %[r];" /* hi<<16, plus one free */
67 "asl.l #8, %[r];" 65 "asl.l #8, %[r];"
68 "lsr.l #8, %[x];" // (unsigned)lo >> 15 66 "lsr.l #8, %[x];" /* (unsigned)lo >> 15 */
69 "lsr.l #7, %[x];" 67 "lsr.l #7, %[x];"
70 "or.l %[x], %[r];" // or 68 "or.l %[x], %[r];" /* logical-or results */
71 : [r] "=&d" (r), [x] "+d" (x) 69 : [r] "=&d" (r), [x] "+d" (x)
72 : [y] "d" (y) 70 : [y] "d" (y)
73 : "cc"); 71 : "cc");
74 return r; 72 return r;
75} 73}
76 74
77 75
78static inline 76static inline
79void XPROD31(ogg_int32_t a, ogg_int32_t b, 77void XPROD31(ogg_int32_t a, ogg_int32_t b,
80 ogg_int32_t t, ogg_int32_t v, 78 ogg_int32_t t, ogg_int32_t v,
81 ogg_int32_t *x, ogg_int32_t *y) 79 ogg_int32_t *x, ogg_int32_t *y)
82{ 80{
83 asm volatile ("mac.l %[a], %[t], %%acc0;" 81 asm volatile ("mac.l %[a], %[t], %%acc0;"
84 "mac.l %[b], %[v], %%acc0;" 82 "mac.l %[b], %[v], %%acc0;"
85 "mac.l %[b], %[t], %%acc1;" 83 "mac.l %[b], %[t], %%acc1;"
86 "msac.l %[a], %[v], %%acc1;" 84 "msac.l %[a], %[v], %%acc1;"
87 "movclr.l %%acc0, %[a];" 85 "movclr.l %%acc0, %[a];"
88 "move.l %[a], (%[x]);" 86 "move.l %[a], (%[x]);"
89 "movclr.l %%acc1, %[a];" 87 "movclr.l %%acc1, %[a];"
90 "move.l %[a], (%[y]);" 88 "move.l %[a], (%[y]);"
91 : [a] "+&r" (a) 89 : [a] "+&r" (a)
92 : [x] "a" (x), [y] "a" (y), 90 : [x] "a" (x), [y] "a" (y),
93 [b] "r" (b), [t] "r" (t), [v] "r" (v) 91 [b] "r" (b), [t] "r" (t), [v] "r" (v)
94 : "cc", "memory"); 92 : "cc", "memory");
95} 93}
96 94
97 95
98static inline 96static inline
99void XNPROD31(ogg_int32_t a, ogg_int32_t b, 97void XNPROD31(ogg_int32_t a, ogg_int32_t b,
100 ogg_int32_t t, ogg_int32_t v, 98 ogg_int32_t t, ogg_int32_t v,
101 ogg_int32_t *x, ogg_int32_t *y) 99 ogg_int32_t *x, ogg_int32_t *y)
102{ 100{
103 asm volatile ("mac.l %[a], %[t], %%acc0;" 101 asm volatile ("mac.l %[a], %[t], %%acc0;"
104 "msac.l %[b], %[v], %%acc0;" 102 "msac.l %[b], %[v], %%acc0;"
105 "mac.l %[b], %[t], %%acc1;" 103 "mac.l %[b], %[t], %%acc1;"
106 "mac.l %[a], %[v], %%acc1;" 104 "mac.l %[a], %[v], %%acc1;"
107 "movclr.l %%acc0, %[a];" 105 "movclr.l %%acc0, %[a];"
108 "move.l %[a], (%[x]);" 106 "move.l %[a], (%[x]);"
109 "movclr.l %%acc1, %[a];" 107 "movclr.l %%acc1, %[a];"
110 "move.l %[a], (%[y]);" 108 "move.l %[a], (%[y]);"
111 : [a] "+&r" (a) 109 : [a] "+&r" (a)
112 : [x] "a" (x), [y] "a" (y), 110 : [x] "a" (x), [y] "a" (y),
113 [b] "r" (b), [t] "r" (t), [v] "r" (v) 111 [b] "r" (b), [t] "r" (t), [v] "r" (v)
114 : "cc", "memory"); 112 : "cc", "memory");
115} 113}
116 114
117 115
118 116
119/* is there no better way of doing this using the MAC? */ 117
120#define XPROD32(_a, _b, _t, _v, _x, _y) \ 118#if 1 /* Canonical definition */
121 { (_x)=MULT32(_a,_t)+MULT32(_b,_v); \ 119#define XPROD32(_a, _b, _t, _v, _x, _y) \
120 { (_x)=MULT32(_a,_t)+MULT32(_b,_v); \
122 (_y)=MULT32(_b,_t)-MULT32(_a,_v); } 121 (_y)=MULT32(_b,_t)-MULT32(_a,_v); }
122#else
123/* Thom Johansen suggestion; this could loose the lsb by overflow
124 but does it matter in practice? */
125#define XPROD32(_a, _b, _t, _v, _x, _y) \
126 asm volatile ("mac.l %[a], %[t], %%acc0;" \
127 "mac.l %[b], %[v], %%acc0;" \
128 "mac.l %[b], %[t], %%acc1;" \
129 "msac.l %[a], %[v], %%acc1;" \
130 "movclr.l %%acc0, %[x];" \
131 "asr.l #1, %[x];" \
132 "movclr.l %%acc1, %[y];" \
133 "asr.l #1, %[y];" \
134 : [x] "=&d" (_x), [y] "=&d" (_y) \
135 : [a] "r" (_a), [b] "r" (_b), \
136 [t] "r" (_t), [v] "r" (_v) \
137 : "cc");
138#endif
123 139
124 140
125/* asm versions of vector multiplication for window.c */ 141/* asm versions of vector multiplication for window.c */
@@ -127,94 +143,94 @@ void XNPROD31(ogg_int32_t a, ogg_int32_t b,
127static inline 143static inline
128void mcf5249_vect_mult_fw(ogg_int32_t *data, LOOKUP_T *window, int n) 144void mcf5249_vect_mult_fw(ogg_int32_t *data, LOOKUP_T *window, int n)
129{ 145{
130 asm volatile ("movem.l (%[d]), %%d0-%%d3;" // loop start 146 asm volatile ("movem.l (%[d]), %%d0-%%d3;" /* loop start */
131 "movem.l (%[w]), %%a0-%%a3;" // pre-fetch registers 147 "movem.l (%[w]), %%a0-%%a3;" /* pre-fetch registers */
132 "lea.l (4*4, %[w]), %[w];" 148 "lea.l (4*4, %[w]), %[w];"
133 "bra 1f;" // jump to loop condition 149 "bra 1f;" /* jump to loop condition */
134 "0:" // loop body 150 "0:" /* loop body */
135 // multiply and load next window values 151 /* multiply and load next window values */
136 "mac.l %%d0, %%a0, (%[w])+, %%a0, %%acc0;" 152 "mac.l %%d0, %%a0, (%[w])+, %%a0, %%acc0;"
137 "mac.l %%d1, %%a1, (%[w])+, %%a1, %%acc1;" 153 "mac.l %%d1, %%a1, (%[w])+, %%a1, %%acc1;"
138 "mac.l %%d2, %%a2, (%[w])+, %%a2, %%acc2;" 154 "mac.l %%d2, %%a2, (%[w])+, %%a2, %%acc2;"
139 "mac.l %%d3, %%a3, (%[w])+, %%a3, %%acc3;" 155 "mac.l %%d3, %%a3, (%[w])+, %%a3, %%acc3;"
140 "movclr.l %%acc0, %%d0;" // get the products 156 "movclr.l %%acc0, %%d0;" /* get the products */
141 "movclr.l %%acc1, %%d1;" 157 "movclr.l %%acc1, %%d1;"
142 "movclr.l %%acc2, %%d2;" 158 "movclr.l %%acc2, %%d2;"
143 "movclr.l %%acc3, %%d3;" 159 "movclr.l %%acc3, %%d3;"
144 // store and advance 160 /* store and advance */
145 "movem.l %%d0-%%d3, (%[d]);" 161 "movem.l %%d0-%%d3, (%[d]);"
146 "lea.l (4*4, %[d]), %[d];" 162 "lea.l (4*4, %[d]), %[d];"
147 "movem.l (%[d]), %%d0-%%d3;" 163 "movem.l (%[d]), %%d0-%%d3;"
148 "subq.l #4, %[n];" // done 4 elements 164 "subq.l #4, %[n];" /* done 4 elements */
149 "1: cmpi.l #4, %[n];" 165 "1: cmpi.l #4, %[n];"
150 "bge 0b;" 166 "bge 0b;"
151 // multiply final elements 167 /* multiply final elements */
152 "tst.l %[n];" 168 "tst.l %[n];"
153 "beq 1f;" // n=0 169 "beq 1f;" /* n=0 */
154 "mac.l %%d0, %%a0, %%acc0;" 170 "mac.l %%d0, %%a0, %%acc0;"
155 "movclr.l %%acc0, %%d0;" 171 "movclr.l %%acc0, %%d0;"
156 "move.l %%d0, (%[d])+;" 172 "move.l %%d0, (%[d])+;"
157 "subq.l #1, %[n];" 173 "subq.l #1, %[n];"
158 "beq 1f;" // n=1 174 "beq 1f;" /* n=1 */
159 "mac.l %%d1, %%a1, %%acc0;" 175 "mac.l %%d1, %%a1, %%acc0;"
160 "movclr.l %%acc0, %%d1;" 176 "movclr.l %%acc0, %%d1;"
161 "move.l %%d1, (%[d])+;" 177 "move.l %%d1, (%[d])+;"
162 "subq.l #1, %[n];" 178 "subq.l #1, %[n];"
163 "beq 1f;" // n=2 179 "beq 1f;" /* n=2 */
164 // otherwise n = 3 180 /* otherwise n = 3 */
165 "mac.l %%d2, %%a2, %%acc0;" 181 "mac.l %%d2, %%a2, %%acc0;"
166 "movclr.l %%acc0, %%d2;" 182 "movclr.l %%acc0, %%d2;"
167 "move.l %%d2, (%[d])+;" 183 "move.l %%d2, (%[d])+;"
168 "1:" 184 "1:"
169 : [n] "+d" (n), [d] "+a" (data), [w] "+a" (window) 185 : [n] "+d" (n), [d] "+a" (data), [w] "+a" (window)
170 : : "%d0", "%d1", "%d2", "%d3", "%a0", "%a1", "%a2", "%a3", 186 : : "%d0", "%d1", "%d2", "%d3", "%a0", "%a1", "%a2", "%a3",
171 "cc", "memory"); 187 "cc", "memory");
172} 188}
173 189
174static inline 190static inline
175void mcf5249_vect_mult_bw(ogg_int32_t *data, LOOKUP_T *window, int n) 191void mcf5249_vect_mult_bw(ogg_int32_t *data, LOOKUP_T *window, int n)
176{ 192{
177 asm volatile ("lea.l (-3*4, %[w]), %[w];" // loop start 193 asm volatile ("lea.l (-3*4, %[w]), %[w];" /* loop start */
178 "movem.l (%[d]), %%d0-%%d3;" // pre-fetch registers 194 "movem.l (%[d]), %%d0-%%d3;" /* pre-fetch registers */
179 "movem.l (%[w]), %%a0-%%a3;" 195 "movem.l (%[w]), %%a0-%%a3;"
180 "bra 1f;" // jump to loop condition 196 "bra 1f;" /* jump to loop condition */
181 "0:" // loop body 197 "0:" /* loop body */
182 // multiply and load next window value 198 /* multiply and load next window value */
183 "mac.l %%d0, %%a3, -(%[w]), %%a3, %%acc0;" 199 "mac.l %%d0, %%a3, -(%[w]), %%a3, %%acc0;"
184 "mac.l %%d1, %%a2, -(%[w]), %%a2, %%acc1;" 200 "mac.l %%d1, %%a2, -(%[w]), %%a2, %%acc1;"
185 "mac.l %%d2, %%a1, -(%[w]), %%a1, %%acc2;" 201 "mac.l %%d2, %%a1, -(%[w]), %%a1, %%acc2;"
186 "mac.l %%d3, %%a0, -(%[w]), %%a0, %%acc3;" 202 "mac.l %%d3, %%a0, -(%[w]), %%a0, %%acc3;"
187 "movclr.l %%acc0, %%d0;" // get the products 203 "movclr.l %%acc0, %%d0;" /* get the products */
188 "movclr.l %%acc1, %%d1;" 204 "movclr.l %%acc1, %%d1;"
189 "movclr.l %%acc2, %%d2;" 205 "movclr.l %%acc2, %%d2;"
190 "movclr.l %%acc3, %%d3;" 206 "movclr.l %%acc3, %%d3;"
191 // store and advance 207 /* store and advance */
192 "movem.l %%d0-%%d3, (%[d]);" 208 "movem.l %%d0-%%d3, (%[d]);"
193 "lea.l (4*4, %[d]), %[d];" 209 "lea.l (4*4, %[d]), %[d];"
194 "movem.l (%[d]), %%d0-%%d3;" 210 "movem.l (%[d]), %%d0-%%d3;"
195 "subq.l #4, %[n];" // done 4 elements 211 "subq.l #4, %[n];" /* done 4 elements */
196 "1: cmpi.l #4, %[n];" 212 "1: cmpi.l #4, %[n];"
197 "bge 0b;" 213 "bge 0b;"
198 // multiply final elements 214 /* multiply final elements */
199 "tst.l %[n];" 215 "tst.l %[n];"
200 "beq 1f;" // n=0 216 "beq 1f;" /* n=0 */
201 "mac.l %%d0, %%a3, %%acc0;" 217 "mac.l %%d0, %%a3, %%acc0;"
202 "movclr.l %%acc0, %%d0;" 218 "movclr.l %%acc0, %%d0;"
203 "move.l %%d0, (%[d])+;" 219 "move.l %%d0, (%[d])+;"
204 "subq.l #1, %[n];" 220 "subq.l #1, %[n];"
205 "beq 1f;" // n=1 221 "beq 1f;" /* n=1 */
206 "mac.l %%d1, %%a2, %%acc0;" 222 "mac.l %%d1, %%a2, %%acc0;"
207 "movclr.l %%acc0, %%d1;" 223 "movclr.l %%acc0, %%d1;"
208 "move.l %%d1, (%[d])+;" 224 "move.l %%d1, (%[d])+;"
209 "subq.l #1, %[n];" 225 "subq.l #1, %[n];"
210 "beq 1f;" // n=2 226 "beq 1f;" /* n=2 */
211 // otherwise n = 3 227 /* otherwise n = 3 */
212 "mac.l %%d2, %%a1, %%acc0;" 228 "mac.l %%d2, %%a1, %%acc0;"
213 "movclr.l %%acc0, %%d2;" 229 "movclr.l %%acc0, %%d2;"
214 "move.l %%d2, (%[d])+;" 230 "move.l %%d2, (%[d])+;"
215 "1:" 231 "1:"
216 : [n] "+d" (n), [d] "+a" (data), [w] "+a" (window) 232 : [n] "+d" (n), [d] "+a" (data), [w] "+a" (window)
217 : : "%d0", "%d1", "%d2", "%d3", "%a0", "%a1", "%a2", "%a3", 233 : : "%d0", "%d1", "%d2", "%d3", "%a0", "%a1", "%a2", "%a3",
218 "cc", "memory"); 234 "cc", "memory");
219} 235}
220 236
@@ -223,33 +239,43 @@ static inline
223void mcf5249_vect_zero(ogg_int32_t *ptr, int n) 239void mcf5249_vect_zero(ogg_int32_t *ptr, int n)
224{ 240{
225 asm volatile ("clr.l %%d0;" 241 asm volatile ("clr.l %%d0;"
226 "clr.l %%d1;" 242 "clr.l %%d1;"
227 "clr.l %%d2;" 243 "clr.l %%d2;"
228 "clr.l %%d3;" 244 "clr.l %%d3;"
229 // loop start 245 /* loop start */
230 "tst.l %[n];" 246 "tst.l %[n];"
231 "bra 1f;" 247 "bra 1f;"
232 "0: movem.l %%d0-%%d3, (%[ptr]);" 248 "0: movem.l %%d0-%%d3, (%[ptr]);"
233 "lea (4*4, %[ptr]), %[ptr];" 249 "lea (4*4, %[ptr]), %[ptr];"
234 "subq.l #4, %[n];" 250 "subq.l #4, %[n];"
235 "1: bgt 0b;" 251 "1: bgt 0b;"
236 // remaing elements 252 /* remaing elements */
237 "tst.l %[n];" 253 "tst.l %[n];"
238 "beq 1f;" // n=0 254 "beq 1f;" /* n=0 */
239 "clr.l (%[ptr])+;" 255 "clr.l (%[ptr])+;"
240 "subq.l #1, %[n];" 256 "subq.l #1, %[n];"
241 "beq 1f;" // n=1 257 "beq 1f;" /* n=1 */
242 "clr.l (%[ptr])+;" 258 "clr.l (%[ptr])+;"
243 "subq.l #1, %[n];" 259 "subq.l #1, %[n];"
244 "beq 1f;" // n=2 260 "beq 1f;" /* n=2 */
245 // otherwise n = 3 261 /* otherwise n = 3 */
246 "clr.l (%[ptr])+;" 262 "clr.l (%[ptr])+;"
247 "1:" 263 "1:"
248 : [n] "+d" (n), [ptr] "+a" (ptr) 264 : [n] "+d" (n), [ptr] "+a" (ptr)
249 : 265 :
250 : "%d0","%d1","%d2","%d3","cc","memory"); 266 : "%d0","%d1","%d2","%d3","cc","memory");
251} 267}
252 268
269#endif
270
271#ifndef _V_CLIP_MATH
272#define _V_CLIP_MATH
273
274/* this is portable C and simple; why not use this as default? */
275static inline ogg_int32_t CLIP_TO_15(register ogg_int32_t x) {
276 register ogg_int32_t hi=32767, lo=-32768;
277 return (x>=hi ? hi : (x<=lo ? lo : x));
278}
253 279
254#endif 280#endif
255#endif 281#endif
diff --git a/apps/codecs/Tremor/floor1.c b/apps/codecs/Tremor/floor1.c
index 9632dee9b0..e01b08cd11 100644
--- a/apps/codecs/Tremor/floor1.c
+++ b/apps/codecs/Tremor/floor1.c
@@ -91,7 +91,7 @@ static vorbis_info_floor *floor1_unpack (vorbis_info *vi,oggpack_buffer *opb){
91 for(k=0;k<(1<<info->class_subs[j]);k++){ 91 for(k=0;k<(1<<info->class_subs[j]);k++){
92 info->class_subbook[j][k]=oggpack_read(opb,8)-1; 92 info->class_subbook[j][k]=oggpack_read(opb,8)-1;
93 if(info->class_subbook[j][k]<-1 || info->class_subbook[j][k]>=ci->books) 93 if(info->class_subbook[j][k]<-1 || info->class_subbook[j][k]>=ci->books)
94 goto err_out; 94 goto err_out;
95 } 95 }
96 } 96 }
97 97
@@ -104,7 +104,7 @@ static vorbis_info_floor *floor1_unpack (vorbis_info *vi,oggpack_buffer *opb){
104 for(;k<count;k++){ 104 for(;k<count;k++){
105 int t=info->postlist[k+2]=oggpack_read(opb,rangebits); 105 int t=info->postlist[k+2]=oggpack_read(opb,rangebits);
106 if(t<0 || t>=(1<<rangebits)) 106 if(t<0 || t>=(1<<rangebits))
107 goto err_out; 107 goto err_out;
108 } 108 }
109 } 109 }
110 info->postlist[0]=0; 110 info->postlist[0]=0;
@@ -179,12 +179,12 @@ static vorbis_look_floor *floor1_look(vorbis_dsp_state *vd,vorbis_info_mode *mi,
179 for(j=0;j<i+2;j++){ 179 for(j=0;j<i+2;j++){
180 int x=info->postlist[j]; 180 int x=info->postlist[j];
181 if(x>lx && x<currentx){ 181 if(x>lx && x<currentx){
182 lo=j; 182 lo=j;
183 lx=x; 183 lx=x;
184 } 184 }
185 if(x<hx && x>currentx){ 185 if(x<hx && x>currentx){
186 hi=j; 186 hi=j;
187 hx=x; 187 hx=x;
188 } 188 }
189 } 189 }
190 look->loneighbor[i]=lo; 190 look->loneighbor[i]=lo;
@@ -216,7 +216,8 @@ static int render_point(int x0,int x1,int y0,int y1,int x){
216# define XdB(n) (n) 216# define XdB(n) (n)
217#endif 217#endif
218 218
219static ogg_int32_t FLOOR_fromdB_LOOKUP[256] ={ 219/* keep the floor lookup table in fast IRAM */
220static ogg_int32_t FLOOR_fromdB_LOOKUP[256] IDATA_ATTR = {
220 XdB(0x000000e5), XdB(0x000000f4), XdB(0x00000103), XdB(0x00000114), 221 XdB(0x000000e5), XdB(0x000000f4), XdB(0x00000103), XdB(0x00000114),
221 XdB(0x00000126), XdB(0x00000139), XdB(0x0000014e), XdB(0x00000163), 222 XdB(0x00000126), XdB(0x00000139), XdB(0x0000014e), XdB(0x00000163),
222 XdB(0x0000017a), XdB(0x00000193), XdB(0x000001ad), XdB(0x000001c9), 223 XdB(0x0000017a), XdB(0x00000193), XdB(0x000001ad), XdB(0x000001c9),
@@ -334,20 +335,20 @@ static void *floor1_inverse1(vorbis_block *vb,vorbis_look_floor *in){
334 335
335 /* decode the partition's first stage cascade value */ 336 /* decode the partition's first stage cascade value */
336 if(csubbits){ 337 if(csubbits){
337 cval=vorbis_book_decode(books+info->class_book[classv],&vb->opb); 338 cval=vorbis_book_decode(books+info->class_book[classv],&vb->opb);
338 339
339 if(cval==-1)goto eop; 340 if(cval==-1)goto eop;
340 } 341 }
341 342
342 for(k=0;k<cdim;k++){ 343 for(k=0;k<cdim;k++){
343 int book=info->class_subbook[classv][cval&(csub-1)]; 344 int book=info->class_subbook[classv][cval&(csub-1)];
344 cval>>=csubbits; 345 cval>>=csubbits;
345 if(book>=0){ 346 if(book>=0){
346 if((fit_value[j+k]=vorbis_book_decode(books+book,&vb->opb))==-1) 347 if((fit_value[j+k]=vorbis_book_decode(books+book,&vb->opb))==-1)
347 goto eop; 348 goto eop;
348 }else{ 349 }else{
349 fit_value[j+k]=0; 350 fit_value[j+k]=0;
350 } 351 }
351 } 352 }
352 j+=cdim; 353 j+=cdim;
353 } 354 }
@@ -355,38 +356,38 @@ static void *floor1_inverse1(vorbis_block *vb,vorbis_look_floor *in){
355 /* unwrap positive values and reconsitute via linear interpolation */ 356 /* unwrap positive values and reconsitute via linear interpolation */
356 for(i=2;i<look->posts;i++){ 357 for(i=2;i<look->posts;i++){
357 int predicted=render_point(info->postlist[look->loneighbor[i-2]], 358 int predicted=render_point(info->postlist[look->loneighbor[i-2]],
358 info->postlist[look->hineighbor[i-2]], 359 info->postlist[look->hineighbor[i-2]],
359 fit_value[look->loneighbor[i-2]], 360 fit_value[look->loneighbor[i-2]],
360 fit_value[look->hineighbor[i-2]], 361 fit_value[look->hineighbor[i-2]],
361 info->postlist[i]); 362 info->postlist[i]);
362 int hiroom=look->quant_q-predicted; 363 int hiroom=look->quant_q-predicted;
363 int loroom=predicted; 364 int loroom=predicted;
364 int room=(hiroom<loroom?hiroom:loroom)<<1; 365 int room=(hiroom<loroom?hiroom:loroom)<<1;
365 int val=fit_value[i]; 366 int val=fit_value[i];
366 367
367 if(val){ 368 if(val){
368 if(val>=room){ 369 if(val>=room){
369 if(hiroom>loroom){ 370 if(hiroom>loroom){
370 val = val-loroom; 371 val = val-loroom;
371 }else{ 372 }else{
372 val = -1-(val-hiroom); 373 val = -1-(val-hiroom);
373 } 374 }
374 }else{ 375 }else{
375 if(val&1){ 376 if(val&1){
376 val= -((val+1)>>1); 377 val= -((val+1)>>1);
377 }else{ 378 }else{
378 val>>=1; 379 val>>=1;
379 } 380 }
380 } 381 }
381 382
382 fit_value[i]=val+predicted; 383 fit_value[i]=val+predicted;
383 fit_value[look->loneighbor[i-2]]&=0x7fff; 384 fit_value[look->loneighbor[i-2]]&=0x7fff;
384 fit_value[look->hineighbor[i-2]]&=0x7fff; 385 fit_value[look->hineighbor[i-2]]&=0x7fff;
385 386
386 }else{ 387 }else{
387 fit_value[i]=predicted|0x8000; 388 fit_value[i]=predicted|0x8000;
388 } 389 }
389 390
390 } 391 }
391 392
392 return(fit_value); 393 return(fit_value);
@@ -396,7 +397,7 @@ static void *floor1_inverse1(vorbis_block *vb,vorbis_look_floor *in){
396} 397}
397 398
398static int floor1_inverse2(vorbis_block *vb,vorbis_look_floor *in,void *memo, 399static int floor1_inverse2(vorbis_block *vb,vorbis_look_floor *in,void *memo,
399 ogg_int32_t *out){ 400 ogg_int32_t *out){
400 vorbis_look_floor1 *look=(vorbis_look_floor1 *)in; 401 vorbis_look_floor1 *look=(vorbis_look_floor1 *)in;
401 vorbis_info_floor1 *info=look->vi; 402 vorbis_info_floor1 *info=look->vi;
402 403
@@ -414,14 +415,14 @@ static int floor1_inverse2(vorbis_block *vb,vorbis_look_floor *in,void *memo,
414 int current=look->forward_index[j]; 415 int current=look->forward_index[j];
415 int hy=fit_value[current]&0x7fff; 416 int hy=fit_value[current]&0x7fff;
416 if(hy==fit_value[current]){ 417 if(hy==fit_value[current]){
417 418
418 hy*=info->mult; 419 hy*=info->mult;
419 hx=info->postlist[current]; 420 hx=info->postlist[current];
420 421
421 render_line(lx,hx,ly,hy,out); 422 render_line(lx,hx,ly,hy,out);
422 423
423 lx=hx; 424 lx=hx;
424 ly=hy; 425 ly=hy;
425 } 426 }
426 } 427 }
427 for(j=hx;j<n;j++)out[j]*=ly; /* be certain */ 428 for(j=hx;j<n;j++)out[j]*=ly; /* be certain */
diff --git a/apps/codecs/Tremor/mapping0.c b/apps/codecs/Tremor/mapping0.c
index c88f072706..c53383de8f 100644
--- a/apps/codecs/Tremor/mapping0.c
+++ b/apps/codecs/Tremor/mapping0.c
@@ -52,7 +52,7 @@ typedef struct {
52 52
53 int ch; 53 int ch;
54 long lastframe; /* if a different mode is called, we need to 54 long lastframe; /* if a different mode is called, we need to
55 invalidate decay */ 55 invalidate decay */
56} vorbis_look_mapping0; 56} vorbis_look_mapping0;
57 57
58static void mapping0_free_info(vorbis_info_mapping *i){ 58static void mapping0_free_info(vorbis_info_mapping *i){
@@ -83,7 +83,7 @@ static void mapping0_free_look(vorbis_look_mapping *look){
83} 83}
84 84
85static vorbis_look_mapping *mapping0_look(vorbis_dsp_state *vd,vorbis_info_mode *vm, 85static vorbis_look_mapping *mapping0_look(vorbis_dsp_state *vd,vorbis_info_mode *vm,
86 vorbis_info_mapping *m){ 86 vorbis_info_mapping *m){
87 int i; 87 int i;
88 vorbis_info *vi=vd->vi; 88 vorbis_info *vi=vd->vi;
89 codec_setup_info *ci=(codec_setup_info *)vi->codec_setup; 89 codec_setup_info *ci=(codec_setup_info *)vi->codec_setup;
@@ -147,10 +147,10 @@ static vorbis_info_mapping *mapping0_unpack(vorbis_info *vi,oggpack_buffer *opb)
147 int testA=info->coupling_ang[i]=oggpack_read(opb,ilog(vi->channels)); 147 int testA=info->coupling_ang[i]=oggpack_read(opb,ilog(vi->channels));
148 148
149 if(testM<0 || 149 if(testM<0 ||
150 testA<0 || 150 testA<0 ||
151 testM==testA || 151 testM==testA ||
152 testM>=vi->channels || 152 testM>=vi->channels ||
153 testA>=vi->channels) goto err_out; 153 testA>=vi->channels) goto err_out;
154 } 154 }
155 155
156 } 156 }
@@ -237,16 +237,16 @@ static int mapping0_inverse(vorbis_block *vb,vorbis_look_mapping *l){
237 int ch_in_bundle=0; 237 int ch_in_bundle=0;
238 for(j=0;j<vi->channels;j++){ 238 for(j=0;j<vi->channels;j++){
239 if(info->chmuxlist[j]==i){ 239 if(info->chmuxlist[j]==i){
240 if(nonzero[j]) 240 if(nonzero[j])
241 zerobundle[ch_in_bundle]=1; 241 zerobundle[ch_in_bundle]=1;
242 else 242 else
243 zerobundle[ch_in_bundle]=0; 243 zerobundle[ch_in_bundle]=0;
244 pcmbundle[ch_in_bundle++]=vb->pcm[j]; 244 pcmbundle[ch_in_bundle++]=vb->pcm[j];
245 } 245 }
246 } 246 }
247 247
248 look->residue_func[i]->inverse(vb,look->residue_look[i], 248 look->residue_func[i]->inverse(vb,look->residue_look[i],
249 pcmbundle,zerobundle,ch_in_bundle); 249 pcmbundle,zerobundle,ch_in_bundle);
250 } 250 }
251 251
252 //for(j=0;j<vi->channels;j++) 252 //for(j=0;j<vi->channels;j++)
@@ -263,21 +263,21 @@ static int mapping0_inverse(vorbis_block *vb,vorbis_look_mapping *l){
263 ogg_int32_t ang=pcmA[j]; 263 ogg_int32_t ang=pcmA[j];
264 264
265 if(mag>0) 265 if(mag>0)
266 if(ang>0){ 266 if(ang>0){
267 pcmM[j]=mag; 267 pcmM[j]=mag;
268 pcmA[j]=mag-ang; 268 pcmA[j]=mag-ang;
269 }else{ 269 }else{
270 pcmA[j]=mag; 270 pcmA[j]=mag;
271 pcmM[j]=mag+ang; 271 pcmM[j]=mag+ang;
272 } 272 }
273 else 273 else
274 if(ang>0){ 274 if(ang>0){
275 pcmM[j]=mag; 275 pcmM[j]=mag;
276 pcmA[j]=mag+ang; 276 pcmA[j]=mag+ang;
277 }else{ 277 }else{
278 pcmA[j]=mag; 278 pcmA[j]=mag;
279 pcmM[j]=mag-ang; 279 pcmM[j]=mag-ang;
280 } 280 }
281 } 281 }
282 } 282 }
283 283
@@ -303,13 +303,13 @@ static int mapping0_inverse(vorbis_block *vb,vorbis_look_mapping *l){
303 ogg_int32_t *pcm=vb->pcm[i]; 303 ogg_int32_t *pcm=vb->pcm[i];
304 304
305 if(nonzero[i]) { 305 if(nonzero[i]) {
306 mdct_backward(n, pcm, pcm); 306 mdct_backward(n, pcm, pcm);
307 /* window the data */ 307 /* window the data */
308 _vorbis_apply_window(pcm,b->window,ci->blocksizes,vb->lW,vb->W,vb->nW); 308 _vorbis_apply_window(pcm,b->window,ci->blocksizes,vb->lW,vb->W,vb->nW);
309 } 309 }
310 else 310 else
311 memset(pcm, 0, sizeof(ogg_int32_t)*n); 311 memset(pcm, 0, sizeof(ogg_int32_t)*n);
312 } 312 }
313 313
314 //for(j=0;j<vi->channels;j++) 314 //for(j=0;j<vi->channels;j++)
315 //_analysis_output("imdct",seq+j,vb->pcm[j],-24,n,0,0); 315 //_analysis_output("imdct",seq+j,vb->pcm[j],-24,n,0,0);
diff --git a/apps/codecs/Tremor/mdct.c b/apps/codecs/Tremor/mdct.c
index 53d1ed4f0c..27a340bcad 100644
--- a/apps/codecs/Tremor/mdct.c
+++ b/apps/codecs/Tremor/mdct.c
@@ -50,15 +50,15 @@ STIN void mdct_butterfly_8(DATA_TYPE *x){
50 REG_TYPE r6 = x[7] + x[3]; 50 REG_TYPE r6 = x[7] + x[3];
51 REG_TYPE r7 = x[7] - x[3]; 51 REG_TYPE r7 = x[7] - x[3];
52 52
53 x[0] = r5 + r3; 53 x[0] = r5 + r3;
54 x[1] = r7 - r1; 54 x[1] = r7 - r1;
55 x[2] = r5 - r3; 55 x[2] = r5 - r3;
56 x[3] = r7 + r1; 56 x[3] = r7 + r1;
57 x[4] = r4 - r0; 57 x[4] = r4 - r0;
58 x[5] = r6 - r2; 58 x[5] = r6 - r2;
59 x[6] = r4 + r0; 59 x[6] = r4 + r0;
60 x[7] = r6 + r2; 60 x[7] = r6 + r2;
61 MB(); 61 MB();
62} 62}
63 63
64/* 16 point butterfly (in place, 4 register) */ 64/* 16 point butterfly (in place, 4 register) */
@@ -66,30 +66,30 @@ STIN void mdct_butterfly_16(DATA_TYPE *x){
66 66
67 REG_TYPE r0, r1; 67 REG_TYPE r0, r1;
68 68
69 r0 = x[ 0] - x[ 8]; x[ 8] += x[ 0]; 69 r0 = x[ 0] - x[ 8]; x[ 8] += x[ 0];
70 r1 = x[ 1] - x[ 9]; x[ 9] += x[ 1]; 70 r1 = x[ 1] - x[ 9]; x[ 9] += x[ 1];
71 x[ 0] = MULT31((r0 + r1) , cPI2_8); 71 x[ 0] = MULT31((r0 + r1) , cPI2_8);
72 x[ 1] = MULT31((r1 - r0) , cPI2_8); 72 x[ 1] = MULT31((r1 - r0) , cPI2_8);
73 MB(); 73 MB();
74 74
75 r0 = x[10] - x[ 2]; x[10] += x[ 2]; 75 r0 = x[10] - x[ 2]; x[10] += x[ 2];
76 r1 = x[ 3] - x[11]; x[11] += x[ 3]; 76 r1 = x[ 3] - x[11]; x[11] += x[ 3];
77 x[ 2] = r1; x[ 3] = r0; 77 x[ 2] = r1; x[ 3] = r0;
78 MB(); 78 MB();
79 79
80 r0 = x[12] - x[ 4]; x[12] += x[ 4]; 80 r0 = x[12] - x[ 4]; x[12] += x[ 4];
81 r1 = x[13] - x[ 5]; x[13] += x[ 5]; 81 r1 = x[13] - x[ 5]; x[13] += x[ 5];
82 x[ 4] = MULT31((r0 - r1) , cPI2_8); 82 x[ 4] = MULT31((r0 - r1) , cPI2_8);
83 x[ 5] = MULT31((r0 + r1) , cPI2_8); 83 x[ 5] = MULT31((r0 + r1) , cPI2_8);
84 MB(); 84 MB();
85 85
86 r0 = x[14] - x[ 6]; x[14] += x[ 6]; 86 r0 = x[14] - x[ 6]; x[14] += x[ 6];
87 r1 = x[15] - x[ 7]; x[15] += x[ 7]; 87 r1 = x[15] - x[ 7]; x[15] += x[ 7];
88 x[ 6] = r0; x[ 7] = r1; 88 x[ 6] = r0; x[ 7] = r1;
89 MB(); 89 MB();
90 90
91 mdct_butterfly_8(x); 91 mdct_butterfly_8(x);
92 mdct_butterfly_8(x+8); 92 mdct_butterfly_8(x+8);
93} 93}
94 94
95/* 32 point butterfly (in place, 4 register) */ 95/* 32 point butterfly (in place, 4 register) */
@@ -97,50 +97,50 @@ STIN void mdct_butterfly_32(DATA_TYPE *x){
97 97
98 REG_TYPE r0, r1; 98 REG_TYPE r0, r1;
99 99
100 r0 = x[30] - x[14]; x[30] += x[14]; 100 r0 = x[30] - x[14]; x[30] += x[14];
101 r1 = x[31] - x[15]; x[31] += x[15]; 101 r1 = x[31] - x[15]; x[31] += x[15];
102 x[14] = r0; x[15] = r1; 102 x[14] = r0; x[15] = r1;
103 MB(); 103 MB();
104 104
105 r0 = x[28] - x[12]; x[28] += x[12]; 105 r0 = x[28] - x[12]; x[28] += x[12];
106 r1 = x[29] - x[13]; x[29] += x[13]; 106 r1 = x[29] - x[13]; x[29] += x[13];
107 XNPROD31( r0, r1, cPI1_8, cPI3_8, &x[12], &x[13] ); 107 XNPROD31( r0, r1, cPI1_8, cPI3_8, &x[12], &x[13] );
108 MB(); 108 MB();
109 109
110 r0 = x[26] - x[10]; x[26] += x[10]; 110 r0 = x[26] - x[10]; x[26] += x[10];
111 r1 = x[27] - x[11]; x[27] += x[11]; 111 r1 = x[27] - x[11]; x[27] += x[11];
112 x[10] = MULT31((r0 - r1) , cPI2_8); 112 x[10] = MULT31((r0 - r1) , cPI2_8);
113 x[11] = MULT31((r0 + r1) , cPI2_8); 113 x[11] = MULT31((r0 + r1) , cPI2_8);
114 MB(); 114 MB();
115 115
116 r0 = x[24] - x[ 8]; x[24] += x[ 8]; 116 r0 = x[24] - x[ 8]; x[24] += x[ 8];
117 r1 = x[25] - x[ 9]; x[25] += x[ 9]; 117 r1 = x[25] - x[ 9]; x[25] += x[ 9];
118 XNPROD31( r0, r1, cPI3_8, cPI1_8, &x[ 8], &x[ 9] ); 118 XNPROD31( r0, r1, cPI3_8, cPI1_8, &x[ 8], &x[ 9] );
119 MB(); 119 MB();
120 120
121 r0 = x[22] - x[ 6]; x[22] += x[ 6]; 121 r0 = x[22] - x[ 6]; x[22] += x[ 6];
122 r1 = x[ 7] - x[23]; x[23] += x[ 7]; 122 r1 = x[ 7] - x[23]; x[23] += x[ 7];
123 x[ 6] = r1; x[ 7] = r0; 123 x[ 6] = r1; x[ 7] = r0;
124 MB(); 124 MB();
125 125
126 r0 = x[ 4] - x[20]; x[20] += x[ 4]; 126 r0 = x[ 4] - x[20]; x[20] += x[ 4];
127 r1 = x[ 5] - x[21]; x[21] += x[ 5]; 127 r1 = x[ 5] - x[21]; x[21] += x[ 5];
128 XPROD31 ( r0, r1, cPI3_8, cPI1_8, &x[ 4], &x[ 5] ); 128 XPROD31 ( r0, r1, cPI3_8, cPI1_8, &x[ 4], &x[ 5] );
129 MB(); 129 MB();
130 130
131 r0 = x[ 2] - x[18]; x[18] += x[ 2]; 131 r0 = x[ 2] - x[18]; x[18] += x[ 2];
132 r1 = x[ 3] - x[19]; x[19] += x[ 3]; 132 r1 = x[ 3] - x[19]; x[19] += x[ 3];
133 x[ 2] = MULT31((r1 + r0) , cPI2_8); 133 x[ 2] = MULT31((r1 + r0) , cPI2_8);
134 x[ 3] = MULT31((r1 - r0) , cPI2_8); 134 x[ 3] = MULT31((r1 - r0) , cPI2_8);
135 MB(); 135 MB();
136 136
137 r0 = x[ 0] - x[16]; x[16] += x[ 0]; 137 r0 = x[ 0] - x[16]; x[16] += x[ 0];
138 r1 = x[ 1] - x[17]; x[17] += x[ 1]; 138 r1 = x[ 1] - x[17]; x[17] += x[ 1];
139 XPROD31 ( r0, r1, cPI1_8, cPI3_8, &x[ 0], &x[ 1] ); 139 XPROD31 ( r0, r1, cPI1_8, cPI3_8, &x[ 0], &x[ 1] );
140 MB(); 140 MB();
141 141
142 mdct_butterfly_16(x); 142 mdct_butterfly_16(x);
143 mdct_butterfly_16(x+16); 143 mdct_butterfly_16(x+16);
144} 144}
145 145
146/* N/stage point generic N stage butterfly (in place, 4 register) */ 146/* N/stage point generic N stage butterfly (in place, 4 register) */
@@ -262,34 +262,34 @@ STIN void mdct_bitreverse(DATA_TYPE *x,int n,int step,int shift) {
262 REG_TYPE r0 = x0[0] + x1[0]; 262 REG_TYPE r0 = x0[0] + x1[0];
263 REG_TYPE r1 = x1[1] - x0[1]; 263 REG_TYPE r1 = x1[1] - x0[1];
264 264
265 XPROD32( r0, r1, T[1], T[0], r2, r3 ); T+=step; 265 XPROD32( r0, r1, T[1], T[0], r2, r3 ); T+=step;
266 266
267 w1 -= 4; 267 w1 -= 4;
268 268
269 r0 = (x0[1] + x1[1])>>1; 269 r0 = (x0[1] + x1[1])>>1;
270 r1 = (x0[0] - x1[0])>>1; 270 r1 = (x0[0] - x1[0])>>1;
271 w0[0] = r0 + r2; 271 w0[0] = r0 + r2;
272 w0[1] = r1 + r3; 272 w0[1] = r1 + r3;
273 w1[2] = r0 - r2; 273 w1[2] = r0 - r2;
274 w1[3] = r3 - r1; 274 w1[3] = r3 - r1;
275 275
276 r3 = bitrev12(bit++); 276 r3 = bitrev12(bit++);
277 x0 = x + ((r3 ^ 0xfff)>>shift) -1; 277 x0 = x + ((r3 ^ 0xfff)>>shift) -1;
278 x1 = x + (r3>>shift); 278 x1 = x + (r3>>shift);
279 279
280 r0 = x0[0] + x1[0]; 280 r0 = x0[0] + x1[0];
281 r1 = x1[1] - x0[1]; 281 r1 = x1[1] - x0[1];
282 282
283 XPROD32( r0, r1, T[1], T[0], r2, r3 ); T+=step; 283 XPROD32( r0, r1, T[1], T[0], r2, r3 ); T+=step;
284 284
285 r0 = (x0[1] + x1[1])>>1; 285 r0 = (x0[1] + x1[1])>>1;
286 r1 = (x0[0] - x1[0])>>1; 286 r1 = (x0[0] - x1[0])>>1;
287 w0[2] = r0 + r2; 287 w0[2] = r0 + r2;
288 w0[3] = r1 + r3; 288 w0[3] = r1 + r3;
289 w1[0] = r0 - r2; 289 w1[0] = r0 - r2;
290 w1[1] = r3 - r1; 290 w1[1] = r3 - r1;
291 291
292 w0 += 4; 292 w0 += 4;
293 }while(T<Ttop); 293 }while(T<Ttop);
294 do{ 294 do{
295 REG_TYPE r3 = bitrev12(bit++); 295 REG_TYPE r3 = bitrev12(bit++);
@@ -299,34 +299,34 @@ STIN void mdct_bitreverse(DATA_TYPE *x,int n,int step,int shift) {
299 REG_TYPE r0 = x0[0] + x1[0]; 299 REG_TYPE r0 = x0[0] + x1[0];
300 REG_TYPE r1 = x1[1] - x0[1]; 300 REG_TYPE r1 = x1[1] - x0[1];
301 301
302 T-=step; XPROD32( r0, r1, T[0], T[1], r2, r3 ); 302 T-=step; XPROD32( r0, r1, T[0], T[1], r2, r3 );
303 303
304 w1 -= 4; 304 w1 -= 4;
305 305
306 r0 = (x0[1] + x1[1])>>1; 306 r0 = (x0[1] + x1[1])>>1;
307 r1 = (x0[0] - x1[0])>>1; 307 r1 = (x0[0] - x1[0])>>1;
308 w0[0] = r0 + r2; 308 w0[0] = r0 + r2;
309 w0[1] = r1 + r3; 309 w0[1] = r1 + r3;
310 w1[2] = r0 - r2; 310 w1[2] = r0 - r2;
311 w1[3] = r3 - r1; 311 w1[3] = r3 - r1;
312 312
313 r3 = bitrev12(bit++); 313 r3 = bitrev12(bit++);
314 x0 = x + ((r3 ^ 0xfff)>>shift) -1; 314 x0 = x + ((r3 ^ 0xfff)>>shift) -1;
315 x1 = x + (r3>>shift); 315 x1 = x + (r3>>shift);
316 316
317 r0 = x0[0] + x1[0]; 317 r0 = x0[0] + x1[0];
318 r1 = x1[1] - x0[1]; 318 r1 = x1[1] - x0[1];
319 319
320 T-=step; XPROD32( r0, r1, T[0], T[1], r2, r3 ); 320 T-=step; XPROD32( r0, r1, T[0], T[1], r2, r3 );
321 321
322 r0 = (x0[1] + x1[1])>>1; 322 r0 = (x0[1] + x1[1])>>1;
323 r1 = (x0[0] - x1[0])>>1; 323 r1 = (x0[0] - x1[0])>>1;
324 w0[2] = r0 + r2; 324 w0[2] = r0 + r2;
325 w0[3] = r1 + r3; 325 w0[3] = r1 + r3;
326 w1[0] = r0 - r2; 326 w1[0] = r0 - r2;
327 w1[1] = r3 - r1; 327 w1[1] = r3 - r1;
328 328
329 w0 += 4; 329 w0 += 4;
330 }while(w0<w1); 330 }while(w0<w1);
331} 331}
332 332
@@ -342,7 +342,7 @@ void mdct_backward(int n, DATA_TYPE *in, DATA_TYPE *out) {
342 int step; 342 int step;
343 343
344#if CONFIG_CPU == MCF5249 344#if CONFIG_CPU == MCF5249
345 mcf5249_init_mac(); /* should be redundant */ 345 /* mcf5249_init_mac(); */ /* should be redundant */
346#endif 346#endif
347 347
348 for (shift=6;!(n&(1<<shift));shift++); 348 for (shift=6;!(n&(1<<shift));shift++);
@@ -400,77 +400,77 @@ void mdct_backward(int n, DATA_TYPE *in, DATA_TYPE *out) {
400 T=(step>=4)?(sincos_lookup0+(step>>1)):sincos_lookup1; 400 T=(step>=4)?(sincos_lookup0+(step>>1)):sincos_lookup1;
401 do{ 401 do{
402 oX1-=4; 402 oX1-=4;
403 XPROD31( iX[0], -iX[1], T[0], T[1], &oX1[3], &oX2[0] ); T+=step; 403 XPROD31( iX[0], -iX[1], T[0], T[1], &oX1[3], &oX2[0] ); T+=step;
404 XPROD31( iX[2], -iX[3], T[0], T[1], &oX1[2], &oX2[1] ); T+=step; 404 XPROD31( iX[2], -iX[3], T[0], T[1], &oX1[2], &oX2[1] ); T+=step;
405 XPROD31( iX[4], -iX[5], T[0], T[1], &oX1[1], &oX2[2] ); T+=step; 405 XPROD31( iX[4], -iX[5], T[0], T[1], &oX1[1], &oX2[2] ); T+=step;
406 XPROD31( iX[6], -iX[7], T[0], T[1], &oX1[0], &oX2[3] ); T+=step; 406 XPROD31( iX[6], -iX[7], T[0], T[1], &oX1[0], &oX2[3] ); T+=step;
407 oX2+=4; 407 oX2+=4;
408 iX+=8; 408 iX+=8;
409 }while(iX<oX1); 409 }while(iX<oX1);
410 break; 410 break;
411 } 411 }
412 412
413 case 1: { 413 case 1: {
414 /* linear interpolation between table values: offset=0.5, step=1 */ 414 /* linear interpolation between table values: offset=0.5, step=1 */
415 REG_TYPE t0,t1,v0,v1; 415 REG_TYPE t0,t1,v0,v1;
416 T = sincos_lookup0; 416 T = sincos_lookup0;
417 V = sincos_lookup1; 417 V = sincos_lookup1;
418 t0 = (*T++)>>1; 418 t0 = (*T++)>>1;
419 t1 = (*T++)>>1; 419 t1 = (*T++)>>1;
420 do{ 420 do{
421 oX1-=4; 421 oX1-=4;
422 422
423 t0 += (v0 = (*V++)>>1); 423 t0 += (v0 = (*V++)>>1);
424 t1 += (v1 = (*V++)>>1); 424 t1 += (v1 = (*V++)>>1);
425 XPROD31( iX[0], -iX[1], t0, t1, &oX1[3], &oX2[0] ); 425 XPROD31( iX[0], -iX[1], t0, t1, &oX1[3], &oX2[0] );
426 v0 += (t0 = (*T++)>>1); 426 v0 += (t0 = (*T++)>>1);
427 v1 += (t1 = (*T++)>>1); 427 v1 += (t1 = (*T++)>>1);
428 XPROD31( iX[2], -iX[3], v0, v1, &oX1[2], &oX2[1] ); 428 XPROD31( iX[2], -iX[3], v0, v1, &oX1[2], &oX2[1] );
429 t0 += (v0 = (*V++)>>1); 429 t0 += (v0 = (*V++)>>1);
430 t1 += (v1 = (*V++)>>1); 430 t1 += (v1 = (*V++)>>1);
431 XPROD31( iX[4], -iX[5], t0, t1, &oX1[1], &oX2[2] ); 431 XPROD31( iX[4], -iX[5], t0, t1, &oX1[1], &oX2[2] );
432 v0 += (t0 = (*T++)>>1); 432 v0 += (t0 = (*T++)>>1);
433 v1 += (t1 = (*T++)>>1); 433 v1 += (t1 = (*T++)>>1);
434 XPROD31( iX[6], -iX[7], v0, v1, &oX1[0], &oX2[3] ); 434 XPROD31( iX[6], -iX[7], v0, v1, &oX1[0], &oX2[3] );
435 435
436 oX2+=4; 436 oX2+=4;
437 iX+=8; 437 iX+=8;
438 }while(iX<oX1); 438 }while(iX<oX1);
439 break; 439 break;
440 } 440 }
441 441
442 case 0: { 442 case 0: {
443 /* linear interpolation between table values: offset=0.25, step=0.5 */ 443 /* linear interpolation between table values: offset=0.25, step=0.5 */
444 REG_TYPE t0,t1,v0,v1,q0,q1; 444 REG_TYPE t0,t1,v0,v1,q0,q1;
445 T = sincos_lookup0; 445 T = sincos_lookup0;
446 V = sincos_lookup1; 446 V = sincos_lookup1;
447 t0 = *T++; 447 t0 = *T++;
448 t1 = *T++; 448 t1 = *T++;
449 do{ 449 do{
450 oX1-=4; 450 oX1-=4;
451 451
452 v0 = *V++; 452 v0 = *V++;
453 v1 = *V++; 453 v1 = *V++;
454 t0 += (q0 = (v0-t0)>>2); 454 t0 += (q0 = (v0-t0)>>2);
455 t1 += (q1 = (v1-t1)>>2); 455 t1 += (q1 = (v1-t1)>>2);
456 XPROD31( iX[0], -iX[1], t0, t1, &oX1[3], &oX2[0] ); 456 XPROD31( iX[0], -iX[1], t0, t1, &oX1[3], &oX2[0] );
457 t0 = v0-q0; 457 t0 = v0-q0;
458 t1 = v1-q1; 458 t1 = v1-q1;
459 XPROD31( iX[2], -iX[3], t0, t1, &oX1[2], &oX2[1] ); 459 XPROD31( iX[2], -iX[3], t0, t1, &oX1[2], &oX2[1] );
460 460
461 t0 = *T++; 461 t0 = *T++;
462 t1 = *T++; 462 t1 = *T++;
463 v0 += (q0 = (t0-v0)>>2); 463 v0 += (q0 = (t0-v0)>>2);
464 v1 += (q1 = (t1-v1)>>2); 464 v1 += (q1 = (t1-v1)>>2);
465 XPROD31( iX[4], -iX[5], v0, v1, &oX1[1], &oX2[2] ); 465 XPROD31( iX[4], -iX[5], v0, v1, &oX1[1], &oX2[2] );
466 v0 = t0-q0; 466 v0 = t0-q0;
467 v1 = t1-q1; 467 v1 = t1-q1;
468 XPROD31( iX[6], -iX[7], v0, v1, &oX1[0], &oX2[3] ); 468 XPROD31( iX[6], -iX[7], v0, v1, &oX1[0], &oX2[3] );
469 469
470 oX2+=4; 470 oX2+=4;
471 iX+=8; 471 iX+=8;
472 }while(iX<oX1); 472 }while(iX<oX1);
473 break; 473 break;
474 } 474 }
475 } 475 }
476 476
diff --git a/apps/codecs/Tremor/mdct_lookup.h b/apps/codecs/Tremor/mdct_lookup.h
index 63e0775ef7..dfbdacbf6e 100644
--- a/apps/codecs/Tremor/mdct_lookup.h
+++ b/apps/codecs/Tremor/mdct_lookup.h
@@ -17,7 +17,8 @@
17 17
18#include "os_types.h" 18#include "os_types.h"
19 19
20/* keep lookup tables in fast IRAM */ 20/* we keep the most used sin cosine table in fast IRAM;
21 unfortunately, we don't have the space for both tables */
21 22
22/* {sin(2*i*PI/4096), cos(2*i*PI/4096)}, with i = 0 to 512 */ 23/* {sin(2*i*PI/4096), cos(2*i*PI/4096)}, with i = 0 to 512 */
23static LOOKUP_T sincos_lookup0[1026] IDATA_ATTR = { 24static LOOKUP_T sincos_lookup0[1026] IDATA_ATTR = {
diff --git a/apps/codecs/Tremor/misc.h b/apps/codecs/Tremor/misc.h
index dc2dccf116..feaa21f9ae 100644
--- a/apps/codecs/Tremor/misc.h
+++ b/apps/codecs/Tremor/misc.h
@@ -37,7 +37,7 @@ void* alloca(size_t size);
37 37
38#ifndef _LOW_ACCURACY_ 38#ifndef _LOW_ACCURACY_
39/* 64 bit multiply */ 39/* 64 bit multiply */
40//#include <sys/types.h> 40/* #include <sys/types.h> */
41 41
42#if BYTE_ORDER==LITTLE_ENDIAN 42#if BYTE_ORDER==LITTLE_ENDIAN
43union magic { 43union magic {
diff --git a/apps/codecs/Tremor/res012.c b/apps/codecs/Tremor/res012.c
index 66947ffe7e..303a58c2f2 100644
--- a/apps/codecs/Tremor/res012.c
+++ b/apps/codecs/Tremor/res012.c
@@ -119,7 +119,7 @@ vorbis_info_residue *res0_unpack(vorbis_info *vi,oggpack_buffer *opb){
119} 119}
120 120
121vorbis_look_residue *res0_look(vorbis_dsp_state *vd,vorbis_info_mode *vm, 121vorbis_look_residue *res0_look(vorbis_dsp_state *vd,vorbis_info_mode *vm,
122 vorbis_info_residue *vr){ 122 vorbis_info_residue *vr){
123 vorbis_info_residue0 *info=(vorbis_info_residue0 *)vr; 123 vorbis_info_residue0 *info=(vorbis_info_residue0 *)vr;
124 vorbis_look_residue0 *look=(vorbis_look_residue0 *)_ogg_calloc(1,sizeof(*look)); 124 vorbis_look_residue0 *look=(vorbis_look_residue0 *)_ogg_calloc(1,sizeof(*look));
125 codec_setup_info *ci=(codec_setup_info *)vd->vi->codec_setup; 125 codec_setup_info *ci=(codec_setup_info *)vd->vi->codec_setup;
@@ -143,13 +143,13 @@ vorbis_look_residue *res0_look(vorbis_dsp_state *vd,vorbis_info_mode *vm,
143 if(stages>maxstage)maxstage=stages; 143 if(stages>maxstage)maxstage=stages;
144 look->partbooks[j]=(codebook **)_ogg_calloc(stages,sizeof(*look->partbooks[j])); 144 look->partbooks[j]=(codebook **)_ogg_calloc(stages,sizeof(*look->partbooks[j]));
145 for(k=0;k<stages;k++) 145 for(k=0;k<stages;k++)
146 if(info->secondstages[j]&(1<<k)){ 146 if(info->secondstages[j]&(1<<k)){
147 look->partbooks[j][k]=ci->fullbooks+info->booklist[acc++]; 147 look->partbooks[j][k]=ci->fullbooks+info->booklist[acc++];
148#ifdef TRAIN_RES 148#ifdef TRAIN_RES
149 look->training_data[k][j]=calloc(look->partbooks[j][k]->entries, 149 look->training_data[k][j]=calloc(look->partbooks[j][k]->entries,
150 sizeof(***look->training_data)); 150 sizeof(***look->training_data));
151#endif 151#endif
152 } 152 }
153 } 153 }
154 } 154 }
155 155
@@ -176,9 +176,9 @@ vorbis_look_residue *res0_look(vorbis_dsp_state *vd,vorbis_info_mode *vm,
176 176
177/* a truncated packet here just means 'stop working'; it's not an error */ 177/* a truncated packet here just means 'stop working'; it's not an error */
178static int _01inverse(vorbis_block *vb,vorbis_look_residue *vl, 178static int _01inverse(vorbis_block *vb,vorbis_look_residue *vl,
179 ogg_int32_t **in,int ch, 179 ogg_int32_t **in,int ch,
180 long (*decodepart)(codebook *, ogg_int32_t *, 180 long (*decodepart)(codebook *, ogg_int32_t *,
181 oggpack_buffer *,int,int)){ 181 oggpack_buffer *,int,int)){
182 182
183 long i,j,k,l,s; 183 long i,j,k,l,s;
184 vorbis_look_residue0 *look=(vorbis_look_residue0 *)vl; 184 vorbis_look_residue0 *look=(vorbis_look_residue0 *)vl;
@@ -202,27 +202,27 @@ static int _01inverse(vorbis_block *vb,vorbis_look_residue *vl,
202 partitions_pre_word partitions */ 202 partitions_pre_word partitions */
203 for(i=0,l=0;i<partvals;l++){ 203 for(i=0,l=0;i<partvals;l++){
204 if(s==0){ 204 if(s==0){
205 /* fetch the partition word for each channel */ 205 /* fetch the partition word for each channel */
206 for(j=0;j<ch;j++){ 206 for(j=0;j<ch;j++){
207 int temp=vorbis_book_decode(look->phrasebook,&vb->opb); 207 int temp=vorbis_book_decode(look->phrasebook,&vb->opb);
208 if(temp==-1)goto eopbreak; 208 if(temp==-1)goto eopbreak;
209 partword[j][l]=look->decodemap[temp]; 209 partword[j][l]=look->decodemap[temp];
210 if(partword[j][l]==NULL)goto errout; 210 if(partword[j][l]==NULL)goto errout;
211 } 211 }
212 } 212 }
213 213
214 /* now we decode residual values for the partitions */ 214 /* now we decode residual values for the partitions */
215 for(k=0;k<partitions_per_word && i<partvals;k++,i++) 215 for(k=0;k<partitions_per_word && i<partvals;k++,i++)
216 for(j=0;j<ch;j++){ 216 for(j=0;j<ch;j++){
217 long offset=info->begin+i*samples_per_partition; 217 long offset=info->begin+i*samples_per_partition;
218 if(info->secondstages[partword[j][l][k]]&(1<<s)){ 218 if(info->secondstages[partword[j][l][k]]&(1<<s)){
219 codebook *stagebook=look->partbooks[partword[j][l][k]][s]; 219 codebook *stagebook=look->partbooks[partword[j][l][k]][s];
220 if(stagebook){ 220 if(stagebook){
221 if(decodepart(stagebook,in[j]+offset,&vb->opb, 221 if(decodepart(stagebook,in[j]+offset,&vb->opb,
222 samples_per_partition,-8)==-1)goto eopbreak; 222 samples_per_partition,-8)==-1)goto eopbreak;
223 } 223 }
224 } 224 }
225 } 225 }
226 } 226 }
227 } 227 }
228 228
@@ -232,7 +232,7 @@ static int _01inverse(vorbis_block *vb,vorbis_look_residue *vl,
232} 232}
233 233
234int res0_inverse(vorbis_block *vb,vorbis_look_residue *vl, 234int res0_inverse(vorbis_block *vb,vorbis_look_residue *vl,
235 ogg_int32_t **in,int *nonzero,int ch){ 235 ogg_int32_t **in,int *nonzero,int ch){
236 int i,used=0; 236 int i,used=0;
237 for(i=0;i<ch;i++) 237 for(i=0;i<ch;i++)
238 if(nonzero[i]) 238 if(nonzero[i])
@@ -244,7 +244,7 @@ int res0_inverse(vorbis_block *vb,vorbis_look_residue *vl,
244} 244}
245 245
246int res1_inverse(vorbis_block *vb,vorbis_look_residue *vl, 246int res1_inverse(vorbis_block *vb,vorbis_look_residue *vl,
247 ogg_int32_t **in,int *nonzero,int ch){ 247 ogg_int32_t **in,int *nonzero,int ch){
248 int i,used=0; 248 int i,used=0;
249 for(i=0;i<ch;i++) 249 for(i=0;i<ch;i++)
250 if(nonzero[i]) 250 if(nonzero[i])
@@ -259,7 +259,7 @@ int res1_inverse(vorbis_block *vb,vorbis_look_residue *vl,
259 259
260/* duplicate code here as speed is somewhat more important */ 260/* duplicate code here as speed is somewhat more important */
261int res2_inverse(vorbis_block *vb,vorbis_look_residue *vl, 261int res2_inverse(vorbis_block *vb,vorbis_look_residue *vl,
262 ogg_int32_t **in,int *nonzero,int ch){ 262 ogg_int32_t **in,int *nonzero,int ch){
263 long i,k,l,s; 263 long i,k,l,s;
264 vorbis_look_residue0 *look=(vorbis_look_residue0 *)vl; 264 vorbis_look_residue0 *look=(vorbis_look_residue0 *)vl;
265 vorbis_info_residue0 *info=look->info; 265 vorbis_info_residue0 *info=look->info;
@@ -283,25 +283,25 @@ int res2_inverse(vorbis_block *vb,vorbis_look_residue *vl,
283 for(i=0,l=0;i<partvals;l++){ 283 for(i=0,l=0;i<partvals;l++){
284 284
285 if(s==0){ 285 if(s==0){
286 /* fetch the partition word */ 286 /* fetch the partition word */
287 int temp=vorbis_book_decode(look->phrasebook,&vb->opb); 287 int temp=vorbis_book_decode(look->phrasebook,&vb->opb);
288 if(temp==-1)goto eopbreak; 288 if(temp==-1)goto eopbreak;
289 partword[l]=look->decodemap[temp]; 289 partword[l]=look->decodemap[temp];
290 if(partword[l]==NULL)goto errout; 290 if(partword[l]==NULL)goto errout;
291 } 291 }
292 292
293 /* now we decode residual values for the partitions */ 293 /* now we decode residual values for the partitions */
294 for(k=0;k<partitions_per_word && i<partvals;k++,i++) 294 for(k=0;k<partitions_per_word && i<partvals;k++,i++)
295 if(info->secondstages[partword[l][k]]&(1<<s)){ 295 if(info->secondstages[partword[l][k]]&(1<<s)){
296 codebook *stagebook=look->partbooks[partword[l][k]][s]; 296 codebook *stagebook=look->partbooks[partword[l][k]][s];
297 if(stagebook){ 297 if(stagebook){
298 if(vorbis_book_decodevv_add(stagebook,in, 298 if(vorbis_book_decodevv_add(stagebook,in,
299 i*samples_per_partition+beginoff,ch, 299 i*samples_per_partition+beginoff,ch,
300 &vb->opb, 300 &vb->opb,
301 samples_per_partition,-8)==-1) 301 samples_per_partition,-8)==-1)
302 goto eopbreak; 302 goto eopbreak;
303 } 303 }
304 } 304 }
305 } 305 }
306 } 306 }
307 307
diff --git a/apps/codecs/Tremor/synthesis.c b/apps/codecs/Tremor/synthesis.c
index 35c09f8ddb..db178e7e9f 100644
--- a/apps/codecs/Tremor/synthesis.c
+++ b/apps/codecs/Tremor/synthesis.c
@@ -26,8 +26,8 @@
26 26
27 27
28/* IRAM buffer keep the block pcm data; only for windows size upto 2048 28/* IRAM buffer keep the block pcm data; only for windows size upto 2048
29 for space restrictions. No real compromise, larger window sizes 29 for space restrictions.
30 are only used for very low quality settings (q<0?) */ 30 libVorbis 1.1 Oggenc doesn't use larger windows anyway. */
31/* max 2 channels on the ihp-1xx (stereo), 2048 samples (2*2048*4=16Kb) */ 31/* max 2 channels on the ihp-1xx (stereo), 2048 samples (2*2048*4=16Kb) */
32#define IRAM_PCM_END 2048 32#define IRAM_PCM_END 2048
33#define CHANNELS 2 33#define CHANNELS 2
@@ -80,12 +80,12 @@ int vorbis_synthesis(vorbis_block *vb,ogg_packet *op,int decodep){
80 /* use statically allocated iram buffer */ 80 /* use statically allocated iram buffer */
81 vb->pcm = ipcm_vect; 81 vb->pcm = ipcm_vect;
82 for(i=0; i<CHANNELS; i++) 82 for(i=0; i<CHANNELS; i++)
83 vb->pcm[i] = &ipcm_buff[i*IRAM_PCM_END]; 83 vb->pcm[i] = &ipcm_buff[i*IRAM_PCM_END];
84 } else { 84 } else {
85 /* dynamic allocation (slower) */ 85 /* dynamic allocation (slower) */
86 vb->pcm=(ogg_int32_t **)_vorbis_block_alloc(vb,sizeof(*vb->pcm)*vi->channels); 86 vb->pcm=(ogg_int32_t **)_vorbis_block_alloc(vb,sizeof(*vb->pcm)*vi->channels);
87 for(i=0;i<vi->channels;i++) 87 for(i=0;i<vi->channels;i++)
88 vb->pcm[i]=(ogg_int32_t *)_vorbis_block_alloc(vb,vb->pcmend*sizeof(*vb->pcm[i])); 88 vb->pcm[i]=(ogg_int32_t *)_vorbis_block_alloc(vb,vb->pcmend*sizeof(*vb->pcm[i]));
89 } 89 }
90 90
91 /* unpack_header enforces range checking */ 91 /* unpack_header enforces range checking */
diff --git a/apps/codecs/Tremor/vorbisfile.c b/apps/codecs/Tremor/vorbisfile.c
index 74bff6a3fb..67cff2269e 100644
--- a/apps/codecs/Tremor/vorbisfile.c
+++ b/apps/codecs/Tremor/vorbisfile.c
@@ -91,7 +91,7 @@ static void _seek_helper(OggVorbis_File *vf,ogg_int64_t offset){
91 91
92 boundary: -1) unbounded search 92 boundary: -1) unbounded search
93 0) read no additional data; use cached only 93 0) read no additional data; use cached only
94 n) search for a new page beginning for n bytes 94 n) search for a new page beginning for n bytes
95 95
96 return: <0) did not find a page (OV_FALSE, OV_EOF, OV_EREAD) 96 return: <0) did not find a page (OV_FALSE, OV_EOF, OV_EREAD)
97 n) found a page at absolute offset n 97 n) found a page at absolute offset n
@@ -99,7 +99,7 @@ static void _seek_helper(OggVorbis_File *vf,ogg_int64_t offset){
99 produces a refcounted page */ 99 produces a refcounted page */
100 100
101static ogg_int64_t _get_next_page(OggVorbis_File *vf,ogg_page *og, 101static ogg_int64_t _get_next_page(OggVorbis_File *vf,ogg_page *og,
102 ogg_int64_t boundary){ 102 ogg_int64_t boundary){
103 if(boundary>0)boundary+=vf->offset; 103 if(boundary>0)boundary+=vf->offset;
104 while(1){ 104 while(1){
105 long more; 105 long more;
@@ -112,20 +112,20 @@ static ogg_int64_t _get_next_page(OggVorbis_File *vf,ogg_page *og,
112 vf->offset-=more; 112 vf->offset-=more;
113 }else{ 113 }else{
114 if(more==0){ 114 if(more==0){
115 /* send more paramedics */ 115 /* send more paramedics */
116 if(!boundary)return(OV_FALSE); 116 if(!boundary)return(OV_FALSE);
117 { 117 {
118 long ret=_get_data(vf); 118 long ret=_get_data(vf);
119 if(ret==0)return(OV_EOF); 119 if(ret==0)return(OV_EOF);
120 if(ret<0)return(OV_EREAD); 120 if(ret<0)return(OV_EREAD);
121 } 121 }
122 }else{ 122 }else{
123 /* got a page. Return the offset at the page beginning, 123 /* got a page. Return the offset at the page beginning,
124 advance the internal offset past the page end */ 124 advance the internal offset past the page end */
125 ogg_int64_t ret=vf->offset; 125 ogg_int64_t ret=vf->offset;
126 vf->offset+=more; 126 vf->offset+=more;
127 return(ret); 127 return(ret);
128 128
129 } 129 }
130 } 130 }
131 } 131 }
@@ -152,9 +152,9 @@ static ogg_int64_t _get_prev_page(OggVorbis_File *vf,ogg_page *og){
152 ret=_get_next_page(vf,og,end-vf->offset); 152 ret=_get_next_page(vf,og,end-vf->offset);
153 if(ret==OV_EREAD)return(OV_EREAD); 153 if(ret==OV_EREAD)return(OV_EREAD);
154 if(ret<0){ 154 if(ret<0){
155 break; 155 break;
156 }else{ 156 }else{
157 offset=ret; 157 offset=ret;
158 } 158 }
159 } 159 }
160 } 160 }
@@ -174,11 +174,11 @@ static ogg_int64_t _get_prev_page(OggVorbis_File *vf,ogg_page *og){
174 Recurses for each link so it can alloc the link storage after 174 Recurses for each link so it can alloc the link storage after
175 finding them all, then unroll and fill the cache at the same time */ 175 finding them all, then unroll and fill the cache at the same time */
176static int _bisect_forward_serialno(OggVorbis_File *vf, 176static int _bisect_forward_serialno(OggVorbis_File *vf,
177 ogg_int64_t begin, 177 ogg_int64_t begin,
178 ogg_int64_t searched, 178 ogg_int64_t searched,
179 ogg_int64_t end, 179 ogg_int64_t end,
180 ogg_uint32_t currentno, 180 ogg_uint32_t currentno,
181 long m){ 181 long m){
182 ogg_int64_t endsearched=end; 182 ogg_int64_t endsearched=end;
183 ogg_int64_t next=end; 183 ogg_int64_t next=end;
184 ogg_page og={0,0,0,0}; 184 ogg_page og={0,0,0,0};
@@ -219,7 +219,7 @@ static int _bisect_forward_serialno(OggVorbis_File *vf,
219 vf->offsets[m+1]=searched; 219 vf->offsets[m+1]=searched;
220 }else{ 220 }else{
221 ret=_bisect_forward_serialno(vf,next,vf->offset, 221 ret=_bisect_forward_serialno(vf,next,vf->offset,
222 end,ogg_page_serialno(&og),m+1); 222 end,ogg_page_serialno(&og),m+1);
223 ogg_page_release(&og); 223 ogg_page_release(&og);
224 if(ret==OV_EREAD)return(OV_EREAD); 224 if(ret==OV_EREAD)return(OV_EREAD);
225 } 225 }
@@ -234,10 +234,10 @@ static int _bisect_forward_serialno(OggVorbis_File *vf,
234/* consumes the page that's passed in (if any) */ 234/* consumes the page that's passed in (if any) */
235 235
236static int _fetch_headers(OggVorbis_File *vf, 236static int _fetch_headers(OggVorbis_File *vf,
237 vorbis_info *vi, 237 vorbis_info *vi,
238 vorbis_comment *vc, 238 vorbis_comment *vc,
239 ogg_uint32_t *serialno, 239 ogg_uint32_t *serialno,
240 ogg_page *og_ptr){ 240 ogg_page *og_ptr){
241 ogg_page og={0,0,0,0}; 241 ogg_page og={0,0,0,0};
242 ogg_packet op={0,0,0,0,0,0}; 242 ogg_packet op={0,0,0,0,0,0};
243 int i,ret; 243 int i,ret;
@@ -266,18 +266,18 @@ static int _fetch_headers(OggVorbis_File *vf,
266 int result=ogg_stream_packetout(vf->os,&op); 266 int result=ogg_stream_packetout(vf->os,&op);
267 if(result==0)break; 267 if(result==0)break;
268 if(result==-1){ 268 if(result==-1){
269 ret=OV_EBADHEADER; 269 ret=OV_EBADHEADER;
270 goto bail_header; 270 goto bail_header;
271 } 271 }
272 if((ret=vorbis_synthesis_headerin(vi,vc,&op))){ 272 if((ret=vorbis_synthesis_headerin(vi,vc,&op))){
273 goto bail_header; 273 goto bail_header;
274 } 274 }
275 i++; 275 i++;
276 } 276 }
277 if(i<3) 277 if(i<3)
278 if(_get_next_page(vf,og_ptr,CHUNKSIZE)<0){ 278 if(_get_next_page(vf,og_ptr,CHUNKSIZE)<0){
279 ret=OV_EBADHEADER; 279 ret=OV_EBADHEADER;
280 goto bail_header; 280 goto bail_header;
281 } 281 }
282 } 282 }
283 283
@@ -326,9 +326,9 @@ static void _prefetch_all_headers(OggVorbis_File *vf, ogg_int64_t dataoffset){
326 326
327 _seek_helper(vf,vf->offsets[i]); 327 _seek_helper(vf,vf->offsets[i]);
328 if(_fetch_headers(vf,vf->vi+i,vf->vc+i,NULL,NULL)<0){ 328 if(_fetch_headers(vf,vf->vi+i,vf->vc+i,NULL,NULL)<0){
329 vf->dataoffsets[i]=-1; 329 vf->dataoffsets[i]=-1;
330 }else{ 330 }else{
331 vf->dataoffsets[i]=vf->offset; 331 vf->dataoffsets[i]=vf->offset;
332 } 332 }
333 } 333 }
334 334
@@ -342,36 +342,36 @@ static void _prefetch_all_headers(OggVorbis_File *vf, ogg_int64_t dataoffset){
342 ogg_stream_reset_serialno(vf->os,vf->serialnos[i]); 342 ogg_stream_reset_serialno(vf->os,vf->serialnos[i]);
343 343
344 while(1){ 344 while(1){
345 ogg_packet op={0,0,0,0,0,0}; 345 ogg_packet op={0,0,0,0,0,0};
346 346
347 ret=_get_next_page(vf,&og,-1); 347 ret=_get_next_page(vf,&og,-1);
348 if(ret<0) 348 if(ret<0)
349 /* this should not be possible unless the file is 349 /* this should not be possible unless the file is
350 truncated/mangled */ 350 truncated/mangled */
351 break; 351 break;
352 352
353 if(ogg_page_serialno(&og)!=vf->serialnos[i]) 353 if(ogg_page_serialno(&og)!=vf->serialnos[i])
354 break; 354 break;
355 355
356 pos=ogg_page_granulepos(&og); 356 pos=ogg_page_granulepos(&og);
357 357
358 /* count blocksizes of all frames in the page */ 358 /* count blocksizes of all frames in the page */
359 ogg_stream_pagein(vf->os,&og); 359 ogg_stream_pagein(vf->os,&og);
360 while((result=ogg_stream_packetout(vf->os,&op))){ 360 while((result=ogg_stream_packetout(vf->os,&op))){
361 if(result>0){ /* ignore holes */ 361 if(result>0){ /* ignore holes */
362 long thisblock=vorbis_packet_blocksize(vf->vi+i,&op); 362 long thisblock=vorbis_packet_blocksize(vf->vi+i,&op);
363 if(lastblock!=-1) 363 if(lastblock!=-1)
364 accumulated+=(lastblock+thisblock)>>2; 364 accumulated+=(lastblock+thisblock)>>2;
365 lastblock=thisblock; 365 lastblock=thisblock;
366 } 366 }
367 } 367 }
368 ogg_packet_release(&op); 368 ogg_packet_release(&op);
369 369
370 if(pos!=-1){ 370 if(pos!=-1){
371 /* pcm offset of last packet on the first audio page */ 371 /* pcm offset of last packet on the first audio page */
372 accumulated= pos-accumulated; 372 accumulated= pos-accumulated;
373 break; 373 break;
374 } 374 }
375 } 375 }
376 376
377 /* less than zero? This is a stream with samples trimmed off 377 /* less than zero? This is a stream with samples trimmed off
@@ -388,18 +388,18 @@ static void _prefetch_all_headers(OggVorbis_File *vf, ogg_int64_t dataoffset){
388 _seek_helper(vf,end); 388 _seek_helper(vf,end);
389 389
390 while(1){ 390 while(1){
391 ret=_get_prev_page(vf,&og); 391 ret=_get_prev_page(vf,&og);
392 if(ret<0){ 392 if(ret<0){
393 /* this should not be possible */ 393 /* this should not be possible */
394 vorbis_info_clear(vf->vi+i); 394 vorbis_info_clear(vf->vi+i);
395 vorbis_comment_clear(vf->vc+i); 395 vorbis_comment_clear(vf->vc+i);
396 break; 396 break;
397 } 397 }
398 if(ogg_page_granulepos(&og)!=-1){ 398 if(ogg_page_granulepos(&og)!=-1){
399 vf->pcmlengths[i*2+1]=ogg_page_granulepos(&og)-vf->pcmlengths[i*2]; 399 vf->pcmlengths[i*2+1]=ogg_page_granulepos(&og)-vf->pcmlengths[i*2];
400 break; 400 break;
401 } 401 }
402 vf->offset=ret; 402 vf->offset=ret;
403 } 403 }
404 } 404 }
405 } 405 }
@@ -474,12 +474,12 @@ static void _decode_clear(OggVorbis_File *vf){
474 474
475 return: <0) error, OV_HOLE (lost packet) or OV_EOF 475 return: <0) error, OV_HOLE (lost packet) or OV_EOF
476 0) need more data (only if readp==0) 476 0) need more data (only if readp==0)
477 1) got a packet 477 1) got a packet
478*/ 478*/
479 479
480static int _fetch_and_process_packet(OggVorbis_File *vf, 480static int _fetch_and_process_packet(OggVorbis_File *vf,
481 int readp, 481 int readp,
482 int spanp){ 482 int spanp){
483 ogg_page og={0,0,0,0}; 483 ogg_page og={0,0,0,0};
484 ogg_packet op={0,0,0,0,0,0}; 484 ogg_packet op={0,0,0,0,0,0};
485 int ret=0; 485 int ret=0;
@@ -492,110 +492,110 @@ static int _fetch_and_process_packet(OggVorbis_File *vf,
492 neither is a page */ 492 neither is a page */
493 if(vf->ready_state==INITSET){ 493 if(vf->ready_state==INITSET){
494 while(1) { 494 while(1) {
495 int result=ogg_stream_packetout(vf->os,&op); 495 int result=ogg_stream_packetout(vf->os,&op);
496 ogg_int64_t granulepos; 496 ogg_int64_t granulepos;
497 497
498 if(result<0){ 498 if(result<0){
499 ret=OV_HOLE; /* hole in the data. */ 499 ret=OV_HOLE; /* hole in the data. */
500 goto cleanup; 500 goto cleanup;
501 } 501 }
502 if(result>0){ 502 if(result>0){
503 /* got a packet. process it */ 503 /* got a packet. process it */
504 granulepos=op.granulepos; 504 granulepos=op.granulepos;
505 if(!vorbis_synthesis(&vf->vb,&op,1)){ /* lazy check for lazy 505 if(!vorbis_synthesis(&vf->vb,&op,1)){ /* lazy check for lazy
506 header handling. The 506 header handling. The
507 header packets aren't 507 header packets aren't
508 audio, so if/when we 508 audio, so if/when we
509 submit them, 509 submit them,
510 vorbis_synthesis will 510 vorbis_synthesis will
511 reject them */ 511 reject them */
512 512
513 /* suck in the synthesis data and track bitrate */ 513 /* suck in the synthesis data and track bitrate */
514 { 514 {
515 int oldsamples=vorbis_synthesis_pcmout(&vf->vd,NULL); 515 int oldsamples=vorbis_synthesis_pcmout(&vf->vd,NULL);
516 /* for proper use of libvorbis within libvorbisfile, 516 /* for proper use of libvorbis within libvorbisfile,
517 oldsamples will always be zero. */ 517 oldsamples will always be zero. */
518 if(oldsamples){ 518 if(oldsamples){
519 ret=OV_EFAULT; 519 ret=OV_EFAULT;
520 goto cleanup; 520 goto cleanup;
521 } 521 }
522 522
523 vorbis_synthesis_blockin(&vf->vd,&vf->vb); 523 vorbis_synthesis_blockin(&vf->vd,&vf->vb);
524 vf->samptrack+=vorbis_synthesis_pcmout(&vf->vd,NULL)-oldsamples; 524 vf->samptrack+=vorbis_synthesis_pcmout(&vf->vd,NULL)-oldsamples;
525 vf->bittrack+=op.bytes*8; 525 vf->bittrack+=op.bytes*8;
526 } 526 }
527 527
528 /* update the pcm offset. */ 528 /* update the pcm offset. */
529 if(granulepos!=-1 && !op.e_o_s){ 529 if(granulepos!=-1 && !op.e_o_s){
530 int link=(vf->seekable?vf->current_link:0); 530 int link=(vf->seekable?vf->current_link:0);
531 int i,samples; 531 int i,samples;
532 532
533 /* this packet has a pcm_offset on it (the last packet 533 /* this packet has a pcm_offset on it (the last packet
534 completed on a page carries the offset) After processing 534 completed on a page carries the offset) After processing
535 (above), we know the pcm position of the *last* sample 535 (above), we know the pcm position of the *last* sample
536 ready to be returned. Find the offset of the *first* 536 ready to be returned. Find the offset of the *first*
537 537
538 As an aside, this trick is inaccurate if we begin 538 As an aside, this trick is inaccurate if we begin
539 reading anew right at the last page; the end-of-stream 539 reading anew right at the last page; the end-of-stream
540 granulepos declares the last frame in the stream, and the 540 granulepos declares the last frame in the stream, and the
541 last packet of the last page may be a partial frame. 541 last packet of the last page may be a partial frame.
542 So, we need a previous granulepos from an in-sequence page 542 So, we need a previous granulepos from an in-sequence page
543 to have a reference point. Thus the !op.e_o_s clause 543 to have a reference point. Thus the !op.e_o_s clause
544 above */ 544 above */
545 545
546 if(vf->seekable && link>0) 546 if(vf->seekable && link>0)
547 granulepos-=vf->pcmlengths[link*2]; 547 granulepos-=vf->pcmlengths[link*2];
548 if(granulepos<0)granulepos=0; /* actually, this 548 if(granulepos<0)granulepos=0; /* actually, this
549 shouldn't be possible 549 shouldn't be possible
550 here unless the stream 550 here unless the stream
551 is very broken */ 551 is very broken */
552 552
553 samples=vorbis_synthesis_pcmout(&vf->vd,NULL); 553 samples=vorbis_synthesis_pcmout(&vf->vd,NULL);
554 554
555 granulepos-=samples; 555 granulepos-=samples;
556 for(i=0;i<link;i++) 556 for(i=0;i<link;i++)
557 granulepos+=vf->pcmlengths[i*2+1]; 557 granulepos+=vf->pcmlengths[i*2+1];
558 vf->pcm_offset=granulepos; 558 vf->pcm_offset=granulepos;
559 } 559 }
560 ret=1; 560 ret=1;
561 goto cleanup; 561 goto cleanup;
562 } 562 }
563 } 563 }
564 else 564 else
565 break; 565 break;
566 } 566 }
567 } 567 }
568 568
569 if(vf->ready_state>=OPENED){ 569 if(vf->ready_state>=OPENED){
570 int ret; 570 int ret;
571 if(!readp){ 571 if(!readp){
572 ret=0; 572 ret=0;
573 goto cleanup; 573 goto cleanup;
574 } 574 }
575 if((ret=_get_next_page(vf,&og,-1))<0){ 575 if((ret=_get_next_page(vf,&og,-1))<0){
576 ret=OV_EOF; /* eof. leave unitialized */ 576 ret=OV_EOF; /* eof. leave unitialized */
577 goto cleanup; 577 goto cleanup;
578 } 578 }
579 579
580 /* bitrate tracking; add the header's bytes here, the body bytes 580 /* bitrate tracking; add the header's bytes here, the body bytes
581 are done by packet above */ 581 are done by packet above */
582 vf->bittrack+=og.header_len*8; 582 vf->bittrack+=og.header_len*8;
583 583
584 /* has our decoding just traversed a bitstream boundary? */ 584 /* has our decoding just traversed a bitstream boundary? */
585 if(vf->ready_state==INITSET){ 585 if(vf->ready_state==INITSET){
586 if(vf->current_serialno!=ogg_page_serialno(&og)){ 586 if(vf->current_serialno!=ogg_page_serialno(&og)){
587 if(!spanp){ 587 if(!spanp){
588 ret=OV_EOF; 588 ret=OV_EOF;
589 goto cleanup; 589 goto cleanup;
590 } 590 }
591 591
592 _decode_clear(vf); 592 _decode_clear(vf);
593 593
594 if(!vf->seekable){ 594 if(!vf->seekable){
595 vorbis_info_clear(vf->vi); 595 vorbis_info_clear(vf->vi);
596 vorbis_comment_clear(vf->vc); 596 vorbis_comment_clear(vf->vc);
597 } 597 }
598 } 598 }
599 } 599 }
600 } 600 }
601 601
@@ -615,34 +615,34 @@ static int _fetch_and_process_packet(OggVorbis_File *vf,
615 int link; 615 int link;
616 616
617 if(vf->ready_state<STREAMSET){ 617 if(vf->ready_state<STREAMSET){
618 if(vf->seekable){ 618 if(vf->seekable){
619 vf->current_serialno=ogg_page_serialno(&og); 619 vf->current_serialno=ogg_page_serialno(&og);
620 620
621 /* match the serialno to bitstream section. We use this rather than 621 /* match the serialno to bitstream section. We use this rather than
622 offset positions to avoid problems near logical bitstream 622 offset positions to avoid problems near logical bitstream
623 boundaries */ 623 boundaries */
624 for(link=0;link<vf->links;link++) 624 for(link=0;link<vf->links;link++)
625 if(vf->serialnos[link]==vf->current_serialno)break; 625 if(vf->serialnos[link]==vf->current_serialno)break;
626 if(link==vf->links){ 626 if(link==vf->links){
627 ret=OV_EBADLINK; /* sign of a bogus stream. error out, 627 ret=OV_EBADLINK; /* sign of a bogus stream. error out,
628 leave machine uninitialized */ 628 leave machine uninitialized */
629 goto cleanup; 629 goto cleanup;
630 } 630 }
631 631
632 vf->current_link=link; 632 vf->current_link=link;
633 633
634 ogg_stream_reset_serialno(vf->os,vf->current_serialno); 634 ogg_stream_reset_serialno(vf->os,vf->current_serialno);
635 vf->ready_state=STREAMSET; 635 vf->ready_state=STREAMSET;
636 636
637 }else{ 637 }else{
638 /* we're streaming */ 638 /* we're streaming */
639 /* fetch the three header packets, build the info struct */ 639 /* fetch the three header packets, build the info struct */
640 640
641 int ret=_fetch_headers(vf,vf->vi,vf->vc,&vf->current_serialno,&og); 641 int ret=_fetch_headers(vf,vf->vi,vf->vc,&vf->current_serialno,&og);
642 if(ret) goto cleanup; 642 if(ret) goto cleanup;
643 vf->current_link++; 643 vf->current_link++;
644 link=0; 644 link=0;
645 } 645 }
646 } 646 }
647 647
648 _make_decode_ready(vf); 648 _make_decode_ready(vf);
@@ -665,7 +665,7 @@ static int _fseek64_wrap(FILE *f,ogg_int64_t off,int whence){
665#endif 665#endif
666 666
667static int _ov_open1(void *f,OggVorbis_File *vf,char *initial, 667static int _ov_open1(void *f,OggVorbis_File *vf,char *initial,
668 long ibytes, ov_callbacks callbacks){ 668 long ibytes, ov_callbacks callbacks){
669 int offsettest=(f?callbacks.seek_func(f,0,SEEK_CUR):-1); 669 int offsettest=(f?callbacks.seek_func(f,0,SEEK_CUR):-1);
670 int ret; 670 int ret;
671 671
@@ -734,8 +734,8 @@ int ov_clear(OggVorbis_File *vf){
734 if(vf->vi && vf->links){ 734 if(vf->vi && vf->links){
735 int i; 735 int i;
736 for(i=0;i<vf->links;i++){ 736 for(i=0;i<vf->links;i++){
737 vorbis_info_clear(vf->vi+i); 737 vorbis_info_clear(vf->vi+i);
738 vorbis_comment_clear(vf->vc+i); 738 vorbis_comment_clear(vf->vc+i);
739 } 739 }
740 _ogg_free(vf->vi); 740 _ogg_free(vf->vi);
741 _ogg_free(vf->vc); 741 _ogg_free(vf->vc);
@@ -852,16 +852,16 @@ long ov_bitrate(OggVorbis_File *vf,int i){
852 }else{ 852 }else{
853 /* return nominal if set */ 853 /* return nominal if set */
854 if(vf->vi[i].bitrate_nominal>0){ 854 if(vf->vi[i].bitrate_nominal>0){
855 return vf->vi[i].bitrate_nominal; 855 return vf->vi[i].bitrate_nominal;
856 }else{ 856 }else{
857 if(vf->vi[i].bitrate_upper>0){ 857 if(vf->vi[i].bitrate_upper>0){
858 if(vf->vi[i].bitrate_lower>0){ 858 if(vf->vi[i].bitrate_lower>0){
859 return (vf->vi[i].bitrate_upper+vf->vi[i].bitrate_lower)/2; 859 return (vf->vi[i].bitrate_upper+vf->vi[i].bitrate_lower)/2;
860 }else{ 860 }else{
861 return vf->vi[i].bitrate_upper; 861 return vf->vi[i].bitrate_upper;
862 } 862 }
863 } 863 }
864 return(OV_FALSE); 864 return(OV_FALSE);
865 } 865 }
866 } 866 }
867 } 867 }
@@ -895,8 +895,8 @@ long ov_serialnumber(OggVorbis_File *vf,int i){
895 895
896/* returns: total raw (compressed) length of content if i==-1 896/* returns: total raw (compressed) length of content if i==-1
897 raw (compressed) length of that logical bitstream for i==0 to n 897 raw (compressed) length of that logical bitstream for i==0 to n
898 OV_EINVAL if the stream is not seekable (we can't know the length) 898 OV_EINVAL if the stream is not seekable (we can't know the length)
899 or if stream is only partially open 899 or if stream is only partially open
900*/ 900*/
901ogg_int64_t ov_raw_total(OggVorbis_File *vf,int i){ 901ogg_int64_t ov_raw_total(OggVorbis_File *vf,int i){
902 if(vf->ready_state<OPENED)return(OV_EINVAL); 902 if(vf->ready_state<OPENED)return(OV_EINVAL);
@@ -913,9 +913,9 @@ ogg_int64_t ov_raw_total(OggVorbis_File *vf,int i){
913} 913}
914 914
915/* returns: total PCM length (samples) of content if i==-1 PCM length 915/* returns: total PCM length (samples) of content if i==-1 PCM length
916 (samples) of that logical bitstream for i==0 to n 916 (samples) of that logical bitstream for i==0 to n
917 OV_EINVAL if the stream is not seekable (we can't know the 917 OV_EINVAL if the stream is not seekable (we can't know the
918 length) or only partially open 918 length) or only partially open
919*/ 919*/
920ogg_int64_t ov_pcm_total(OggVorbis_File *vf,int i){ 920ogg_int64_t ov_pcm_total(OggVorbis_File *vf,int i){
921 if(vf->ready_state<OPENED)return(OV_EINVAL); 921 if(vf->ready_state<OPENED)return(OV_EINVAL);
@@ -933,8 +933,8 @@ ogg_int64_t ov_pcm_total(OggVorbis_File *vf,int i){
933 933
934/* returns: total milliseconds of content if i==-1 934/* returns: total milliseconds of content if i==-1
935 milliseconds in that logical bitstream for i==0 to n 935 milliseconds in that logical bitstream for i==0 to n
936 OV_EINVAL if the stream is not seekable (we can't know the 936 OV_EINVAL if the stream is not seekable (we can't know the
937 length) or only partially open 937 length) or only partially open
938*/ 938*/
939ogg_int64_t ov_time_total(OggVorbis_File *vf,int i){ 939ogg_int64_t ov_time_total(OggVorbis_File *vf,int i){
940 if(vf->ready_state<OPENED)return(OV_EINVAL); 940 if(vf->ready_state<OPENED)return(OV_EINVAL);
@@ -974,7 +974,7 @@ int ov_raw_seek(OggVorbis_File *vf,ogg_int64_t pos){
974 boundary */ 974 boundary */
975 vf->pcm_offset=-1; 975 vf->pcm_offset=-1;
976 ogg_stream_reset_serialno(vf->os, 976 ogg_stream_reset_serialno(vf->os,
977 vf->current_serialno); /* must set serialno */ 977 vf->current_serialno); /* must set serialno */
978 vorbis_synthesis_restart(&vf->vd); 978 vorbis_synthesis_restart(&vf->vd);
979 979
980 _seek_helper(vf,pos); 980 _seek_helper(vf,pos);
@@ -1003,83 +1003,83 @@ int ov_raw_seek(OggVorbis_File *vf,ogg_int64_t pos){
1003 work_os=ogg_stream_create(vf->current_serialno); /* get the memory ready */ 1003 work_os=ogg_stream_create(vf->current_serialno); /* get the memory ready */
1004 while(1){ 1004 while(1){
1005 if(vf->ready_state>=STREAMSET){ 1005 if(vf->ready_state>=STREAMSET){
1006 /* snarf/scan a packet if we can */ 1006 /* snarf/scan a packet if we can */
1007 int result=ogg_stream_packetout(work_os,&op); 1007 int result=ogg_stream_packetout(work_os,&op);
1008 1008
1009 if(result>0){ 1009 if(result>0){
1010 1010
1011 if(vf->vi[vf->current_link].codec_setup){ 1011 if(vf->vi[vf->current_link].codec_setup){
1012 thisblock=vorbis_packet_blocksize(vf->vi+vf->current_link,&op); 1012 thisblock=vorbis_packet_blocksize(vf->vi+vf->current_link,&op);
1013 if(thisblock<0){ 1013 if(thisblock<0){
1014 ogg_stream_packetout(vf->os,NULL); 1014 ogg_stream_packetout(vf->os,NULL);
1015 thisblock=0; 1015 thisblock=0;
1016 }else{ 1016 }else{
1017 1017
1018 if(eosflag) 1018 if(eosflag)
1019 ogg_stream_packetout(vf->os,NULL); 1019 ogg_stream_packetout(vf->os,NULL);
1020 else 1020 else
1021 if(lastblock)accblock+=(lastblock+thisblock)>>2; 1021 if(lastblock)accblock+=(lastblock+thisblock)>>2;
1022 } 1022 }
1023 1023
1024 if(op.granulepos!=-1){ 1024 if(op.granulepos!=-1){
1025 int i,link=vf->current_link; 1025 int i,link=vf->current_link;
1026 ogg_int64_t granulepos=op.granulepos-vf->pcmlengths[link*2]; 1026 ogg_int64_t granulepos=op.granulepos-vf->pcmlengths[link*2];
1027 if(granulepos<0)granulepos=0; 1027 if(granulepos<0)granulepos=0;
1028 1028
1029 for(i=0;i<link;i++) 1029 for(i=0;i<link;i++)
1030 granulepos+=vf->pcmlengths[i*2+1]; 1030 granulepos+=vf->pcmlengths[i*2+1];
1031 vf->pcm_offset=granulepos-accblock; 1031 vf->pcm_offset=granulepos-accblock;
1032 break; 1032 break;
1033 } 1033 }
1034 lastblock=thisblock; 1034 lastblock=thisblock;
1035 continue; 1035 continue;
1036 }else 1036 }else
1037 ogg_stream_packetout(vf->os,NULL); 1037 ogg_stream_packetout(vf->os,NULL);
1038 } 1038 }
1039 } 1039 }
1040 1040
1041 if(!lastblock){ 1041 if(!lastblock){
1042 if(_get_next_page(vf,&og,-1)<0){ 1042 if(_get_next_page(vf,&og,-1)<0){
1043 vf->pcm_offset=ov_pcm_total(vf,-1); 1043 vf->pcm_offset=ov_pcm_total(vf,-1);
1044 break; 1044 break;
1045 } 1045 }
1046 }else{ 1046 }else{
1047 /* huh? Bogus stream with packets but no granulepos */ 1047 /* huh? Bogus stream with packets but no granulepos */
1048 vf->pcm_offset=-1; 1048 vf->pcm_offset=-1;
1049 break; 1049 break;
1050 } 1050 }
1051 1051
1052 /* has our decoding just traversed a bitstream boundary? */ 1052 /* has our decoding just traversed a bitstream boundary? */
1053 if(vf->ready_state>=STREAMSET) 1053 if(vf->ready_state>=STREAMSET)
1054 if(vf->current_serialno!=ogg_page_serialno(&og)){ 1054 if(vf->current_serialno!=ogg_page_serialno(&og)){
1055 _decode_clear(vf); /* clear out stream state */ 1055 _decode_clear(vf); /* clear out stream state */
1056 ogg_stream_destroy(work_os); 1056 ogg_stream_destroy(work_os);
1057 } 1057 }
1058 1058
1059 if(vf->ready_state<STREAMSET){ 1059 if(vf->ready_state<STREAMSET){
1060 int link; 1060 int link;
1061 1061
1062 vf->current_serialno=ogg_page_serialno(&og); 1062 vf->current_serialno=ogg_page_serialno(&og);
1063 for(link=0;link<vf->links;link++) 1063 for(link=0;link<vf->links;link++)
1064 if(vf->serialnos[link]==vf->current_serialno)break; 1064 if(vf->serialnos[link]==vf->current_serialno)break;
1065 if(link==vf->links) 1065 if(link==vf->links)
1066 goto seek_error; /* sign of a bogus stream. error out, 1066 goto seek_error; /* sign of a bogus stream. error out,
1067 leave machine uninitialized */ 1067 leave machine uninitialized */
1068 1068
1069 vf->current_link=link; 1069 vf->current_link=link;
1070 1070
1071 ogg_stream_reset_serialno(vf->os,vf->current_serialno); 1071 ogg_stream_reset_serialno(vf->os,vf->current_serialno);
1072 ogg_stream_reset_serialno(work_os,vf->current_serialno); 1072 ogg_stream_reset_serialno(work_os,vf->current_serialno);
1073 vf->ready_state=STREAMSET; 1073 vf->ready_state=STREAMSET;
1074 1074
1075 } 1075 }
1076 1076
1077 { 1077 {
1078 ogg_page dup; 1078 ogg_page dup;
1079 ogg_page_dup(&dup,&og); 1079 ogg_page_dup(&dup,&og);
1080 eosflag=ogg_page_eos(&og); 1080 eosflag=ogg_page_eos(&og);
1081 ogg_stream_pagein(vf->os,&og); 1081 ogg_stream_pagein(vf->os,&og);
1082 ogg_stream_pagein(work_os,&dup); 1082 ogg_stream_pagein(work_os,&dup);
1083 } 1083 }
1084 } 1084 }
1085 } 1085 }
@@ -1144,56 +1144,56 @@ int ov_pcm_seek_page(OggVorbis_File *vf,ogg_int64_t pos){
1144 ogg_int64_t bisect; 1144 ogg_int64_t bisect;
1145 1145
1146 if(end-begin<CHUNKSIZE){ 1146 if(end-begin<CHUNKSIZE){
1147 bisect=begin; 1147 bisect=begin;
1148 }else{ 1148 }else{
1149 /* take a (pretty decent) guess. */ 1149 /* take a (pretty decent) guess. */
1150 bisect=begin + 1150 bisect=begin +
1151 (target-begintime)*(end-begin)/(endtime-begintime) - CHUNKSIZE; 1151 (target-begintime)*(end-begin)/(endtime-begintime) - CHUNKSIZE;
1152 if(bisect<=begin) 1152 if(bisect<=begin)
1153 bisect=begin+1; 1153 bisect=begin+1;
1154 } 1154 }
1155 1155
1156 _seek_helper(vf,bisect); 1156 _seek_helper(vf,bisect);
1157 1157
1158 while(begin<end){ 1158 while(begin<end){
1159 result=_get_next_page(vf,&og,end-vf->offset); 1159 result=_get_next_page(vf,&og,end-vf->offset);
1160 if(result==OV_EREAD) goto seek_error; 1160 if(result==OV_EREAD) goto seek_error;
1161 if(result<0){ 1161 if(result<0){
1162 if(bisect<=begin+1) 1162 if(bisect<=begin+1)
1163 end=begin; /* found it */ 1163 end=begin; /* found it */
1164 else{ 1164 else{
1165 if(bisect==0) goto seek_error; 1165 if(bisect==0) goto seek_error;
1166 bisect-=CHUNKSIZE; 1166 bisect-=CHUNKSIZE;
1167 if(bisect<=begin)bisect=begin+1; 1167 if(bisect<=begin)bisect=begin+1;
1168 _seek_helper(vf,bisect); 1168 _seek_helper(vf,bisect);
1169 } 1169 }
1170 }else{ 1170 }else{
1171 ogg_int64_t granulepos=ogg_page_granulepos(&og); 1171 ogg_int64_t granulepos=ogg_page_granulepos(&og);
1172 if(granulepos==-1)continue; 1172 if(granulepos==-1)continue;
1173 if(granulepos<target){ 1173 if(granulepos<target){
1174 best=result; /* raw offset of packet with granulepos */ 1174 best=result; /* raw offset of packet with granulepos */
1175 begin=vf->offset; /* raw offset of next page */ 1175 begin=vf->offset; /* raw offset of next page */
1176 begintime=granulepos; 1176 begintime=granulepos;
1177 1177
1178 if(target-begintime>44100)break; 1178 if(target-begintime>44100)break;
1179 bisect=begin; /* *not* begin + 1 */ 1179 bisect=begin; /* *not* begin + 1 */
1180 }else{ 1180 }else{
1181 if(bisect<=begin+1) 1181 if(bisect<=begin+1)
1182 end=begin; /* found it */ 1182 end=begin; /* found it */
1183 else{ 1183 else{
1184 if(end==vf->offset){ /* we're pretty close - we'd be stuck in */ 1184 if(end==vf->offset){ /* we're pretty close - we'd be stuck in */
1185 end=result; 1185 end=result;
1186 bisect-=CHUNKSIZE; /* an endless loop otherwise. */ 1186 bisect-=CHUNKSIZE; /* an endless loop otherwise. */
1187 if(bisect<=begin)bisect=begin+1; 1187 if(bisect<=begin)bisect=begin+1;
1188 _seek_helper(vf,bisect); 1188 _seek_helper(vf,bisect);
1189 }else{ 1189 }else{
1190 end=result; 1190 end=result;
1191 endtime=granulepos; 1191 endtime=granulepos;
1192 break; 1192 break;
1193 } 1193 }
1194 } 1194 }
1195 } 1195 }
1196 } 1196 }
1197 } 1197 }
1198 } 1198 }
1199 1199
@@ -1206,20 +1206,20 @@ int ov_pcm_seek_page(OggVorbis_File *vf,ogg_int64_t pos){
1206 vf->pcm_offset=-1; 1206 vf->pcm_offset=-1;
1207 1207
1208 if(_get_next_page(vf,&og,-1)<0){ 1208 if(_get_next_page(vf,&og,-1)<0){
1209 ogg_page_release(&og); 1209 ogg_page_release(&og);
1210 return(OV_EOF); /* shouldn't happen */ 1210 return(OV_EOF); /* shouldn't happen */
1211 } 1211 }
1212 1212
1213 if(link!=vf->current_link){ 1213 if(link!=vf->current_link){
1214 /* Different link; dump entire decode machine */ 1214 /* Different link; dump entire decode machine */
1215 _decode_clear(vf); 1215 _decode_clear(vf);
1216 1216
1217 vf->current_link=link; 1217 vf->current_link=link;
1218 vf->current_serialno=ogg_page_serialno(&og); 1218 vf->current_serialno=ogg_page_serialno(&og);
1219 vf->ready_state=STREAMSET; 1219 vf->ready_state=STREAMSET;
1220 1220
1221 }else{ 1221 }else{
1222 vorbis_synthesis_restart(&vf->vd); 1222 vorbis_synthesis_restart(&vf->vd);
1223 } 1223 }
1224 1224
1225 ogg_stream_reset_serialno(vf->os,vf->current_serialno); 1225 ogg_stream_reset_serialno(vf->os,vf->current_serialno);
@@ -1227,36 +1227,36 @@ int ov_pcm_seek_page(OggVorbis_File *vf,ogg_int64_t pos){
1227 1227
1228 /* pull out all but last packet; the one with granulepos */ 1228 /* pull out all but last packet; the one with granulepos */
1229 while(1){ 1229 while(1){
1230 result=ogg_stream_packetpeek(vf->os,&op); 1230 result=ogg_stream_packetpeek(vf->os,&op);
1231 if(result==0){ 1231 if(result==0){
1232 /* !!! the packet finishing this page originated on a 1232 /* !!! the packet finishing this page originated on a
1233 preceeding page. Keep fetching previous pages until we 1233 preceeding page. Keep fetching previous pages until we
1234 get one with a granulepos or without the 'continued' flag 1234 get one with a granulepos or without the 'continued' flag
1235 set. Then just use raw_seek for simplicity. */ 1235 set. Then just use raw_seek for simplicity. */
1236 1236
1237 _seek_helper(vf,best); 1237 _seek_helper(vf,best);
1238 1238
1239 while(1){ 1239 while(1){
1240 result=_get_prev_page(vf,&og); 1240 result=_get_prev_page(vf,&og);
1241 if(result<0) goto seek_error; 1241 if(result<0) goto seek_error;
1242 if(ogg_page_granulepos(&og)>-1 || 1242 if(ogg_page_granulepos(&og)>-1 ||
1243 !ogg_page_continued(&og)){ 1243 !ogg_page_continued(&og)){
1244 return ov_raw_seek(vf,result); 1244 return ov_raw_seek(vf,result);
1245 } 1245 }
1246 vf->offset=result; 1246 vf->offset=result;
1247 } 1247 }
1248 } 1248 }
1249 if(result<0){ 1249 if(result<0){
1250 result = OV_EBADPACKET; 1250 result = OV_EBADPACKET;
1251 goto seek_error; 1251 goto seek_error;
1252 } 1252 }
1253 if(op.granulepos!=-1){ 1253 if(op.granulepos!=-1){
1254 vf->pcm_offset=op.granulepos-vf->pcmlengths[vf->current_link*2]; 1254 vf->pcm_offset=op.granulepos-vf->pcmlengths[vf->current_link*2];
1255 if(vf->pcm_offset<0)vf->pcm_offset=0; 1255 if(vf->pcm_offset<0)vf->pcm_offset=0;
1256 vf->pcm_offset+=total; 1256 vf->pcm_offset+=total;
1257 break; 1257 break;
1258 }else 1258 }else
1259 result=ogg_stream_packetout(vf->os,NULL); 1259 result=ogg_stream_packetout(vf->os,NULL);
1260 } 1260 }
1261 } 1261 }
1262 } 1262 }
@@ -1304,33 +1304,33 @@ int ov_pcm_seek(OggVorbis_File *vf,ogg_int64_t pos){
1304 if(ret>0){ 1304 if(ret>0){
1305 thisblock=vorbis_packet_blocksize(vf->vi+vf->current_link,&op); 1305 thisblock=vorbis_packet_blocksize(vf->vi+vf->current_link,&op);
1306 if(thisblock<0){ 1306 if(thisblock<0){
1307 ogg_stream_packetout(vf->os,NULL); 1307 ogg_stream_packetout(vf->os,NULL);
1308 continue; /* non audio packet */ 1308 continue; /* non audio packet */
1309 } 1309 }
1310 if(lastblock)vf->pcm_offset+=(lastblock+thisblock)>>2; 1310 if(lastblock)vf->pcm_offset+=(lastblock+thisblock)>>2;
1311 1311
1312 if(vf->pcm_offset+((thisblock+ 1312 if(vf->pcm_offset+((thisblock+
1313 vorbis_info_blocksize(vf->vi,1))>>2)>=pos)break; 1313 vorbis_info_blocksize(vf->vi,1))>>2)>=pos)break;
1314 1314
1315 /* remove the packet from packet queue and track its granulepos */ 1315 /* remove the packet from packet queue and track its granulepos */
1316 ogg_stream_packetout(vf->os,NULL); 1316 ogg_stream_packetout(vf->os,NULL);
1317 vorbis_synthesis(&vf->vb,&op,0); /* set up a vb with 1317 vorbis_synthesis(&vf->vb,&op,0); /* set up a vb with
1318 only tracking, no 1318 only tracking, no
1319 pcm_decode */ 1319 pcm_decode */
1320 vorbis_synthesis_blockin(&vf->vd,&vf->vb); 1320 vorbis_synthesis_blockin(&vf->vd,&vf->vb);
1321 1321
1322 /* end of logical stream case is hard, especially with exact 1322 /* end of logical stream case is hard, especially with exact
1323 length positioning. */ 1323 length positioning. */
1324 1324
1325 if(op.granulepos>-1){ 1325 if(op.granulepos>-1){
1326 int i; 1326 int i;
1327 /* always believe the stream markers */ 1327 /* always believe the stream markers */
1328 vf->pcm_offset=op.granulepos-vf->pcmlengths[vf->current_link*2]; 1328 vf->pcm_offset=op.granulepos-vf->pcmlengths[vf->current_link*2];
1329 if(vf->pcm_offset<0)vf->pcm_offset=0; 1329 if(vf->pcm_offset<0)vf->pcm_offset=0;
1330 for(i=0;i<vf->current_link;i++) 1330 for(i=0;i<vf->current_link;i++)
1331 vf->pcm_offset+=vf->pcmlengths[i*2+1]; 1331 vf->pcm_offset+=vf->pcmlengths[i*2+1];
1332 } 1332 }
1333 1333
1334 lastblock=thisblock; 1334 lastblock=thisblock;
1335 1335
1336 }else{ 1336 }else{
@@ -1341,22 +1341,22 @@ int ov_pcm_seek(OggVorbis_File *vf,ogg_int64_t pos){
1341 if(vf->current_serialno!=ogg_page_serialno(&og))_decode_clear(vf); 1341 if(vf->current_serialno!=ogg_page_serialno(&og))_decode_clear(vf);
1342 1342
1343 if(vf->ready_state<STREAMSET){ 1343 if(vf->ready_state<STREAMSET){
1344 int link; 1344 int link;
1345 1345
1346 vf->current_serialno=ogg_page_serialno(&og); 1346 vf->current_serialno=ogg_page_serialno(&og);
1347 for(link=0;link<vf->links;link++) 1347 for(link=0;link<vf->links;link++)
1348 if(vf->serialnos[link]==vf->current_serialno)break; 1348 if(vf->serialnos[link]==vf->current_serialno)break;
1349 if(link==vf->links){ 1349 if(link==vf->links){
1350 ogg_page_release(&og); 1350 ogg_page_release(&og);
1351 ogg_packet_release(&op); 1351 ogg_packet_release(&op);
1352 return(OV_EBADLINK); 1352 return(OV_EBADLINK);
1353 } 1353 }
1354 vf->current_link=link; 1354 vf->current_link=link;
1355 1355
1356 ogg_stream_reset_serialno(vf->os,vf->current_serialno); 1356 ogg_stream_reset_serialno(vf->os,vf->current_serialno);
1357 vf->ready_state=STREAMSET; 1357 vf->ready_state=STREAMSET;
1358 _make_decode_ready(vf); 1358 _make_decode_ready(vf);
1359 lastblock=0; 1359 lastblock=0;
1360 } 1360 }
1361 1361
1362 ogg_stream_pagein(vf->os,&og); 1362 ogg_stream_pagein(vf->os,&og);
@@ -1377,7 +1377,7 @@ int ov_pcm_seek(OggVorbis_File *vf,ogg_int64_t pos){
1377 1377
1378 if(samples<target) 1378 if(samples<target)
1379 if(_fetch_and_process_packet(vf,1,1)<=0) 1379 if(_fetch_and_process_packet(vf,1,1)<=0)
1380 vf->pcm_offset=ov_pcm_total(vf,-1); /* eof */ 1380 vf->pcm_offset=ov_pcm_total(vf,-1); /* eof */
1381 } 1381 }
1382 1382
1383 ogg_page_release(&og); 1383 ogg_page_release(&og);
@@ -1486,14 +1486,14 @@ vorbis_info *ov_info(OggVorbis_File *vf,int link){
1486 if(vf->seekable){ 1486 if(vf->seekable){
1487 if(link<0) 1487 if(link<0)
1488 if(vf->ready_state>=STREAMSET) 1488 if(vf->ready_state>=STREAMSET)
1489 return vf->vi+vf->current_link; 1489 return vf->vi+vf->current_link;
1490 else 1490 else
1491 return vf->vi; 1491 return vf->vi;
1492 else 1492 else
1493 if(link>=vf->links) 1493 if(link>=vf->links)
1494 return NULL; 1494 return NULL;
1495 else 1495 else
1496 return vf->vi+link; 1496 return vf->vi+link;
1497 }else{ 1497 }else{
1498 return vf->vi; 1498 return vf->vi;
1499 } 1499 }
@@ -1504,14 +1504,14 @@ vorbis_comment *ov_comment(OggVorbis_File *vf,int link){
1504 if(vf->seekable){ 1504 if(vf->seekable){
1505 if(link<0) 1505 if(link<0)
1506 if(vf->ready_state>=STREAMSET) 1506 if(vf->ready_state>=STREAMSET)
1507 return vf->vc+vf->current_link; 1507 return vf->vc+vf->current_link;
1508 else 1508 else
1509 return vf->vc; 1509 return vf->vc;
1510 else 1510 else
1511 if(link>=vf->links) 1511 if(link>=vf->links)
1512 return NULL; 1512 return NULL;
1513 else 1513 else
1514 return vf->vc+link; 1514 return vf->vc+link;
1515 }else{ 1515 }else{
1516 return vf->vc; 1516 return vf->vc;
1517 } 1517 }
@@ -1533,16 +1533,16 @@ vorbis_comment *ov_comment(OggVorbis_File *vf,int link){
1533 functions above are aware of this dichotomy). 1533 functions above are aware of this dichotomy).
1534 1534
1535 input values: buffer) a buffer to hold packed PCM data for return 1535 input values: buffer) a buffer to hold packed PCM data for return
1536 length) the byte length requested to be placed into buffer 1536 length) the byte length requested to be placed into buffer
1537 1537
1538 return values: <0) error/hole in data (OV_HOLE), partial open (OV_EINVAL) 1538 return values: <0) error/hole in data (OV_HOLE), partial open (OV_EINVAL)
1539 0) EOF 1539 0) EOF
1540 n) number of bytes of PCM actually returned. The 1540 n) number of bytes of PCM actually returned. The
1541 below works on a packet-by-packet basis, so the 1541 below works on a packet-by-packet basis, so the
1542 return length is not related to the 'length' passed 1542 return length is not related to the 'length' passed
1543 in, just guaranteed to fit. 1543 in, just guaranteed to fit.
1544 1544
1545 *section) set to the logical bitstream number */ 1545 *section) set to the logical bitstream number */
1546 1546
1547long ov_read(OggVorbis_File *vf,char *buffer,int bytes_req,int *bitstream){ 1547long ov_read(OggVorbis_File *vf,char *buffer,int bytes_req,int *bitstream){
1548 int i,j; 1548 int i,j;
@@ -1562,9 +1562,9 @@ long ov_read(OggVorbis_File *vf,char *buffer,int bytes_req,int *bitstream){
1562 { 1562 {
1563 int ret=_fetch_and_process_packet(vf,1,1); 1563 int ret=_fetch_and_process_packet(vf,1,1);
1564 if(ret==OV_EOF) 1564 if(ret==OV_EOF)
1565 return(0); 1565 return(0);
1566 if(ret<=0) 1566 if(ret<=0)
1567 return(ret); 1567 return(ret);
1568 } 1568 }
1569 1569
1570 } 1570 }
diff --git a/apps/codecs/Tremor/window.c b/apps/codecs/Tremor/window.c
index b447ce5ad9..c20aecd289 100644
--- a/apps/codecs/Tremor/window.c
+++ b/apps/codecs/Tremor/window.c
@@ -54,8 +54,8 @@ const void *_vorbis_window(int type, int left){
54} 54}
55 55
56void _vorbis_apply_window(ogg_int32_t *d,const void *window_p[2], 56void _vorbis_apply_window(ogg_int32_t *d,const void *window_p[2],
57 long *blocksizes, 57 long *blocksizes,
58 int lW,int W,int nW){ 58 int lW,int W,int nW){
59 LOOKUP_T *window[2]={window_p[0],window_p[1]}; 59 LOOKUP_T *window[2]={window_p[0],window_p[1]};
60 long n=blocksizes[W]; 60 long n=blocksizes[W];
61 long ln=blocksizes[lW]; 61 long ln=blocksizes[lW];
@@ -68,7 +68,7 @@ void _vorbis_apply_window(ogg_int32_t *d,const void *window_p[2],
68 long rightend=rightbegin+rn/2; 68 long rightend=rightbegin+rn/2;
69 69
70#if CONFIG_CPU == MCF5249 70#if CONFIG_CPU == MCF5249
71 mcf5249_init_mac(); /* shouldn't be needed, but just in case */ 71 /* mcf5249_init_mac(); */ /* shouldn't be needed, but just in case */
72 mcf5249_vect_zero(&d[0], leftbegin); 72 mcf5249_vect_zero(&d[0], leftbegin);
73 mcf5249_vect_mult_fw(&d[leftbegin], &window[lW][0], leftend-leftbegin); 73 mcf5249_vect_mult_fw(&d[leftbegin], &window[lW][0], leftend-leftbegin);
74 mcf5249_vect_mult_bw(&d[rightbegin], &window[nW][rn/2-1], rightend-rightbegin); 74 mcf5249_vect_mult_bw(&d[rightbegin], &window[nW][rn/2-1], rightend-rightbegin);
diff --git a/apps/codecs/Tremor/window_lookup.h b/apps/codecs/Tremor/window_lookup.h
index fdc099b741..71a413bcd5 100644
--- a/apps/codecs/Tremor/window_lookup.h
+++ b/apps/codecs/Tremor/window_lookup.h
@@ -18,8 +18,10 @@
18 18
19#include "os_types.h" 19#include "os_types.h"
20 20
21/* keep small window tables in fast IRAM */ 21/* Oggenc 1.1 seems to use exclusively windows sizes 256, 2048
22static LOOKUP_T vwin64[32] IDATA_ATTR = { 22 keep the most common sizes in fast IRAM;
23 because we have the available space also 128, 512 */
24static LOOKUP_T vwin64[32] = {
23 X(0x001f0003), X(0x01168c98), X(0x030333c8), X(0x05dfe3a4), 25 X(0x001f0003), X(0x01168c98), X(0x030333c8), X(0x05dfe3a4),
24 X(0x09a49562), X(0x0e45df18), X(0x13b47ef2), X(0x19dcf676), 26 X(0x09a49562), X(0x0e45df18), X(0x13b47ef2), X(0x19dcf676),
25 X(0x20a74d83), X(0x27f7137c), X(0x2fabb05a), X(0x37a1105a), 27 X(0x20a74d83), X(0x27f7137c), X(0x2fabb05a), X(0x37a1105a),
@@ -151,7 +153,7 @@ static LOOKUP_T vwin512[256] IDATA_ATTR = {
151 X(0x7ffffdcd), X(0x7fffff6d), X(0x7fffffed), X(0x7fffffff), 153 X(0x7ffffdcd), X(0x7fffff6d), X(0x7fffffed), X(0x7fffffff),
152}; 154};
153 155
154static LOOKUP_T vwin1024[512] IDATA_ATTR = { 156static LOOKUP_T vwin1024[512] = {
155 X(0x00001f02), X(0x0001170e), X(0x00030724), X(0x0005ef40), 157 X(0x00001f02), X(0x0001170e), X(0x00030724), X(0x0005ef40),
156 X(0x0009cf59), X(0x000ea767), X(0x0014775e), X(0x001b3f2e), 158 X(0x0009cf59), X(0x000ea767), X(0x0014775e), X(0x001b3f2e),
157 X(0x0022fec8), X(0x002bb618), X(0x00356508), X(0x00400b81), 159 X(0x0022fec8), X(0x002bb618), X(0x00356508), X(0x00400b81),
@@ -541,8 +543,6 @@ static LOOKUP_T vwin2048[1024] IDATA_ATTR = {
541 X(0x7ffffffe), X(0x7fffffff), X(0x7fffffff), X(0x7fffffff), 543 X(0x7ffffffe), X(0x7fffffff), X(0x7fffffff), X(0x7fffffff),
542}; 544};
543 545
544/* The remaining large window sizes are used only for very low
545 quality Vorbis files so we don't bother to put them in IRAM */
546static LOOKUP_T vwin4096[2048] = { 546static LOOKUP_T vwin4096[2048] = {
547 X(0x000001f0), X(0x00001171), X(0x00003072), X(0x00005ef5), 547 X(0x000001f0), X(0x00001171), X(0x00003072), X(0x00005ef5),
548 X(0x00009cf8), X(0x0000ea7c), X(0x00014780), X(0x0001b405), 548 X(0x00009cf8), X(0x0000ea7c), X(0x00014780), X(0x0001b405),