Rev 1905 | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 1905 | Rev 3960 | ||
---|---|---|---|
1 | /* |
1 | /* |
2 | layer1.c: the layer 1 decoder |
2 | layer1.c: the layer 1 decoder |
3 | 3 | ||
4 | copyright 1995-2008 by the mpg123 project - free software under the terms of the LGPL 2.1 |
4 | copyright 1995-2009 by the mpg123 project - free software under the terms of the LGPL 2.1 |
5 | see COPYING and AUTHORS files in distribution or http://mpg123.org |
5 | see COPYING and AUTHORS files in distribution or http://mpg123.org |
6 | initially written by Michael Hipp |
6 | initially written by Michael Hipp |
7 | 7 | ||
8 | may have a few bugs after last optimization ... |
8 | may have a few bugs after last optimization ... |
9 | */ |
9 | */ |
10 | 10 | ||
11 | #include "mpg123lib_intern.h" |
11 | #include "mpg123lib_intern.h" |
12 | #include "getbits.h" |
12 | #include "getbits.h" |
13 | 13 | ||
14 | void I_step_one(unsigned int balloc[], unsigned int scale_index[2][SBLIMIT],mpg123_handle *fr) |
14 | static void I_step_one(unsigned int balloc[], unsigned int scale_index[2][SBLIMIT],mpg123_handle *fr) |
15 | { |
15 | { |
16 | unsigned int *ba=balloc; |
16 | unsigned int *ba=balloc; |
17 | unsigned int *sca = (unsigned int *) scale_index; |
17 | unsigned int *sca = (unsigned int *) scale_index; |
18 | 18 | ||
19 | if(fr->stereo == 2) |
19 | if(fr->stereo == 2) |
20 | { |
20 | { |
21 | int i; |
21 | int i; |
22 | int jsbound = fr->jsbound; |
22 | int jsbound = fr->jsbound; |
23 | for(i=0;i |
23 | for(i=0;i |
24 | { |
24 | { |
25 | *ba++ = getbits(fr, 4); |
25 | *ba++ = getbits(fr, 4); |
26 | *ba++ = getbits(fr, 4); |
26 | *ba++ = getbits(fr, 4); |
27 | } |
27 | } |
28 | for(i=jsbound;i |
28 | for(i=jsbound;i |
29 | 29 | ||
30 | ba = balloc; |
30 | ba = balloc; |
31 | 31 | ||
32 | for(i=0;i |
32 | for(i=0;i |
33 | { |
33 | { |
34 | if ((*ba++)) |
34 | if ((*ba++)) |
35 | *sca++ = getbits(fr, 6); |
35 | *sca++ = getbits(fr, 6); |
36 | if ((*ba++)) |
36 | if ((*ba++)) |
37 | *sca++ = getbits(fr, 6); |
37 | *sca++ = getbits(fr, 6); |
38 | } |
38 | } |
39 | for (i=jsbound;i |
39 | for (i=jsbound;i |
40 | if((*ba++)) |
40 | if((*ba++)) |
41 | { |
41 | { |
42 | *sca++ = getbits(fr, 6); |
42 | *sca++ = getbits(fr, 6); |
43 | *sca++ = getbits(fr, 6); |
43 | *sca++ = getbits(fr, 6); |
44 | } |
44 | } |
45 | } |
45 | } |
46 | else |
46 | else |
47 | { |
47 | { |
48 | int i; |
48 | int i; |
49 | for(i=0;i |
49 | for(i=0;i |
50 | 50 | ||
51 | ba = balloc; |
51 | ba = balloc; |
52 | for (i=0;i |
52 | for (i=0;i |
53 | if ((*ba++)) |
53 | if ((*ba++)) |
54 | *sca++ = getbits(fr, 6); |
54 | *sca++ = getbits(fr, 6); |
55 | } |
55 | } |
56 | } |
56 | } |
57 | 57 | ||
58 | void I_step_two(real fraction[2][SBLIMIT],unsigned int balloc[2*SBLIMIT], unsigned int scale_index[2][SBLIMIT],mpg123_handle *fr) |
58 | static void I_step_two(real fraction[2][SBLIMIT],unsigned int balloc[2*SBLIMIT], unsigned int scale_index[2][SBLIMIT],mpg123_handle *fr) |
59 | { |
59 | { |
60 | int i,n; |
60 | int i,n; |
61 | int smpb[2*SBLIMIT]; /* values: 0-65535 */ |
61 | int smpb[2*SBLIMIT]; /* values: 0-65535 */ |
62 | int *sample; |
62 | int *sample; |
63 | register unsigned int *ba; |
63 | register unsigned int *ba; |
64 | register unsigned int *sca = (unsigned int *) scale_index; |
64 | register unsigned int *sca = (unsigned int *) scale_index; |
65 | 65 | ||
66 | if(fr->stereo == 2) |
66 | if(fr->stereo == 2) |
67 | { |
67 | { |
68 | int jsbound = fr->jsbound; |
68 | int jsbound = fr->jsbound; |
69 | register real *f0 = fraction[0]; |
69 | register real *f0 = fraction[0]; |
70 | register real *f1 = fraction[1]; |
70 | register real *f1 = fraction[1]; |
71 | ba = balloc; |
71 | ba = balloc; |
72 | for(sample=smpb,i=0;i |
72 | for(sample=smpb,i=0;i |
73 | { |
73 | { |
74 | if((n = *ba++)) *sample++ = getbits(fr, n+1); |
74 | if((n = *ba++)) *sample++ = getbits(fr, n+1); |
75 | 75 | ||
76 | if((n = *ba++)) *sample++ = getbits(fr, n+1); |
76 | if((n = *ba++)) *sample++ = getbits(fr, n+1); |
77 | } |
77 | } |
78 | for(i=jsbound;i |
78 | for(i=jsbound;i |
79 | if((n = *ba++)) |
79 | if((n = *ba++)) |
80 | *sample++ = getbits(fr, n+1); |
80 | *sample++ = getbits(fr, n+1); |
81 | 81 | ||
82 | ba = balloc; |
82 | ba = balloc; |
83 | for(sample=smpb,i=0;i |
83 | for(sample=smpb,i=0;i |
84 | { |
84 | { |
85 | if((n=*ba++)) |
85 | if((n=*ba++)) |
86 | *f0++ = REAL_MUL_SCALE_LAYER12(DOUBLE_TO_REAL_15( ((-1)< |
86 | *f0++ = REAL_MUL_SCALE_LAYER12(DOUBLE_TO_REAL_15( ((-1)< |
87 | else *f0++ = DOUBLE_TO_REAL(0.0); |
87 | else *f0++ = DOUBLE_TO_REAL(0.0); |
88 | 88 | ||
89 | if((n=*ba++)) |
89 | if((n=*ba++)) |
90 | *f1++ = REAL_MUL_SCALE_LAYER12(DOUBLE_TO_REAL_15( ((-1)< |
90 | *f1++ = REAL_MUL_SCALE_LAYER12(DOUBLE_TO_REAL_15( ((-1)< |
91 | else *f1++ = DOUBLE_TO_REAL(0.0); |
91 | else *f1++ = DOUBLE_TO_REAL(0.0); |
92 | } |
92 | } |
93 | for(i=jsbound;i |
93 | for(i=jsbound;i |
94 | { |
94 | { |
95 | if((n=*ba++)) |
95 | if((n=*ba++)) |
96 | { |
96 | { |
97 | real samp = DOUBLE_TO_REAL_15( ((-1)< |
97 | real samp = DOUBLE_TO_REAL_15( ((-1)< |
98 | *f0++ = REAL_MUL_SCALE_LAYER12(samp, fr->muls[n+1][*sca++]); |
98 | *f0++ = REAL_MUL_SCALE_LAYER12(samp, fr->muls[n+1][*sca++]); |
99 | *f1++ = REAL_MUL_SCALE_LAYER12(samp, fr->muls[n+1][*sca++]); |
99 | *f1++ = REAL_MUL_SCALE_LAYER12(samp, fr->muls[n+1][*sca++]); |
100 | } |
100 | } |
101 | else *f0++ = *f1++ = DOUBLE_TO_REAL(0.0); |
101 | else *f0++ = *f1++ = DOUBLE_TO_REAL(0.0); |
102 | } |
102 | } |
103 | for(i=fr->down_sample_sblimit;i<32;i++) |
103 | for(i=fr->down_sample_sblimit;i<32;i++) |
104 | fraction[0][i] = fraction[1][i] = 0.0; |
104 | fraction[0][i] = fraction[1][i] = 0.0; |
105 | } |
105 | } |
106 | else |
106 | else |
107 | { |
107 | { |
108 | register real *f0 = fraction[0]; |
108 | register real *f0 = fraction[0]; |
109 | ba = balloc; |
109 | ba = balloc; |
110 | for(sample=smpb,i=0;i |
110 | for(sample=smpb,i=0;i |
111 | if ((n = *ba++)) |
111 | if ((n = *ba++)) |
112 | *sample++ = getbits(fr, n+1); |
112 | *sample++ = getbits(fr, n+1); |
113 | 113 | ||
114 | ba = balloc; |
114 | ba = balloc; |
115 | for(sample=smpb,i=0;i |
115 | for(sample=smpb,i=0;i |
116 | { |
116 | { |
117 | if((n=*ba++)) |
117 | if((n=*ba++)) |
118 | *f0++ = REAL_MUL_SCALE_LAYER12(DOUBLE_TO_REAL_15( ((-1)< |
118 | *f0++ = REAL_MUL_SCALE_LAYER12(DOUBLE_TO_REAL_15( ((-1)< |
119 | else *f0++ = DOUBLE_TO_REAL(0.0); |
119 | else *f0++ = DOUBLE_TO_REAL(0.0); |
120 | } |
120 | } |
121 | for(i=fr->down_sample_sblimit;i<32;i++) |
121 | for(i=fr->down_sample_sblimit;i<32;i++) |
122 | fraction[0][i] = DOUBLE_TO_REAL(0.0); |
122 | fraction[0][i] = DOUBLE_TO_REAL(0.0); |
123 | } |
123 | } |
124 | } |
124 | } |
125 | 125 | ||
126 | int do_layer1(mpg123_handle *fr) |
126 | int do_layer1(mpg123_handle *fr) |
127 | { |
127 | { |
128 | int clip=0; |
128 | int clip=0; |
129 | int i,stereo = fr->stereo; |
129 | int i,stereo = fr->stereo; |
130 | unsigned int balloc[2*SBLIMIT]; |
130 | unsigned int balloc[2*SBLIMIT]; |
131 | unsigned int scale_index[2][SBLIMIT]; |
131 | unsigned int scale_index[2][SBLIMIT]; |
132 | ALIGNED(16) real fraction[2][SBLIMIT]; |
132 | real (*fraction)[SBLIMIT] = fr->layer1.fraction; /* fraction[2][SBLIMIT] */ |
133 | int single = fr->single; |
133 | int single = fr->single; |
134 | 134 | ||
135 | fr->jsbound = (fr->mode == MPG_MD_JOINT_STEREO) ? (fr->mode_ext<<2)+4 : 32; |
135 | fr->jsbound = (fr->mode == MPG_MD_JOINT_STEREO) ? (fr->mode_ext<<2)+4 : 32; |
136 | 136 | ||
137 | if(stereo == 1 || single == SINGLE_MIX) /* I don't see mixing handled here */ |
137 | if(stereo == 1 || single == SINGLE_MIX) /* I don't see mixing handled here */ |
138 | single = SINGLE_LEFT; |
138 | single = SINGLE_LEFT; |
139 | 139 | ||
140 | I_step_one(balloc,scale_index,fr); |
140 | I_step_one(balloc,scale_index,fr); |
141 | 141 | ||
142 | for(i=0;i |
142 | for(i=0;i |
143 | { |
143 | { |
144 | I_step_two(fraction,balloc,scale_index,fr); |
144 | I_step_two(fraction,balloc,scale_index,fr); |
145 | 145 | ||
146 | if(single != SINGLE_STEREO) |
146 | if(single != SINGLE_STEREO) |
147 | clip += (fr->synth_mono)(fraction[single], fr); |
147 | clip += (fr->synth_mono)(fraction[single], fr); |
148 | else |
148 | else |
149 | clip += (fr->synth_stereo)(fraction[0], fraction[1], fr); |
149 | clip += (fr->synth_stereo)(fraction[0], fraction[1], fr); |
150 | } |
150 | } |
151 | 151 | ||
152 | return clip; |
152 | return clip; |
153 | } |
153 | } |
154 | >2)+4><2)+4>32;i++) |
154 | >2)+4><2)+4>32;i++) |
155 | > |
155 | > |
156 | > |
156 | > |
157 | >32;i++) |
157 | >32;i++) |
158 | > |
158 | > |
159 | > |
159 | > |
160 | > |
160 | > |
161 | > |
161 | > |
162 | > |
162 | > |
163 | > |
163 | > |
164 | > |
164 | > |
165 | > |
165 | > |