1
/*____________________________________________________________________________
3
FreeAmp - The Free MP3 Player
5
MP3 Decoder originally Copyright (C) 1995-1997 Xing Technology
6
Corp. http://www.xingtech.com
8
Portions Copyright (C) 1998-1999 EMusic.com
10
This program is free software; you can redistribute it and/or modify
11
it under the terms of the GNU General Public License as published by
12
the Free Software Foundation; either version 2 of the License, or
13
(at your option) any later version.
15
This program is distributed in the hope that it will be useful,
16
but WITHOUT ANY WARRANTY; without even the implied warranty of
17
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18
GNU General Public License for more details.
20
You should have received a copy of the GNU General Public License
21
along with this program; if not, write to the Free Software
22
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24
$Id: l3dq.c,v 1.1 1999/12/07 05:46:02 markster Exp $
25
____________________________________________________________________________*/
27
/**** quant.c ***************************************************
30
does reordering of short blocks
32
mod 8/19/98 decode 22 sf bands
34
******************************************************************/
49
int s[14];} sfBandTable[3] =
50
{{{0,4,8,12,16,20,24,30,36,44,52,62,74,90,110,134,162,196,238,288,342,418,576},
51
{0,4,8,12,16,22,30,40,52,66,84,106,136,192}},
52
{{0,4,8,12,16,20,24,30,36,42,50,60,72,88,106,128,156,190,230,276,330,384,576},
53
{0,4,8,12,16,22,28,38,50,64,80,100,126,192}},
54
{{0,4,8,12,16,20,24,30,36,44,54,66,82,102,126,156,194,240,296,364,448,550,576},
55
{0,4,8,12,16,22,30,42,58,78,104,138,180,192}}};
58
/*--------------------------------*/
59
static int pretab[2][22] =
61
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
62
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 3, 3, 3, 2, 0},
66
/* 8 bit plus 2 lookup x = pow(2.0, 0.25*(global_gain-210)) */
67
/* two extra slots to do 1/sqrt(2) scaling for ms */
68
/* 4 extra slots to do 1/2 scaling for cvt to mono */
70
/*-------- scaling lookup
71
x = pow(2.0, -0.5*(1+scalefact_scale)*scalefac + preemp)
72
look_scale[scalefact_scale][preemp][scalefac]
73
-----------------------*/
75
typedef float LS[4][32];
78
/*--- iSample**(4/3) lookup, -32<=i<=31 ---*/
80
/*-- pow(2.0, -0.25*8.0*subblock_gain) --*/
82
/*-- reorder buffer ---*/
83
typedef float ARRAY3[3];
86
/*=============================================================*/
87
float *quant_init_global_addr(MPEG *m)
89
return m->cupl.look_global;
91
/*-------------------------------------------------------------*/
92
LS *quant_init_scale_addr(MPEG *m)
94
return m->cupl.look_scale;
96
/*-------------------------------------------------------------*/
97
float *quant_init_pow_addr(MPEG *m)
99
return m->cupl.look_pow;
101
/*-------------------------------------------------------------*/
102
float *quant_init_subblock_addr(MPEG *m)
104
return m->cupl.look_subblock;
106
/*=============================================================*/
109
#pragma warning(disable: 4056)
112
void dequant(MPEG *m, SAMPLE Sample[], int *nsamp,
115
CB_INFO * cb_info, int ncbl_mixed)
124
ARRAY3 *buf; /* short block reorder */
133
ncbl = 22; /* long block cb end */
134
cbs0 = 12; /* short block cb start */
135
/* ncbl_mixed = 8 or 6 mpeg1 or 2 */
136
if (gr->block_type == 2)
140
if (gr->mixed_block_flag)
146
/* fill in cb_info -- */
147
/* This doesn't seem used anywhere...
148
cb_info->lb_type = gr->block_type;
149
if (gr->block_type == 2)
152
cb_info->cbs0 = cbs0;
153
cb_info->ncbl = ncbl;
155
cbmax[2] = cbmax[1] = cbmax[0] = 0;
156
/* global gain pre-adjusted by 2 if ms_mode, 0 otherwise */
157
x0 = m->cupl.look_global[(2 + 4) + gr->global_gain];
159
/*----- long blocks ---*/
160
for (cb = 0; cb < ncbl; cb++)
163
xs = x0 * m->cupl.look_scale[gr->scalefac_scale][pretab[gr->preflag][cb]][sf->l[cb]];
164
n = m->cupl.nBand[0][cb];
165
for (j = 0; j < n; j++, i++)
167
if (Sample[i].s == 0)
172
if ((Sample[i].s >= (-ISMAX)) && (Sample[i].s < ISMAX))
173
Sample[i].x = xs * m->cupl.look_pow[ISMAX + Sample[i].s];
176
float tmpConst = (float)(1.0/3.0);
177
tmp = (double) Sample[i].s;
178
Sample[i].x = (float) (xs * tmp * pow(fabs(tmp), tmpConst));
188
cb_info->cbmax = cbmax[0];
189
cb_info->cbtype = 0; // type = long
193
/*---------------------------
194
block type = 2 short blocks
195
----------------------------*/
196
cbmax[2] = cbmax[1] = cbmax[0] = cbs0;
197
i0 = i; /* save for reorder */
198
buf = m->cupl.re_buf;
199
for (w = 0; w < 3; w++)
200
xsb[w] = x0 * m->cupl.look_subblock[gr->subblock_gain[w]];
201
for (cb = cbs0; cb < 13; cb++)
203
n = m->cupl.nBand[1][cb];
204
for (w = 0; w < 3; w++)
207
xs = xsb[w] * m->cupl.look_scale[gr->scalefac_scale][0][sf->s[w][cb]];
208
for (j = 0; j < n; j++, i++)
210
if (Sample[i].s == 0)
215
if ((Sample[i].s >= (-ISMAX)) && (Sample[i].s < ISMAX))
216
buf[j][w] = xs * m->cupl.look_pow[ISMAX + Sample[i].s];
219
float tmpConst = (float)(1.0/3.0);
220
tmp = (double) Sample[i].s;
221
buf[j][w] = (float) (xs * tmp * pow(fabs(tmp), tmpConst));
234
memmove(&Sample[i0].x, &m->cupl.re_buf[0][0], sizeof(float) * (i - i0));
236
*nsamp = i; /* update nsamp */
237
cb_info->cbmax_s[0] = cbmax[0];
238
cb_info->cbmax_s[1] = cbmax[1];
239
cb_info->cbmax_s[2] = cbmax[2];
240
if (cbmax[1] > cbmax[0])
242
if (cbmax[2] > cbmax[0])
245
cb_info->cbmax = cbmax[0];
246
cb_info->cbtype = 1; /* type = short */
253
#pragma warning(default: 4056)
256
/*-------------------------------------------------------------*/