⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 cupl3.c

📁 这是一个mp3的源代码
💻 C
📖 第 1 页 / 共 3 页
字号:

   iframe++;


   bitget_init(bs);		/* initialize bit getter */
/* test sync */
   in_out.in_bytes = 0;		/* assume fail */
   in_out.out_bytes = 0;
   sync = bitget(12);

// if( sync != 0xFFF ) return in_out;       /* sync fail */

   mpeg25_flag = 0;
   if (sync != 0xFFF)
   {
      mpeg25_flag = 1;		/* mpeg 2.5 sync */
      if (sync != 0xFFE)
	 return in_out;		/* sync fail */
   }
/*-----------*/


/*-- unpack side info --*/
   side_bytes = unpack_side_MPEG2(igr);
   padframebytes = framebytes + pad;
   in_out.in_bytes = padframebytes;

   buf_ptr0 = buf_ptr1 - side_info.main_data_begin;	/* decode start point */
   if (buf_ptr1 > BUF_TRIGGER)
   {				/* shift buffer */
      memmove(buf, buf + buf_ptr0, side_info.main_data_begin);
      buf_ptr0 = 0;
      buf_ptr1 = side_info.main_data_begin;
   }
   nbytes = padframebytes - side_bytes - crcbytes;
   // RAK: This is no bueno. :-(
	if (nbytes < 0 || nbytes > NBUF)
	{
	    in_out.in_bytes = 0;
		 return in_out;
   }
   memmove(buf + buf_ptr1, bs + side_bytes + crcbytes, nbytes);
   buf_ptr1 += nbytes;
/*-----------------------*/

   if (buf_ptr0 >= 0)
   {
      main_pos_bit = buf_ptr0 << 3;
      unpack_main(pcm, igr);
      in_out.out_bytes = outbytes;
   }
   else
   {
      memset(pcm, zero_level_pcm, outbytes);	/* fill out skipped frames */
      in_out.out_bytes = outbytes;
// iframe--;  in_out.out_bytes = 0; return in_out;// test test */
   }



   igr = igr ^ 1;
   return in_out;
}
/*--------------------------------------------------------------------*/
/*--------------------------------------------------------------------*/
/*--------------------------------------------------------------------*/
static int const sr_table[8] =
{22050, 24000, 16000, 1,
 44100, 48000, 32000, 1};

static const struct
{
   int l[23];
   int s[14];
}
sfBandIndexTable[3][3] =
{
/* mpeg-2 */
   {
      {
	 {
	    0, 6, 12, 18, 24, 30, 36, 44, 54, 66, 80, 96, 116, 140, 168, 200, 238, 284, 336, 396, 464, 522, 576
	 }
	 ,
	 {
	    0, 4, 8, 12, 18, 24, 32, 42, 56, 74, 100, 132, 174, 192
	 }
      }
      ,
      {
	 {
	    0, 6, 12, 18, 24, 30, 36, 44, 54, 66, 80, 96, 114, 136, 162, 194, 232, 278, 332, 394, 464, 540, 576
	 }
	 ,
	 {
	    0, 4, 8, 12, 18, 26, 36, 48, 62, 80, 104, 136, 180, 192
	 }
      }
      ,
      {
	 {
	    0, 6, 12, 18, 24, 30, 36, 44, 54, 66, 80, 96, 116, 140, 168, 200, 238, 284, 336, 396, 464, 522, 576
	 }
	 ,
	 {
	    0, 4, 8, 12, 18, 26, 36, 48, 62, 80, 104, 134, 174, 192
	 }
      }
      ,
   }
   ,
/* mpeg-1 */
   {
      {
	 {
	    0, 4, 8, 12, 16, 20, 24, 30, 36, 44, 52, 62, 74, 90, 110, 134, 162, 196, 238, 288, 342, 418, 576
	 }
	 ,
	 {
	    0, 4, 8, 12, 16, 22, 30, 40, 52, 66, 84, 106, 136, 192
	 }
      }
      ,
      {
	 {
	    0, 4, 8, 12, 16, 20, 24, 30, 36, 42, 50, 60, 72, 88, 106, 128, 156, 190, 230, 276, 330, 384, 576
	 }
	 ,
	 {
	    0, 4, 8, 12, 16, 22, 28, 38, 50, 64, 80, 100, 126, 192
	 }
      }
      ,
      {
	 {
	    0, 4, 8, 12, 16, 20, 24, 30, 36, 44, 54, 66, 82, 102, 126, 156, 194, 240, 296, 364, 448, 550, 576
	 }
	 ,
	 {
	    0, 4, 8, 12, 16, 22, 30, 42, 58, 78, 104, 138, 180, 192
	 }
      }
   }
   ,

/* mpeg-2.5, 11 & 12 KHz seem ok, 8 ok */
   {
      {
	 {
	    0, 6, 12, 18, 24, 30, 36, 44, 54, 66, 80, 96, 116, 140, 168, 200, 238, 284, 336, 396, 464, 522, 576
	 }
	 ,
	 {
	    0, 4, 8, 12, 18, 26, 36, 48, 62, 80, 104, 134, 174, 192
	 }
      }
      ,
      {
	 {
	    0, 6, 12, 18, 24, 30, 36, 44, 54, 66, 80, 96, 116, 140, 168, 200, 238, 284, 336, 396, 464, 522, 576
	 }
	 ,
	 {
	    0, 4, 8, 12, 18, 26, 36, 48, 62, 80, 104, 134, 174, 192
	 }
      }
      ,
// this 8khz table, and only 8khz, from mpeg123)
      {
	 {
	    0, 12, 24, 36, 48, 60, 72, 88, 108, 132, 160, 192, 232, 280, 336, 400, 476, 566, 568, 570, 572, 574, 576
	 }
	 ,
	 {
	    0, 8, 16, 24, 36, 52, 72, 96, 124, 160, 162, 164, 166, 192
	 }
      }
      ,
   }
   ,
};


void sbt_mono_L3(float *sample, signed short *pcm, int ch);
void sbt_dual_L3(float *sample, signed short *pcm, int ch);
void sbt16_mono_L3(float *sample, signed short *pcm, int ch);
void sbt16_dual_L3(float *sample, signed short *pcm, int ch);
void sbt8_mono_L3(float *sample, signed short *pcm, int ch);
void sbt8_dual_L3(float *sample, signed short *pcm, int ch);

void sbtB_mono_L3(float *sample, unsigned char *pcm, int ch);
void sbtB_dual_L3(float *sample, unsigned char *pcm, int ch);
void sbtB16_mono_L3(float *sample, unsigned char *pcm, int ch);
void sbtB16_dual_L3(float *sample, unsigned char *pcm, int ch);
void sbtB8_mono_L3(float *sample, unsigned char *pcm, int ch);
void sbtB8_dual_L3(float *sample, unsigned char *pcm, int ch);



static SBT_FUNCTION sbt_table[2][3][2] =
{
{{ (SBT_FUNCTION) sbt_mono_L3,
   (SBT_FUNCTION) sbt_dual_L3 } ,
 { (SBT_FUNCTION) sbt16_mono_L3,
   (SBT_FUNCTION) sbt16_dual_L3 } ,
 { (SBT_FUNCTION) sbt8_mono_L3,
   (SBT_FUNCTION) sbt8_dual_L3 }} ,
/*-- 8 bit output -*/
{{ (SBT_FUNCTION) sbtB_mono_L3,
   (SBT_FUNCTION) sbtB_dual_L3 },
 { (SBT_FUNCTION) sbtB16_mono_L3,
   (SBT_FUNCTION) sbtB16_dual_L3 },
 { (SBT_FUNCTION) sbtB8_mono_L3,
   (SBT_FUNCTION) sbtB8_dual_L3 }}
};


void Xform_mono(void *pcm, int igr);
void Xform_dual(void *pcm, int igr);
void Xform_dual_mono(void *pcm, int igr);
void Xform_dual_right(void *pcm, int igr);

static XFORM_FUNCTION xform_table[5] =
{
   Xform_mono,
   Xform_dual,
   Xform_dual_mono,
   Xform_mono,			/* left */
   Xform_dual_right,
};
int L3table_init();
void msis_init();
void sbt_init();
typedef int iARRAY22[22];
iARRAY22 *quant_init_band_addr();
iARRAY22 *msis_init_band_addr();

/*---------------------------------------------------------*/
/* mpeg_head defined in mhead.h  frame bytes is without pad */
int L3audio_decode_init(MPEG_HEAD * h, int framebytes_arg,
		   int reduction_code, int transform_code, int convert_code,
			int freq_limit)
{
   int i, j, k;
   // static int first_pass = 1;
   int samprate;
   int limit;
   int bit_code;
   int out_chans;

   buf_ptr0 = 0;
   buf_ptr1 = 0;

/* check if code handles */
   if (h->option != 1)
      return 0;			/* layer III only */

   if (h->id)
      ncbl_mixed = 8;		/* mpeg-1 */
   else
      ncbl_mixed = 6;		/* mpeg-2 */

   framebytes = framebytes_arg;

   transform_code = transform_code;	/* not used, asm compatability */
   bit_code = 0;
   if (convert_code & 8)
      bit_code = 1;
   convert_code = convert_code & 3;	/* higher bits used by dec8 freq cvt */
   if (reduction_code < 0)
      reduction_code = 0;
   if (reduction_code > 2)
      reduction_code = 2;
   if (freq_limit < 1000)
      freq_limit = 1000;


   samprate = sr_table[4 * h->id + h->sr_index];
   if ((h->sync & 1) == 0)
      samprate = samprate / 2;	// mpeg 2.5 
/*----- compute nsb_limit --------*/
   nsb_limit = (freq_limit * 64L + samprate / 2) / samprate;
/*- caller limit -*/
   limit = (32 >> reduction_code);
   if (limit > 8)
      limit--;
   if (nsb_limit > limit)
      nsb_limit = limit;
   limit = 18 * nsb_limit;

   k = h->id;
   if ((h->sync & 1) == 0)
      k = 2;			// mpeg 2.5 

   if (k == 1)
   {
      band_limit12 = 3 * sfBandIndexTable[k][h->sr_index].s[13];
      band_limit = band_limit21 = sfBandIndexTable[k][h->sr_index].l[22];
   }
   else
   {
      band_limit12 = 3 * sfBandIndexTable[k][h->sr_index].s[12];
      band_limit = band_limit21 = sfBandIndexTable[k][h->sr_index].l[21];
   }
   band_limit += 8;		/* allow for antialias */
   if (band_limit > limit)
      band_limit = limit;

   if (band_limit21 > band_limit)
      band_limit21 = band_limit;
   if (band_limit12 > band_limit)
      band_limit12 = band_limit;


   band_limit_nsb = (band_limit + 17) / 18;	/* limit nsb's rounded up */
/*----------------------------------------------*/
   gain_adjust = 0;		/* adjust gain e.g. cvt to mono sum channel */
   if ((h->mode != 3) && (convert_code == 1))
      gain_adjust = -4;

   outvalues = 1152 >> reduction_code;
   if (h->id == 0)
      outvalues /= 2;

   out_chans = 2;
   if (h->mode == 3)
      out_chans = 1;
   if (convert_code)
      out_chans = 1;

   sbt_L3 = sbt_table[bit_code][reduction_code][out_chans - 1];
   k = 1 + convert_code;
   if (h->mode == 3)
      k = 0;
   Xform = xform_table[k];


   outvalues *= out_chans;

   if (bit_code)
      outbytes = outvalues;
   else
      outbytes = sizeof(short) * outvalues;

   if (bit_code)
      zero_level_pcm = 128;	/* 8 bit output */
   else
      zero_level_pcm = 0;


   decinfo.channels = out_chans;
   decinfo.outvalues = outvalues;
   decinfo.samprate = samprate >> reduction_code;
   if (bit_code)
      decinfo.bits = 8;
   else
      decinfo.bits = sizeof(short) * 8;

   decinfo.framebytes = framebytes;
   decinfo.type = 0;

   half_outbytes = outbytes / 2;
/*------------------------------------------*/

/*- init band tables --*/


   k = h->id;
   if ((h->sync & 1) == 0)
      k = 2;			// mpeg 2.5 

   for (i = 0; i < 22; i++)
      sfBandIndex[0][i] = sfBandIndexTable[k][h->sr_index].l[i + 1];
   for (i = 0; i < 13; i++)
      sfBandIndex[1][i] = 3 * sfBandIndexTable[k][h->sr_index].s[i + 1];
   for (i = 0; i < 22; i++)
      nBand[0][i] =
	 sfBandIndexTable[k][h->sr_index].l[i + 1]
	 - sfBandIndexTable[k][h->sr_index].l[i];
   for (i = 0; i < 13; i++)
      nBand[1][i] =
	 sfBandIndexTable[k][h->sr_index].s[i + 1]
	 - sfBandIndexTable[k][h->sr_index].s[i];


/* init tables */
   L3table_init();
/* init ms and is stereo modes */
   msis_init();

/*----- init sbt ---*/
   sbt_init();



/*--- clear buffers --*/
   for (i = 0; i < 576; i++)
      yout[i] = 0.0f;
   for (j = 0; j < 2; j++)
   {
      for (k = 0; k < 2; k++)
      {
	 for (i = 0; i < 576; i++)
	 {
	    sample[j][k][i].x = 0.0f;
	    sample[j][k][i].s = 0;
	 }
      }
   }

   if (h->id == 1)
      decode_function = L3audio_decode_MPEG1;
   else
      decode_function = L3audio_decode_MPEG2;

   return 1;
}
/*---------------------------------------------------------*/
/*==========================================================*/

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -