comparison decoders/mpglib/decode_i386.c @ 261:9b6e82f7c853

Initial add.
author Ryan C. Gordon <icculus@icculus.org>
date Thu, 21 Feb 2002 19:46:09 +0000
parents
children 52b9f37998db
comparison
equal deleted inserted replaced
260:44a4730a1e6f 261:9b6e82f7c853
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 * 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.
11 */
12
13 #include <stdlib.h>
14 #include <math.h>
15 #include <string.h>
16
17 #include "mpg123_sdlsound.h"
18 #include "mpglib_sdlsound.h"
19
20 extern struct mpstr *gmp;
21
22 /* old WRITE_SAMPLE */
23 #define WRITE_SAMPLE(samples,sum,clip) \
24 if( (sum) > 32767.0) { *(samples) = 0x7fff; (clip)++; } \
25 else if( (sum) < -32768.0) { *(samples) = -0x8000; (clip)++; } \
26 else { *(samples) = sum; }
27
28 int synth_1to1_mono(real *bandPtr,unsigned char *samples,int *pnt)
29 {
30 short samples_tmp[64];
31 short *tmp1 = samples_tmp;
32 int i,ret;
33 int pnt1 = 0;
34
35 ret = synth_1to1(bandPtr,0,(unsigned char *) samples_tmp,&pnt1);
36 samples += *pnt;
37
38 for(i=0;i<32;i++) {
39 *( (short *) samples) = *tmp1;
40 samples += 2;
41 tmp1 += 2;
42 }
43 *pnt += 64;
44
45 return ret;
46 }
47
48
49 int synth_1to1(real *bandPtr,int channel,unsigned char *out,int *pnt)
50 {
51 static const int step = 2;
52 int bo;
53 short *samples = (short *) (out + *pnt);
54
55 real *b0,(*buf)[0x110];
56 int clip = 0;
57 int bo1;
58
59 bo = gmp->synth_bo;
60
61 if(!channel) {
62 bo--;
63 bo &= 0xf;
64 buf = gmp->synth_buffs[0];
65 }
66 else {
67 samples++;
68 buf = gmp->synth_buffs[1];
69 }
70
71 if(bo & 0x1) {
72 b0 = buf[0];
73 bo1 = bo;
74 dct64(buf[1]+((bo+1)&0xf),buf[0]+bo,bandPtr);
75 }
76 else {
77 b0 = buf[1];
78 bo1 = bo+1;
79 dct64(buf[0]+bo,buf[1]+bo+1,bandPtr);
80 }
81
82 gmp->synth_bo = bo;
83
84 {
85 register int j;
86 real *window = decwin + 16 - bo1;
87
88 for (j=16;j;j--,b0+=0x10,window+=0x20,samples+=step)
89 {
90 real sum;
91 sum = window[0x0] * b0[0x0];
92 sum -= window[0x1] * b0[0x1];
93 sum += window[0x2] * b0[0x2];
94 sum -= window[0x3] * b0[0x3];
95 sum += window[0x4] * b0[0x4];
96 sum -= window[0x5] * b0[0x5];
97 sum += window[0x6] * b0[0x6];
98 sum -= window[0x7] * b0[0x7];
99 sum += window[0x8] * b0[0x8];
100 sum -= window[0x9] * b0[0x9];
101 sum += window[0xA] * b0[0xA];
102 sum -= window[0xB] * b0[0xB];
103 sum += window[0xC] * b0[0xC];
104 sum -= window[0xD] * b0[0xD];
105 sum += window[0xE] * b0[0xE];
106 sum -= window[0xF] * b0[0xF];
107
108 WRITE_SAMPLE(samples,sum,clip);
109 }
110
111 {
112 real sum;
113 sum = window[0x0] * b0[0x0];
114 sum += window[0x2] * b0[0x2];
115 sum += window[0x4] * b0[0x4];
116 sum += window[0x6] * b0[0x6];
117 sum += window[0x8] * b0[0x8];
118 sum += window[0xA] * b0[0xA];
119 sum += window[0xC] * b0[0xC];
120 sum += window[0xE] * b0[0xE];
121 WRITE_SAMPLE(samples,sum,clip);
122 b0-=0x10,window-=0x20,samples+=step;
123 }
124 window += bo1<<1;
125
126 for (j=15;j;j--,b0-=0x10,window-=0x20,samples+=step)
127 {
128 real sum;
129 sum = -window[-0x1] * b0[0x0];
130 sum -= window[-0x2] * b0[0x1];
131 sum -= window[-0x3] * b0[0x2];
132 sum -= window[-0x4] * b0[0x3];
133 sum -= window[-0x5] * b0[0x4];
134 sum -= window[-0x6] * b0[0x5];
135 sum -= window[-0x7] * b0[0x6];
136 sum -= window[-0x8] * b0[0x7];
137 sum -= window[-0x9] * b0[0x8];
138 sum -= window[-0xA] * b0[0x9];
139 sum -= window[-0xB] * b0[0xA];
140 sum -= window[-0xC] * b0[0xB];
141 sum -= window[-0xD] * b0[0xC];
142 sum -= window[-0xE] * b0[0xD];
143 sum -= window[-0xF] * b0[0xE];
144 sum -= window[-0x0] * b0[0xF];
145
146 WRITE_SAMPLE(samples,sum,clip);
147 }
148 }
149 *pnt += 128;
150
151 return clip;
152 }
153