2 * Mpeg Layer-1,2,3 audio decoder
3 * ------------------------------
4 * copyright (c) 1995,1996,1997 by Michael Hipp, All rights reserved.
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
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;
49 ret = synth_1to1(bandPtr,0,(unsigned char *) samples_tmp,&pnt1);
53 *( (short *) samples) = *tmp1;
63 int synth_1to1(real *bandPtr,int channel,unsigned char *out,int *pnt)
65 static const int step = 2;
67 short *samples = (short *) (out + *pnt);
69 real *b0,(*buf)[0x110];
78 buf = gmp->synth_buffs[0];
82 buf = gmp->synth_buffs[1];
88 dct64(buf[1]+((bo+1)&0xf),buf[0]+bo,bandPtr);
93 dct64(buf[0]+bo,buf[1]+bo+1,bandPtr);
100 real *window = decwin + 16 - bo1;
102 for (j=16;j;j--,b0+=0x10,window+=0x20,samples+=step)
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);
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;
140 for (j=15;j;j--,b0-=0x10,window-=0x20,samples+=step)
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);