annotate mp3lib/layer1.c @ 15459:ae92bce4e6aa

German man page review part II (finishes "PLAYER-SPEZIFISCHE OPTIONEN")
author kraymer
date Sat, 14 May 2005 12:44:30 +0000
parents 07e7a572bd84
children 0783dd397f74
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
15167
07e7a572bd84 Mark modified imported files as such to comply with (L)GPL ¡ø2a.
diego
parents: 15103
diff changeset
1 /*
07e7a572bd84 Mark modified imported files as such to comply with (L)GPL ¡ø2a.
diego
parents: 15103
diff changeset
2 * Modified for use with MPlayer, for details see the CVS changelog at
07e7a572bd84 Mark modified imported files as such to comply with (L)GPL ¡ø2a.
diego
parents: 15103
diff changeset
3 * http://www.mplayerhq.hu/cgi-bin/cvsweb.cgi/main/
07e7a572bd84 Mark modified imported files as such to comply with (L)GPL ¡ø2a.
diego
parents: 15103
diff changeset
4 * $Id$
07e7a572bd84 Mark modified imported files as such to comply with (L)GPL ¡ø2a.
diego
parents: 15103
diff changeset
5 */
07e7a572bd84 Mark modified imported files as such to comply with (L)GPL ¡ø2a.
diego
parents: 15103
diff changeset
6
10468
e2979f202bb2 layer-1 support
arpi
parents:
diff changeset
7 /*
e2979f202bb2 layer-1 support
arpi
parents:
diff changeset
8 * Mpeg Layer-1 audio decoder
e2979f202bb2 layer-1 support
arpi
parents:
diff changeset
9 * --------------------------
e2979f202bb2 layer-1 support
arpi
parents:
diff changeset
10 * copyright (c) 1995 by Michael Hipp, All rights reserved. See also 'README'
e2979f202bb2 layer-1 support
arpi
parents:
diff changeset
11 * near unoptimzed ...
e2979f202bb2 layer-1 support
arpi
parents:
diff changeset
12 *
e2979f202bb2 layer-1 support
arpi
parents:
diff changeset
13 * may have a few bugs after last optimization ...
e2979f202bb2 layer-1 support
arpi
parents:
diff changeset
14 *
e2979f202bb2 layer-1 support
arpi
parents:
diff changeset
15 */
e2979f202bb2 layer-1 support
arpi
parents:
diff changeset
16
e2979f202bb2 layer-1 support
arpi
parents:
diff changeset
17 //#include "mpg123.h"
e2979f202bb2 layer-1 support
arpi
parents:
diff changeset
18
e2979f202bb2 layer-1 support
arpi
parents:
diff changeset
19 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
20 {
e2979f202bb2 layer-1 support
arpi
parents:
diff changeset
21 unsigned int *ba=balloc;
e2979f202bb2 layer-1 support
arpi
parents:
diff changeset
22 unsigned int *sca = (unsigned int *) scale_index;
e2979f202bb2 layer-1 support
arpi
parents:
diff changeset
23
15103
90670e48d270 Use proper parameter range in stereo test
henry
parents: 10468
diff changeset
24 if(fr->stereo == 2) {
10468
e2979f202bb2 layer-1 support
arpi
parents:
diff changeset
25 int i;
e2979f202bb2 layer-1 support
arpi
parents:
diff changeset
26 int jsbound = fr->jsbound;
e2979f202bb2 layer-1 support
arpi
parents:
diff changeset
27 for (i=0;i<jsbound;i++) {
e2979f202bb2 layer-1 support
arpi
parents:
diff changeset
28 *ba++ = getbits(4);
e2979f202bb2 layer-1 support
arpi
parents:
diff changeset
29 *ba++ = getbits(4);
e2979f202bb2 layer-1 support
arpi
parents:
diff changeset
30 }
e2979f202bb2 layer-1 support
arpi
parents:
diff changeset
31 for (i=jsbound;i<SBLIMIT;i++)
e2979f202bb2 layer-1 support
arpi
parents:
diff changeset
32 *ba++ = getbits(4);
e2979f202bb2 layer-1 support
arpi
parents:
diff changeset
33
e2979f202bb2 layer-1 support
arpi
parents:
diff changeset
34 ba = balloc;
e2979f202bb2 layer-1 support
arpi
parents:
diff changeset
35
e2979f202bb2 layer-1 support
arpi
parents:
diff changeset
36 for (i=0;i<jsbound;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 if ((*ba++))
e2979f202bb2 layer-1 support
arpi
parents:
diff changeset
40 *sca++ = getbits(6);
e2979f202bb2 layer-1 support
arpi
parents:
diff changeset
41 }
e2979f202bb2 layer-1 support
arpi
parents:
diff changeset
42 for (i=jsbound;i<SBLIMIT;i++)
e2979f202bb2 layer-1 support
arpi
parents:
diff changeset
43 if ((*ba++)) {
e2979f202bb2 layer-1 support
arpi
parents:
diff changeset
44 *sca++ = getbits(6);
e2979f202bb2 layer-1 support
arpi
parents:
diff changeset
45 *sca++ = getbits(6);
e2979f202bb2 layer-1 support
arpi
parents:
diff changeset
46 }
e2979f202bb2 layer-1 support
arpi
parents:
diff changeset
47 }
e2979f202bb2 layer-1 support
arpi
parents:
diff changeset
48 else {
e2979f202bb2 layer-1 support
arpi
parents:
diff changeset
49 int i;
e2979f202bb2 layer-1 support
arpi
parents:
diff changeset
50 for (i=0;i<SBLIMIT;i++)
e2979f202bb2 layer-1 support
arpi
parents:
diff changeset
51 *ba++ = getbits(4);
e2979f202bb2 layer-1 support
arpi
parents:
diff changeset
52 ba = balloc;
e2979f202bb2 layer-1 support
arpi
parents:
diff changeset
53 for (i=0;i<SBLIMIT;i++)
e2979f202bb2 layer-1 support
arpi
parents:
diff changeset
54 if ((*ba++))
e2979f202bb2 layer-1 support
arpi
parents:
diff changeset
55 *sca++ = getbits(6);
e2979f202bb2 layer-1 support
arpi
parents:
diff changeset
56 }
e2979f202bb2 layer-1 support
arpi
parents:
diff changeset
57 }
e2979f202bb2 layer-1 support
arpi
parents:
diff changeset
58
e2979f202bb2 layer-1 support
arpi
parents:
diff changeset
59 static void I_step_two(real fraction[2][SBLIMIT],unsigned int balloc[2*SBLIMIT],
e2979f202bb2 layer-1 support
arpi
parents:
diff changeset
60 unsigned int scale_index[2][SBLIMIT],struct frame *fr)
e2979f202bb2 layer-1 support
arpi
parents:
diff changeset
61 {
e2979f202bb2 layer-1 support
arpi
parents:
diff changeset
62 int i,n;
e2979f202bb2 layer-1 support
arpi
parents:
diff changeset
63 int smpb[2*SBLIMIT]; /* values: 0-65535 */
e2979f202bb2 layer-1 support
arpi
parents:
diff changeset
64 int *sample;
e2979f202bb2 layer-1 support
arpi
parents:
diff changeset
65 register unsigned int *ba;
e2979f202bb2 layer-1 support
arpi
parents:
diff changeset
66 register unsigned int *sca = (unsigned int *) scale_index;
e2979f202bb2 layer-1 support
arpi
parents:
diff changeset
67
15103
90670e48d270 Use proper parameter range in stereo test
henry
parents: 10468
diff changeset
68 if(fr->stereo == 2) {
10468
e2979f202bb2 layer-1 support
arpi
parents:
diff changeset
69 int jsbound = fr->jsbound;
e2979f202bb2 layer-1 support
arpi
parents:
diff changeset
70 register real *f0 = fraction[0];
e2979f202bb2 layer-1 support
arpi
parents:
diff changeset
71 register real *f1 = fraction[1];
e2979f202bb2 layer-1 support
arpi
parents:
diff changeset
72 ba = balloc;
e2979f202bb2 layer-1 support
arpi
parents:
diff changeset
73 for (sample=smpb,i=0;i<jsbound;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 if ((n = *ba++))
e2979f202bb2 layer-1 support
arpi
parents:
diff changeset
77 *sample++ = getbits(n+1);
e2979f202bb2 layer-1 support
arpi
parents:
diff changeset
78 }
e2979f202bb2 layer-1 support
arpi
parents:
diff changeset
79 for (i=jsbound;i<SBLIMIT;i++)
e2979f202bb2 layer-1 support
arpi
parents:
diff changeset
80 if ((n = *ba++))
e2979f202bb2 layer-1 support
arpi
parents:
diff changeset
81 *sample++ = getbits(n+1);
e2979f202bb2 layer-1 support
arpi
parents:
diff changeset
82
e2979f202bb2 layer-1 support
arpi
parents:
diff changeset
83 ba = balloc;
e2979f202bb2 layer-1 support
arpi
parents:
diff changeset
84 for (sample=smpb,i=0;i<jsbound;i++) {
e2979f202bb2 layer-1 support
arpi
parents:
diff changeset
85 if((n=*ba++))
e2979f202bb2 layer-1 support
arpi
parents:
diff changeset
86 *f0++ = (real) ( ((-1)<<n) + (*sample++) + 1) * muls[n+1][*sca++];
e2979f202bb2 layer-1 support
arpi
parents:
diff changeset
87 else
e2979f202bb2 layer-1 support
arpi
parents:
diff changeset
88 *f0++ = 0.0;
e2979f202bb2 layer-1 support
arpi
parents:
diff changeset
89 if((n=*ba++))
e2979f202bb2 layer-1 support
arpi
parents:
diff changeset
90 *f1++ = (real) ( ((-1)<<n) + (*sample++) + 1) * muls[n+1][*sca++];
e2979f202bb2 layer-1 support
arpi
parents:
diff changeset
91 else
e2979f202bb2 layer-1 support
arpi
parents:
diff changeset
92 *f1++ = 0.0;
e2979f202bb2 layer-1 support
arpi
parents:
diff changeset
93 }
e2979f202bb2 layer-1 support
arpi
parents:
diff changeset
94 for (i=jsbound;i<SBLIMIT;i++) {
e2979f202bb2 layer-1 support
arpi
parents:
diff changeset
95 if ((n=*ba++)) {
e2979f202bb2 layer-1 support
arpi
parents:
diff changeset
96 real samp = ( ((-1)<<n) + (*sample++) + 1);
e2979f202bb2 layer-1 support
arpi
parents:
diff changeset
97 *f0++ = samp * muls[n+1][*sca++];
e2979f202bb2 layer-1 support
arpi
parents:
diff changeset
98 *f1++ = samp * muls[n+1][*sca++];
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 *f0++ = *f1++ = 0.0;
e2979f202bb2 layer-1 support
arpi
parents:
diff changeset
102 }
e2979f202bb2 layer-1 support
arpi
parents:
diff changeset
103 for(i=fr->down_sample_sblimit;i<32;i++)
e2979f202bb2 layer-1 support
arpi
parents:
diff changeset
104 fraction[0][i] = fraction[1][i] = 0.0;
e2979f202bb2 layer-1 support
arpi
parents:
diff changeset
105 }
e2979f202bb2 layer-1 support
arpi
parents:
diff changeset
106 else {
e2979f202bb2 layer-1 support
arpi
parents:
diff changeset
107 register real *f0 = fraction[0];
e2979f202bb2 layer-1 support
arpi
parents:
diff changeset
108 ba = balloc;
e2979f202bb2 layer-1 support
arpi
parents:
diff changeset
109 for (sample=smpb,i=0;i<SBLIMIT;i++)
e2979f202bb2 layer-1 support
arpi
parents:
diff changeset
110 if ((n = *ba++))
e2979f202bb2 layer-1 support
arpi
parents:
diff changeset
111 *sample++ = getbits(n+1);
e2979f202bb2 layer-1 support
arpi
parents:
diff changeset
112 ba = balloc;
e2979f202bb2 layer-1 support
arpi
parents:
diff changeset
113 for (sample=smpb,i=0;i<SBLIMIT;i++) {
e2979f202bb2 layer-1 support
arpi
parents:
diff changeset
114 if((n=*ba++))
e2979f202bb2 layer-1 support
arpi
parents:
diff changeset
115 *f0++ = (real) ( ((-1)<<n) + (*sample++) + 1) * muls[n+1][*sca++];
e2979f202bb2 layer-1 support
arpi
parents:
diff changeset
116 else
e2979f202bb2 layer-1 support
arpi
parents:
diff changeset
117 *f0++ = 0.0;
e2979f202bb2 layer-1 support
arpi
parents:
diff changeset
118 }
e2979f202bb2 layer-1 support
arpi
parents:
diff changeset
119 for(i=fr->down_sample_sblimit;i<32;i++)
e2979f202bb2 layer-1 support
arpi
parents:
diff changeset
120 fraction[0][i] = 0.0;
e2979f202bb2 layer-1 support
arpi
parents:
diff changeset
121 }
e2979f202bb2 layer-1 support
arpi
parents:
diff changeset
122 }
e2979f202bb2 layer-1 support
arpi
parents:
diff changeset
123
e2979f202bb2 layer-1 support
arpi
parents:
diff changeset
124 static int do_layer1(struct frame *fr,int single)
e2979f202bb2 layer-1 support
arpi
parents:
diff changeset
125 {
e2979f202bb2 layer-1 support
arpi
parents:
diff changeset
126 int clip=0;
e2979f202bb2 layer-1 support
arpi
parents:
diff changeset
127 int i,stereo = fr->stereo;
e2979f202bb2 layer-1 support
arpi
parents:
diff changeset
128 unsigned int balloc[2*SBLIMIT];
e2979f202bb2 layer-1 support
arpi
parents:
diff changeset
129 unsigned int scale_index[2][SBLIMIT];
e2979f202bb2 layer-1 support
arpi
parents:
diff changeset
130 real fraction[2][SBLIMIT];
e2979f202bb2 layer-1 support
arpi
parents:
diff changeset
131 // int single = fr->single;
e2979f202bb2 layer-1 support
arpi
parents:
diff changeset
132
e2979f202bb2 layer-1 support
arpi
parents:
diff changeset
133 // 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
134 // wordpointer[0],wordpointer[1],wordpointer[2],wordpointer[3],wordpointer[4],wordpointer[5],wordpointer[6],wordpointer[7]);
e2979f202bb2 layer-1 support
arpi
parents:
diff changeset
135
e2979f202bb2 layer-1 support
arpi
parents:
diff changeset
136 fr->jsbound = (fr->mode == MPG_MD_JOINT_STEREO) ?
e2979f202bb2 layer-1 support
arpi
parents:
diff changeset
137 (fr->mode_ext<<2)+4 : 32;
e2979f202bb2 layer-1 support
arpi
parents:
diff changeset
138
e2979f202bb2 layer-1 support
arpi
parents:
diff changeset
139 if(stereo == 1 || single == 3)
e2979f202bb2 layer-1 support
arpi
parents:
diff changeset
140 single = 0;
e2979f202bb2 layer-1 support
arpi
parents:
diff changeset
141
e2979f202bb2 layer-1 support
arpi
parents:
diff changeset
142 I_step_one(balloc,scale_index,fr);
e2979f202bb2 layer-1 support
arpi
parents:
diff changeset
143
e2979f202bb2 layer-1 support
arpi
parents:
diff changeset
144 for (i=0;i<SCALE_BLOCK;i++)
e2979f202bb2 layer-1 support
arpi
parents:
diff changeset
145 {
e2979f202bb2 layer-1 support
arpi
parents:
diff changeset
146 I_step_two(fraction,balloc,scale_index,fr);
e2979f202bb2 layer-1 support
arpi
parents:
diff changeset
147
e2979f202bb2 layer-1 support
arpi
parents:
diff changeset
148 if(single >= 0)
e2979f202bb2 layer-1 support
arpi
parents:
diff changeset
149 {
e2979f202bb2 layer-1 support
arpi
parents:
diff changeset
150 clip += (fr->synth_mono)( (real *) fraction[single],pcm_sample,&pcm_point);
e2979f202bb2 layer-1 support
arpi
parents:
diff changeset
151 }
e2979f202bb2 layer-1 support
arpi
parents:
diff changeset
152 else {
e2979f202bb2 layer-1 support
arpi
parents:
diff changeset
153 int p1 = pcm_point;
e2979f202bb2 layer-1 support
arpi
parents:
diff changeset
154 clip += (fr->synth)( (real *) fraction[0],0,pcm_sample,&p1);
e2979f202bb2 layer-1 support
arpi
parents:
diff changeset
155 clip += (fr->synth)( (real *) fraction[1],1,pcm_sample,&pcm_point);
e2979f202bb2 layer-1 support
arpi
parents:
diff changeset
156 }
e2979f202bb2 layer-1 support
arpi
parents:
diff changeset
157
e2979f202bb2 layer-1 support
arpi
parents:
diff changeset
158 }
e2979f202bb2 layer-1 support
arpi
parents:
diff changeset
159
e2979f202bb2 layer-1 support
arpi
parents:
diff changeset
160 return clip;
e2979f202bb2 layer-1 support
arpi
parents:
diff changeset
161 }
e2979f202bb2 layer-1 support
arpi
parents:
diff changeset
162
e2979f202bb2 layer-1 support
arpi
parents:
diff changeset
163