Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
2 | pj | 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.h" |
||
18 | |||
19 | #define WRITE_SAMPLE(samples,sum,clip) \ |
||
20 | if( (sum) > 32767.0) { *(samples) = 0x7fff; (clip)++; } \ |
||
21 | else if( (sum) < -32768.0) { *(samples) = -0x8000; (clip)++; } \ |
||
22 | else { *(samples) = sum; } |
||
23 | |||
24 | int synth_1to1_8bit(real *bandPtr,int channel,unsigned char *samples) |
||
25 | { |
||
26 | short samples_tmp[64]; |
||
27 | short *tmp1 = samples_tmp + channel; |
||
28 | int i,ret; |
||
29 | |||
30 | samples += channel; |
||
31 | ret = synth_1to1(bandPtr,channel,(unsigned char *)samples_tmp); |
||
32 | |||
33 | for(i=0;i<32;i++) { |
||
34 | *samples = conv16to8[*tmp1>>4]; |
||
35 | samples += 2; |
||
36 | tmp1 += 2; |
||
37 | } |
||
38 | |||
39 | return ret; |
||
40 | } |
||
41 | |||
42 | int synth_1to1_8bit_mono(real *bandPtr,unsigned char *samples) |
||
43 | { |
||
44 | short samples_tmp[64]; |
||
45 | short *tmp1 = samples_tmp; |
||
46 | int i,ret; |
||
47 | |||
48 | ret = synth_1to1(bandPtr,0,(unsigned char *)samples_tmp); |
||
49 | |||
50 | for(i=0;i<32;i++) { |
||
51 | *samples++ = conv16to8[*tmp1>>4]; |
||
52 | *samples++ = conv16to8[*tmp1>>4]; |
||
53 | tmp1 += 2; |
||
54 | } |
||
55 | |||
56 | return ret; |
||
57 | } |
||
58 | |||
59 | int synth_1to1_mono(real *bandPtr,unsigned char *samples) |
||
60 | { |
||
61 | int i,ret = synth_1to1(bandPtr,0,samples); |
||
62 | for(i=0;i<32;i++) { |
||
63 | ((short *)samples)[1] = ((short *)samples)[0]; |
||
64 | samples+=4; |
||
65 | } |
||
66 | return ret; |
||
67 | } |
||
68 | |||
69 | int synth_1to1(real *bandPtr,int channel,unsigned char *out) |
||
70 | { |
||
71 | static real buffs[2][2][0x110]; |
||
72 | static const int step = 2; |
||
73 | static int bo = 1; |
||
74 | short *samples = (short *) out; |
||
75 | |||
76 | real *b0,(*buf)[0x110]; |
||
77 | int clip = 0; |
||
78 | int bo1; |
||
79 | |||
80 | if(!channel) { |
||
81 | bo--; |
||
82 | bo &= 0xf; |
||
83 | buf = buffs[0]; |
||
84 | } |
||
85 | else { |
||
86 | samples++; |
||
87 | buf = buffs[1]; |
||
88 | } |
||
89 | |||
90 | if(bo & 0x1) { |
||
91 | b0 = buf[0]; |
||
92 | bo1 = bo; |
||
93 | dct64(buf[1]+((bo+1)&0xf),buf[0]+bo,bandPtr); |
||
94 | } |
||
95 | else { |
||
96 | b0 = buf[1]; |
||
97 | bo1 = bo+1; |
||
98 | dct64(buf[0]+bo,buf[1]+bo+1,bandPtr); |
||
99 | } |
||
100 | |||
101 | { |
||
102 | register int j; |
||
103 | real *window = decwin + 16 - bo1; |
||
104 | |||
105 | for (j=16;j;j--,b0+=0x10,window+=0x20,samples+=step) |
||
106 | { |
||
107 | real sum; |
||
108 | sum = window[0x0] * b0[0x0]; |
||
109 | sum -= window[0x1] * b0[0x1]; |
||
110 | sum += window[0x2] * b0[0x2]; |
||
111 | sum -= window[0x3] * b0[0x3]; |
||
112 | sum += window[0x4] * b0[0x4]; |
||
113 | sum -= window[0x5] * b0[0x5]; |
||
114 | sum += window[0x6] * b0[0x6]; |
||
115 | sum -= window[0x7] * b0[0x7]; |
||
116 | sum += window[0x8] * b0[0x8]; |
||
117 | sum -= window[0x9] * b0[0x9]; |
||
118 | sum += window[0xA] * b0[0xA]; |
||
119 | sum -= window[0xB] * b0[0xB]; |
||
120 | sum += window[0xC] * b0[0xC]; |
||
121 | sum -= window[0xD] * b0[0xD]; |
||
122 | sum += window[0xE] * b0[0xE]; |
||
123 | sum -= window[0xF] * b0[0xF]; |
||
124 | |||
125 | WRITE_SAMPLE(samples,sum,clip); |
||
126 | } |
||
127 | |||
128 | { |
||
129 | real sum; |
||
130 | sum = window[0x0] * b0[0x0]; |
||
131 | sum += window[0x2] * b0[0x2]; |
||
132 | sum += window[0x4] * b0[0x4]; |
||
133 | sum += window[0x6] * b0[0x6]; |
||
134 | sum += window[0x8] * b0[0x8]; |
||
135 | sum += window[0xA] * b0[0xA]; |
||
136 | sum += window[0xC] * b0[0xC]; |
||
137 | sum += window[0xE] * b0[0xE]; |
||
138 | WRITE_SAMPLE(samples,sum,clip); |
||
139 | b0-=0x10,window-=0x20,samples+=step; |
||
140 | } |
||
141 | window += bo1<<1; |
||
142 | |||
143 | for (j=15;j;j--,b0-=0x10,window-=0x20,samples+=step) |
||
144 | { |
||
145 | real sum; |
||
146 | sum = -window[-0x1] * b0[0x0]; |
||
147 | sum -= window[-0x2] * b0[0x1]; |
||
148 | sum -= window[-0x3] * b0[0x2]; |
||
149 | sum -= window[-0x4] * b0[0x3]; |
||
150 | sum -= window[-0x5] * b0[0x4]; |
||
151 | sum -= window[-0x6] * b0[0x5]; |
||
152 | sum -= window[-0x7] * b0[0x6]; |
||
153 | sum -= window[-0x8] * b0[0x7]; |
||
154 | sum -= window[-0x9] * b0[0x8]; |
||
155 | sum -= window[-0xA] * b0[0x9]; |
||
156 | sum -= window[-0xB] * b0[0xA]; |
||
157 | sum -= window[-0xC] * b0[0xB]; |
||
158 | sum -= window[-0xD] * b0[0xC]; |
||
159 | sum -= window[-0xE] * b0[0xD]; |
||
160 | sum -= window[-0xF] * b0[0xE]; |
||
161 | sum -= window[-0x0] * b0[0xF]; |
||
162 | |||
163 | WRITE_SAMPLE(samples,sum,clip); |
||
164 | } |
||
165 | } |
||
166 | return clip; |
||
167 | } |
||
168 | |||
169 |