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