Debian Codegraph @

src/libmpg123/synth_ntom.h

raw
1 /*
2
3
4 This header is used multiple times to create different variants of this function.
5 Hint: MONO_NAME, MONO2STEREO_NAME, SYNTH_NAME and SAMPLE_T as well as WRITE_SAMPLE do vary.
6
7 copyright 1995-2008 by the mpg123 project - free software under the terms of the LGPL 2.1
8 see COPYING and AUTHORS files in distribution or http://mpg123.org
9 initially written by Michael Hipp, generalized by Thomas Orgis
10
11 Well, this is very simple resampling... you may or may not like what you hear.
12 But it's cheap.
13 But still, we don't implement a non-autoincrement version of this one.
14 */
15
16 /* Note: These mono functions would also work generically,
17 it's just that they need a runtime calculation for the conversion loop...
18 The fixed XtoY functions have the chance for loop unrolling... */
19
20 int MONO_NAME(real *bandPtr, mpg123_handle *fr)
21 {
22 SAMPLE_T samples_tmp[8*64];
23 SAMPLE_T *tmp1 = samples_tmp;
24 size_t i;
25 int ret;
26
27 size_t pnt = fr->buffer.fill;
28 unsigned char *samples = fr->buffer.data;
29 fr->buffer.data = (unsigned char*) samples_tmp;
30 fr->buffer.fill = 0;
31 ret = SYNTH_NAME(bandPtr, 0, fr, 1);
32 fr->buffer.data = samples;
33
34 samples += pnt;
35 for(i=0;i<(fr->buffer.fill/(2*sizeof(SAMPLE_T)));i++)
36 {
37 *( (SAMPLE_T *)samples) = *tmp1;
38 samples += sizeof(SAMPLE_T);
39 tmp1 += 2;
40 }
41 fr->buffer.fill = pnt + (fr->buffer.fill/2);
42
43 return ret;
44 }
45
46
47 int MONO2STEREO_NAME(real *bandPtr, mpg123_handle *fr)
48 {
49 size_t i;
50 int ret;
51 size_t pnt1 = fr->buffer.fill;
52 unsigned char *samples = fr->buffer.data + pnt1;
53
54 ret = SYNTH_NAME(bandPtr, 0, fr, 1);
55
56 for(i=0;i<((fr->buffer.fill-pnt1)/(2*sizeof(SAMPLE_T)));i++)
57 {
58 ((SAMPLE_T *)samples)[1] = ((SAMPLE_T *)samples)[0];
59 samples+=2*sizeof(SAMPLE_T);
60 }
61
62 return ret;
63 }
64
65
66 int SYNTH_NAME(real *bandPtr,int channel, mpg123_handle *fr, int final)
67 {
68 static const int step = 2;
69 SAMPLE_T *samples = (SAMPLE_T *) (fr->buffer.data + fr->buffer.fill);
70
71 real *b0, **buf; /* (*buf)[0x110]; */
72 int clip = 0;
73 int bo1;
74 int ntom;
75 #ifndef NO_EQUALIZER
76 if(fr->have_eq_settings) INT123_do_equalizer(bandPtr,channel,fr->equalizer);
77 #endif
78 if(!channel)
79 {
80 fr->bo--;
81 fr->bo &= 0xf;
82 buf = fr->real_buffs[0];
83 ntom = fr->INT123_ntom_val[1] = fr->INT123_ntom_val[0];
84 }
85 else
86 {
87 samples++;
88 buf = fr->real_buffs[1];
89 ntom = fr->INT123_ntom_val[1];
90 }
91
92 if(fr->bo & 0x1)
93 {
94 b0 = buf[0];
95 bo1 = fr->bo;
96 INT123_dct64(buf[1]+((fr->bo+1)&0xf),buf[0]+fr->bo,bandPtr);
97 }
98 else
99 {
100 b0 = buf[1];
101 bo1 = fr->bo+1;
102 INT123_dct64(buf[0]+fr->bo,buf[1]+fr->bo+1,bandPtr);
103 }
104
105 {
106 register int j;
107 real *window = fr->decwin + 16 - bo1;
108
109 for (j=16;j;j--,window+=0x10)
110 {
111 real sum;
112
113 ntom += fr->ntom_step;
114 if(ntom < NTOM_MUL)
115 {
116 window += 16;
117 b0 += 16;
118 continue;
119 }
120
121 sum = REAL_MUL_SYNTH(*window++, *b0++);
122 sum -= REAL_MUL_SYNTH(*window++, *b0++);
123 sum += REAL_MUL_SYNTH(*window++, *b0++);
124 sum -= REAL_MUL_SYNTH(*window++, *b0++);
125 sum += REAL_MUL_SYNTH(*window++, *b0++);
126 sum -= REAL_MUL_SYNTH(*window++, *b0++);
127 sum += REAL_MUL_SYNTH(*window++, *b0++);
128 sum -= REAL_MUL_SYNTH(*window++, *b0++);
129 sum += REAL_MUL_SYNTH(*window++, *b0++);
130 sum -= REAL_MUL_SYNTH(*window++, *b0++);
131 sum += REAL_MUL_SYNTH(*window++, *b0++);
132 sum -= REAL_MUL_SYNTH(*window++, *b0++);
133 sum += REAL_MUL_SYNTH(*window++, *b0++);
134 sum -= REAL_MUL_SYNTH(*window++, *b0++);
135 sum += REAL_MUL_SYNTH(*window++, *b0++);
136 sum -= REAL_MUL_SYNTH(*window++, *b0++);
137
138 while(ntom >= NTOM_MUL)
139 {
140 WRITE_SAMPLE(samples,sum,clip);
141 samples += step;
142 ntom -= NTOM_MUL;
143 }
144 }
145
146 ntom += fr->ntom_step;
147 if(ntom >= NTOM_MUL)
148 {
149 real sum;
150 sum = REAL_MUL_SYNTH(window[0x0], b0[0x0]);
151 sum += REAL_MUL_SYNTH(window[0x2], b0[0x2]);
152 sum += REAL_MUL_SYNTH(window[0x4], b0[0x4]);
153 sum += REAL_MUL_SYNTH(window[0x6], b0[0x6]);
154 sum += REAL_MUL_SYNTH(window[0x8], b0[0x8]);
155 sum += REAL_MUL_SYNTH(window[0xA], b0[0xA]);
156 sum += REAL_MUL_SYNTH(window[0xC], b0[0xC]);
157 sum += REAL_MUL_SYNTH(window[0xE], b0[0xE]);
158
159 while(ntom >= NTOM_MUL)
160 {
161 WRITE_SAMPLE(samples,sum,clip);
162 samples += step;
163 ntom -= NTOM_MUL;
164 }
165 }
166
167 b0-=0x10,window-=0x20;
168 window += bo1<<1;
169
170 for (j=15;j;j--,b0-=0x20,window-=0x10)
171 {
172 real sum;
173
174 ntom += fr->ntom_step;
175 if(ntom < NTOM_MUL)
176 {
177 window -= 16;
178 b0 += 16;
179 continue;
180 }
181
182 sum = REAL_MUL_SYNTH(-*(--window), *b0++);
183 sum -= REAL_MUL_SYNTH(*(--window), *b0++);
184 sum -= REAL_MUL_SYNTH(*(--window), *b0++);
185 sum -= REAL_MUL_SYNTH(*(--window), *b0++);
186 sum -= REAL_MUL_SYNTH(*(--window), *b0++);
187 sum -= REAL_MUL_SYNTH(*(--window), *b0++);
188 sum -= REAL_MUL_SYNTH(*(--window), *b0++);
189 sum -= REAL_MUL_SYNTH(*(--window), *b0++);
190 sum -= REAL_MUL_SYNTH(*(--window), *b0++);
191 sum -= REAL_MUL_SYNTH(*(--window), *b0++);
192 sum -= REAL_MUL_SYNTH(*(--window), *b0++);
193 sum -= REAL_MUL_SYNTH(*(--window), *b0++);
194 sum -= REAL_MUL_SYNTH(*(--window), *b0++);
195 sum -= REAL_MUL_SYNTH(*(--window), *b0++);
196 sum -= REAL_MUL_SYNTH(*(--window), *b0++);
197 sum -= REAL_MUL_SYNTH(*(--window), *b0++);
198
199 while(ntom >= NTOM_MUL)
200 {
201 WRITE_SAMPLE(samples,sum,clip);
202 samples += step;
203 ntom -= NTOM_MUL;
204 }
205 }
206 }
207
208 fr->INT123_ntom_val[channel] = ntom;
209 if(final) fr->buffer.fill = ((unsigned char *) samples - fr->buffer.data - (channel ? sizeof(SAMPLE_T) : 0));
210
211 return clip;
212 }
213