2 * Mpeg Layer-1,2,3 audio decoder
3 * ------------------------------
4 * copyright (c) 1995,1996,1997 by Michael Hipp, All rights reserved.
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.
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
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; }
40 int synth_1to1_mono(struct mpstr *mp,real *bandPtr,unsigned char *samples,int *pnt)
42 short samples_tmp[64];
43 short *tmp1 = samples_tmp;
47 ret = synth_1to1(mp,bandPtr,0,(unsigned char *) samples_tmp,&pnt1);
51 *( (short *) samples) = *tmp1;
61 int synth_1to1(struct mpstr *mp,real *bandPtr,int channel,unsigned char *out,int *pnt)
63 static const int step = 2;
65 short *samples = (short *) (out + *pnt);
67 real *b0,(*buf)[0x110];
76 buf = mp->synth_buffs[0];
80 buf = mp->synth_buffs[1];
86 dct64(buf[1]+((bo+1)&0xf),buf[0]+bo,bandPtr);
91 dct64(buf[0]+bo,buf[1]+bo+1,bandPtr);
98 real *window = decwin + 16 - bo1;
100 for (j=16;j;j--,b0+=0x10,window+=0x20,samples+=step)
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];
120 WRITE_SAMPLE(samples,sum,clip);
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;
138 for (j=15;j;j--,b0-=0x10,window-=0x20,samples+=step)
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];
158 WRITE_SAMPLE(samples,sum,clip);