0029a92c70541787f2427558b3a732d4be82a824
[reactos.git] / reactos / dll / win32 / winemp3.acm / decode_i386.c
1 /*
2 * Mpeg Layer-1,2,3 audio decoder
3 * ------------------------------
4 * copyright (c) 1995,1996,1997 by Michael Hipp, All rights reserved.
5 * See also 'README'
6 *
7 * Slightly optimized for machines without autoincrement/decrement.
8 * The performance is highly compiler dependent. Maybe
9 * the decode.c version for 'normal' processor may be faster
10 * even for Intel processors.
11 *
12 * This library is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU Lesser General Public
14 * License as published by the Free Software Foundation; either
15 * version 2.1 of the License, or (at your option) any later version.
16 *
17 * This library is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 * Lesser General Public License for more details.
21 *
22 * You should have received a copy of the GNU Lesser General Public
23 * License along with this library; if not, write to the Free Software
24 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
25 */
26
27 #include <stdlib.h>
28 #include <math.h>
29 #include <string.h>
30
31 #include "mpg123.h"
32 #include "mpglib.h"
33
34 /* old WRITE_SAMPLE */
35 #define WRITE_SAMPLE(samples,sum,clip) \
36 if( (sum) > 32767.0) { *(samples) = 0x7fff; (clip)++; } \
37 else if( (sum) < -32768.0) { *(samples) = -0x8000; (clip)++; } \
38 else { *(samples) = sum; }
39
40 int synth_1to1_mono(struct mpstr *mp,real *bandPtr,unsigned char *samples,int *pnt)
41 {
42 short samples_tmp[64];
43 short *tmp1 = samples_tmp;
44 int i,ret;
45 int pnt1 = 0;
46
47 ret = synth_1to1(mp,bandPtr,0,(unsigned char *) samples_tmp,&pnt1);
48 samples += *pnt;
49
50 for(i=0;i<32;i++) {
51 *( (short *) samples) = *tmp1;
52 samples += 2;
53 tmp1 += 2;
54 }
55 *pnt += 64;
56
57 return ret;
58 }
59
60
61 int synth_1to1(struct mpstr *mp,real *bandPtr,int channel,unsigned char *out,int *pnt)
62 {
63 static const int step = 2;
64 int bo;
65 short *samples = (short *) (out + *pnt);
66
67 real *b0,(*buf)[0x110];
68 int clip = 0;
69 int bo1;
70
71 bo = mp->synth_bo;
72
73 if(!channel) {
74 bo--;
75 bo &= 0xf;
76 buf = mp->synth_buffs[0];
77 }
78 else {
79 samples++;
80 buf = mp->synth_buffs[1];
81 }
82
83 if(bo & 0x1) {
84 b0 = buf[0];
85 bo1 = bo;
86 dct64(buf[1]+((bo+1)&0xf),buf[0]+bo,bandPtr);
87 }
88 else {
89 b0 = buf[1];
90 bo1 = bo+1;
91 dct64(buf[0]+bo,buf[1]+bo+1,bandPtr);
92 }
93
94 mp->synth_bo = bo;
95
96 {
97 register int j;
98 real *window = decwin + 16 - bo1;
99
100 for (j=16;j;j--,b0+=0x10,window+=0x20,samples+=step)
101 {
102 real sum;
103 sum = window[0x0] * b0[0x0];
104 sum -= window[0x1] * b0[0x1];
105 sum += window[0x2] * b0[0x2];
106 sum -= window[0x3] * b0[0x3];
107 sum += window[0x4] * b0[0x4];
108 sum -= window[0x5] * b0[0x5];
109 sum += window[0x6] * b0[0x6];
110 sum -= window[0x7] * b0[0x7];
111 sum += window[0x8] * b0[0x8];
112 sum -= window[0x9] * b0[0x9];
113 sum += window[0xA] * b0[0xA];
114 sum -= window[0xB] * b0[0xB];
115 sum += window[0xC] * b0[0xC];
116 sum -= window[0xD] * b0[0xD];
117 sum += window[0xE] * b0[0xE];
118 sum -= window[0xF] * b0[0xF];
119
120 WRITE_SAMPLE(samples,sum,clip);
121 }
122
123 {
124 real sum;
125 sum = window[0x0] * b0[0x0];
126 sum += window[0x2] * b0[0x2];
127 sum += window[0x4] * b0[0x4];
128 sum += window[0x6] * b0[0x6];
129 sum += window[0x8] * b0[0x8];
130 sum += window[0xA] * b0[0xA];
131 sum += window[0xC] * b0[0xC];
132 sum += window[0xE] * b0[0xE];
133 WRITE_SAMPLE(samples,sum,clip);
134 b0-=0x10,window-=0x20,samples+=step;
135 }
136 window += bo1<<1;
137
138 for (j=15;j;j--,b0-=0x10,window-=0x20,samples+=step)
139 {
140 real sum;
141 sum = -window[-0x1] * b0[0x0];
142 sum -= window[-0x2] * b0[0x1];
143 sum -= window[-0x3] * b0[0x2];
144 sum -= window[-0x4] * b0[0x3];
145 sum -= window[-0x5] * b0[0x4];
146 sum -= window[-0x6] * b0[0x5];
147 sum -= window[-0x7] * b0[0x6];
148 sum -= window[-0x8] * b0[0x7];
149 sum -= window[-0x9] * b0[0x8];
150 sum -= window[-0xA] * b0[0x9];
151 sum -= window[-0xB] * b0[0xA];
152 sum -= window[-0xC] * b0[0xB];
153 sum -= window[-0xD] * b0[0xC];
154 sum -= window[-0xE] * b0[0xD];
155 sum -= window[-0xF] * b0[0xE];
156 sum -= window[-0x0] * b0[0xF];
157
158 WRITE_SAMPLE(samples,sum,clip);
159 }
160 }
161 *pnt += 128;
162
163 return clip;
164 }