/src/mpg123/src/libmpg123/synth_8bit.h
Line | Count | Source |
1 | | /* |
2 | | synth_8bit.h: Wrappers over optimized synth_xtoy for converting signed short to 8bit. |
3 | | |
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, code generalized to the wrapper by Thomas Orgis |
7 | | |
8 | | Only variable is the BLOCK size to choose 1to1, 2to1 or 4to1. |
9 | | Oh, and the names: BASE_SYNTH_NAME, SYNTH_NAME, MONO_NAME, MONO2STEREO_NAME |
10 | | (p.ex. opt_synth_1to1(fr), INT123_synth_1to1_8bit, INT123_synth_1to1_8bit_mono, ...). |
11 | | */ |
12 | | |
13 | | int SYNTH_NAME(real *bandPtr, int channel, mpg123_handle *fr, int final) |
14 | 0 | { |
15 | 0 | short samples_tmp[BLOCK]; |
16 | 0 | short *tmp1 = samples_tmp + channel; |
17 | 0 | int i,ret; |
18 | |
|
19 | 0 | unsigned char *samples = fr->buffer.data; |
20 | 0 | int pnt = fr->buffer.fill; |
21 | 0 | fr->buffer.data = (unsigned char*) samples_tmp; |
22 | 0 | fr->buffer.fill = 0; |
23 | 0 | ret = BASE_SYNTH_NAME(bandPtr, channel, fr , 0); |
24 | 0 | fr->buffer.data = samples; |
25 | |
|
26 | 0 | samples += channel + pnt; |
27 | 0 | for(i=0;i<(BLOCK/2);i++) |
28 | 0 | { |
29 | 0 | *samples = fr->conv16to8[*tmp1>>AUSHIFT]; |
30 | 0 | samples += 2; |
31 | 0 | tmp1 += 2; |
32 | 0 | } |
33 | 0 | fr->buffer.fill = pnt + (final ? BLOCK : 0 ); |
34 | |
|
35 | 0 | return ret; |
36 | 0 | } |
37 | | |
38 | | int MONO_NAME(real *bandPtr, mpg123_handle *fr) |
39 | 0 | { |
40 | 0 | short samples_tmp[BLOCK]; |
41 | 0 | short *tmp1 = samples_tmp; |
42 | 0 | int i,ret; |
43 | | |
44 | 0 | unsigned char *samples = fr->buffer.data; |
45 | 0 | int pnt = fr->buffer.fill; |
46 | 0 | fr->buffer.data = (unsigned char*) samples_tmp; |
47 | 0 | fr->buffer.fill = 0; |
48 | 0 | ret = BASE_SYNTH_NAME(bandPtr, 0, fr, 0); |
49 | 0 | fr->buffer.data = samples; |
50 | |
|
51 | 0 | samples += pnt; |
52 | 0 | for(i=0;i<(BLOCK/2);i++) |
53 | 0 | { |
54 | 0 | *samples++ = fr->conv16to8[*tmp1>>AUSHIFT]; |
55 | 0 | tmp1+=2; |
56 | 0 | } |
57 | 0 | fr->buffer.fill = pnt + BLOCK/2; |
58 | |
|
59 | 0 | return ret; |
60 | 0 | } |
61 | | |
62 | | int MONO2STEREO_NAME(real *bandPtr, mpg123_handle *fr) |
63 | 0 | { |
64 | 0 | short samples_tmp[BLOCK]; |
65 | 0 | short *tmp1 = samples_tmp; |
66 | 0 | int i,ret; |
67 | |
|
68 | 0 | unsigned char *samples = fr->buffer.data; |
69 | 0 | int pnt = fr->buffer.fill; |
70 | 0 | fr->buffer.data = (unsigned char*) samples_tmp; |
71 | 0 | fr->buffer.fill = 0; |
72 | 0 | ret = BASE_SYNTH_NAME(bandPtr, 0, fr, 0); |
73 | 0 | fr->buffer.data = samples; |
74 | |
|
75 | 0 | samples += pnt; |
76 | 0 | for(i=0;i<(BLOCK/2);i++) |
77 | 0 | { |
78 | 0 | *samples++ = fr->conv16to8[*tmp1>>AUSHIFT]; |
79 | 0 | *samples++ = fr->conv16to8[*tmp1>>AUSHIFT]; |
80 | 0 | tmp1 += 2; |
81 | 0 | } |
82 | 0 | fr->buffer.fill = pnt + BLOCK; |
83 | |
|
84 | 0 | return ret; |
85 | 0 | } |
86 | | |