summaryrefslogtreecommitdiff
path: root/apps
diff options
context:
space:
mode:
Diffstat (limited to 'apps')
-rw-r--r--apps/codecs/libwma/mdct.c63
-rw-r--r--apps/codecs/libwma/mdct.h2
2 files changed, 40 insertions, 25 deletions
diff --git a/apps/codecs/libwma/mdct.c b/apps/codecs/libwma/mdct.c
index e66be0e825..a764f47eed 100644
--- a/apps/codecs/libwma/mdct.c
+++ b/apps/codecs/libwma/mdct.c
@@ -20,7 +20,14 @@
20#include "wmafixed.h" 20#include "wmafixed.h"
21#include "mdct.h" 21#include "mdct.h"
22 22
23fixed32 tcos0[1024], tsin0[1024]; //these are the sin and cos rotations used by the MDCT 23/*these are the sin and cos rotations used by the MDCT*/
24
25/*accessed too infrequently to give much speedup in IRAM*/
26
27fixed32 *tcosarray[5], *tsinarray[5];
28fixed32 tcos0[1024], tcos1[512], tcos2[256], tcos3[128], tcos4[64];
29fixed32 tsin0[1024], tsin1[512], tsin2[256], tsin3[128], tsin4[64];
30
24uint16_t revtab0[1024]; 31uint16_t revtab0[1024];
25 32
26/** 33/**
@@ -28,16 +35,28 @@ uint16_t revtab0[1024];
28 */ 35 */
29int ff_mdct_init(MDCTContext *s, int nbits, int inverse) 36int ff_mdct_init(MDCTContext *s, int nbits, int inverse)
30{ 37{
31 int n; 38 int n, n4, i;
32 // fixed32 alpha;
33 39
34 memset(s, 0, sizeof(*s)); 40 memset(s, 0, sizeof(*s));
35 n = 1 << nbits; //nbits ranges from 12 to 8 inclusive 41 n = 1 << nbits; //nbits ranges from 12 to 8 inclusive
36
37 s->nbits = nbits; 42 s->nbits = nbits;
38 s->n = n; 43 s->n = n;
44 n4 = n >> 2;
45 s->tcos = tcosarray[12-nbits];
46 s->tsin = tsinarray[12-nbits];
47 for(i=0;i<n4;i++)
48 {
49
50 fixed32 ip = itofix32(i) + 0x2000;
51 ip = ip >> nbits;
52
53 /*I can't remember why this works, but it seems to agree for ~24 bits, maybe more!*/
54 s->tsin[i] = - fsincos(ip<<16, &(s->tcos[i]));
55 s->tcos[i] *=-1;
56 }
39 57
40 (&s->fft)->nbits = nbits-2; 58 (&s->fft)->nbits = nbits-2;
59
41 (&s->fft)->inverse = inverse; 60 (&s->fft)->inverse = inverse;
42 61
43 return 0; 62 return 0;
@@ -55,6 +74,8 @@ void ff_imdct_calc(MDCTContext *s,
55 fixed32 *input) 74 fixed32 *input)
56{ 75{
57 int k, n8, n4, n2, n, j,scale; 76 int k, n8, n4, n2, n, j,scale;
77 const fixed32 *tcos = s->tcos;
78 const fixed32 *tsin = s->tsin;
58 const fixed32 *in1, *in2; 79 const fixed32 *in1, *in2;
59 FFTComplex *z1 = (FFTComplex *)output; 80 FFTComplex *z1 = (FFTComplex *)output;
60 FFTComplex *z2 = (FFTComplex *)input; 81 FFTComplex *z2 = (FFTComplex *)input;
@@ -73,21 +94,19 @@ void ff_imdct_calc(MDCTContext *s,
73 94
74 for(k = 0; k < n4; k++) 95 for(k = 0; k < n4; k++)
75 { 96 {
76 int kshift = k<<revtabshift; 97 j=revtab0[k<<revtabshift];
77 j=revtab0[kshift]; 98 CMUL(&z1[j].re, &z1[j].im, *in2, *in1, tcos[k], tsin[k]);
78 CMUL(&z1[j].re, &z1[j].im, *in2, *in1, tcos0[kshift], tsin0[kshift]);
79 in1 += 2; 99 in1 += 2;
80 in2 -= 2; 100 in2 -= 2;
81 } 101 }
82 102
83 scale = fft_calc_unscaled(&s->fft, z1); 103 scale = fft_calc_unscaled(&s->fft, z1);
84 104
85 /* post rotation + reordering */ 105 /* post rotation + reordering */
86 106
87 for(k = 0; k < n4; k++) 107 for(k = 0; k < n4; k++)
88 { 108 {
89 int kshift = k<<revtabshift; 109 CMUL(&z2[k].re, &z2[k].im, (z1[k].re), (z1[k].im), tcos[k], tsin[k]);
90 CMUL(&z2[k].re, &z2[k].im, (z1[k].re), (z1[k].im), tcos0[kshift], tsin0[kshift]);
91 } 110 }
92 111
93 for(k = 0; k < n8; k++) 112 for(k = 0; k < n8; k++)
@@ -116,9 +135,18 @@ void ff_imdct_calc(MDCTContext *s,
116 } 135 }
117} 136}
118 137
138/* init MDCT */
139
119int mdct_init_global(void) 140int mdct_init_global(void)
120{ 141{
121 int i,j,m; 142 int i,j,m;
143
144 /* although seemingly degenerate, these cannot actually be merged together without
145 a substantial increase in error which is unjustified by the tiny memory savings*/
146
147 tcosarray[0] = tcos0; tcosarray[1] = tcos1; tcosarray[2] = tcos2; tcosarray[3] = tcos3;tcosarray[4] = tcos4;
148 tsinarray[0] = tsin0; tsinarray[1] = tsin1; tsinarray[2] = tsin2; tsinarray[3] = tsin3;tsinarray[4] = tsin4;
149
122 /* init the MDCT bit reverse table here rather then in fft_init */ 150 /* init the MDCT bit reverse table here rather then in fft_init */
123 151
124 for(i=0;i<1024;i++) /*hard coded to a 2048 bit rotation*/ 152 for(i=0;i<1024;i++) /*hard coded to a 2048 bit rotation*/
@@ -132,21 +160,6 @@ int mdct_init_global(void)
132 revtab0[i]=m; 160 revtab0[i]=m;
133 } 161 }
134 162
135 for(i=0;i<1024;i++)
136 {
137 //fixed32 pi2 = fixmul32(0x20000, M_PI_F);
138 fixed32 ip = itofix32(i) + 0x2000;
139 ip = ip >> 12;
140 //ip = fixdiv32(ip,itofix32(n)); // PJJ optimize
141 //alpha = fixmul32(TWO_M_PI_F, ip);
142 //s->tcos[i] = -fixcos32(alpha); //alpha between 0 and pi/2
143 //s->tsin[i] = -fixsin32(alpha);
144
145 //I can't remember why this works, but it seems to agree for ~24 bits, maybe more!
146 tsin0[i] = - fsincos(ip<<16, &(tcos0[i]));
147 tcos0[i] *=-1;
148 }
149
150 fft_init_global(); 163 fft_init_global();
151 164
152 return 0; 165 return 0;
diff --git a/apps/codecs/libwma/mdct.h b/apps/codecs/libwma/mdct.h
index 67f510164b..57d65ae9a7 100644
--- a/apps/codecs/libwma/mdct.h
+++ b/apps/codecs/libwma/mdct.h
@@ -25,6 +25,8 @@ typedef struct MDCTContext
25 int n; /* size of MDCT (i.e. number of input data * 2) */ 25 int n; /* size of MDCT (i.e. number of input data * 2) */
26 int nbits; /* n = 2^nbits */ 26 int nbits; /* n = 2^nbits */
27 /* pre/post rotation tables */ 27 /* pre/post rotation tables */
28 fixed32 *tcos;
29 fixed32 *tsin;
28 FFTContext fft; 30 FFTContext fft;
29} 31}
30MDCTContext; 32MDCTContext;