Subversion Repositories Kolibri OS

Rev

Rev 1905 | Details | Compare with Previous | Last modification | View Log | RSS feed

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