typo fixes
[mplayer/greg.git] / mp3lib / layer1.c
blobbe4d6c7c7eb15f933696f3f3aff058068dc4ac0f
1 /*
2 * Modified for use with MPlayer, for details see the CVS changelog at
3 * http://www.mplayerhq.hu/cgi-bin/cvsweb.cgi/main/
4 * $Id$
5 */
7 /*
8 * Mpeg Layer-1 audio decoder
9 * --------------------------
10 * copyright (c) 1995 by Michael Hipp, All rights reserved. See also 'README'
11 * near unoptimzed ...
13 * may have a few bugs after last optimization ...
17 //#include "mpg123.h"
19 static void I_step_one(unsigned int balloc[], unsigned int scale_index[2][SBLIMIT],struct frame *fr)
21 unsigned int *ba=balloc;
22 unsigned int *sca = (unsigned int *) scale_index;
24 if(fr->stereo == 2) {
25 int i;
26 int jsbound = fr->jsbound;
27 for (i=0;i<jsbound;i++) {
28 *ba++ = getbits(4);
29 *ba++ = getbits(4);
31 for (i=jsbound;i<SBLIMIT;i++)
32 *ba++ = getbits(4);
34 ba = balloc;
36 for (i=0;i<jsbound;i++) {
37 if ((*ba++))
38 *sca++ = getbits(6);
39 if ((*ba++))
40 *sca++ = getbits(6);
42 for (i=jsbound;i<SBLIMIT;i++)
43 if ((*ba++)) {
44 *sca++ = getbits(6);
45 *sca++ = getbits(6);
48 else {
49 int i;
50 for (i=0;i<SBLIMIT;i++)
51 *ba++ = getbits(4);
52 ba = balloc;
53 for (i=0;i<SBLIMIT;i++)
54 if ((*ba++))
55 *sca++ = getbits(6);
59 static void I_step_two(real fraction[2][SBLIMIT],unsigned int balloc[2*SBLIMIT],
60 unsigned int scale_index[2][SBLIMIT],struct frame *fr)
62 int i,n;
63 int smpb[2*SBLIMIT]; /* values: 0-65535 */
64 int *sample;
65 register unsigned int *ba;
66 register unsigned int *sca = (unsigned int *) scale_index;
68 if(fr->stereo == 2) {
69 int jsbound = fr->jsbound;
70 register real *f0 = fraction[0];
71 register real *f1 = fraction[1];
72 ba = balloc;
73 for (sample=smpb,i=0;i<jsbound;i++) {
74 if ((n = *ba++))
75 *sample++ = getbits(n+1);
76 if ((n = *ba++))
77 *sample++ = getbits(n+1);
79 for (i=jsbound;i<SBLIMIT;i++)
80 if ((n = *ba++))
81 *sample++ = getbits(n+1);
83 ba = balloc;
84 for (sample=smpb,i=0;i<jsbound;i++) {
85 if((n=*ba++))
86 *f0++ = (real) ( ((-1)<<n) + (*sample++) + 1) * muls[n+1][*sca++];
87 else
88 *f0++ = 0.0;
89 if((n=*ba++))
90 *f1++ = (real) ( ((-1)<<n) + (*sample++) + 1) * muls[n+1][*sca++];
91 else
92 *f1++ = 0.0;
94 for (i=jsbound;i<SBLIMIT;i++) {
95 if ((n=*ba++)) {
96 real samp = ( ((-1)<<n) + (*sample++) + 1);
97 *f0++ = samp * muls[n+1][*sca++];
98 *f1++ = samp * muls[n+1][*sca++];
100 else
101 *f0++ = *f1++ = 0.0;
103 for(i=fr->down_sample_sblimit;i<32;i++)
104 fraction[0][i] = fraction[1][i] = 0.0;
106 else {
107 register real *f0 = fraction[0];
108 ba = balloc;
109 for (sample=smpb,i=0;i<SBLIMIT;i++)
110 if ((n = *ba++))
111 *sample++ = getbits(n+1);
112 ba = balloc;
113 for (sample=smpb,i=0;i<SBLIMIT;i++) {
114 if((n=*ba++))
115 *f0++ = (real) ( ((-1)<<n) + (*sample++) + 1) * muls[n+1][*sca++];
116 else
117 *f0++ = 0.0;
119 for(i=fr->down_sample_sblimit;i<32;i++)
120 fraction[0][i] = 0.0;
124 static int do_layer1(struct frame *fr,int single)
126 int clip=0;
127 int i,stereo = fr->stereo;
128 unsigned int balloc[2*SBLIMIT];
129 unsigned int scale_index[2][SBLIMIT];
130 real fraction[2][SBLIMIT];
131 // int single = fr->single;
133 // printf("do_layer1(0x%02X 0x%02X 0x%02X 0x%02X 0x%02X 0x%02X 0x%02X 0x%02X )\n",
134 // wordpointer[0],wordpointer[1],wordpointer[2],wordpointer[3],wordpointer[4],wordpointer[5],wordpointer[6],wordpointer[7]);
136 fr->jsbound = (fr->mode == MPG_MD_JOINT_STEREO) ?
137 (fr->mode_ext<<2)+4 : 32;
139 if(stereo == 1 || single == 3)
140 single = 0;
142 I_step_one(balloc,scale_index,fr);
144 for (i=0;i<SCALE_BLOCK;i++)
146 I_step_two(fraction,balloc,scale_index,fr);
148 if(single >= 0)
150 clip += (fr->synth_mono)( (real *) fraction[single],pcm_sample,&pcm_point);
152 else {
153 int p1 = pcm_point;
154 clip += (fr->synth)( (real *) fraction[0],0,pcm_sample,&p1);
155 clip += (fr->synth)( (real *) fraction[1],1,pcm_sample,&pcm_point);
160 return clip;