annotate mp3lib/layer1.c @ 13348:2242f7d95b14

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