wine.inf: We should not override existing associations.
[wine/hacks.git] / dlls / winemp3.acm / decode_i386.c
blob575c53cdd7e5059a095192b17e60ff1ceabe90fe
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'
7 * slighlty optimized for machines without autoincrement/decrement.
8 * The performance is highly compiler dependend. Maybe
9 * the decode.c version for 'normal' processor may be faster
10 * even for Intel processors.
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.
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.
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
27 #include <stdlib.h>
28 #include <math.h>
29 #include <string.h>
31 #include "mpg123.h"
32 #include "mpglib.h"
34 extern struct mpstr *gmp;
36 /* old WRITE_SAMPLE */
37 #define WRITE_SAMPLE(samples,sum,clip) \
38 if( (sum) > 32767.0) { *(samples) = 0x7fff; (clip)++; } \
39 else if( (sum) < -32768.0) { *(samples) = -0x8000; (clip)++; } \
40 else { *(samples) = sum; }
42 int synth_1to1_mono(real *bandPtr,unsigned char *samples,int *pnt)
44 short samples_tmp[64];
45 short *tmp1 = samples_tmp;
46 int i,ret;
47 int pnt1 = 0;
49 ret = synth_1to1(bandPtr,0,(unsigned char *) samples_tmp,&pnt1);
50 samples += *pnt;
52 for(i=0;i<32;i++) {
53 *( (short *) samples) = *tmp1;
54 samples += 2;
55 tmp1 += 2;
57 *pnt += 64;
59 return ret;
63 int synth_1to1(real *bandPtr,int channel,unsigned char *out,int *pnt)
65 static const int step = 2;
66 int bo;
67 short *samples = (short *) (out + *pnt);
69 real *b0,(*buf)[0x110];
70 int clip = 0;
71 int bo1;
73 bo = gmp->synth_bo;
75 if(!channel) {
76 bo--;
77 bo &= 0xf;
78 buf = gmp->synth_buffs[0];
80 else {
81 samples++;
82 buf = gmp->synth_buffs[1];
85 if(bo & 0x1) {
86 b0 = buf[0];
87 bo1 = bo;
88 dct64(buf[1]+((bo+1)&0xf),buf[0]+bo,bandPtr);
90 else {
91 b0 = buf[1];
92 bo1 = bo+1;
93 dct64(buf[0]+bo,buf[1]+bo+1,bandPtr);
96 gmp->synth_bo = bo;
99 register int j;
100 real *window = decwin + 16 - bo1;
102 for (j=16;j;j--,b0+=0x10,window+=0x20,samples+=step)
104 real sum;
105 sum = window[0x0] * b0[0x0];
106 sum -= window[0x1] * b0[0x1];
107 sum += window[0x2] * b0[0x2];
108 sum -= window[0x3] * b0[0x3];
109 sum += window[0x4] * b0[0x4];
110 sum -= window[0x5] * b0[0x5];
111 sum += window[0x6] * b0[0x6];
112 sum -= window[0x7] * b0[0x7];
113 sum += window[0x8] * b0[0x8];
114 sum -= window[0x9] * b0[0x9];
115 sum += window[0xA] * b0[0xA];
116 sum -= window[0xB] * b0[0xB];
117 sum += window[0xC] * b0[0xC];
118 sum -= window[0xD] * b0[0xD];
119 sum += window[0xE] * b0[0xE];
120 sum -= window[0xF] * b0[0xF];
122 WRITE_SAMPLE(samples,sum,clip);
126 real sum;
127 sum = window[0x0] * b0[0x0];
128 sum += window[0x2] * b0[0x2];
129 sum += window[0x4] * b0[0x4];
130 sum += window[0x6] * b0[0x6];
131 sum += window[0x8] * b0[0x8];
132 sum += window[0xA] * b0[0xA];
133 sum += window[0xC] * b0[0xC];
134 sum += window[0xE] * b0[0xE];
135 WRITE_SAMPLE(samples,sum,clip);
136 b0-=0x10,window-=0x20,samples+=step;
138 window += bo1<<1;
140 for (j=15;j;j--,b0-=0x10,window-=0x20,samples+=step)
142 real sum;
143 sum = -window[-0x1] * b0[0x0];
144 sum -= window[-0x2] * b0[0x1];
145 sum -= window[-0x3] * b0[0x2];
146 sum -= window[-0x4] * b0[0x3];
147 sum -= window[-0x5] * b0[0x4];
148 sum -= window[-0x6] * b0[0x5];
149 sum -= window[-0x7] * b0[0x6];
150 sum -= window[-0x8] * b0[0x7];
151 sum -= window[-0x9] * b0[0x8];
152 sum -= window[-0xA] * b0[0x9];
153 sum -= window[-0xB] * b0[0xA];
154 sum -= window[-0xC] * b0[0xB];
155 sum -= window[-0xD] * b0[0xC];
156 sum -= window[-0xE] * b0[0xD];
157 sum -= window[-0xF] * b0[0xE];
158 sum -= window[-0x0] * b0[0xF];
160 WRITE_SAMPLE(samples,sum,clip);
163 *pnt += 128;
165 return clip;