1  /********************************************************************** <BR>


2  This file is part of Crack dot Com's free source code release of


3  Golgotha. <a href="http://www.crack.com/golgotha_release"> <BR> for


4  information about compiling & licensing issues visit this URL</a>


5  <PRE> If that doesn't help, contact Jonathan Clark at


6  golgotha_source@usa.net (Subject should have "GOLG" in it)


7  ***********************************************************************/


8 


9  /*


10  * Mpeg Layer1 audio decoder


11  * 


12  * copyright (c) 1995 by Michael Hipp, All rights reserved. See also 'README'


13  * near unoptimzed ...


14  *


15  * may have a few bugs after last optimization ...


16  *


17  */


18 


19  #include "loaders/mp3/mpg123.hh"


20 


21  void I_step_one(unsigned int balloc[], unsigned int scale_index[2][SBLIMIT],struct frame *fr)


22  {


23  unsigned int *ba=balloc;


24  unsigned int *sca = (unsigned int *) scale_index;


25 


26  if(fr>stereo) {


27  int i;


28  int jsbound = fr>jsbound;


29  for (i=0;i<jsbound;i++) {


30  *ba++ = getbits(4);


31  *ba++ = getbits(4);


32  }


33  for (i=jsbound;i<SBLIMIT;i++)


34  *ba++ = getbits(4);


35 


36  ba = balloc;


37 


38  for (i=0;i<jsbound;i++) {


39  if ((*ba++))


40  *sca++ = getbits(6);


41  if ((*ba++))


42  *sca++ = getbits(6);


43  }


44  for (i=jsbound;i<SBLIMIT;i++)


45  if ((*ba++)) {


46  *sca++ = getbits(6);


47  *sca++ = getbits(6);


48  }


49  }


50  else {


51  int i;


52  for (i=0;i<SBLIMIT;i++)


53  *ba++ = getbits(4);


54  ba = balloc;


55  for (i=0;i<SBLIMIT;i++)


56  if ((*ba++))


57  *sca++ = getbits(6);


58  }


59  }


60 


61  void I_step_two(real fraction[2][SBLIMIT],unsigned int balloc[2*SBLIMIT],


62  unsigned int scale_index[2][SBLIMIT],struct frame *fr)


63  {


64  int i,n;


65  int smpb[2*SBLIMIT]; /* values: 065535 */


66  int *sample;


67  register unsigned int *ba;


68  register unsigned int *sca = (unsigned int *) scale_index;


69 


70  if(fr>stereo) {


71  int jsbound = fr>jsbound;


72  register real *f0 = fraction[0];


73  register real *f1 = fraction[1];


74  ba = balloc;


75  for (sample=smpb,i=0;i<jsbound;i++) {


76  if ((n = *ba++))


77  *sample++ = getbits(n+1);


78  if ((n = *ba++))


79  *sample++ = getbits(n+1);


80  }


81  for (i=jsbound;i<SBLIMIT;i++)


82  if ((n = *ba++))


83  *sample++ = getbits(n+1);


84 


85  ba = balloc;


86  for (sample=smpb,i=0;i<jsbound;i++) {


87  if((n=*ba++))


88  *f0++ = (real) ( ((1)<<n) + (*sample++) + 1) * muls[n+1][*sca++];


89  else


90  *f0++ = 0.0;


91  if((n=*ba++))


92  *f1++ = (real) ( ((1)<<n) + (*sample++) + 1) * muls[n+1][*sca++];


93  else


94  *f1++ = 0.0;


95  }


96  for (sample=smpb,i=jsbound;i<SBLIMIT;i++) {


97  if ((n=*ba++)) {


98  real samp = ( ((1)<<n) + (*sample++) + 1);


99  *f0++ = samp * muls[n+1][*sca++];


100  *f1++ = samp * muls[n+1][*sca++];


101  }


102  else


103  *f0++ = *f1++ = 0.0;


104  }


105  for(i=SBLIMIT>>fr>down_sample;i<32;i++)


106  fraction[0][i] = fraction[1][i] = 0.0;


107  }


108  else {


109  register real *f0 = fraction[0];


110  ba = balloc;


111  for (sample=smpb,i=0;i<SBLIMIT;i++)


112  if ((n = *ba++))


113  *sample++ = getbits(n+1);


114  ba = balloc;


115  for (sample=smpb,i=0;i<SBLIMIT;i++) {


116  if((n=*ba++))


117  *f0++ = (real) ( ((1)<<n) + (*sample++) + 1) * muls[n+1][*sca++];


118  else


119  *f0++ = 0.0;


120  }


121  for(i=SBLIMIT>>fr>down_sample;i<32;i++)


122  fraction[0][i] = 0.0;


123  }


124  }


125 


126  int do_layer1(struct frame *fr,int outmode,struct audio_info_struct *ai)


127  {


128  int clip=0;


129  int i,stereo = fr>stereo;


130  unsigned int balloc[2*SBLIMIT];


131  unsigned int scale_index[2][SBLIMIT];


132  real fraction[2][SBLIMIT];


133  int single = fr>single;


134 


135  if(stereo == 1  single == 3)


136  single = 0;


137 


138  I_step_one(balloc,scale_index,fr);


139 


140  for (i=0;i<SCALE_BLOCK;i++)


141  {


142  I_step_two(fraction,balloc,scale_index,fr);


143 


144  if(single >= 0)


145  {


146  clip += (fr>synth_mono)( (real *) fraction[single],pcm_sample+pcm_point);


147  }


148  else {


149  clip += (fr>synth)( (real *) fraction[0],0,pcm_sample+pcm_point);


150  clip += (fr>synth)( (real *) fraction[1],1,pcm_sample+pcm_point);


151  }


152  pcm_point += fr>block_size;


153 


154  if(pcm_point == audiobufsize)


155  audio_flush(outmode,ai);


156  }


157 


158  return clip;


159  }


160 


161 

