562
|
1 /*
|
|
2 layer1.c: the layer 1 decoder
|
|
3
|
|
4 copyright 1995-2007 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
|
|
6 initially written by Michael Hipp
|
|
7
|
|
8 may have a few bugs after last optimization ...
|
|
9 */
|
|
10
|
|
11 #include "mpg123lib_intern.h"
|
|
12 #include "getbits.h"
|
|
13
|
|
14 void I_step_one(unsigned int balloc[], unsigned int scale_index[2][SBLIMIT],mpg123_handle *fr)
|
|
15 {
|
|
16 unsigned int *ba=balloc;
|
|
17 unsigned int *sca = (unsigned int *) scale_index;
|
|
18
|
|
19 if(fr->stereo == 2) {
|
|
20 int i;
|
|
21 int jsbound = fr->jsbound;
|
|
22 for (i=0;i<jsbound;i++) {
|
|
23 *ba++ = getbits(fr, 4);
|
|
24 *ba++ = getbits(fr, 4);
|
|
25 }
|
|
26 for (i=jsbound;i<SBLIMIT;i++)
|
|
27 *ba++ = getbits(fr, 4);
|
|
28
|
|
29 ba = balloc;
|
|
30
|
|
31 for (i=0;i<jsbound;i++) {
|
|
32 if ((*ba++))
|
|
33 *sca++ = getbits(fr, 6);
|
|
34 if ((*ba++))
|
|
35 *sca++ = getbits(fr, 6);
|
|
36 }
|
|
37 for (i=jsbound;i<SBLIMIT;i++)
|
|
38 if ((*ba++)) {
|
|
39 *sca++ = getbits(fr, 6);
|
|
40 *sca++ = getbits(fr, 6);
|
|
41 }
|
|
42 }
|
|
43 else {
|
|
44 int i;
|
|
45 for (i=0;i<SBLIMIT;i++)
|
|
46 *ba++ = getbits(fr, 4);
|
|
47 ba = balloc;
|
|
48 for (i=0;i<SBLIMIT;i++)
|
|
49 if ((*ba++))
|
|
50 *sca++ = getbits(fr, 6);
|
|
51 }
|
|
52 }
|
|
53
|
|
54 void I_step_two(real fraction[2][SBLIMIT],unsigned int balloc[2*SBLIMIT],
|
|
55 unsigned int scale_index[2][SBLIMIT],mpg123_handle *fr)
|
|
56 {
|
|
57 int i,n;
|
|
58 int smpb[2*SBLIMIT]; /* values: 0-65535 */
|
|
59 int *sample;
|
|
60 register unsigned int *ba;
|
|
61 register unsigned int *sca = (unsigned int *) scale_index;
|
|
62
|
|
63 if(fr->stereo == 2) {
|
|
64 int jsbound = fr->jsbound;
|
|
65 register real *f0 = fraction[0];
|
|
66 register real *f1 = fraction[1];
|
|
67 ba = balloc;
|
|
68 for (sample=smpb,i=0;i<jsbound;i++) {
|
|
69 if ((n = *ba++))
|
|
70 *sample++ = getbits(fr, n+1);
|
|
71 if ((n = *ba++))
|
|
72 *sample++ = getbits(fr, n+1);
|
|
73 }
|
|
74 for (i=jsbound;i<SBLIMIT;i++)
|
|
75 if ((n = *ba++))
|
|
76 *sample++ = getbits(fr, n+1);
|
|
77
|
|
78 ba = balloc;
|
|
79 for (sample=smpb,i=0;i<jsbound;i++) {
|
|
80 if((n=*ba++))
|
|
81 *f0++ = (real) ( ((-1)<<n) + (*sample++) + 1) * fr->muls[n+1][*sca++];
|
|
82 else
|
|
83 *f0++ = 0.0;
|
|
84 if((n=*ba++))
|
|
85 *f1++ = (real) ( ((-1)<<n) + (*sample++) + 1) * fr->muls[n+1][*sca++];
|
|
86 else
|
|
87 *f1++ = 0.0;
|
|
88 }
|
|
89 for (i=jsbound;i<SBLIMIT;i++) {
|
|
90 if ((n=*ba++)) {
|
|
91 real samp = ( ((-1)<<n) + (*sample++) + 1);
|
|
92 *f0++ = samp * fr->muls[n+1][*sca++];
|
|
93 *f1++ = samp * fr->muls[n+1][*sca++];
|
|
94 }
|
|
95 else
|
|
96 *f0++ = *f1++ = 0.0;
|
|
97 }
|
|
98 for(i=fr->down_sample_sblimit;i<32;i++)
|
|
99 fraction[0][i] = fraction[1][i] = 0.0;
|
|
100 }
|
|
101 else {
|
|
102 register real *f0 = fraction[0];
|
|
103 ba = balloc;
|
|
104 for (sample=smpb,i=0;i<SBLIMIT;i++)
|
|
105 if ((n = *ba++))
|
|
106 *sample++ = getbits(fr, n+1);
|
|
107 ba = balloc;
|
|
108 for (sample=smpb,i=0;i<SBLIMIT;i++) {
|
|
109 if((n=*ba++))
|
|
110 *f0++ = (real) ( ((-1)<<n) + (*sample++) + 1) * fr->muls[n+1][*sca++];
|
|
111 else
|
|
112 *f0++ = 0.0;
|
|
113 }
|
|
114 for(i=fr->down_sample_sblimit;i<32;i++)
|
|
115 fraction[0][i] = 0.0;
|
|
116 }
|
|
117 }
|
|
118
|
|
119 int do_layer1(mpg123_handle *fr)
|
|
120 {
|
|
121 int clip=0;
|
|
122 int i,stereo = fr->stereo;
|
|
123 unsigned int balloc[2*SBLIMIT];
|
|
124 unsigned int scale_index[2][SBLIMIT];
|
|
125 ALIGNED(16) real fraction[2][SBLIMIT];
|
|
126 int single = fr->single;
|
|
127
|
|
128 fr->jsbound = (fr->mode == MPG_MD_JOINT_STEREO) ? (fr->mode_ext<<2)+4 : 32;
|
|
129
|
|
130 if(stereo == 1 || single == SINGLE_MIX) /* I don't see mixing handled here */
|
|
131 single = SINGLE_LEFT;
|
|
132
|
|
133 I_step_one(balloc,scale_index,fr);
|
|
134
|
|
135 for (i=0;i<SCALE_BLOCK;i++)
|
|
136 {
|
|
137 I_step_two(fraction,balloc,scale_index,fr);
|
|
138
|
|
139 if(single != SINGLE_STEREO)
|
|
140 {
|
|
141 clip += (fr->synth_mono)( (real *) fraction[single], fr);
|
|
142 }
|
|
143 else
|
|
144 {
|
|
145 clip += (fr->synth)( (real *) fraction[0], 0, fr, 0);
|
|
146 clip += (fr->synth)( (real *) fraction[1], 1, fr, 1);
|
|
147 }
|
|
148 }
|
|
149
|
|
150 return clip;
|
|
151 }
|
|
152
|
|
153
|