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 @@ #ifndef _V_WIDE_MATH #define _V_WIDE_MATH -//#define MB() asm volatile ("" : : : "memory") #define MB() static inline void mcf5249_init_mac(void) { int r; - asm volatile ("move.l #0x20, %%macsr;" // frac, truncate, no saturation - "movclr.l %%acc0, %[r];" // clear accumulators - "move.l %%acc0, %%acc1;" - "move.l %%acc0, %%acc2;" - "move.l %%acc0, %%acc3;" - : [r] "=r" (r)); + asm volatile ("move.l #0x20, %%macsr;" /* frac, truncate, no saturation */ + "movclr.l %%acc0, %[r];" /* clear accumulators */ + "move.l %%acc0, %%acc1;" + "move.l %%acc0, %%acc2;" + "move.l %%acc0, %%acc3;" + : [r] "=r" (r)); } static inline ogg_int32_t MULT32(ogg_int32_t x, ogg_int32_t y) { - ogg_int32_t r; - asm volatile ("mac.l %[x], %[y], %%acc0;" // multiply into acc - "movclr.l %%acc0, %[r];" // move & clear acc - "asr.l #1, %[r];" // no overflow test - : [r] "=d" (r) - : [x] "r" (x), [y] "r" (y) - : "cc"); - return r; + asm volatile ("mac.l %[x], %[y], %%acc0;" /* multiply & shift */ + "movclr.l %%acc0, %[x];" /* move & clear acc */ + "asr.l #1, %[x];" /* no overflow test */ + : [x] "+&d" (x) + : [y] "r" (y) + : "cc"); + return x; } static inline ogg_int32_t MULT31(ogg_int32_t x, ogg_int32_t y) { - asm volatile ("mac.l %[x], %[y], %%acc0;" // multiply - "movclr.l %%acc0, %[x];" // move and clear - : [x] "+&r" (x) - : [y] "r" (y) - : "cc"); + asm volatile ("mac.l %[x], %[y], %%acc0;" /* multiply */ + "movclr.l %%acc0, %[x];" /* move and clear */ + : [x] "+&r" (x) + : [y] "r" (y) + : "cc"); return x; } static inline ogg_int32_t MULT31_SHIFT15(ogg_int32_t x, ogg_int32_t y) { ogg_int32_t r; - asm volatile ("mac.l %[x], %[y], %%acc0;" // multiply - "movclr.l %%acc0, %[r];" // get higher half - "mulu.l %[y], %[x];" // get lower half - "asl.l #8, %[r];" // hi << 17 - "asl.l #8, %[r];" - "lsr.l #8, %[x];" // (unsigned)lo >> 15 - "lsr.l #7, %[x];" - "or.l %[x], %[r];" // or - : [r] "=&d" (r), [x] "+d" (x) - : [y] "d" (y) - : "cc"); + asm volatile ("mac.l %[x], %[y], %%acc0;" /* multiply */ + "movclr.l %%acc0, %[r];" /* get higher half */ + "mulu.l %[y], %[x];" /* get lower half */ + "asl.l #8, %[r];" /* hi<<16, plus one free */ + "asl.l #8, %[r];" + "lsr.l #8, %[x];" /* (unsigned)lo >> 15 */ + "lsr.l #7, %[x];" + "or.l %[x], %[r];" /* logical-or results */ + : [r] "=&d" (r), [x] "+d" (x) + : [y] "d" (y) + : "cc"); return r; } static inline void XPROD31(ogg_int32_t a, ogg_int32_t b, - ogg_int32_t t, ogg_int32_t v, - ogg_int32_t *x, ogg_int32_t *y) + ogg_int32_t t, ogg_int32_t v, + ogg_int32_t *x, ogg_int32_t *y) { asm volatile ("mac.l %[a], %[t], %%acc0;" - "mac.l %[b], %[v], %%acc0;" - "mac.l %[b], %[t], %%acc1;" - "msac.l %[a], %[v], %%acc1;" - "movclr.l %%acc0, %[a];" - "move.l %[a], (%[x]);" - "movclr.l %%acc1, %[a];" - "move.l %[a], (%[y]);" - : [a] "+&r" (a) - : [x] "a" (x), [y] "a" (y), - [b] "r" (b), [t] "r" (t), [v] "r" (v) - : "cc", "memory"); + "mac.l %[b], %[v], %%acc0;" + "mac.l %[b], %[t], %%acc1;" + "msac.l %[a], %[v], %%acc1;" + "movclr.l %%acc0, %[a];" + "move.l %[a], (%[x]);" + "movclr.l %%acc1, %[a];" + "move.l %[a], (%[y]);" + : [a] "+&r" (a) + : [x] "a" (x), [y] "a" (y), + [b] "r" (b), [t] "r" (t), [v] "r" (v) + : "cc", "memory"); } static inline void XNPROD31(ogg_int32_t a, ogg_int32_t b, - ogg_int32_t t, ogg_int32_t v, - ogg_int32_t *x, ogg_int32_t *y) + ogg_int32_t t, ogg_int32_t v, + ogg_int32_t *x, ogg_int32_t *y) { asm volatile ("mac.l %[a], %[t], %%acc0;" - "msac.l %[b], %[v], %%acc0;" - "mac.l %[b], %[t], %%acc1;" - "mac.l %[a], %[v], %%acc1;" - "movclr.l %%acc0, %[a];" - "move.l %[a], (%[x]);" - "movclr.l %%acc1, %[a];" - "move.l %[a], (%[y]);" - : [a] "+&r" (a) - : [x] "a" (x), [y] "a" (y), - [b] "r" (b), [t] "r" (t), [v] "r" (v) - : "cc", "memory"); + "msac.l %[b], %[v], %%acc0;" + "mac.l %[b], %[t], %%acc1;" + "mac.l %[a], %[v], %%acc1;" + "movclr.l %%acc0, %[a];" + "move.l %[a], (%[x]);" + "movclr.l %%acc1, %[a];" + "move.l %[a], (%[y]);" + : [a] "+&r" (a) + : [x] "a" (x), [y] "a" (y), + [b] "r" (b), [t] "r" (t), [v] "r" (v) + : "cc", "memory"); } -/* is there no better way of doing this using the MAC? */ -#define XPROD32(_a, _b, _t, _v, _x, _y) \ - { (_x)=MULT32(_a,_t)+MULT32(_b,_v); \ + +#if 1 /* Canonical definition */ +#define XPROD32(_a, _b, _t, _v, _x, _y) \ + { (_x)=MULT32(_a,_t)+MULT32(_b,_v); \ (_y)=MULT32(_b,_t)-MULT32(_a,_v); } +#else +/* Thom Johansen suggestion; this could loose the lsb by overflow + but does it matter in practice? */ +#define XPROD32(_a, _b, _t, _v, _x, _y) \ + asm volatile ("mac.l %[a], %[t], %%acc0;" \ + "mac.l %[b], %[v], %%acc0;" \ + "mac.l %[b], %[t], %%acc1;" \ + "msac.l %[a], %[v], %%acc1;" \ + "movclr.l %%acc0, %[x];" \ + "asr.l #1, %[x];" \ + "movclr.l %%acc1, %[y];" \ + "asr.l #1, %[y];" \ + : [x] "=&d" (_x), [y] "=&d" (_y) \ + : [a] "r" (_a), [b] "r" (_b), \ + [t] "r" (_t), [v] "r" (_v) \ + : "cc"); +#endif /* asm versions of vector multiplication for window.c */ @@ -127,94 +143,94 @@ void XNPROD31(ogg_int32_t a, ogg_int32_t b, static inline void mcf5249_vect_mult_fw(ogg_int32_t *data, LOOKUP_T *window, int n) { - asm volatile ("movem.l (%[d]), %%d0-%%d3;" // loop start - "movem.l (%[w]), %%a0-%%a3;" // pre-fetch registers - "lea.l (4*4, %[w]), %[w];" - "bra 1f;" // jump to loop condition - "0:" // loop body - // multiply and load next window values - "mac.l %%d0, %%a0, (%[w])+, %%a0, %%acc0;" - "mac.l %%d1, %%a1, (%[w])+, %%a1, %%acc1;" - "mac.l %%d2, %%a2, (%[w])+, %%a2, %%acc2;" - "mac.l %%d3, %%a3, (%[w])+, %%a3, %%acc3;" - "movclr.l %%acc0, %%d0;" // get the products - "movclr.l %%acc1, %%d1;" - "movclr.l %%acc2, %%d2;" - "movclr.l %%acc3, %%d3;" - // store and advance - "movem.l %%d0-%%d3, (%[d]);" - "lea.l (4*4, %[d]), %[d];" - "movem.l (%[d]), %%d0-%%d3;" - "subq.l #4, %[n];" // done 4 elements - "1: cmpi.l #4, %[n];" - "bge 0b;" - // multiply final elements - "tst.l %[n];" - "beq 1f;" // n=0 - "mac.l %%d0, %%a0, %%acc0;" - "movclr.l %%acc0, %%d0;" - "move.l %%d0, (%[d])+;" - "subq.l #1, %[n];" - "beq 1f;" // n=1 - "mac.l %%d1, %%a1, %%acc0;" - "movclr.l %%acc0, %%d1;" - "move.l %%d1, (%[d])+;" - "subq.l #1, %[n];" - "beq 1f;" // n=2 - // otherwise n = 3 - "mac.l %%d2, %%a2, %%acc0;" - "movclr.l %%acc0, %%d2;" - "move.l %%d2, (%[d])+;" - "1:" - : [n] "+d" (n), [d] "+a" (data), [w] "+a" (window) - : : "%d0", "%d1", "%d2", "%d3", "%a0", "%a1", "%a2", "%a3", + asm volatile ("movem.l (%[d]), %%d0-%%d3;" /* loop start */ + "movem.l (%[w]), %%a0-%%a3;" /* pre-fetch registers */ + "lea.l (4*4, %[w]), %[w];" + "bra 1f;" /* jump to loop condition */ + "0:" /* loop body */ + /* multiply and load next window values */ + "mac.l %%d0, %%a0, (%[w])+, %%a0, %%acc0;" + "mac.l %%d1, %%a1, (%[w])+, %%a1, %%acc1;" + "mac.l %%d2, %%a2, (%[w])+, %%a2, %%acc2;" + "mac.l %%d3, %%a3, (%[w])+, %%a3, %%acc3;" + "movclr.l %%acc0, %%d0;" /* get the products */ + "movclr.l %%acc1, %%d1;" + "movclr.l %%acc2, %%d2;" + "movclr.l %%acc3, %%d3;" + /* store and advance */ + "movem.l %%d0-%%d3, (%[d]);" + "lea.l (4*4, %[d]), %[d];" + "movem.l (%[d]), %%d0-%%d3;" + "subq.l #4, %[n];" /* done 4 elements */ + "1: cmpi.l #4, %[n];" + "bge 0b;" + /* multiply final elements */ + "tst.l %[n];" + "beq 1f;" /* n=0 */ + "mac.l %%d0, %%a0, %%acc0;" + "movclr.l %%acc0, %%d0;" + "move.l %%d0, (%[d])+;" + "subq.l #1, %[n];" + "beq 1f;" /* n=1 */ + "mac.l %%d1, %%a1, %%acc0;" + "movclr.l %%acc0, %%d1;" + "move.l %%d1, (%[d])+;" + "subq.l #1, %[n];" + "beq 1f;" /* n=2 */ + /* otherwise n = 3 */ + "mac.l %%d2, %%a2, %%acc0;" + "movclr.l %%acc0, %%d2;" + "move.l %%d2, (%[d])+;" + "1:" + : [n] "+d" (n), [d] "+a" (data), [w] "+a" (window) + : : "%d0", "%d1", "%d2", "%d3", "%a0", "%a1", "%a2", "%a3", "cc", "memory"); } static inline void mcf5249_vect_mult_bw(ogg_int32_t *data, LOOKUP_T *window, int n) { - asm volatile ("lea.l (-3*4, %[w]), %[w];" // loop start - "movem.l (%[d]), %%d0-%%d3;" // pre-fetch registers - "movem.l (%[w]), %%a0-%%a3;" - "bra 1f;" // jump to loop condition - "0:" // loop body - // multiply and load next window value - "mac.l %%d0, %%a3, -(%[w]), %%a3, %%acc0;" - "mac.l %%d1, %%a2, -(%[w]), %%a2, %%acc1;" - "mac.l %%d2, %%a1, -(%[w]), %%a1, %%acc2;" - "mac.l %%d3, %%a0, -(%[w]), %%a0, %%acc3;" - "movclr.l %%acc0, %%d0;" // get the products - "movclr.l %%acc1, %%d1;" - "movclr.l %%acc2, %%d2;" - "movclr.l %%acc3, %%d3;" - // store and advance - "movem.l %%d0-%%d3, (%[d]);" - "lea.l (4*4, %[d]), %[d];" - "movem.l (%[d]), %%d0-%%d3;" - "subq.l #4, %[n];" // done 4 elements - "1: cmpi.l #4, %[n];" - "bge 0b;" - // multiply final elements - "tst.l %[n];" - "beq 1f;" // n=0 - "mac.l %%d0, %%a3, %%acc0;" - "movclr.l %%acc0, %%d0;" - "move.l %%d0, (%[d])+;" - "subq.l #1, %[n];" - "beq 1f;" // n=1 - "mac.l %%d1, %%a2, %%acc0;" - "movclr.l %%acc0, %%d1;" - "move.l %%d1, (%[d])+;" - "subq.l #1, %[n];" - "beq 1f;" // n=2 - // otherwise n = 3 - "mac.l %%d2, %%a1, %%acc0;" - "movclr.l %%acc0, %%d2;" - "move.l %%d2, (%[d])+;" - "1:" - : [n] "+d" (n), [d] "+a" (data), [w] "+a" (window) - : : "%d0", "%d1", "%d2", "%d3", "%a0", "%a1", "%a2", "%a3", + asm volatile ("lea.l (-3*4, %[w]), %[w];" /* loop start */ + "movem.l (%[d]), %%d0-%%d3;" /* pre-fetch registers */ + "movem.l (%[w]), %%a0-%%a3;" + "bra 1f;" /* jump to loop condition */ + "0:" /* loop body */ + /* multiply and load next window value */ + "mac.l %%d0, %%a3, -(%[w]), %%a3, %%acc0;" + "mac.l %%d1, %%a2, -(%[w]), %%a2, %%acc1;" + "mac.l %%d2, %%a1, -(%[w]), %%a1, %%acc2;" + "mac.l %%d3, %%a0, -(%[w]), %%a0, %%acc3;" + "movclr.l %%acc0, %%d0;" /* get the products */ + "movclr.l %%acc1, %%d1;" + "movclr.l %%acc2, %%d2;" + "movclr.l %%acc3, %%d3;" + /* store and advance */ + "movem.l %%d0-%%d3, (%[d]);" + "lea.l (4*4, %[d]), %[d];" + "movem.l (%[d]), %%d0-%%d3;" + "subq.l #4, %[n];" /* done 4 elements */ + "1: cmpi.l #4, %[n];" + "bge 0b;" + /* multiply final elements */ + "tst.l %[n];" + "beq 1f;" /* n=0 */ + "mac.l %%d0, %%a3, %%acc0;" + "movclr.l %%acc0, %%d0;" + "move.l %%d0, (%[d])+;" + "subq.l #1, %[n];" + "beq 1f;" /* n=1 */ + "mac.l %%d1, %%a2, %%acc0;" + "movclr.l %%acc0, %%d1;" + "move.l %%d1, (%[d])+;" + "subq.l #1, %[n];" + "beq 1f;" /* n=2 */ + /* otherwise n = 3 */ + "mac.l %%d2, %%a1, %%acc0;" + "movclr.l %%acc0, %%d2;" + "move.l %%d2, (%[d])+;" + "1:" + : [n] "+d" (n), [d] "+a" (data), [w] "+a" (window) + : : "%d0", "%d1", "%d2", "%d3", "%a0", "%a1", "%a2", "%a3", "cc", "memory"); } @@ -223,33 +239,43 @@ static inline void mcf5249_vect_zero(ogg_int32_t *ptr, int n) { asm volatile ("clr.l %%d0;" - "clr.l %%d1;" - "clr.l %%d2;" - "clr.l %%d3;" - // loop start - "tst.l %[n];" - "bra 1f;" - "0: movem.l %%d0-%%d3, (%[ptr]);" - "lea (4*4, %[ptr]), %[ptr];" - "subq.l #4, %[n];" - "1: bgt 0b;" - // remaing elements - "tst.l %[n];" - "beq 1f;" // n=0 - "clr.l (%[ptr])+;" - "subq.l #1, %[n];" - "beq 1f;" // n=1 - "clr.l (%[ptr])+;" - "subq.l #1, %[n];" - "beq 1f;" // n=2 - // otherwise n = 3 - "clr.l (%[ptr])+;" - "1:" - : [n] "+d" (n), [ptr] "+a" (ptr) - : - : "%d0","%d1","%d2","%d3","cc","memory"); + "clr.l %%d1;" + "clr.l %%d2;" + "clr.l %%d3;" + /* loop start */ + "tst.l %[n];" + "bra 1f;" + "0: movem.l %%d0-%%d3, (%[ptr]);" + "lea (4*4, %[ptr]), %[ptr];" + "subq.l #4, %[n];" + "1: bgt 0b;" + /* remaing elements */ + "tst.l %[n];" + "beq 1f;" /* n=0 */ + "clr.l (%[ptr])+;" + "subq.l #1, %[n];" + "beq 1f;" /* n=1 */ + "clr.l (%[ptr])+;" + "subq.l #1, %[n];" + "beq 1f;" /* n=2 */ + /* otherwise n = 3 */ + "clr.l (%[ptr])+;" + "1:" + : [n] "+d" (n), [ptr] "+a" (ptr) + : + : "%d0","%d1","%d2","%d3","cc","memory"); } +#endif + +#ifndef _V_CLIP_MATH +#define _V_CLIP_MATH + +/* this is portable C and simple; why not use this as default? */ +static inline ogg_int32_t CLIP_TO_15(register ogg_int32_t x) { + register ogg_int32_t hi=32767, lo=-32768; + return (x>=hi ? hi : (x<=lo ? lo : x)); +} #endif #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){ for(k=0;k<(1<class_subs[j]);k++){ info->class_subbook[j][k]=oggpack_read(opb,8)-1; if(info->class_subbook[j][k]<-1 || info->class_subbook[j][k]>=ci->books) - goto err_out; + goto err_out; } } @@ -104,7 +104,7 @@ static vorbis_info_floor *floor1_unpack (vorbis_info *vi,oggpack_buffer *opb){ for(;kpostlist[k+2]=oggpack_read(opb,rangebits); if(t<0 || t>=(1<postlist[0]=0; @@ -179,12 +179,12 @@ static vorbis_look_floor *floor1_look(vorbis_dsp_state *vd,vorbis_info_mode *mi, for(j=0;jpostlist[j]; if(x>lx && xcurrentx){ - hi=j; - hx=x; + hi=j; + hx=x; } } look->loneighbor[i]=lo; @@ -216,7 +216,8 @@ static int render_point(int x0,int x1,int y0,int y1,int x){ # define XdB(n) (n) #endif -static ogg_int32_t FLOOR_fromdB_LOOKUP[256] ={ +/* keep the floor lookup table in fast IRAM */ +static ogg_int32_t FLOOR_fromdB_LOOKUP[256] IDATA_ATTR = { XdB(0x000000e5), XdB(0x000000f4), XdB(0x00000103), XdB(0x00000114), XdB(0x00000126), XdB(0x00000139), XdB(0x0000014e), XdB(0x00000163), XdB(0x0000017a), XdB(0x00000193), XdB(0x000001ad), XdB(0x000001c9), @@ -334,20 +335,20 @@ static void *floor1_inverse1(vorbis_block *vb,vorbis_look_floor *in){ /* decode the partition's first stage cascade value */ if(csubbits){ - cval=vorbis_book_decode(books+info->class_book[classv],&vb->opb); + cval=vorbis_book_decode(books+info->class_book[classv],&vb->opb); - if(cval==-1)goto eop; + if(cval==-1)goto eop; } for(k=0;kclass_subbook[classv][cval&(csub-1)]; - cval>>=csubbits; - if(book>=0){ - if((fit_value[j+k]=vorbis_book_decode(books+book,&vb->opb))==-1) - goto eop; - }else{ - fit_value[j+k]=0; - } + int book=info->class_subbook[classv][cval&(csub-1)]; + cval>>=csubbits; + if(book>=0){ + if((fit_value[j+k]=vorbis_book_decode(books+book,&vb->opb))==-1) + goto eop; + }else{ + fit_value[j+k]=0; + } } j+=cdim; } @@ -355,38 +356,38 @@ static void *floor1_inverse1(vorbis_block *vb,vorbis_look_floor *in){ /* unwrap positive values and reconsitute via linear interpolation */ for(i=2;iposts;i++){ int predicted=render_point(info->postlist[look->loneighbor[i-2]], - info->postlist[look->hineighbor[i-2]], - fit_value[look->loneighbor[i-2]], - fit_value[look->hineighbor[i-2]], - info->postlist[i]); + info->postlist[look->hineighbor[i-2]], + fit_value[look->loneighbor[i-2]], + fit_value[look->hineighbor[i-2]], + info->postlist[i]); int hiroom=look->quant_q-predicted; int loroom=predicted; int room=(hiroom=room){ - if(hiroom>loroom){ - val = val-loroom; - }else{ - val = -1-(val-hiroom); - } - }else{ - if(val&1){ - val= -((val+1)>>1); - }else{ - val>>=1; - } - } + if(val>=room){ + if(hiroom>loroom){ + val = val-loroom; + }else{ + val = -1-(val-hiroom); + } + }else{ + if(val&1){ + val= -((val+1)>>1); + }else{ + val>>=1; + } + } - fit_value[i]=val+predicted; - fit_value[look->loneighbor[i-2]]&=0x7fff; - fit_value[look->hineighbor[i-2]]&=0x7fff; + fit_value[i]=val+predicted; + fit_value[look->loneighbor[i-2]]&=0x7fff; + fit_value[look->hineighbor[i-2]]&=0x7fff; }else{ - fit_value[i]=predicted|0x8000; + fit_value[i]=predicted|0x8000; } - + } return(fit_value); @@ -396,7 +397,7 @@ static void *floor1_inverse1(vorbis_block *vb,vorbis_look_floor *in){ } static int floor1_inverse2(vorbis_block *vb,vorbis_look_floor *in,void *memo, - ogg_int32_t *out){ + ogg_int32_t *out){ vorbis_look_floor1 *look=(vorbis_look_floor1 *)in; vorbis_info_floor1 *info=look->vi; @@ -414,14 +415,14 @@ static int floor1_inverse2(vorbis_block *vb,vorbis_look_floor *in,void *memo, int current=look->forward_index[j]; int hy=fit_value[current]&0x7fff; if(hy==fit_value[current]){ - - hy*=info->mult; - hx=info->postlist[current]; - - render_line(lx,hx,ly,hy,out); - - lx=hx; - ly=hy; + + hy*=info->mult; + hx=info->postlist[current]; + + render_line(lx,hx,ly,hy,out); + + lx=hx; + ly=hy; } } for(j=hx;jvi; 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) int testA=info->coupling_ang[i]=oggpack_read(opb,ilog(vi->channels)); if(testM<0 || - testA<0 || - testM==testA || - testM>=vi->channels || - testA>=vi->channels) goto err_out; + testA<0 || + testM==testA || + testM>=vi->channels || + testA>=vi->channels) goto err_out; } } @@ -237,16 +237,16 @@ static int mapping0_inverse(vorbis_block *vb,vorbis_look_mapping *l){ int ch_in_bundle=0; for(j=0;jchannels;j++){ if(info->chmuxlist[j]==i){ - if(nonzero[j]) - zerobundle[ch_in_bundle]=1; - else - zerobundle[ch_in_bundle]=0; - pcmbundle[ch_in_bundle++]=vb->pcm[j]; + if(nonzero[j]) + zerobundle[ch_in_bundle]=1; + else + zerobundle[ch_in_bundle]=0; + pcmbundle[ch_in_bundle++]=vb->pcm[j]; } } look->residue_func[i]->inverse(vb,look->residue_look[i], - pcmbundle,zerobundle,ch_in_bundle); + pcmbundle,zerobundle,ch_in_bundle); } //for(j=0;jchannels;j++) @@ -263,21 +263,21 @@ static int mapping0_inverse(vorbis_block *vb,vorbis_look_mapping *l){ ogg_int32_t ang=pcmA[j]; if(mag>0) - if(ang>0){ - pcmM[j]=mag; - pcmA[j]=mag-ang; - }else{ - pcmA[j]=mag; - pcmM[j]=mag+ang; - } + if(ang>0){ + pcmM[j]=mag; + pcmA[j]=mag-ang; + }else{ + pcmA[j]=mag; + pcmM[j]=mag+ang; + } else - if(ang>0){ - pcmM[j]=mag; - pcmA[j]=mag+ang; - }else{ - pcmA[j]=mag; - pcmM[j]=mag-ang; - } + if(ang>0){ + pcmM[j]=mag; + pcmA[j]=mag+ang; + }else{ + pcmA[j]=mag; + pcmM[j]=mag-ang; + } } } @@ -303,13 +303,13 @@ static int mapping0_inverse(vorbis_block *vb,vorbis_look_mapping *l){ ogg_int32_t *pcm=vb->pcm[i]; if(nonzero[i]) { - mdct_backward(n, pcm, pcm); - /* window the data */ - _vorbis_apply_window(pcm,b->window,ci->blocksizes,vb->lW,vb->W,vb->nW); + mdct_backward(n, pcm, pcm); + /* window the data */ + _vorbis_apply_window(pcm,b->window,ci->blocksizes,vb->lW,vb->W,vb->nW); } else - memset(pcm, 0, sizeof(ogg_int32_t)*n); - } + memset(pcm, 0, sizeof(ogg_int32_t)*n); + } //for(j=0;jchannels;j++) //_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){ REG_TYPE r6 = x[7] + x[3]; REG_TYPE r7 = x[7] - x[3]; - x[0] = r5 + r3; - x[1] = r7 - r1; - x[2] = r5 - r3; - x[3] = r7 + r1; + x[0] = r5 + r3; + x[1] = r7 - r1; + x[2] = r5 - r3; + x[3] = r7 + r1; x[4] = r4 - r0; - x[5] = r6 - r2; + x[5] = r6 - r2; x[6] = r4 + r0; - x[7] = r6 + r2; - MB(); + x[7] = r6 + r2; + MB(); } /* 16 point butterfly (in place, 4 register) */ @@ -66,30 +66,30 @@ STIN void mdct_butterfly_16(DATA_TYPE *x){ REG_TYPE r0, r1; - r0 = x[ 0] - x[ 8]; x[ 8] += x[ 0]; - r1 = x[ 1] - x[ 9]; x[ 9] += x[ 1]; - x[ 0] = MULT31((r0 + r1) , cPI2_8); - x[ 1] = MULT31((r1 - r0) , cPI2_8); - MB(); + r0 = x[ 0] - x[ 8]; x[ 8] += x[ 0]; + r1 = x[ 1] - x[ 9]; x[ 9] += x[ 1]; + x[ 0] = MULT31((r0 + r1) , cPI2_8); + x[ 1] = MULT31((r1 - r0) , cPI2_8); + MB(); - r0 = x[10] - x[ 2]; x[10] += x[ 2]; - r1 = x[ 3] - x[11]; x[11] += x[ 3]; - x[ 2] = r1; x[ 3] = r0; - MB(); + r0 = x[10] - x[ 2]; x[10] += x[ 2]; + r1 = x[ 3] - x[11]; x[11] += x[ 3]; + x[ 2] = r1; x[ 3] = r0; + MB(); - r0 = x[12] - x[ 4]; x[12] += x[ 4]; - r1 = x[13] - x[ 5]; x[13] += x[ 5]; - x[ 4] = MULT31((r0 - r1) , cPI2_8); - x[ 5] = MULT31((r0 + r1) , cPI2_8); - MB(); + r0 = x[12] - x[ 4]; x[12] += x[ 4]; + r1 = x[13] - x[ 5]; x[13] += x[ 5]; + x[ 4] = MULT31((r0 - r1) , cPI2_8); + x[ 5] = MULT31((r0 + r1) , cPI2_8); + MB(); - r0 = x[14] - x[ 6]; x[14] += x[ 6]; - r1 = x[15] - x[ 7]; x[15] += x[ 7]; - x[ 6] = r0; x[ 7] = r1; - MB(); + r0 = x[14] - x[ 6]; x[14] += x[ 6]; + r1 = x[15] - x[ 7]; x[15] += x[ 7]; + x[ 6] = r0; x[ 7] = r1; + MB(); - mdct_butterfly_8(x); - mdct_butterfly_8(x+8); + mdct_butterfly_8(x); + mdct_butterfly_8(x+8); } /* 32 point butterfly (in place, 4 register) */ @@ -97,50 +97,50 @@ STIN void mdct_butterfly_32(DATA_TYPE *x){ REG_TYPE r0, r1; - r0 = x[30] - x[14]; x[30] += x[14]; - r1 = x[31] - x[15]; x[31] += x[15]; - x[14] = r0; x[15] = r1; - MB(); + r0 = x[30] - x[14]; x[30] += x[14]; + r1 = x[31] - x[15]; x[31] += x[15]; + x[14] = r0; x[15] = r1; + MB(); - r0 = x[28] - x[12]; x[28] += x[12]; - r1 = x[29] - x[13]; x[29] += x[13]; - XNPROD31( r0, r1, cPI1_8, cPI3_8, &x[12], &x[13] ); - MB(); + r0 = x[28] - x[12]; x[28] += x[12]; + r1 = x[29] - x[13]; x[29] += x[13]; + XNPROD31( r0, r1, cPI1_8, cPI3_8, &x[12], &x[13] ); + MB(); - r0 = x[26] - x[10]; x[26] += x[10]; - r1 = x[27] - x[11]; x[27] += x[11]; - x[10] = MULT31((r0 - r1) , cPI2_8); - x[11] = MULT31((r0 + r1) , cPI2_8); - MB(); + r0 = x[26] - x[10]; x[26] += x[10]; + r1 = x[27] - x[11]; x[27] += x[11]; + x[10] = MULT31((r0 - r1) , cPI2_8); + x[11] = MULT31((r0 + r1) , cPI2_8); + MB(); - r0 = x[24] - x[ 8]; x[24] += x[ 8]; - r1 = x[25] - x[ 9]; x[25] += x[ 9]; - XNPROD31( r0, r1, cPI3_8, cPI1_8, &x[ 8], &x[ 9] ); - MB(); + r0 = x[24] - x[ 8]; x[24] += x[ 8]; + r1 = x[25] - x[ 9]; x[25] += x[ 9]; + XNPROD31( r0, r1, cPI3_8, cPI1_8, &x[ 8], &x[ 9] ); + MB(); - r0 = x[22] - x[ 6]; x[22] += x[ 6]; - r1 = x[ 7] - x[23]; x[23] += x[ 7]; - x[ 6] = r1; x[ 7] = r0; - MB(); + r0 = x[22] - x[ 6]; x[22] += x[ 6]; + r1 = x[ 7] - x[23]; x[23] += x[ 7]; + x[ 6] = r1; x[ 7] = r0; + MB(); - r0 = x[ 4] - x[20]; x[20] += x[ 4]; - r1 = x[ 5] - x[21]; x[21] += x[ 5]; - XPROD31 ( r0, r1, cPI3_8, cPI1_8, &x[ 4], &x[ 5] ); - MB(); + r0 = x[ 4] - x[20]; x[20] += x[ 4]; + r1 = x[ 5] - x[21]; x[21] += x[ 5]; + XPROD31 ( r0, r1, cPI3_8, cPI1_8, &x[ 4], &x[ 5] ); + MB(); - r0 = x[ 2] - x[18]; x[18] += x[ 2]; - r1 = x[ 3] - x[19]; x[19] += x[ 3]; - x[ 2] = MULT31((r1 + r0) , cPI2_8); - x[ 3] = MULT31((r1 - r0) , cPI2_8); - MB(); + r0 = x[ 2] - x[18]; x[18] += x[ 2]; + r1 = x[ 3] - x[19]; x[19] += x[ 3]; + x[ 2] = MULT31((r1 + r0) , cPI2_8); + x[ 3] = MULT31((r1 - r0) , cPI2_8); + MB(); - r0 = x[ 0] - x[16]; x[16] += x[ 0]; - r1 = x[ 1] - x[17]; x[17] += x[ 1]; - XPROD31 ( r0, r1, cPI1_8, cPI3_8, &x[ 0], &x[ 1] ); - MB(); + r0 = x[ 0] - x[16]; x[16] += x[ 0]; + r1 = x[ 1] - x[17]; x[17] += x[ 1]; + XPROD31 ( r0, r1, cPI1_8, cPI3_8, &x[ 0], &x[ 1] ); + MB(); - mdct_butterfly_16(x); - mdct_butterfly_16(x+16); + mdct_butterfly_16(x); + mdct_butterfly_16(x+16); } /* 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) { REG_TYPE r0 = x0[0] + x1[0]; REG_TYPE r1 = x1[1] - x0[1]; - XPROD32( r0, r1, T[1], T[0], r2, r3 ); T+=step; + XPROD32( r0, r1, T[1], T[0], r2, r3 ); T+=step; - w1 -= 4; + w1 -= 4; - r0 = (x0[1] + x1[1])>>1; + r0 = (x0[1] + x1[1])>>1; r1 = (x0[0] - x1[0])>>1; - w0[0] = r0 + r2; - w0[1] = r1 + r3; - w1[2] = r0 - r2; - w1[3] = r3 - r1; + w0[0] = r0 + r2; + w0[1] = r1 + r3; + w1[2] = r0 - r2; + w1[3] = r3 - r1; - r3 = bitrev12(bit++); + r3 = bitrev12(bit++); x0 = x + ((r3 ^ 0xfff)>>shift) -1; x1 = x + (r3>>shift); r0 = x0[0] + x1[0]; r1 = x1[1] - x0[1]; - XPROD32( r0, r1, T[1], T[0], r2, r3 ); T+=step; + XPROD32( r0, r1, T[1], T[0], r2, r3 ); T+=step; r0 = (x0[1] + x1[1])>>1; r1 = (x0[0] - x1[0])>>1; - w0[2] = r0 + r2; - w0[3] = r1 + r3; - w1[0] = r0 - r2; - w1[1] = r3 - r1; + w0[2] = r0 + r2; + w0[3] = r1 + r3; + w1[0] = r0 - r2; + w1[1] = r3 - r1; - w0 += 4; + w0 += 4; }while(T>1; + r0 = (x0[1] + x1[1])>>1; r1 = (x0[0] - x1[0])>>1; - w0[0] = r0 + r2; - w0[1] = r1 + r3; - w1[2] = r0 - r2; - w1[3] = r3 - r1; + w0[0] = r0 + r2; + w0[1] = r1 + r3; + w1[2] = r0 - r2; + w1[3] = r3 - r1; - r3 = bitrev12(bit++); + r3 = bitrev12(bit++); x0 = x + ((r3 ^ 0xfff)>>shift) -1; x1 = x + (r3>>shift); r0 = x0[0] + x1[0]; r1 = x1[1] - x0[1]; - T-=step; XPROD32( r0, r1, T[0], T[1], r2, r3 ); + T-=step; XPROD32( r0, r1, T[0], T[1], r2, r3 ); r0 = (x0[1] + x1[1])>>1; r1 = (x0[0] - x1[0])>>1; - w0[2] = r0 + r2; - w0[3] = r1 + r3; - w1[0] = r0 - r2; - w1[1] = r3 - r1; + w0[2] = r0 + r2; + w0[3] = r1 + r3; + w1[0] = r0 - r2; + w1[1] = r3 - r1; - w0 += 4; + w0 += 4; }while(w0=4)?(sincos_lookup0+(step>>1)):sincos_lookup1; do{ oX1-=4; - XPROD31( iX[0], -iX[1], T[0], T[1], &oX1[3], &oX2[0] ); T+=step; - XPROD31( iX[2], -iX[3], T[0], T[1], &oX1[2], &oX2[1] ); T+=step; - XPROD31( iX[4], -iX[5], T[0], T[1], &oX1[1], &oX2[2] ); T+=step; - XPROD31( iX[6], -iX[7], T[0], T[1], &oX1[0], &oX2[3] ); T+=step; - oX2+=4; - iX+=8; - }while(iX>1; - t1 = (*T++)>>1; + t0 = (*T++)>>1; + t1 = (*T++)>>1; do{ oX1-=4; - t0 += (v0 = (*V++)>>1); - t1 += (v1 = (*V++)>>1); - XPROD31( iX[0], -iX[1], t0, t1, &oX1[3], &oX2[0] ); - v0 += (t0 = (*T++)>>1); - v1 += (t1 = (*T++)>>1); - XPROD31( iX[2], -iX[3], v0, v1, &oX1[2], &oX2[1] ); - t0 += (v0 = (*V++)>>1); - t1 += (v1 = (*V++)>>1); - XPROD31( iX[4], -iX[5], t0, t1, &oX1[1], &oX2[2] ); - v0 += (t0 = (*T++)>>1); - v1 += (t1 = (*T++)>>1); - XPROD31( iX[6], -iX[7], v0, v1, &oX1[0], &oX2[3] ); + t0 += (v0 = (*V++)>>1); + t1 += (v1 = (*V++)>>1); + XPROD31( iX[0], -iX[1], t0, t1, &oX1[3], &oX2[0] ); + v0 += (t0 = (*T++)>>1); + v1 += (t1 = (*T++)>>1); + XPROD31( iX[2], -iX[3], v0, v1, &oX1[2], &oX2[1] ); + t0 += (v0 = (*V++)>>1); + t1 += (v1 = (*V++)>>1); + XPROD31( iX[4], -iX[5], t0, t1, &oX1[1], &oX2[2] ); + v0 += (t0 = (*T++)>>1); + v1 += (t1 = (*T++)>>1); + XPROD31( iX[6], -iX[7], v0, v1, &oX1[0], &oX2[3] ); - oX2+=4; - iX+=8; - }while(iX>2); - t1 += (q1 = (v1-t1)>>2); - XPROD31( iX[0], -iX[1], t0, t1, &oX1[3], &oX2[0] ); - t0 = v0-q0; - t1 = v1-q1; - XPROD31( iX[2], -iX[3], t0, t1, &oX1[2], &oX2[1] ); + v0 = *V++; + v1 = *V++; + t0 += (q0 = (v0-t0)>>2); + t1 += (q1 = (v1-t1)>>2); + XPROD31( iX[0], -iX[1], t0, t1, &oX1[3], &oX2[0] ); + t0 = v0-q0; + t1 = v1-q1; + XPROD31( iX[2], -iX[3], t0, t1, &oX1[2], &oX2[1] ); - t0 = *T++; - t1 = *T++; - v0 += (q0 = (t0-v0)>>2); - v1 += (q1 = (t1-v1)>>2); - XPROD31( iX[4], -iX[5], v0, v1, &oX1[1], &oX2[2] ); - v0 = t0-q0; - v1 = t1-q1; - XPROD31( iX[6], -iX[7], v0, v1, &oX1[0], &oX2[3] ); + t0 = *T++; + t1 = *T++; + v0 += (q0 = (t0-v0)>>2); + v1 += (q1 = (t1-v1)>>2); + XPROD31( iX[4], -iX[5], v0, v1, &oX1[1], &oX2[2] ); + v0 = t0-q0; + v1 = t1-q1; + XPROD31( iX[6], -iX[7], v0, v1, &oX1[0], &oX2[3] ); - oX2+=4; - iX+=8; - }while(iX +/* #include */ #if BYTE_ORDER==LITTLE_ENDIAN union 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){ } vorbis_look_residue *res0_look(vorbis_dsp_state *vd,vorbis_info_mode *vm, - vorbis_info_residue *vr){ + vorbis_info_residue *vr){ vorbis_info_residue0 *info=(vorbis_info_residue0 *)vr; vorbis_look_residue0 *look=(vorbis_look_residue0 *)_ogg_calloc(1,sizeof(*look)); 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, if(stages>maxstage)maxstage=stages; look->partbooks[j]=(codebook **)_ogg_calloc(stages,sizeof(*look->partbooks[j])); for(k=0;ksecondstages[j]&(1<partbooks[j][k]=ci->fullbooks+info->booklist[acc++]; + if(info->secondstages[j]&(1<partbooks[j][k]=ci->fullbooks+info->booklist[acc++]; #ifdef TRAIN_RES - look->training_data[k][j]=calloc(look->partbooks[j][k]->entries, - sizeof(***look->training_data)); + look->training_data[k][j]=calloc(look->partbooks[j][k]->entries, + sizeof(***look->training_data)); #endif - } + } } } @@ -176,9 +176,9 @@ vorbis_look_residue *res0_look(vorbis_dsp_state *vd,vorbis_info_mode *vm, /* a truncated packet here just means 'stop working'; it's not an error */ static int _01inverse(vorbis_block *vb,vorbis_look_residue *vl, - ogg_int32_t **in,int ch, - long (*decodepart)(codebook *, ogg_int32_t *, - oggpack_buffer *,int,int)){ + ogg_int32_t **in,int ch, + long (*decodepart)(codebook *, ogg_int32_t *, + oggpack_buffer *,int,int)){ long i,j,k,l,s; vorbis_look_residue0 *look=(vorbis_look_residue0 *)vl; @@ -202,27 +202,27 @@ static int _01inverse(vorbis_block *vb,vorbis_look_residue *vl, partitions_pre_word partitions */ for(i=0,l=0;iphrasebook,&vb->opb); - if(temp==-1)goto eopbreak; - partword[j][l]=look->decodemap[temp]; - if(partword[j][l]==NULL)goto errout; - } + /* fetch the partition word for each channel */ + for(j=0;jphrasebook,&vb->opb); + if(temp==-1)goto eopbreak; + partword[j][l]=look->decodemap[temp]; + if(partword[j][l]==NULL)goto errout; + } } /* now we decode residual values for the partitions */ for(k=0;kbegin+i*samples_per_partition; - if(info->secondstages[partword[j][l][k]]&(1<partbooks[partword[j][l][k]][s]; - if(stagebook){ - if(decodepart(stagebook,in[j]+offset,&vb->opb, - samples_per_partition,-8)==-1)goto eopbreak; - } - } - } + for(j=0;jbegin+i*samples_per_partition; + if(info->secondstages[partword[j][l][k]]&(1<partbooks[partword[j][l][k]][s]; + if(stagebook){ + if(decodepart(stagebook,in[j]+offset,&vb->opb, + samples_per_partition,-8)==-1)goto eopbreak; + } + } + } } } @@ -232,7 +232,7 @@ static int _01inverse(vorbis_block *vb,vorbis_look_residue *vl, } int res0_inverse(vorbis_block *vb,vorbis_look_residue *vl, - ogg_int32_t **in,int *nonzero,int ch){ + ogg_int32_t **in,int *nonzero,int ch){ int i,used=0; for(i=0;iinfo; @@ -283,25 +283,25 @@ int res2_inverse(vorbis_block *vb,vorbis_look_residue *vl, for(i=0,l=0;iphrasebook,&vb->opb); - if(temp==-1)goto eopbreak; - partword[l]=look->decodemap[temp]; - if(partword[l]==NULL)goto errout; + /* fetch the partition word */ + int temp=vorbis_book_decode(look->phrasebook,&vb->opb); + if(temp==-1)goto eopbreak; + partword[l]=look->decodemap[temp]; + if(partword[l]==NULL)goto errout; } /* now we decode residual values for the partitions */ for(k=0;ksecondstages[partword[l][k]]&(1<partbooks[partword[l][k]][s]; - if(stagebook){ - if(vorbis_book_decodevv_add(stagebook,in, - i*samples_per_partition+beginoff,ch, - &vb->opb, - samples_per_partition,-8)==-1) - goto eopbreak; - } - } + if(info->secondstages[partword[l][k]]&(1<partbooks[partword[l][k]][s]; + if(stagebook){ + if(vorbis_book_decodevv_add(stagebook,in, + i*samples_per_partition+beginoff,ch, + &vb->opb, + samples_per_partition,-8)==-1) + goto eopbreak; + } + } } } 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 @@ /* IRAM buffer keep the block pcm data; only for windows size upto 2048 - for space restrictions. No real compromise, larger window sizes - are only used for very low quality settings (q<0?) */ + for space restrictions. + libVorbis 1.1 Oggenc doesn't use larger windows anyway. */ /* max 2 channels on the ihp-1xx (stereo), 2048 samples (2*2048*4=16Kb) */ #define IRAM_PCM_END 2048 #define CHANNELS 2 @@ -80,12 +80,12 @@ int vorbis_synthesis(vorbis_block *vb,ogg_packet *op,int decodep){ /* use statically allocated iram buffer */ vb->pcm = ipcm_vect; for(i=0; ipcm[i] = &ipcm_buff[i*IRAM_PCM_END]; + vb->pcm[i] = &ipcm_buff[i*IRAM_PCM_END]; } else { /* dynamic allocation (slower) */ vb->pcm=(ogg_int32_t **)_vorbis_block_alloc(vb,sizeof(*vb->pcm)*vi->channels); for(i=0;ichannels;i++) - vb->pcm[i]=(ogg_int32_t *)_vorbis_block_alloc(vb,vb->pcmend*sizeof(*vb->pcm[i])); + vb->pcm[i]=(ogg_int32_t *)_vorbis_block_alloc(vb,vb->pcmend*sizeof(*vb->pcm[i])); } /* 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){ boundary: -1) unbounded search 0) read no additional data; use cached only - n) search for a new page beginning for n bytes + n) search for a new page beginning for n bytes return: <0) did not find a page (OV_FALSE, OV_EOF, OV_EREAD) n) found a page at absolute offset n @@ -99,7 +99,7 @@ static void _seek_helper(OggVorbis_File *vf,ogg_int64_t offset){ produces a refcounted page */ static ogg_int64_t _get_next_page(OggVorbis_File *vf,ogg_page *og, - ogg_int64_t boundary){ + ogg_int64_t boundary){ if(boundary>0)boundary+=vf->offset; while(1){ long more; @@ -112,20 +112,20 @@ static ogg_int64_t _get_next_page(OggVorbis_File *vf,ogg_page *og, vf->offset-=more; }else{ if(more==0){ - /* send more paramedics */ - if(!boundary)return(OV_FALSE); - { - long ret=_get_data(vf); - if(ret==0)return(OV_EOF); - if(ret<0)return(OV_EREAD); - } + /* send more paramedics */ + if(!boundary)return(OV_FALSE); + { + long ret=_get_data(vf); + if(ret==0)return(OV_EOF); + if(ret<0)return(OV_EREAD); + } }else{ - /* got a page. Return the offset at the page beginning, + /* got a page. Return the offset at the page beginning, advance the internal offset past the page end */ - ogg_int64_t ret=vf->offset; - vf->offset+=more; - return(ret); - + ogg_int64_t ret=vf->offset; + vf->offset+=more; + return(ret); + } } } @@ -152,9 +152,9 @@ static ogg_int64_t _get_prev_page(OggVorbis_File *vf,ogg_page *og){ ret=_get_next_page(vf,og,end-vf->offset); if(ret==OV_EREAD)return(OV_EREAD); if(ret<0){ - break; + break; }else{ - offset=ret; + offset=ret; } } } @@ -174,11 +174,11 @@ static ogg_int64_t _get_prev_page(OggVorbis_File *vf,ogg_page *og){ Recurses for each link so it can alloc the link storage after finding them all, then unroll and fill the cache at the same time */ static int _bisect_forward_serialno(OggVorbis_File *vf, - ogg_int64_t begin, - ogg_int64_t searched, - ogg_int64_t end, - ogg_uint32_t currentno, - long m){ + ogg_int64_t begin, + ogg_int64_t searched, + ogg_int64_t end, + ogg_uint32_t currentno, + long m){ ogg_int64_t endsearched=end; ogg_int64_t next=end; ogg_page og={0,0,0,0}; @@ -219,7 +219,7 @@ static int _bisect_forward_serialno(OggVorbis_File *vf, vf->offsets[m+1]=searched; }else{ ret=_bisect_forward_serialno(vf,next,vf->offset, - end,ogg_page_serialno(&og),m+1); + end,ogg_page_serialno(&og),m+1); ogg_page_release(&og); if(ret==OV_EREAD)return(OV_EREAD); } @@ -234,10 +234,10 @@ static int _bisect_forward_serialno(OggVorbis_File *vf, /* consumes the page that's passed in (if any) */ static int _fetch_headers(OggVorbis_File *vf, - vorbis_info *vi, - vorbis_comment *vc, - ogg_uint32_t *serialno, - ogg_page *og_ptr){ + vorbis_info *vi, + vorbis_comment *vc, + ogg_uint32_t *serialno, + ogg_page *og_ptr){ ogg_page og={0,0,0,0}; ogg_packet op={0,0,0,0,0,0}; int i,ret; @@ -266,18 +266,18 @@ static int _fetch_headers(OggVorbis_File *vf, int result=ogg_stream_packetout(vf->os,&op); if(result==0)break; if(result==-1){ - ret=OV_EBADHEADER; - goto bail_header; + ret=OV_EBADHEADER; + goto bail_header; } if((ret=vorbis_synthesis_headerin(vi,vc,&op))){ - goto bail_header; + goto bail_header; } i++; } if(i<3) if(_get_next_page(vf,og_ptr,CHUNKSIZE)<0){ - ret=OV_EBADHEADER; - goto bail_header; + ret=OV_EBADHEADER; + goto bail_header; } } @@ -326,9 +326,9 @@ static void _prefetch_all_headers(OggVorbis_File *vf, ogg_int64_t dataoffset){ _seek_helper(vf,vf->offsets[i]); if(_fetch_headers(vf,vf->vi+i,vf->vc+i,NULL,NULL)<0){ - vf->dataoffsets[i]=-1; + vf->dataoffsets[i]=-1; }else{ - vf->dataoffsets[i]=vf->offset; + vf->dataoffsets[i]=vf->offset; } } @@ -342,36 +342,36 @@ static void _prefetch_all_headers(OggVorbis_File *vf, ogg_int64_t dataoffset){ ogg_stream_reset_serialno(vf->os,vf->serialnos[i]); while(1){ - ogg_packet op={0,0,0,0,0,0}; + ogg_packet op={0,0,0,0,0,0}; - ret=_get_next_page(vf,&og,-1); - if(ret<0) - /* this should not be possible unless the file is + ret=_get_next_page(vf,&og,-1); + if(ret<0) + /* this should not be possible unless the file is truncated/mangled */ - break; + break; - if(ogg_page_serialno(&og)!=vf->serialnos[i]) - break; - - pos=ogg_page_granulepos(&og); + if(ogg_page_serialno(&og)!=vf->serialnos[i]) + break; + + pos=ogg_page_granulepos(&og); - /* count blocksizes of all frames in the page */ - ogg_stream_pagein(vf->os,&og); - while((result=ogg_stream_packetout(vf->os,&op))){ - if(result>0){ /* ignore holes */ - long thisblock=vorbis_packet_blocksize(vf->vi+i,&op); - if(lastblock!=-1) - accumulated+=(lastblock+thisblock)>>2; - lastblock=thisblock; - } - } - ogg_packet_release(&op); + /* count blocksizes of all frames in the page */ + ogg_stream_pagein(vf->os,&og); + while((result=ogg_stream_packetout(vf->os,&op))){ + if(result>0){ /* ignore holes */ + long thisblock=vorbis_packet_blocksize(vf->vi+i,&op); + if(lastblock!=-1) + accumulated+=(lastblock+thisblock)>>2; + lastblock=thisblock; + } + } + ogg_packet_release(&op); - if(pos!=-1){ - /* pcm offset of last packet on the first audio page */ - accumulated= pos-accumulated; - break; - } + if(pos!=-1){ + /* pcm offset of last packet on the first audio page */ + accumulated= pos-accumulated; + break; + } } /* 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){ _seek_helper(vf,end); while(1){ - ret=_get_prev_page(vf,&og); - if(ret<0){ - /* this should not be possible */ - vorbis_info_clear(vf->vi+i); - vorbis_comment_clear(vf->vc+i); - break; - } - if(ogg_page_granulepos(&og)!=-1){ - vf->pcmlengths[i*2+1]=ogg_page_granulepos(&og)-vf->pcmlengths[i*2]; - break; - } - vf->offset=ret; + ret=_get_prev_page(vf,&og); + if(ret<0){ + /* this should not be possible */ + vorbis_info_clear(vf->vi+i); + vorbis_comment_clear(vf->vc+i); + break; + } + if(ogg_page_granulepos(&og)!=-1){ + vf->pcmlengths[i*2+1]=ogg_page_granulepos(&og)-vf->pcmlengths[i*2]; + break; + } + vf->offset=ret; } } } @@ -474,12 +474,12 @@ static void _decode_clear(OggVorbis_File *vf){ return: <0) error, OV_HOLE (lost packet) or OV_EOF 0) need more data (only if readp==0) - 1) got a packet + 1) got a packet */ static int _fetch_and_process_packet(OggVorbis_File *vf, - int readp, - int spanp){ + int readp, + int spanp){ ogg_page og={0,0,0,0}; ogg_packet op={0,0,0,0,0,0}; int ret=0; @@ -492,110 +492,110 @@ static int _fetch_and_process_packet(OggVorbis_File *vf, neither is a page */ if(vf->ready_state==INITSET){ while(1) { - int result=ogg_stream_packetout(vf->os,&op); - ogg_int64_t granulepos; + int result=ogg_stream_packetout(vf->os,&op); + ogg_int64_t granulepos; - if(result<0){ - ret=OV_HOLE; /* hole in the data. */ - goto cleanup; - } - if(result>0){ - /* got a packet. process it */ - granulepos=op.granulepos; - if(!vorbis_synthesis(&vf->vb,&op,1)){ /* lazy check for lazy - header handling. The - header packets aren't - audio, so if/when we - submit them, - vorbis_synthesis will - reject them */ + if(result<0){ + ret=OV_HOLE; /* hole in the data. */ + goto cleanup; + } + if(result>0){ + /* got a packet. process it */ + granulepos=op.granulepos; + if(!vorbis_synthesis(&vf->vb,&op,1)){ /* lazy check for lazy + header handling. The + header packets aren't + audio, so if/when we + submit them, + vorbis_synthesis will + reject them */ - /* suck in the synthesis data and track bitrate */ - { - int oldsamples=vorbis_synthesis_pcmout(&vf->vd,NULL); - /* for proper use of libvorbis within libvorbisfile, + /* suck in the synthesis data and track bitrate */ + { + int oldsamples=vorbis_synthesis_pcmout(&vf->vd,NULL); + /* for proper use of libvorbis within libvorbisfile, oldsamples will always be zero. */ - if(oldsamples){ - ret=OV_EFAULT; - goto cleanup; - } + if(oldsamples){ + ret=OV_EFAULT; + goto cleanup; + } - vorbis_synthesis_blockin(&vf->vd,&vf->vb); - vf->samptrack+=vorbis_synthesis_pcmout(&vf->vd,NULL)-oldsamples; - vf->bittrack+=op.bytes*8; - } - - /* update the pcm offset. */ - if(granulepos!=-1 && !op.e_o_s){ - int link=(vf->seekable?vf->current_link:0); - int i,samples; - - /* this packet has a pcm_offset on it (the last packet - completed on a page carries the offset) After processing - (above), we know the pcm position of the *last* sample - ready to be returned. Find the offset of the *first* + vorbis_synthesis_blockin(&vf->vd,&vf->vb); + vf->samptrack+=vorbis_synthesis_pcmout(&vf->vd,NULL)-oldsamples; + vf->bittrack+=op.bytes*8; + } + + /* update the pcm offset. */ + if(granulepos!=-1 && !op.e_o_s){ + int link=(vf->seekable?vf->current_link:0); + int i,samples; + + /* this packet has a pcm_offset on it (the last packet + completed on a page carries the offset) After processing + (above), we know the pcm position of the *last* sample + ready to be returned. Find the offset of the *first* - As an aside, this trick is inaccurate if we begin - reading anew right at the last page; the end-of-stream - granulepos declares the last frame in the stream, and the - last packet of the last page may be a partial frame. - So, we need a previous granulepos from an in-sequence page - to have a reference point. Thus the !op.e_o_s clause - above */ + As an aside, this trick is inaccurate if we begin + reading anew right at the last page; the end-of-stream + granulepos declares the last frame in the stream, and the + last packet of the last page may be a partial frame. + So, we need a previous granulepos from an in-sequence page + to have a reference point. Thus the !op.e_o_s clause + above */ - if(vf->seekable && link>0) - granulepos-=vf->pcmlengths[link*2]; - if(granulepos<0)granulepos=0; /* actually, this - shouldn't be possible - here unless the stream - is very broken */ + if(vf->seekable && link>0) + granulepos-=vf->pcmlengths[link*2]; + if(granulepos<0)granulepos=0; /* actually, this + shouldn't be possible + here unless the stream + is very broken */ - samples=vorbis_synthesis_pcmout(&vf->vd,NULL); - - granulepos-=samples; - for(i=0;ipcmlengths[i*2+1]; - vf->pcm_offset=granulepos; - } - ret=1; - goto cleanup; - } - } - else - break; + samples=vorbis_synthesis_pcmout(&vf->vd,NULL); + + granulepos-=samples; + for(i=0;ipcmlengths[i*2+1]; + vf->pcm_offset=granulepos; + } + ret=1; + goto cleanup; + } + } + else + break; } } if(vf->ready_state>=OPENED){ int ret; if(!readp){ - ret=0; - goto cleanup; + ret=0; + goto cleanup; } if((ret=_get_next_page(vf,&og,-1))<0){ - ret=OV_EOF; /* eof. leave unitialized */ - goto cleanup; + ret=OV_EOF; /* eof. leave unitialized */ + goto cleanup; } - /* bitrate tracking; add the header's bytes here, the body bytes - are done by packet above */ + /* bitrate tracking; add the header's bytes here, the body bytes + are done by packet above */ vf->bittrack+=og.header_len*8; /* has our decoding just traversed a bitstream boundary? */ if(vf->ready_state==INITSET){ - if(vf->current_serialno!=ogg_page_serialno(&og)){ - if(!spanp){ - ret=OV_EOF; - goto cleanup; - } + if(vf->current_serialno!=ogg_page_serialno(&og)){ + if(!spanp){ + ret=OV_EOF; + goto cleanup; + } - _decode_clear(vf); - - if(!vf->seekable){ - vorbis_info_clear(vf->vi); - vorbis_comment_clear(vf->vc); - } - } + _decode_clear(vf); + + if(!vf->seekable){ + vorbis_info_clear(vf->vi); + vorbis_comment_clear(vf->vc); + } + } } } @@ -615,34 +615,34 @@ static int _fetch_and_process_packet(OggVorbis_File *vf, int link; if(vf->ready_stateseekable){ - vf->current_serialno=ogg_page_serialno(&og); - - /* match the serialno to bitstream section. We use this rather than - offset positions to avoid problems near logical bitstream - boundaries */ - for(link=0;linklinks;link++) - if(vf->serialnos[link]==vf->current_serialno)break; - if(link==vf->links){ - ret=OV_EBADLINK; /* sign of a bogus stream. error out, - leave machine uninitialized */ - goto cleanup; - } - - vf->current_link=link; - - ogg_stream_reset_serialno(vf->os,vf->current_serialno); - vf->ready_state=STREAMSET; - - }else{ - /* we're streaming */ - /* fetch the three header packets, build the info struct */ - - int ret=_fetch_headers(vf,vf->vi,vf->vc,&vf->current_serialno,&og); - if(ret) goto cleanup; - vf->current_link++; - link=0; - } + if(vf->seekable){ + vf->current_serialno=ogg_page_serialno(&og); + + /* match the serialno to bitstream section. We use this rather than + offset positions to avoid problems near logical bitstream + boundaries */ + for(link=0;linklinks;link++) + if(vf->serialnos[link]==vf->current_serialno)break; + if(link==vf->links){ + ret=OV_EBADLINK; /* sign of a bogus stream. error out, + leave machine uninitialized */ + goto cleanup; + } + + vf->current_link=link; + + ogg_stream_reset_serialno(vf->os,vf->current_serialno); + vf->ready_state=STREAMSET; + + }else{ + /* we're streaming */ + /* fetch the three header packets, build the info struct */ + + int ret=_fetch_headers(vf,vf->vi,vf->vc,&vf->current_serialno,&og); + if(ret) goto cleanup; + vf->current_link++; + link=0; + } } _make_decode_ready(vf); @@ -665,7 +665,7 @@ static int _fseek64_wrap(FILE *f,ogg_int64_t off,int whence){ #endif static int _ov_open1(void *f,OggVorbis_File *vf,char *initial, - long ibytes, ov_callbacks callbacks){ + long ibytes, ov_callbacks callbacks){ int offsettest=(f?callbacks.seek_func(f,0,SEEK_CUR):-1); int ret; @@ -734,8 +734,8 @@ int ov_clear(OggVorbis_File *vf){ if(vf->vi && vf->links){ int i; for(i=0;ilinks;i++){ - vorbis_info_clear(vf->vi+i); - vorbis_comment_clear(vf->vc+i); + vorbis_info_clear(vf->vi+i); + vorbis_comment_clear(vf->vc+i); } _ogg_free(vf->vi); _ogg_free(vf->vc); @@ -852,16 +852,16 @@ long ov_bitrate(OggVorbis_File *vf,int i){ }else{ /* return nominal if set */ if(vf->vi[i].bitrate_nominal>0){ - return vf->vi[i].bitrate_nominal; + return vf->vi[i].bitrate_nominal; }else{ - if(vf->vi[i].bitrate_upper>0){ - if(vf->vi[i].bitrate_lower>0){ - return (vf->vi[i].bitrate_upper+vf->vi[i].bitrate_lower)/2; - }else{ - return vf->vi[i].bitrate_upper; - } - } - return(OV_FALSE); + if(vf->vi[i].bitrate_upper>0){ + if(vf->vi[i].bitrate_lower>0){ + return (vf->vi[i].bitrate_upper+vf->vi[i].bitrate_lower)/2; + }else{ + return vf->vi[i].bitrate_upper; + } + } + return(OV_FALSE); } } } @@ -895,8 +895,8 @@ long ov_serialnumber(OggVorbis_File *vf,int i){ /* returns: total raw (compressed) length of content if i==-1 raw (compressed) length of that logical bitstream for i==0 to n - OV_EINVAL if the stream is not seekable (we can't know the length) - or if stream is only partially open + OV_EINVAL if the stream is not seekable (we can't know the length) + or if stream is only partially open */ ogg_int64_t ov_raw_total(OggVorbis_File *vf,int i){ if(vf->ready_stateready_stateready_statepcm_offset=-1; ogg_stream_reset_serialno(vf->os, - vf->current_serialno); /* must set serialno */ + vf->current_serialno); /* must set serialno */ vorbis_synthesis_restart(&vf->vd); _seek_helper(vf,pos); @@ -1003,83 +1003,83 @@ int ov_raw_seek(OggVorbis_File *vf,ogg_int64_t pos){ work_os=ogg_stream_create(vf->current_serialno); /* get the memory ready */ while(1){ if(vf->ready_state>=STREAMSET){ - /* snarf/scan a packet if we can */ - int result=ogg_stream_packetout(work_os,&op); + /* snarf/scan a packet if we can */ + int result=ogg_stream_packetout(work_os,&op); - if(result>0){ + if(result>0){ - if(vf->vi[vf->current_link].codec_setup){ - thisblock=vorbis_packet_blocksize(vf->vi+vf->current_link,&op); - if(thisblock<0){ - ogg_stream_packetout(vf->os,NULL); - thisblock=0; - }else{ - - if(eosflag) - ogg_stream_packetout(vf->os,NULL); - else - if(lastblock)accblock+=(lastblock+thisblock)>>2; - } + if(vf->vi[vf->current_link].codec_setup){ + thisblock=vorbis_packet_blocksize(vf->vi+vf->current_link,&op); + if(thisblock<0){ + ogg_stream_packetout(vf->os,NULL); + thisblock=0; + }else{ + + if(eosflag) + ogg_stream_packetout(vf->os,NULL); + else + if(lastblock)accblock+=(lastblock+thisblock)>>2; + } - if(op.granulepos!=-1){ - int i,link=vf->current_link; - ogg_int64_t granulepos=op.granulepos-vf->pcmlengths[link*2]; - if(granulepos<0)granulepos=0; - - for(i=0;ipcmlengths[i*2+1]; - vf->pcm_offset=granulepos-accblock; - break; - } - lastblock=thisblock; - continue; - }else - ogg_stream_packetout(vf->os,NULL); - } + if(op.granulepos!=-1){ + int i,link=vf->current_link; + ogg_int64_t granulepos=op.granulepos-vf->pcmlengths[link*2]; + if(granulepos<0)granulepos=0; + + for(i=0;ipcmlengths[i*2+1]; + vf->pcm_offset=granulepos-accblock; + break; + } + lastblock=thisblock; + continue; + }else + ogg_stream_packetout(vf->os,NULL); + } } if(!lastblock){ - if(_get_next_page(vf,&og,-1)<0){ - vf->pcm_offset=ov_pcm_total(vf,-1); - break; - } + if(_get_next_page(vf,&og,-1)<0){ + vf->pcm_offset=ov_pcm_total(vf,-1); + break; + } }else{ - /* huh? Bogus stream with packets but no granulepos */ - vf->pcm_offset=-1; - break; + /* huh? Bogus stream with packets but no granulepos */ + vf->pcm_offset=-1; + break; } /* has our decoding just traversed a bitstream boundary? */ if(vf->ready_state>=STREAMSET) - if(vf->current_serialno!=ogg_page_serialno(&og)){ - _decode_clear(vf); /* clear out stream state */ - ogg_stream_destroy(work_os); - } + if(vf->current_serialno!=ogg_page_serialno(&og)){ + _decode_clear(vf); /* clear out stream state */ + ogg_stream_destroy(work_os); + } if(vf->ready_statecurrent_serialno=ogg_page_serialno(&og); - for(link=0;linklinks;link++) - if(vf->serialnos[link]==vf->current_serialno)break; - if(link==vf->links) - goto seek_error; /* sign of a bogus stream. error out, - leave machine uninitialized */ + int link; + + vf->current_serialno=ogg_page_serialno(&og); + for(link=0;linklinks;link++) + if(vf->serialnos[link]==vf->current_serialno)break; + if(link==vf->links) + goto seek_error; /* sign of a bogus stream. error out, + leave machine uninitialized */ - vf->current_link=link; - - ogg_stream_reset_serialno(vf->os,vf->current_serialno); - ogg_stream_reset_serialno(work_os,vf->current_serialno); - vf->ready_state=STREAMSET; - + vf->current_link=link; + + ogg_stream_reset_serialno(vf->os,vf->current_serialno); + ogg_stream_reset_serialno(work_os,vf->current_serialno); + vf->ready_state=STREAMSET; + } { - ogg_page dup; - ogg_page_dup(&dup,&og); - eosflag=ogg_page_eos(&og); - ogg_stream_pagein(vf->os,&og); - ogg_stream_pagein(work_os,&dup); + ogg_page dup; + ogg_page_dup(&dup,&og); + eosflag=ogg_page_eos(&og); + ogg_stream_pagein(vf->os,&og); + ogg_stream_pagein(work_os,&dup); } } } @@ -1144,56 +1144,56 @@ int ov_pcm_seek_page(OggVorbis_File *vf,ogg_int64_t pos){ ogg_int64_t bisect; if(end-beginoffset); - if(result==OV_EREAD) goto seek_error; - if(result<0){ - if(bisect<=begin+1) - end=begin; /* found it */ - else{ - if(bisect==0) goto seek_error; - bisect-=CHUNKSIZE; - if(bisect<=begin)bisect=begin+1; - _seek_helper(vf,bisect); - } - }else{ - ogg_int64_t granulepos=ogg_page_granulepos(&og); - if(granulepos==-1)continue; - if(granuleposoffset; /* raw offset of next page */ - begintime=granulepos; - - if(target-begintime>44100)break; - bisect=begin; /* *not* begin + 1 */ - }else{ - if(bisect<=begin+1) - end=begin; /* found it */ - else{ - if(end==vf->offset){ /* we're pretty close - we'd be stuck in */ - end=result; - bisect-=CHUNKSIZE; /* an endless loop otherwise. */ - if(bisect<=begin)bisect=begin+1; - _seek_helper(vf,bisect); - }else{ - end=result; - endtime=granulepos; - break; - } - } - } - } + result=_get_next_page(vf,&og,end-vf->offset); + if(result==OV_EREAD) goto seek_error; + if(result<0){ + if(bisect<=begin+1) + end=begin; /* found it */ + else{ + if(bisect==0) goto seek_error; + bisect-=CHUNKSIZE; + if(bisect<=begin)bisect=begin+1; + _seek_helper(vf,bisect); + } + }else{ + ogg_int64_t granulepos=ogg_page_granulepos(&og); + if(granulepos==-1)continue; + if(granuleposoffset; /* raw offset of next page */ + begintime=granulepos; + + if(target-begintime>44100)break; + bisect=begin; /* *not* begin + 1 */ + }else{ + if(bisect<=begin+1) + end=begin; /* found it */ + else{ + if(end==vf->offset){ /* we're pretty close - we'd be stuck in */ + end=result; + bisect-=CHUNKSIZE; /* an endless loop otherwise. */ + if(bisect<=begin)bisect=begin+1; + _seek_helper(vf,bisect); + }else{ + end=result; + endtime=granulepos; + break; + } + } + } + } } } @@ -1206,20 +1206,20 @@ int ov_pcm_seek_page(OggVorbis_File *vf,ogg_int64_t pos){ vf->pcm_offset=-1; if(_get_next_page(vf,&og,-1)<0){ - ogg_page_release(&og); - return(OV_EOF); /* shouldn't happen */ + ogg_page_release(&og); + return(OV_EOF); /* shouldn't happen */ } if(link!=vf->current_link){ - /* Different link; dump entire decode machine */ - _decode_clear(vf); - - vf->current_link=link; - vf->current_serialno=ogg_page_serialno(&og); - vf->ready_state=STREAMSET; - + /* Different link; dump entire decode machine */ + _decode_clear(vf); + + vf->current_link=link; + vf->current_serialno=ogg_page_serialno(&og); + vf->ready_state=STREAMSET; + }else{ - vorbis_synthesis_restart(&vf->vd); + vorbis_synthesis_restart(&vf->vd); } 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){ /* pull out all but last packet; the one with granulepos */ while(1){ - result=ogg_stream_packetpeek(vf->os,&op); - if(result==0){ - /* !!! the packet finishing this page originated on a + result=ogg_stream_packetpeek(vf->os,&op); + if(result==0){ + /* !!! the packet finishing this page originated on a preceeding page. Keep fetching previous pages until we get one with a granulepos or without the 'continued' flag set. Then just use raw_seek for simplicity. */ - - _seek_helper(vf,best); - - while(1){ - result=_get_prev_page(vf,&og); - if(result<0) goto seek_error; - if(ogg_page_granulepos(&og)>-1 || - !ogg_page_continued(&og)){ - return ov_raw_seek(vf,result); - } - vf->offset=result; - } - } - if(result<0){ - result = OV_EBADPACKET; - goto seek_error; - } - if(op.granulepos!=-1){ - vf->pcm_offset=op.granulepos-vf->pcmlengths[vf->current_link*2]; - if(vf->pcm_offset<0)vf->pcm_offset=0; - vf->pcm_offset+=total; - break; - }else - result=ogg_stream_packetout(vf->os,NULL); + + _seek_helper(vf,best); + + while(1){ + result=_get_prev_page(vf,&og); + if(result<0) goto seek_error; + if(ogg_page_granulepos(&og)>-1 || + !ogg_page_continued(&og)){ + return ov_raw_seek(vf,result); + } + vf->offset=result; + } + } + if(result<0){ + result = OV_EBADPACKET; + goto seek_error; + } + if(op.granulepos!=-1){ + vf->pcm_offset=op.granulepos-vf->pcmlengths[vf->current_link*2]; + if(vf->pcm_offset<0)vf->pcm_offset=0; + vf->pcm_offset+=total; + break; + }else + result=ogg_stream_packetout(vf->os,NULL); } } } @@ -1304,33 +1304,33 @@ int ov_pcm_seek(OggVorbis_File *vf,ogg_int64_t pos){ if(ret>0){ thisblock=vorbis_packet_blocksize(vf->vi+vf->current_link,&op); if(thisblock<0){ - ogg_stream_packetout(vf->os,NULL); - continue; /* non audio packet */ + ogg_stream_packetout(vf->os,NULL); + continue; /* non audio packet */ } if(lastblock)vf->pcm_offset+=(lastblock+thisblock)>>2; if(vf->pcm_offset+((thisblock+ - vorbis_info_blocksize(vf->vi,1))>>2)>=pos)break; + vorbis_info_blocksize(vf->vi,1))>>2)>=pos)break; /* remove the packet from packet queue and track its granulepos */ ogg_stream_packetout(vf->os,NULL); vorbis_synthesis(&vf->vb,&op,0); /* set up a vb with - only tracking, no - pcm_decode */ + only tracking, no + pcm_decode */ vorbis_synthesis_blockin(&vf->vd,&vf->vb); /* end of logical stream case is hard, especially with exact - length positioning. */ + length positioning. */ if(op.granulepos>-1){ - int i; - /* always believe the stream markers */ - vf->pcm_offset=op.granulepos-vf->pcmlengths[vf->current_link*2]; - if(vf->pcm_offset<0)vf->pcm_offset=0; - for(i=0;icurrent_link;i++) - vf->pcm_offset+=vf->pcmlengths[i*2+1]; + int i; + /* always believe the stream markers */ + vf->pcm_offset=op.granulepos-vf->pcmlengths[vf->current_link*2]; + if(vf->pcm_offset<0)vf->pcm_offset=0; + for(i=0;icurrent_link;i++) + vf->pcm_offset+=vf->pcmlengths[i*2+1]; } - + lastblock=thisblock; }else{ @@ -1341,22 +1341,22 @@ int ov_pcm_seek(OggVorbis_File *vf,ogg_int64_t pos){ if(vf->current_serialno!=ogg_page_serialno(&og))_decode_clear(vf); if(vf->ready_statecurrent_serialno=ogg_page_serialno(&og); - for(link=0;linklinks;link++) - if(vf->serialnos[link]==vf->current_serialno)break; - if(link==vf->links){ - ogg_page_release(&og); - ogg_packet_release(&op); - return(OV_EBADLINK); - } - vf->current_link=link; - - ogg_stream_reset_serialno(vf->os,vf->current_serialno); - vf->ready_state=STREAMSET; - _make_decode_ready(vf); - lastblock=0; + int link; + + vf->current_serialno=ogg_page_serialno(&og); + for(link=0;linklinks;link++) + if(vf->serialnos[link]==vf->current_serialno)break; + if(link==vf->links){ + ogg_page_release(&og); + ogg_packet_release(&op); + return(OV_EBADLINK); + } + vf->current_link=link; + + ogg_stream_reset_serialno(vf->os,vf->current_serialno); + vf->ready_state=STREAMSET; + _make_decode_ready(vf); + lastblock=0; } ogg_stream_pagein(vf->os,&og); @@ -1377,7 +1377,7 @@ int ov_pcm_seek(OggVorbis_File *vf,ogg_int64_t pos){ if(samplespcm_offset=ov_pcm_total(vf,-1); /* eof */ + vf->pcm_offset=ov_pcm_total(vf,-1); /* eof */ } ogg_page_release(&og); @@ -1486,14 +1486,14 @@ vorbis_info *ov_info(OggVorbis_File *vf,int link){ if(vf->seekable){ if(link<0) if(vf->ready_state>=STREAMSET) - return vf->vi+vf->current_link; + return vf->vi+vf->current_link; else return vf->vi; else if(link>=vf->links) - return NULL; + return NULL; else - return vf->vi+link; + return vf->vi+link; }else{ return vf->vi; } @@ -1504,14 +1504,14 @@ vorbis_comment *ov_comment(OggVorbis_File *vf,int link){ if(vf->seekable){ if(link<0) if(vf->ready_state>=STREAMSET) - return vf->vc+vf->current_link; + return vf->vc+vf->current_link; else - return vf->vc; + return vf->vc; else if(link>=vf->links) - return NULL; + return NULL; else - return vf->vc+link; + return vf->vc+link; }else{ return vf->vc; } @@ -1533,16 +1533,16 @@ vorbis_comment *ov_comment(OggVorbis_File *vf,int link){ functions above are aware of this dichotomy). input values: buffer) a buffer to hold packed PCM data for return - length) the byte length requested to be placed into buffer + length) the byte length requested to be placed into buffer return values: <0) error/hole in data (OV_HOLE), partial open (OV_EINVAL) 0) EOF - n) number of bytes of PCM actually returned. The - below works on a packet-by-packet basis, so the - return length is not related to the 'length' passed - in, just guaranteed to fit. + n) number of bytes of PCM actually returned. The + below works on a packet-by-packet basis, so the + return length is not related to the 'length' passed + in, just guaranteed to fit. - *section) set to the logical bitstream number */ + *section) set to the logical bitstream number */ long ov_read(OggVorbis_File *vf,char *buffer,int bytes_req,int *bitstream){ int i,j; @@ -1562,9 +1562,9 @@ long ov_read(OggVorbis_File *vf,char *buffer,int bytes_req,int *bitstream){ { int ret=_fetch_and_process_packet(vf,1,1); if(ret==OV_EOF) - return(0); + return(0); if(ret<=0) - return(ret); + return(ret); } } 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){ } void _vorbis_apply_window(ogg_int32_t *d,const void *window_p[2], - long *blocksizes, - int lW,int W,int nW){ + long *blocksizes, + int lW,int W,int nW){ LOOKUP_T *window[2]={window_p[0],window_p[1]}; long n=blocksizes[W]; long ln=blocksizes[lW]; @@ -68,7 +68,7 @@ void _vorbis_apply_window(ogg_int32_t *d,const void *window_p[2], long rightend=rightbegin+rn/2; #if CONFIG_CPU == MCF5249 - mcf5249_init_mac(); /* shouldn't be needed, but just in case */ + /* mcf5249_init_mac(); */ /* shouldn't be needed, but just in case */ mcf5249_vect_zero(&d[0], leftbegin); mcf5249_vect_mult_fw(&d[leftbegin], &window[lW][0], leftend-leftbegin); 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 @@ #include "os_types.h" -/* keep small window tables in fast IRAM */ -static LOOKUP_T vwin64[32] IDATA_ATTR = { +/* Oggenc 1.1 seems to use exclusively windows sizes 256, 2048 + keep the most common sizes in fast IRAM; + because we have the available space also 128, 512 */ +static LOOKUP_T vwin64[32] = { X(0x001f0003), X(0x01168c98), X(0x030333c8), X(0x05dfe3a4), X(0x09a49562), X(0x0e45df18), X(0x13b47ef2), X(0x19dcf676), X(0x20a74d83), X(0x27f7137c), X(0x2fabb05a), X(0x37a1105a), @@ -151,7 +153,7 @@ static LOOKUP_T vwin512[256] IDATA_ATTR = { X(0x7ffffdcd), X(0x7fffff6d), X(0x7fffffed), X(0x7fffffff), }; -static LOOKUP_T vwin1024[512] IDATA_ATTR = { +static LOOKUP_T vwin1024[512] = { X(0x00001f02), X(0x0001170e), X(0x00030724), X(0x0005ef40), X(0x0009cf59), X(0x000ea767), X(0x0014775e), X(0x001b3f2e), X(0x0022fec8), X(0x002bb618), X(0x00356508), X(0x00400b81), @@ -541,8 +543,6 @@ static LOOKUP_T vwin2048[1024] IDATA_ATTR = { X(0x7ffffffe), X(0x7fffffff), X(0x7fffffff), X(0x7fffffff), }; -/* The remaining large window sizes are used only for very low - quality Vorbis files so we don't bother to put them in IRAM */ static LOOKUP_T vwin4096[2048] = { X(0x000001f0), X(0x00001171), X(0x00003072), X(0x00005ef5), X(0x00009cf8), X(0x0000ea7c), X(0x00014780), X(0x0001b405),