~ubuntu-branches/ubuntu/karmic/asterisk/karmic

« back to all changes in this revision

Viewing changes to codecs/mp3/src/l3dq.c

  • Committer: Bazaar Package Importer
  • Author(s): Mark Purcell
  • Date: 2002-04-27 21:19:32 UTC
  • Revision ID: james.westby@ubuntu.com-20020427211932-kqaertc4bg7ss5mc
Tags: upstream-0.1.11
ImportĀ upstreamĀ versionĀ 0.1.11

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*____________________________________________________________________________
 
2
        
 
3
        FreeAmp - The Free MP3 Player
 
4
 
 
5
        MP3 Decoder originally Copyright (C) 1995-1997 Xing Technology
 
6
        Corp.  http://www.xingtech.com
 
7
 
 
8
        Portions Copyright (C) 1998-1999 EMusic.com
 
9
 
 
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.
 
14
 
 
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.
 
19
 
 
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.
 
23
        
 
24
        $Id: l3dq.c,v 1.1 1999/12/07 05:46:02 markster Exp $
 
25
____________________________________________________________________________*/
 
26
 
 
27
/****  quant.c  ***************************************************
 
28
  Layer III  dequant
 
29
 
 
30
  does reordering of short blocks
 
31
 
 
32
  mod 8/19/98 decode 22 sf bands
 
33
 
 
34
******************************************************************/
 
35
 
 
36
#include <stdlib.h>
 
37
#include <stdio.h>
 
38
#include <float.h>
 
39
#include <math.h>
 
40
#include <string.h>
 
41
#include "L3.h"
 
42
#include "mhead.h"
 
43
#include "protos.h"
 
44
 
 
45
 
 
46
/*----------
 
47
static struct  {
 
48
int l[23];
 
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}}};
 
56
----------*/
 
57
 
 
58
/*--------------------------------*/
 
59
static int pretab[2][22] =
 
60
{
 
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},
 
63
};
 
64
 
 
65
 
 
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 */
 
69
 
 
70
/*-------- scaling lookup
 
71
x = pow(2.0, -0.5*(1+scalefact_scale)*scalefac + preemp)
 
72
look_scale[scalefact_scale][preemp][scalefac]
 
73
-----------------------*/
 
74
#if 0
 
75
typedef float LS[4][32];
 
76
#endif
 
77
 
 
78
/*--- iSample**(4/3) lookup, -32<=i<=31 ---*/
 
79
 
 
80
/*-- pow(2.0, -0.25*8.0*subblock_gain) --*/
 
81
 
 
82
/*-- reorder buffer ---*/
 
83
typedef float ARRAY3[3];
 
84
 
 
85
 
 
86
/*=============================================================*/
 
87
float *quant_init_global_addr(MPEG *m)
 
88
{
 
89
   return m->cupl.look_global;
 
90
}
 
91
/*-------------------------------------------------------------*/
 
92
LS *quant_init_scale_addr(MPEG *m)
 
93
{
 
94
   return m->cupl.look_scale;
 
95
}
 
96
/*-------------------------------------------------------------*/
 
97
float *quant_init_pow_addr(MPEG *m)
 
98
{
 
99
   return m->cupl.look_pow;
 
100
}
 
101
/*-------------------------------------------------------------*/
 
102
float *quant_init_subblock_addr(MPEG *m)
 
103
{
 
104
   return m->cupl.look_subblock;
 
105
}
 
106
/*=============================================================*/
 
107
 
 
108
#ifdef _MSC_VER
 
109
#pragma warning(disable: 4056)
 
110
#endif
 
111
 
 
112
void dequant(MPEG *m, SAMPLE Sample[], int *nsamp,
 
113
             SCALEFACT * sf,
 
114
             GR * gr,
 
115
             CB_INFO * cb_info, int ncbl_mixed)
 
116
{
 
117
   int i, j;
 
118
   int cb, n, w;
 
119
   float x0, xs;
 
120
   float xsb[3];
 
121
   double tmp;
 
122
   int ncbl;
 
123
   int cbs0;
 
124
   ARRAY3 *buf;                 /* short block reorder */
 
125
   int nbands;
 
126
   int i0;
 
127
   int non_zero;
 
128
   int cbmax[3];
 
129
 
 
130
   nbands = *nsamp;
 
131
 
 
132
 
 
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)
 
137
   {
 
138
      ncbl = 0;
 
139
      cbs0 = 0;
 
140
      if (gr->mixed_block_flag)
 
141
      {
 
142
         ncbl = ncbl_mixed;
 
143
         cbs0 = 3;
 
144
      }
 
145
   }
 
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)
 
150
      cb_info->lb_type;
 
151
   */
 
152
   cb_info->cbs0 = cbs0;
 
153
   cb_info->ncbl = ncbl;
 
154
 
 
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];
 
158
   i = 0;
 
159
/*----- long blocks ---*/
 
160
   for (cb = 0; cb < ncbl; cb++)
 
161
   {
 
162
      non_zero = 0;
 
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++)
 
166
      {
 
167
         if (Sample[i].s == 0)
 
168
            Sample[i].x = 0.0F;
 
169
         else
 
170
         {
 
171
            non_zero = 1;
 
172
            if ((Sample[i].s >= (-ISMAX)) && (Sample[i].s < ISMAX))
 
173
               Sample[i].x = xs * m->cupl.look_pow[ISMAX + Sample[i].s];
 
174
            else
 
175
            {
 
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));
 
179
            }
 
180
         }
 
181
      }
 
182
      if (non_zero)
 
183
         cbmax[0] = cb;
 
184
      if (i >= nbands)
 
185
         break;
 
186
   }
 
187
 
 
188
   cb_info->cbmax = cbmax[0];
 
189
   cb_info->cbtype = 0;         // type = long
 
190
 
 
191
   if (cbs0 >= 12)
 
192
      return;
 
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++)
 
202
   {
 
203
      n = m->cupl.nBand[1][cb];
 
204
      for (w = 0; w < 3; w++)
 
205
      {
 
206
         non_zero = 0;
 
207
         xs = xsb[w] * m->cupl.look_scale[gr->scalefac_scale][0][sf->s[w][cb]];
 
208
         for (j = 0; j < n; j++, i++)
 
209
         {
 
210
            if (Sample[i].s == 0)
 
211
               buf[j][w] = 0.0F;
 
212
            else
 
213
            {
 
214
               non_zero = 1;
 
215
               if ((Sample[i].s >= (-ISMAX)) && (Sample[i].s < ISMAX))
 
216
                  buf[j][w] = xs * m->cupl.look_pow[ISMAX + Sample[i].s];
 
217
               else
 
218
               {
 
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));
 
222
               }
 
223
            }
 
224
         }
 
225
         if (non_zero)
 
226
            cbmax[w] = cb;
 
227
      }
 
228
      if (i >= nbands)
 
229
         break;
 
230
      buf += n;
 
231
   }
 
232
 
 
233
 
 
234
   memmove(&Sample[i0].x, &m->cupl.re_buf[0][0], sizeof(float) * (i - i0));
 
235
 
 
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])
 
241
      cbmax[0] = cbmax[1];
 
242
   if (cbmax[2] > cbmax[0])
 
243
      cbmax[0] = cbmax[2];
 
244
 
 
245
   cb_info->cbmax = cbmax[0];
 
246
   cb_info->cbtype = 1;         /* type = short */
 
247
 
 
248
 
 
249
   return;
 
250
}
 
251
 
 
252
#ifdef _MSC_VER
 
253
#pragma warning(default: 4056)
 
254
#endif
 
255
 
 
256
/*-------------------------------------------------------------*/