1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
|
/*
* WMA compatible decoder
* Copyright (c) 2002 The FFmpeg Project.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "wmafixed.h"
#include "mdct.h"
/*these are the sin and cos rotations used by the MDCT*/
/*accessed too infrequently to give much speedup in IRAM*/
fixed32 *tcosarray[5], *tsinarray[5];
fixed32 tcos0[1024], tcos1[512], tcos2[256], tcos3[128], tcos4[64];
fixed32 tsin0[1024], tsin1[512], tsin2[256], tsin3[128], tsin4[64];
uint16_t revtab0[1024];
/**
* init MDCT or IMDCT computation.
*/
int ff_mdct_init(MDCTContext *s, int nbits, int inverse)
{
int n, n4, i;
memset(s, 0, sizeof(*s));
n = 1 << nbits; //nbits ranges from 12 to 8 inclusive
s->nbits = nbits;
s->n = n;
n4 = n >> 2;
s->tcos = tcosarray[12-nbits];
s->tsin = tsinarray[12-nbits];
for(i=0;i<n4;i++)
{
fixed32 ip = itofix32(i) + 0x2000;
ip = ip >> nbits;
/*I can't remember why this works, but it seems to agree for ~24 bits, maybe more!*/
s->tsin[i] = - fsincos(ip<<16, &(s->tcos[i]));
s->tcos[i] *=-1;
}
(&s->fft)->nbits = nbits-2;
(&s->fft)->inverse = inverse;
return 0;
}
/**
* Compute inverse MDCT of size N = 2^nbits
* @param output N samples
* @param input N/2 samples
* @param tmp N/2 samples
*/
void ff_imdct_calc(MDCTContext *s,
fixed32 *output,
fixed32 *input)
{
int k, n8, n4, n2, n, j,scale;
const fixed32 *tcos = s->tcos;
const fixed32 *tsin = s->tsin;
const fixed32 *in1, *in2;
FFTComplex *z1 = (FFTComplex *)output;
FFTComplex *z2 = (FFTComplex *)input;
int revtabshift = 12 - s->nbits;
n = 1 << s->nbits;
n2 = n >> 1;
n4 = n >> 2;
n8 = n >> 3;
/* pre rotation */
in1 = input;
in2 = input + n2 - 1;
for(k = 0; k < n4; k++)
{
j=revtab0[k<<revtabshift];
CMUL(&z1[j].re, &z1[j].im, *in2, *in1, tcos[k], tsin[k]);
in1 += 2;
in2 -= 2;
}
scale = fft_calc_unscaled(&s->fft, z1);
/* post rotation + reordering */
for(k = 0; k < n4; k++)
{
CMUL(&z2[k].re, &z2[k].im, (z1[k].re), (z1[k].im), tcos[k], tsin[k]);
}
for(k = 0; k < n8; k++)
{
fixed32 r1,r2,r3,r4,r1n,r2n,r3n;
r1 = z2[n8 + k].im;
r1n = r1 * -1;
r2 = z2[n8-1-k].re;
r2n = r2 * -1;
r3 = z2[k+n8].re;
r3n = r3 * -1;
r4 = z2[n8-k-1].im;
output[2*k] = r1n;
output[n2-1-2*k] = r1;
output[2*k+1] = r2;
output[n2-1-2*k-1] = r2n;
output[n2 + 2*k]= r3n;
output[n-1- 2*k]= r3n;
output[n2 + 2*k+1]= r4;
output[n-2 - 2 * k] = r4;
}
}
/* init MDCT */
int mdct_init_global(void)
{
int i,j,m;
/* although seemingly degenerate, these cannot actually be merged together without
a substantial increase in error which is unjustified by the tiny memory savings*/
tcosarray[0] = tcos0; tcosarray[1] = tcos1; tcosarray[2] = tcos2; tcosarray[3] = tcos3;tcosarray[4] = tcos4;
tsinarray[0] = tsin0; tsinarray[1] = tsin1; tsinarray[2] = tsin2; tsinarray[3] = tsin3;tsinarray[4] = tsin4;
/* init the MDCT bit reverse table here rather then in fft_init */
for(i=0;i<1024;i++) /*hard coded to a 2048 bit rotation*/
{ /*smaller sizes can reuse the largest*/
m=0;
for(j=0;j<10;j++)
{
m |= ((i >> j) & 1) << (10-j-1);
}
revtab0[i]=m;
}
fft_init_global();
return 0;
}
|