1 | /********************************************************************** <BR>
|
---|
2 | This file is part of Crack dot Com's free source code release of
|
---|
3 | Golgotha. <a href="http://www.crack.com/golgotha_release"> <BR> for
|
---|
4 | information about compiling & licensing issues visit this URL</a>
|
---|
5 | <PRE> If that doesn't help, contact Jonathan Clark at
|
---|
6 | golgotha_source@usa.net (Subject should have "GOLG" in it)
|
---|
7 | ***********************************************************************/
|
---|
8 |
|
---|
9 | /*
|
---|
10 | * Mpeg Layer-1,2,3 audio decoder
|
---|
11 | * ------------------------------
|
---|
12 | * copyright (c) 1995,1996,1997 by Michael Hipp, All rights reserved.
|
---|
13 | * See also 'README'
|
---|
14 | *
|
---|
15 | * slighlty optimized for machines without autoincrement/decrement.
|
---|
16 | * The performance is highly compiler dependend. Maybe
|
---|
17 | * the decode.c version for 'normal' processor may be faster
|
---|
18 | * even for Intel processors.
|
---|
19 | */
|
---|
20 |
|
---|
21 | #include <stdlib.h>
|
---|
22 | #include <math.h>
|
---|
23 | #include <string.h>
|
---|
24 |
|
---|
25 | #include "mpg123.h"
|
---|
26 |
|
---|
27 | #define WRITE_SAMPLE(samples,sum,clip) \
|
---|
28 | if( (sum) > 32767.0) { *(samples) = 0x7fff; (clip)++; } \
|
---|
29 | else if( (sum) < -32768.0) { *(samples) = -0x8000; (clip)++; } \
|
---|
30 | else { *(samples) = sum; }
|
---|
31 |
|
---|
32 | static int bo = 1;
|
---|
33 |
|
---|
34 | void init_decode_i386(void)
|
---|
35 | {
|
---|
36 | bo = 1;
|
---|
37 | }
|
---|
38 |
|
---|
39 | int synth_1to1_8bit(real *bandPtr,int channel,unsigned char *samples)
|
---|
40 | {
|
---|
41 | short samples_tmp[64];
|
---|
42 | short *tmp1 = samples_tmp + channel;
|
---|
43 | int i,ret;
|
---|
44 |
|
---|
45 | samples += channel;
|
---|
46 | ret = synth_1to1(bandPtr,channel,(unsigned char *)samples_tmp);
|
---|
47 |
|
---|
48 | for(i=0;i<32;i++) {
|
---|
49 | *samples = conv16to8[*tmp1>>4];
|
---|
50 | samples += 2;
|
---|
51 | tmp1 += 2;
|
---|
52 | }
|
---|
53 |
|
---|
54 | return ret;
|
---|
55 | }
|
---|
56 |
|
---|
57 | int synth_1to1_8bit_mono(real *bandPtr,unsigned char *samples)
|
---|
58 | {
|
---|
59 | short samples_tmp[64];
|
---|
60 | short *tmp1 = samples_tmp;
|
---|
61 | int i,ret;
|
---|
62 |
|
---|
63 | ret = synth_1to1(bandPtr,0,(unsigned char *)samples_tmp);
|
---|
64 |
|
---|
65 | for(i=0;i<32;i++) {
|
---|
66 | *samples++ = conv16to8[*tmp1>>4];
|
---|
67 | tmp1+=2;
|
---|
68 | }
|
---|
69 |
|
---|
70 | return ret;
|
---|
71 | }
|
---|
72 |
|
---|
73 | int synth_1to1_8bit_mono2stereo(real *bandPtr,unsigned char *samples)
|
---|
74 | {
|
---|
75 | short samples_tmp[64];
|
---|
76 | short *tmp1 = samples_tmp;
|
---|
77 | int i,ret;
|
---|
78 |
|
---|
79 | ret = synth_1to1(bandPtr,0,(unsigned char *)samples_tmp);
|
---|
80 |
|
---|
81 | for(i=0;i<32;i++) {
|
---|
82 | *samples++ = conv16to8[*tmp1>>4];
|
---|
83 | *samples++ = conv16to8[*tmp1>>4];
|
---|
84 | tmp1 += 2;
|
---|
85 | }
|
---|
86 |
|
---|
87 | return ret;
|
---|
88 | }
|
---|
89 |
|
---|
90 | int synth_1to1_mono(real *bandPtr,unsigned char *samples)
|
---|
91 | {
|
---|
92 | short samples_tmp[64];
|
---|
93 | short *tmp1 = samples_tmp;
|
---|
94 |
|
---|
95 | int i,ret;
|
---|
96 |
|
---|
97 | ret = synth_1to1(bandPtr,0,(unsigned char *) samples_tmp);
|
---|
98 |
|
---|
99 | for(i=0;i<32;i++) {
|
---|
100 | *( (short *) samples)++ = *tmp1;
|
---|
101 | tmp1 += 2;
|
---|
102 | }
|
---|
103 | return ret;
|
---|
104 | }
|
---|
105 |
|
---|
106 |
|
---|
107 | int synth_1to1_mono2stereo(real *bandPtr,unsigned char *samples)
|
---|
108 | {
|
---|
109 | int i,ret = synth_1to1(bandPtr,0,samples);
|
---|
110 | for(i=0;i<32;i++) {
|
---|
111 | ((short *)samples)[1] = ((short *)samples)[0];
|
---|
112 | samples+=4;
|
---|
113 | }
|
---|
114 | return ret;
|
---|
115 | }
|
---|
116 |
|
---|
117 | #ifndef PENTIUM_OPT
|
---|
118 | int synth_1to1(real *bandPtr,int channel,unsigned char *out)
|
---|
119 | {
|
---|
120 | static real buffs[2][2][0x110];
|
---|
121 | static const int step = 2;
|
---|
122 | short *samples = (short *) out;
|
---|
123 |
|
---|
124 | real *b0,(*buf)[0x110];
|
---|
125 | int clip = 0;
|
---|
126 | int bo1;
|
---|
127 |
|
---|
128 | if(flags.equalizer)
|
---|
129 | do_equalizer(bandPtr,channel);
|
---|
130 |
|
---|
131 | if(!channel) {
|
---|
132 | bo--;
|
---|
133 | bo &= 0xf;
|
---|
134 | buf = buffs[0];
|
---|
135 | }
|
---|
136 | else {
|
---|
137 | samples++;
|
---|
138 | buf = buffs[1];
|
---|
139 | }
|
---|
140 |
|
---|
141 | if(bo & 0x1) {
|
---|
142 | b0 = buf[0];
|
---|
143 | bo1 = bo;
|
---|
144 | dct64(buf[1]+((bo+1)&0xf),buf[0]+bo,bandPtr);
|
---|
145 | }
|
---|
146 | else {
|
---|
147 | b0 = buf[1];
|
---|
148 | bo1 = bo+1;
|
---|
149 | dct64(buf[0]+bo,buf[1]+bo+1,bandPtr);
|
---|
150 | }
|
---|
151 |
|
---|
152 | {
|
---|
153 | register int j;
|
---|
154 | real *window = decwin + 16 - bo1;
|
---|
155 |
|
---|
156 | for (j=16;j;j--,b0+=0x10,window+=0x20,samples+=step)
|
---|
157 | {
|
---|
158 | real sum;
|
---|
159 | sum = window[0x0] * b0[0x0];
|
---|
160 | sum -= window[0x1] * b0[0x1];
|
---|
161 | sum += window[0x2] * b0[0x2];
|
---|
162 | sum -= window[0x3] * b0[0x3];
|
---|
163 | sum += window[0x4] * b0[0x4];
|
---|
164 | sum -= window[0x5] * b0[0x5];
|
---|
165 | sum += window[0x6] * b0[0x6];
|
---|
166 | sum -= window[0x7] * b0[0x7];
|
---|
167 | sum += window[0x8] * b0[0x8];
|
---|
168 | sum -= window[0x9] * b0[0x9];
|
---|
169 | sum += window[0xA] * b0[0xA];
|
---|
170 | sum -= window[0xB] * b0[0xB];
|
---|
171 | sum += window[0xC] * b0[0xC];
|
---|
172 | sum -= window[0xD] * b0[0xD];
|
---|
173 | sum += window[0xE] * b0[0xE];
|
---|
174 | sum -= window[0xF] * b0[0xF];
|
---|
175 |
|
---|
176 | WRITE_SAMPLE(samples,sum,clip);
|
---|
177 | }
|
---|
178 |
|
---|
179 | {
|
---|
180 | real sum;
|
---|
181 | sum = window[0x0] * b0[0x0];
|
---|
182 | sum += window[0x2] * b0[0x2];
|
---|
183 | sum += window[0x4] * b0[0x4];
|
---|
184 | sum += window[0x6] * b0[0x6];
|
---|
185 | sum += window[0x8] * b0[0x8];
|
---|
186 | sum += window[0xA] * b0[0xA];
|
---|
187 | sum += window[0xC] * b0[0xC];
|
---|
188 | sum += window[0xE] * b0[0xE];
|
---|
189 | WRITE_SAMPLE(samples,sum,clip);
|
---|
190 | b0-=0x10,window-=0x20,samples+=step;
|
---|
191 | }
|
---|
192 | window += bo1<<1;
|
---|
193 |
|
---|
194 | for (j=15;j;j--,b0-=0x10,window-=0x20,samples+=step)
|
---|
195 | {
|
---|
196 | real sum;
|
---|
197 | sum = -window[-0x1] * b0[0x0];
|
---|
198 | sum -= window[-0x2] * b0[0x1];
|
---|
199 | sum -= window[-0x3] * b0[0x2];
|
---|
200 | sum -= window[-0x4] * b0[0x3];
|
---|
201 | sum -= window[-0x5] * b0[0x4];
|
---|
202 | sum -= window[-0x6] * b0[0x5];
|
---|
203 | sum -= window[-0x7] * b0[0x6];
|
---|
204 | sum -= window[-0x8] * b0[0x7];
|
---|
205 | sum -= window[-0x9] * b0[0x8];
|
---|
206 | sum -= window[-0xA] * b0[0x9];
|
---|
207 | sum -= window[-0xB] * b0[0xA];
|
---|
208 | sum -= window[-0xC] * b0[0xB];
|
---|
209 | sum -= window[-0xD] * b0[0xC];
|
---|
210 | sum -= window[-0xE] * b0[0xD];
|
---|
211 | sum -= window[-0xF] * b0[0xE];
|
---|
212 | sum -= window[-0x0] * b0[0xF];
|
---|
213 |
|
---|
214 | WRITE_SAMPLE(samples,sum,clip);
|
---|
215 | }
|
---|
216 | }
|
---|
217 | return clip;
|
---|
218 | }
|
---|
219 | #endif
|
---|
220 |
|
---|
221 |
|
---|