summaryrefslogtreecommitdiff
path: root/core/multimedia/opieplayer/libmpeg3/audio/synthesizers.c
Unidiff
Diffstat (limited to 'core/multimedia/opieplayer/libmpeg3/audio/synthesizers.c') (more/less context) (show whitespace changes)
-rw-r--r--core/multimedia/opieplayer/libmpeg3/audio/synthesizers.c174
1 files changed, 174 insertions, 0 deletions
diff --git a/core/multimedia/opieplayer/libmpeg3/audio/synthesizers.c b/core/multimedia/opieplayer/libmpeg3/audio/synthesizers.c
new file mode 100644
index 0000000..71a74b3
--- a/dev/null
+++ b/core/multimedia/opieplayer/libmpeg3/audio/synthesizers.c
@@ -0,0 +1,174 @@
1#include "mpeg3audio.h"
2#include "../libmpeg3.h"
3#include "../mpeg3protos.h"
4#include "tables.h"
5
6#define WRITE_SAMPLE(samples, sum) \
7{ \
8 (*samples) = (sum); \
9}
10
11int mpeg3audio_synth_stereo(mpeg3audio_t *audio, mpeg3_real_t *bandPtr, int channel, mpeg3_real_t *out, int *pnt)
12{
13 const int step = 2;
14 mpeg3_real_t *samples = out + *pnt;
15 register mpeg3_real_t sum;
16 mpeg3_real_t *b0, (*buf)[0x110];
17 int bo1;
18
19 if(!channel)
20 {
21 audio->bo--;
22 audio->bo &= 0xf;
23 buf = audio->synth_stereo_buffs[0];
24 }
25 else
26 {
27 samples++;
28 buf = audio->synth_stereo_buffs[1];
29 }
30
31 if(audio->bo & 0x1)
32 {
33 b0 = buf[0];
34 bo1 = audio->bo;
35 mpeg3audio_dct64(buf[1] + ((audio->bo + 1) & 0xf), buf[0] + audio->bo, bandPtr);
36 }
37 else
38 {
39 b0 = buf[1];
40 bo1 = audio->bo + 1;
41 mpeg3audio_dct64(buf[0] + audio->bo, buf[1] + audio->bo + 1, bandPtr);
42 }
43
44/*printf("%f %f %f\n", buf[0][0], buf[1][0], bandPtr[0]); */
45
46 {
47 register int j;
48 mpeg3_real_t *window = mpeg3_decwin + 16 - bo1;
49
50 for(j = 16; j; j--, b0 += 0x10, window += 0x20, samples += step)
51 {
52 sum = window[0x0] * b0[0x0];
53 sum -= window[0x1] * b0[0x1];
54 sum += window[0x2] * b0[0x2];
55 sum -= window[0x3] * b0[0x3];
56 sum += window[0x4] * b0[0x4];
57 sum -= window[0x5] * b0[0x5];
58 sum += window[0x6] * b0[0x6];
59 sum -= window[0x7] * b0[0x7];
60 sum += window[0x8] * b0[0x8];
61 sum -= window[0x9] * b0[0x9];
62 sum += window[0xA] * b0[0xA];
63 sum -= window[0xB] * b0[0xB];
64 sum += window[0xC] * b0[0xC];
65 sum -= window[0xD] * b0[0xD];
66 sum += window[0xE] * b0[0xE];
67 sum -= window[0xF] * b0[0xF];
68
69 WRITE_SAMPLE(samples, sum);
70 }
71
72 sum = window[0x0] * b0[0x0];
73 sum += window[0x2] * b0[0x2];
74 sum += window[0x4] * b0[0x4];
75 sum += window[0x6] * b0[0x6];
76 sum += window[0x8] * b0[0x8];
77 sum += window[0xA] * b0[0xA];
78 sum += window[0xC] * b0[0xC];
79 sum += window[0xE] * b0[0xE];
80 WRITE_SAMPLE(samples, sum);
81 b0 -= 0x10;
82 window -= 0x20;
83 samples += step;
84 window += bo1 << 1;
85
86 for(j = 15; j; j--, b0 -= 0x10, window -= 0x20, samples += step)
87 {
88 sum = -window[-0x1] * b0[0x0];
89 sum -= window[-0x2] * b0[0x1];
90 sum -= window[-0x3] * b0[0x2];
91 sum -= window[-0x4] * b0[0x3];
92 sum -= window[-0x5] * b0[0x4];
93 sum -= window[-0x6] * b0[0x5];
94 sum -= window[-0x7] * b0[0x6];
95 sum -= window[-0x8] * b0[0x7];
96 sum -= window[-0x9] * b0[0x8];
97 sum -= window[-0xA] * b0[0x9];
98 sum -= window[-0xB] * b0[0xA];
99 sum -= window[-0xC] * b0[0xB];
100 sum -= window[-0xD] * b0[0xC];
101 sum -= window[-0xE] * b0[0xD];
102 sum -= window[-0xF] * b0[0xE];
103 sum -= window[-0x0] * b0[0xF];
104
105 WRITE_SAMPLE(samples, sum);
106 }
107 }
108 *pnt += 64;
109
110 return 0;
111}
112
113int mpeg3audio_synth_mono(mpeg3audio_t *audio, mpeg3_real_t *bandPtr, mpeg3_real_t *samples, int *pnt)
114{
115 mpeg3_real_t *samples_tmp = audio->synth_mono_buff;
116 mpeg3_real_t *tmp1 = samples_tmp;
117 int i, ret;
118 int pnt1 = 0;
119
120 ret = mpeg3audio_synth_stereo(audio, bandPtr, 0, samples_tmp, &pnt1);
121 samples += *pnt;
122
123 for(i = 0; i < 32; i++)
124 {
125 *samples = *tmp1;
126 samples++;
127 tmp1 += 2;
128 }
129 *pnt += 32;
130
131 return ret;
132}
133
134
135/* Call this after every seek to reset the buffers */
136int mpeg3audio_reset_synths(mpeg3audio_t *audio)
137{
138 int i, j, k;
139 for(i = 0; i < 2; i++)
140 {
141 for(j = 0; j < 2; j++)
142 {
143 for(k = 0; k < 0x110; k++)
144 {
145 audio->synth_stereo_buffs[i][j][k] = 0;
146 }
147 }
148 }
149 for(i = 0; i < 64; i++)
150 {
151 audio->synth_mono_buff[i] = 0;
152 audio->layer2_scfsi_buf[i] = 0;
153 }
154 for(i = 0; i < 2; i++)
155 {
156 for(j = 0; j < 2; j++)
157 {
158 for(k = 0; k < SBLIMIT * SSLIMIT; k++)
159 {
160 audio->mp3_block[i][j][k] = 0;
161 }
162 }
163 }
164 audio->mp3_blc[0] = 0;
165 audio->mp3_blc[1] = 0;
166 for(i = 0; i < audio->channels; i++)
167 {
168 for(j = 0; j < AC3_N / 2; j++)
169 {
170 audio->ac3_delay[i][j] = 0;
171 }
172 }
173 return 0;
174}