Subversion Repositories shark

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
2 pj 1
 
2
/*
3
 * Discrete Cosine Tansform (DCT) for subband synthesis
4
 *
5
 * -funroll-loops (for gcc) will remove the loops for better performance
6
 * using loops in the source-code enhances readabillity
7
 */
8
 
9
/*
10
 * TODO: write an optimized version for the down-sampling modes
11
 *       (in these modes the bands 16-31 (2:1) or 8-31 (4:1) are zero
12
 */
13
 
14
#include "mpg123.h"
15
 
16
void dct64(real *out0,real *out1,real *samples)
17
{
18
  real bufs[64];
19
 
20
 {
21
  register int i,j;
22
  register real *b1,*b2,*bs,*costab;
23
 
24
  b1 = samples;
25
  bs = bufs;
26
  costab = pnts[0]+16;
27
  b2 = b1 + 32;
28
 
29
  for(i=15;i>=0;i--)
30
    *bs++ = (*b1++ + *--b2);
31
  for(i=15;i>=0;i--)
32
    *bs++ = (*--b2 - *b1++) * *--costab;
33
 
34
  b1 = bufs;
35
  costab = pnts[1]+8;
36
  b2 = b1 + 16;
37
 
38
  {
39
    for(i=7;i>=0;i--)
40
      *bs++ = (*b1++ + *--b2);
41
    for(i=7;i>=0;i--)
42
      *bs++ = (*--b2 - *b1++) * *--costab;
43
    b2 += 32;
44
    costab += 8;
45
    for(i=7;i>=0;i--)
46
      *bs++ = (*b1++ + *--b2);
47
    for(i=7;i>=0;i--)
48
      *bs++ = (*b1++ - *--b2) * *--costab;
49
    b2 += 32;
50
  }
51
 
52
  bs = bufs;
53
  costab = pnts[2];
54
  b2 = b1 + 8;
55
 
56
  for(j=2;j;j--)
57
  {
58
    for(i=3;i>=0;i--)
59
      *bs++ = (*b1++ + *--b2);
60
    for(i=3;i>=0;i--)
61
      *bs++ = (*--b2 - *b1++) * costab[i];
62
    b2 += 16;
63
    for(i=3;i>=0;i--)
64
      *bs++ = (*b1++ + *--b2);
65
    for(i=3;i>=0;i--)
66
      *bs++ = (*b1++ - *--b2) * costab[i];
67
    b2 += 16;
68
  }
69
 
70
  b1 = bufs;
71
  costab = pnts[3];
72
  b2 = b1 + 4;
73
 
74
  for(j=4;j;j--)
75
  {
76
    *bs++ = (*b1++ + *--b2);
77
    *bs++ = (*b1++ + *--b2);
78
    *bs++ = (*--b2 - *b1++) * costab[1];
79
    *bs++ = (*--b2 - *b1++) * costab[0];
80
    b2 += 8;
81
    *bs++ = (*b1++ + *--b2);
82
    *bs++ = (*b1++ + *--b2);
83
    *bs++ = (*b1++ - *--b2) * costab[1];
84
    *bs++ = (*b1++ - *--b2) * costab[0];
85
    b2 += 8;
86
  }
87
  bs = bufs;
88
  costab = pnts[4];
89
 
90
  for(j=8;j;j--)
91
  {
92
    real v0,v1;
93
    v0=*b1++; v1 = *b1++;
94
    *bs++ = (v0 + v1);
95
    *bs++ = (v0 - v1) * (*costab);
96
    v0=*b1++; v1 = *b1++;
97
    *bs++ = (v0 + v1);
98
    *bs++ = (v1 - v0) * (*costab);
99
  }
100
 
101
 }
102
 
103
 
104
 {
105
  register real *b1;
106
  register int i;
107
 
108
  for(b1=bufs,i=8;i;i--,b1+=4)
109
    b1[2] += b1[3];
110
 
111
  for(b1=bufs,i=4;i;i--,b1+=8)
112
  {
113
    b1[4] += b1[6];
114
    b1[6] += b1[5];
115
    b1[5] += b1[7];
116
  }
117
 
118
  for(b1=bufs,i=2;i;i--,b1+=16)
119
  {
120
    b1[8]  += b1[12];
121
    b1[12] += b1[10];
122
    b1[10] += b1[14];
123
    b1[14] += b1[9];
124
    b1[9]  += b1[13];
125
    b1[13] += b1[11];
126
    b1[11] += b1[15];
127
  }
128
 }
129
 
130
 
131
  out0[0x10*16] = bufs[0];
132
  out0[0x10*15] = bufs[16+0]  + bufs[16+8];
133
  out0[0x10*14] = bufs[8];
134
  out0[0x10*13] = bufs[16+8]  + bufs[16+4];
135
  out0[0x10*12] = bufs[4];
136
  out0[0x10*11] = bufs[16+4]  + bufs[16+12];
137
  out0[0x10*10] = bufs[12];
138
  out0[0x10* 9] = bufs[16+12] + bufs[16+2];
139
  out0[0x10* 8] = bufs[2];
140
  out0[0x10* 7] = bufs[16+2]  + bufs[16+10];
141
  out0[0x10* 6] = bufs[10];
142
  out0[0x10* 5] = bufs[16+10] + bufs[16+6];
143
  out0[0x10* 4] = bufs[6];
144
  out0[0x10* 3] = bufs[16+6]  + bufs[16+14];
145
  out0[0x10* 2] = bufs[14];
146
  out0[0x10* 1] = bufs[16+14] + bufs[16+1];
147
  out0[0x10* 0] = bufs[1];
148
 
149
  out1[0x10* 0] = bufs[1];
150
  out1[0x10* 1] = bufs[16+1]  + bufs[16+9];
151
  out1[0x10* 2] = bufs[9];
152
  out1[0x10* 3] = bufs[16+9]  + bufs[16+5];
153
  out1[0x10* 4] = bufs[5];
154
  out1[0x10* 5] = bufs[16+5]  + bufs[16+13];
155
  out1[0x10* 6] = bufs[13];
156
  out1[0x10* 7] = bufs[16+13] + bufs[16+3];
157
  out1[0x10* 8] = bufs[3];
158
  out1[0x10* 9] = bufs[16+3]  + bufs[16+11];
159
  out1[0x10*10] = bufs[11];
160
  out1[0x10*11] = bufs[16+11] + bufs[16+7];
161
  out1[0x10*12] = bufs[7];
162
  out1[0x10*13] = bufs[16+7]  + bufs[16+15];
163
  out1[0x10*14] = bufs[15];
164
  out1[0x10*15] = bufs[16+15];
165
 
166
}
167
 
168