mpg123: Import upstream release 1.32.2.
[wine.git] / libs / mpg123 / src / libmpg123 / synth_s32.c
blob4c99847f2092b6a609893805c3ccf6d0e142c67a
1 /*
2 synth_s32.c: The functions for synthesizing real (float) samples, at the end of decoding.
4 copyright 1995-2008 by the mpg123 project - free software under the terms of the LGPL 2.1
5 see COPYING and AUTHORS files in distribution or http://mpg123.org
6 initially written by Michael Hipp, heavily dissected and rearranged by Thomas Orgis
7 */
9 #include "mpg123lib_intern.h"
10 #include "sample.h"
11 #include "debug.h"
13 #ifdef REAL_IS_FIXED
14 #error "Do not build this file with fixed point math!"
15 #else
16 /*
17 Part 4: All synth functions that produce signed 32 bit output.
18 What we need is just a special WRITE_SAMPLE.
21 #define SAMPLE_T int32_t
22 #define WRITE_SAMPLE(samples,sum,clip) WRITE_S32_SAMPLE(samples,sum,clip)
24 /* Part 4a: All straight 1to1 decoding functions */
25 #define BLOCK 0x40 /* One decoding block is 64 samples. */
27 #define SYNTH_NAME INT123_synth_1to1_s32
28 #include "synth.h"
29 #undef SYNTH_NAME
31 /* Mono-related synths; they wrap over _some_ INT123_synth_1to1_s32 (could be generic, could be i386). */
32 #define SYNTH_NAME fr->synths.plain[r_1to1][f_32]
33 #define MONO_NAME INT123_synth_1to1_s32_mono
34 #define MONO2STEREO_NAME INT123_synth_1to1_s32_m2s
35 #include "synth_mono.h"
36 #undef SYNTH_NAME
37 #undef MONO_NAME
38 #undef MONO2STEREO_NAME
40 #ifdef OPT_X86
41 #define NO_AUTOINCREMENT
42 #define SYNTH_NAME INT123_synth_1to1_s32_i386
43 #include "synth.h"
44 #undef SYNTH_NAME
45 /* i386 uses the normal mono functions. */
46 #undef NO_AUTOINCREMENT
47 #endif
49 #ifdef OPT_X86_64
50 /* Assembler routines. */
51 int INT123_synth_1to1_s32_x86_64_asm(real *window, real *b0, int32_t *samples, int bo1);
52 int INT123_synth_1to1_s32_s_x86_64_asm(real *window, real *b0l, real *b0r, int32_t *samples, int bo1);
53 void INT123_dct64_real_x86_64(real *out0, real *out1, real *samples);
54 /* Hull for C mpg123 API */
55 int INT123_synth_1to1_s32_x86_64(real *bandPtr,int channel, mpg123_handle *fr, int final)
57 int32_t *samples = (int32_t *) (fr->buffer.data+fr->buffer.fill);
59 real *b0, **buf;
60 int bo1;
61 int clip;
62 #ifndef NO_EQUALIZER
63 if(fr->have_eq_settings) INT123_do_equalizer(bandPtr,channel,fr->equalizer);
64 #endif
65 if(!channel)
67 fr->bo--;
68 fr->bo &= 0xf;
69 buf = fr->real_buffs[0];
71 else
73 samples++;
74 buf = fr->real_buffs[1];
77 if(fr->bo & 0x1)
79 b0 = buf[0];
80 bo1 = fr->bo;
81 INT123_dct64_real_x86_64(buf[1]+((fr->bo+1)&0xf),buf[0]+fr->bo,bandPtr);
83 else
85 b0 = buf[1];
86 bo1 = fr->bo+1;
87 INT123_dct64_real_x86_64(buf[0]+fr->bo,buf[1]+fr->bo+1,bandPtr);
90 clip = INT123_synth_1to1_s32_x86_64_asm(fr->decwin, b0, samples, bo1);
92 if(final) fr->buffer.fill += 256;
94 return clip;
98 int INT123_synth_1to1_s32_stereo_x86_64(real *bandPtr_l, real *bandPtr_r, mpg123_handle *fr)
100 int32_t *samples = (int32_t *) (fr->buffer.data+fr->buffer.fill);
102 real *b0l, *b0r, **bufl, **bufr;
103 int bo1;
104 int clip;
105 #ifndef NO_EQUALIZER
106 if(fr->have_eq_settings)
108 INT123_do_equalizer(bandPtr_l,0,fr->equalizer);
109 INT123_do_equalizer(bandPtr_r,1,fr->equalizer);
111 #endif
112 fr->bo--;
113 fr->bo &= 0xf;
114 bufl = fr->real_buffs[0];
115 bufr = fr->real_buffs[1];
117 if(fr->bo & 0x1)
119 b0l = bufl[0];
120 b0r = bufr[0];
121 bo1 = fr->bo;
122 INT123_dct64_real_x86_64(bufl[1]+((fr->bo+1)&0xf),bufl[0]+fr->bo,bandPtr_l);
123 INT123_dct64_real_x86_64(bufr[1]+((fr->bo+1)&0xf),bufr[0]+fr->bo,bandPtr_r);
125 else
127 b0l = bufl[1];
128 b0r = bufr[1];
129 bo1 = fr->bo+1;
130 INT123_dct64_real_x86_64(bufl[0]+fr->bo,bufl[1]+fr->bo+1,bandPtr_l);
131 INT123_dct64_real_x86_64(bufr[0]+fr->bo,bufr[1]+fr->bo+1,bandPtr_r);
134 clip = INT123_synth_1to1_s32_s_x86_64_asm(fr->decwin, b0l, b0r, samples, bo1);
136 fr->buffer.fill += 256;
138 return clip;
140 #endif
142 #ifdef OPT_AVX
143 /* Assembler routines. */
144 #ifndef OPT_x86_64
145 int INT123_synth_1to1_s32_x86_64_asm(real *window, real *b0, int32_t *samples, int bo1);
146 #endif
147 int INT123_synth_1to1_s32_s_avx_asm(real *window, real *b0l, real *b0r, int32_t *samples, int bo1);
148 void INT123_dct64_real_avx(real *out0, real *out1, real *samples);
149 /* Hull for C mpg123 API */
150 int INT123_synth_1to1_s32_avx(real *bandPtr,int channel, mpg123_handle *fr, int final)
152 int32_t *samples = (int32_t *) (fr->buffer.data+fr->buffer.fill);
154 real *b0, **buf;
155 int bo1;
156 int clip;
157 #ifndef NO_EQUALIZER
158 if(fr->have_eq_settings) INT123_do_equalizer(bandPtr,channel,fr->equalizer);
159 #endif
160 if(!channel)
162 fr->bo--;
163 fr->bo &= 0xf;
164 buf = fr->real_buffs[0];
166 else
168 samples++;
169 buf = fr->real_buffs[1];
172 if(fr->bo & 0x1)
174 b0 = buf[0];
175 bo1 = fr->bo;
176 INT123_dct64_real_avx(buf[1]+((fr->bo+1)&0xf),buf[0]+fr->bo,bandPtr);
178 else
180 b0 = buf[1];
181 bo1 = fr->bo+1;
182 INT123_dct64_real_avx(buf[0]+fr->bo,buf[1]+fr->bo+1,bandPtr);
185 clip = INT123_synth_1to1_s32_x86_64_asm(fr->decwin, b0, samples, bo1);
187 if(final) fr->buffer.fill += 256;
189 return clip;
193 int INT123_synth_1to1_s32_stereo_avx(real *bandPtr_l, real *bandPtr_r, mpg123_handle *fr)
195 int32_t *samples = (int32_t *) (fr->buffer.data+fr->buffer.fill);
197 real *b0l, *b0r, **bufl, **bufr;
198 int bo1;
199 int clip;
200 #ifndef NO_EQUALIZER
201 if(fr->have_eq_settings)
203 INT123_do_equalizer(bandPtr_l,0,fr->equalizer);
204 INT123_do_equalizer(bandPtr_r,1,fr->equalizer);
206 #endif
207 fr->bo--;
208 fr->bo &= 0xf;
209 bufl = fr->real_buffs[0];
210 bufr = fr->real_buffs[1];
212 if(fr->bo & 0x1)
214 b0l = bufl[0];
215 b0r = bufr[0];
216 bo1 = fr->bo;
217 INT123_dct64_real_avx(bufl[1]+((fr->bo+1)&0xf),bufl[0]+fr->bo,bandPtr_l);
218 INT123_dct64_real_avx(bufr[1]+((fr->bo+1)&0xf),bufr[0]+fr->bo,bandPtr_r);
220 else
222 b0l = bufl[1];
223 b0r = bufr[1];
224 bo1 = fr->bo+1;
225 INT123_dct64_real_avx(bufl[0]+fr->bo,bufl[1]+fr->bo+1,bandPtr_l);
226 INT123_dct64_real_avx(bufr[0]+fr->bo,bufr[1]+fr->bo+1,bandPtr_r);
229 clip = INT123_synth_1to1_s32_s_avx_asm(fr->decwin, b0l, b0r, samples, bo1);
231 fr->buffer.fill += 256;
233 return clip;
235 #endif
237 #if defined(OPT_SSE) || defined(OPT_SSE_VINTAGE)
238 /* Assembler routines. */
239 int INT123_synth_1to1_s32_sse_asm(real *window, real *b0, int32_t *samples, int bo1);
240 int INT123_synth_1to1_s32_s_sse_asm(real *window, real *b0l, real *b0r, int32_t *samples, int bo1);
241 void INT123_dct64_real_sse(real *out0, real *out1, real *samples);
242 /* Hull for C mpg123 API */
243 int INT123_synth_1to1_s32_sse(real *bandPtr,int channel, mpg123_handle *fr, int final)
245 int32_t *samples = (int32_t *) (fr->buffer.data+fr->buffer.fill);
247 real *b0, **buf;
248 int bo1;
249 int clip;
250 #ifndef NO_EQUALIZER
251 if(fr->have_eq_settings) INT123_do_equalizer(bandPtr,channel,fr->equalizer);
252 #endif
253 if(!channel)
255 fr->bo--;
256 fr->bo &= 0xf;
257 buf = fr->real_buffs[0];
259 else
261 samples++;
262 buf = fr->real_buffs[1];
265 if(fr->bo & 0x1)
267 b0 = buf[0];
268 bo1 = fr->bo;
269 INT123_dct64_real_sse(buf[1]+((fr->bo+1)&0xf),buf[0]+fr->bo,bandPtr);
271 else
273 b0 = buf[1];
274 bo1 = fr->bo+1;
275 INT123_dct64_real_sse(buf[0]+fr->bo,buf[1]+fr->bo+1,bandPtr);
278 clip = INT123_synth_1to1_s32_sse_asm(fr->decwin, b0, samples, bo1);
280 if(final) fr->buffer.fill += 256;
282 return clip;
286 int INT123_synth_1to1_s32_stereo_sse(real *bandPtr_l, real *bandPtr_r, mpg123_handle *fr)
288 int32_t *samples = (int32_t *) (fr->buffer.data+fr->buffer.fill);
290 real *b0l, *b0r, **bufl, **bufr;
291 int bo1;
292 int clip;
293 #ifndef NO_EQUALIZER
294 if(fr->have_eq_settings)
296 INT123_do_equalizer(bandPtr_l,0,fr->equalizer);
297 INT123_do_equalizer(bandPtr_r,1,fr->equalizer);
299 #endif
300 fr->bo--;
301 fr->bo &= 0xf;
302 bufl = fr->real_buffs[0];
303 bufr = fr->real_buffs[1];
305 if(fr->bo & 0x1)
307 b0l = bufl[0];
308 b0r = bufr[0];
309 bo1 = fr->bo;
310 INT123_dct64_real_sse(bufl[1]+((fr->bo+1)&0xf),bufl[0]+fr->bo,bandPtr_l);
311 INT123_dct64_real_sse(bufr[1]+((fr->bo+1)&0xf),bufr[0]+fr->bo,bandPtr_r);
313 else
315 b0l = bufl[1];
316 b0r = bufr[1];
317 bo1 = fr->bo+1;
318 INT123_dct64_real_sse(bufl[0]+fr->bo,bufl[1]+fr->bo+1,bandPtr_l);
319 INT123_dct64_real_sse(bufr[0]+fr->bo,bufr[1]+fr->bo+1,bandPtr_r);
322 clip = INT123_synth_1to1_s32_s_sse_asm(fr->decwin, b0l, b0r, samples, bo1);
324 fr->buffer.fill += 256;
326 return clip;
328 #endif
330 #ifdef OPT_NEON
331 /* Assembler routines. */
332 int INT123_synth_1to1_s32_neon_asm(real *window, real *b0, int32_t *samples, int bo1);
333 int INT123_synth_1to1_s32_s_neon_asm(real *window, real *b0l, real *b0r, int32_t *samples, int bo1);
334 void INT123_dct64_real_neon(real *out0, real *out1, real *samples);
335 /* Hull for C mpg123 API */
336 int INT123_synth_1to1_s32_neon(real *bandPtr,int channel, mpg123_handle *fr, int final)
338 int32_t *samples = (int32_t *) (fr->buffer.data+fr->buffer.fill);
340 real *b0, **buf;
341 int bo1;
342 int clip;
343 #ifndef NO_EQUALIZER
344 if(fr->have_eq_settings) INT123_do_equalizer(bandPtr,channel,fr->equalizer);
345 #endif
346 if(!channel)
348 fr->bo--;
349 fr->bo &= 0xf;
350 buf = fr->real_buffs[0];
352 else
354 samples++;
355 buf = fr->real_buffs[1];
358 if(fr->bo & 0x1)
360 b0 = buf[0];
361 bo1 = fr->bo;
362 INT123_dct64_real_neon(buf[1]+((fr->bo+1)&0xf),buf[0]+fr->bo,bandPtr);
364 else
366 b0 = buf[1];
367 bo1 = fr->bo+1;
368 INT123_dct64_real_neon(buf[0]+fr->bo,buf[1]+fr->bo+1,bandPtr);
371 clip = INT123_synth_1to1_s32_neon_asm(fr->decwin, b0, samples, bo1);
373 if(final) fr->buffer.fill += 256;
375 return clip;
378 int INT123_synth_1to1_s32_stereo_neon(real *bandPtr_l, real *bandPtr_r, mpg123_handle *fr)
380 int32_t *samples = (int32_t *) (fr->buffer.data+fr->buffer.fill);
382 real *b0l, *b0r, **bufl, **bufr;
383 int bo1;
384 int clip;
385 #ifndef NO_EQUALIZER
386 if(fr->have_eq_settings)
388 INT123_do_equalizer(bandPtr_l,0,fr->equalizer);
389 INT123_do_equalizer(bandPtr_r,1,fr->equalizer);
391 #endif
392 fr->bo--;
393 fr->bo &= 0xf;
394 bufl = fr->real_buffs[0];
395 bufr = fr->real_buffs[1];
397 if(fr->bo & 0x1)
399 b0l = bufl[0];
400 b0r = bufr[0];
401 bo1 = fr->bo;
402 INT123_dct64_real_neon(bufl[1]+((fr->bo+1)&0xf),bufl[0]+fr->bo,bandPtr_l);
403 INT123_dct64_real_neon(bufr[1]+((fr->bo+1)&0xf),bufr[0]+fr->bo,bandPtr_r);
405 else
407 b0l = bufl[1];
408 b0r = bufr[1];
409 bo1 = fr->bo+1;
410 INT123_dct64_real_neon(bufl[0]+fr->bo,bufl[1]+fr->bo+1,bandPtr_l);
411 INT123_dct64_real_neon(bufr[0]+fr->bo,bufr[1]+fr->bo+1,bandPtr_r);
414 clip = INT123_synth_1to1_s32_s_neon_asm(fr->decwin, b0l, b0r, samples, bo1);
416 fr->buffer.fill += 256;
418 return clip;
420 #endif
422 #ifdef OPT_NEON64
423 /* Assembler routines. */
424 int INT123_synth_1to1_s32_neon64_asm(real *window, real *b0, int32_t *samples, int bo1);
425 int INT123_synth_1to1_s32_s_neon64_asm(real *window, real *b0l, real *b0r, int32_t *samples, int bo1);
426 void INT123_dct64_real_neon64(real *out0, real *out1, real *samples);
427 /* Hull for C mpg123 API */
428 int INT123_synth_1to1_s32_neon64(real *bandPtr,int channel, mpg123_handle *fr, int final)
430 int32_t *samples = (int32_t *) (fr->buffer.data+fr->buffer.fill);
432 real *b0, **buf;
433 int bo1;
434 int clip;
435 #ifndef NO_EQUALIZER
436 if(fr->have_eq_settings) INT123_do_equalizer(bandPtr,channel,fr->equalizer);
437 #endif
438 if(!channel)
440 fr->bo--;
441 fr->bo &= 0xf;
442 buf = fr->real_buffs[0];
444 else
446 samples++;
447 buf = fr->real_buffs[1];
450 if(fr->bo & 0x1)
452 b0 = buf[0];
453 bo1 = fr->bo;
454 INT123_dct64_real_neon64(buf[1]+((fr->bo+1)&0xf),buf[0]+fr->bo,bandPtr);
456 else
458 b0 = buf[1];
459 bo1 = fr->bo+1;
460 INT123_dct64_real_neon64(buf[0]+fr->bo,buf[1]+fr->bo+1,bandPtr);
463 clip = INT123_synth_1to1_s32_neon64_asm(fr->decwin, b0, samples, bo1);
465 if(final) fr->buffer.fill += 256;
467 return clip;
470 int INT123_synth_1to1_s32st_neon64(real *bandPtr_l, real *bandPtr_r, mpg123_handle *fr)
472 int32_t *samples = (int32_t *) (fr->buffer.data+fr->buffer.fill);
474 real *b0l, *b0r, **bufl, **bufr;
475 int bo1;
476 int clip;
477 #ifndef NO_EQUALIZER
478 if(fr->have_eq_settings)
480 INT123_do_equalizer(bandPtr_l,0,fr->equalizer);
481 INT123_do_equalizer(bandPtr_r,1,fr->equalizer);
483 #endif
484 fr->bo--;
485 fr->bo &= 0xf;
486 bufl = fr->real_buffs[0];
487 bufr = fr->real_buffs[1];
489 if(fr->bo & 0x1)
491 b0l = bufl[0];
492 b0r = bufr[0];
493 bo1 = fr->bo;
494 INT123_dct64_real_neon64(bufl[1]+((fr->bo+1)&0xf),bufl[0]+fr->bo,bandPtr_l);
495 INT123_dct64_real_neon64(bufr[1]+((fr->bo+1)&0xf),bufr[0]+fr->bo,bandPtr_r);
497 else
499 b0l = bufl[1];
500 b0r = bufr[1];
501 bo1 = fr->bo+1;
502 INT123_dct64_real_neon64(bufl[0]+fr->bo,bufl[1]+fr->bo+1,bandPtr_l);
503 INT123_dct64_real_neon64(bufr[0]+fr->bo,bufr[1]+fr->bo+1,bandPtr_r);
506 clip = INT123_synth_1to1_s32_s_neon64_asm(fr->decwin, b0l, b0r, samples, bo1);
508 fr->buffer.fill += 256;
510 return clip;
512 #endif
514 #undef BLOCK
516 #ifndef NO_DOWNSAMPLE
519 Part 4b: 2to1 synth. Only generic and i386.
521 #define BLOCK 0x20 /* One decoding block is 32 samples. */
523 #define SYNTH_NAME INT123_synth_2to1_s32
524 #include "synth.h"
525 #undef SYNTH_NAME
527 /* Mono-related synths; they wrap over _some_ INT123_synth_2to1_s32 (could be generic, could be i386). */
528 #define SYNTH_NAME fr->synths.plain[r_2to1][f_32]
529 #define MONO_NAME INT123_synth_2to1_s32_mono
530 #define MONO2STEREO_NAME INT123_synth_2to1_s32_m2s
531 #include "synth_mono.h"
532 #undef SYNTH_NAME
533 #undef MONO_NAME
534 #undef MONO2STEREO_NAME
536 #ifdef OPT_X86
537 #define NO_AUTOINCREMENT
538 #define SYNTH_NAME INT123_synth_2to1_s32_i386
539 #include "synth.h"
540 #undef SYNTH_NAME
541 /* i386 uses the normal mono functions. */
542 #undef NO_AUTOINCREMENT
543 #endif
545 #undef BLOCK
548 Part 4c: 4to1 synth. Only generic and i386.
550 #define BLOCK 0x10 /* One decoding block is 16 samples. */
552 #define SYNTH_NAME INT123_synth_4to1_s32
553 #include "synth.h"
554 #undef SYNTH_NAME
556 /* Mono-related synths; they wrap over _some_ INT123_synth_4to1_s32 (could be generic, could be i386). */
557 #define SYNTH_NAME fr->synths.plain[r_4to1][f_32]
558 #define MONO_NAME INT123_synth_4to1_s32_mono
559 #define MONO2STEREO_NAME INT123_synth_4to1_s32_m2s
560 #include "synth_mono.h"
561 #undef SYNTH_NAME
562 #undef MONO_NAME
563 #undef MONO2STEREO_NAME
565 #ifdef OPT_X86
566 #define NO_AUTOINCREMENT
567 #define SYNTH_NAME INT123_synth_4to1_s32_i386
568 #include "synth.h"
569 #undef SYNTH_NAME
570 /* i386 uses the normal mono functions. */
571 #undef NO_AUTOINCREMENT
572 #endif
574 #undef BLOCK
576 #endif /* NO_DOWNSAMPLE */
578 #ifndef NO_NTOM
580 Part 4d: ntom synth.
581 Same procedure as above... Just no extra play anymore, straight synth that may use an optimized INT123_dct64.
584 /* These are all in one header, there's no flexibility to gain. */
585 #define SYNTH_NAME INT123_synth_ntom_s32
586 #define MONO_NAME INT123_synth_ntom_s32_mono
587 #define MONO2STEREO_NAME INT123_synth_ntom_s32_m2s
588 #include "synth_ntom.h"
589 #undef SYNTH_NAME
590 #undef MONO_NAME
591 #undef MONO2STEREO_NAME
593 #endif
595 #undef SAMPLE_T
596 #undef WRITE_SAMPLE
598 #endif /* non-fixed type */