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

📄 sublay2.cpp

📁 VC++视频音频开发实用工程案例精选.rar配套光盘代码。
💻 CPP
📖 第 1 页 / 共 4 页
字号:

  if (header->version() == MPEG1) {

	  uint32 channel_bitrate = header->bitrate_index();

	  // calculate bitrate per channel:
	  if (header->mode() != single_channel)
		 if (channel_bitrate == 4)
			channel_bitrate = 1;
		 else
			channel_bitrate -= 4;

	  if (channel_bitrate == 1 || channel_bitrate == 2)
		 // table 3-B.2c or 3-B.2d
		 if (subbandnumber <= 1)
			return 4;
		 else
			return 3;
	  else
		 // tables 3-B.2a or 3-B.2b
		 if (subbandnumber <= 10)
			return 4;
		 else if (subbandnumber <= 22)
			return 3;
		 else
			return 2;

  } else { // MPEG-2 LSF -- Jeff

	  // table B.1 of ISO/IEC 13818-3
     if (subbandnumber <= 3)
     		return 4;
     else if (subbandnumber <= 10)
     		return 3;
     else
     		return 2;
  }

}

void SubbandLayer2::prepare_sample_reading(Header *header, uint32 allocation,
													 	 const real **groupingtable,
                                           real *factor, uint32 *codelength,
                                           real *c, real *d)
{
  uint32 channel_bitrate = header->bitrate_index();

  // calculate bitrate per channel:
  if (header->mode() != single_channel)
	 if (channel_bitrate == 4)
		channel_bitrate = 1;
	 else
		channel_bitrate -= 4;

  if (channel_bitrate == 1 || channel_bitrate == 2)
  {
	 // table 3-B.2c or 3-B.2d
	 *groupingtable = table_cd_groupingtables[allocation];
	 *factor = table_cd_factor[allocation];
	 *codelength = table_cd_codelength[allocation];
	 *c = table_cd_c[allocation];
	 *d = table_cd_d[allocation];
  }
  else
  {
	 // tables 3-B.2a or 3-B.2b
	 if (subbandnumber <= 2)
	 {
		*groupingtable = table_ab1_groupingtables[allocation];
		*factor = table_ab1_factor[allocation];
		*codelength = table_ab1_codelength[allocation];
      *c = table_ab1_c[allocation];
      *d = table_ab1_d[allocation];
    }
	 else
	 {
      *groupingtable = table_ab234_groupingtables[allocation];
		if (subbandnumber <= 10)
		{
			*factor = table_ab2_factor[allocation];
			*codelength = table_ab2_codelength[allocation];
			*c = table_ab2_c[allocation];
			*d = table_ab2_d[allocation];
      }
      else if (subbandnumber <= 22)
      {
			*factor = table_ab3_factor[allocation];
			*codelength = table_ab3_codelength[allocation];
			*c = table_ab3_c[allocation];
			*d = table_ab3_d[allocation];
      }
		else
      {
			*factor = table_ab4_factor[allocation];
			*codelength = table_ab4_codelength[allocation];
			*c = table_ab4_c[allocation];
			*d = table_ab4_d[allocation];
      }
    }
  }
}


void SubbandLayer2::read_allocation(Ibitstream *stream, Header *header, Crc16 *crc)
{
  register uint32 length = get_allocationlength(header);
  allocation = stream->get_bits(length);
  if (crc)
    crc->add_bits(allocation, length);
}


void SubbandLayer2::read_scalefactor_selection(Ibitstream *stream, Crc16 *crc)
{
  if (allocation)
  {
    scfsi = stream->get_bits(2);
    if (crc)
		crc->add_bits(scfsi, 2);
  }
}


void SubbandLayer2::read_scalefactor(Ibitstream *stream, Header *header)
{
  if (allocation)
  {
    switch (scfsi)
    {
      case 0:
  	   scalefactor1 = scalefactors[stream->get_bits(6)];
	   scalefactor2 = scalefactors[stream->get_bits(6)];
	   scalefactor3 = scalefactors[stream->get_bits(6)];
	   break;

		case 1:
	   scalefactor1 = scalefactor2 = scalefactors[stream->get_bits(6)];
	   scalefactor3 = scalefactors[stream->get_bits(6)];
	   break;
      case 2:
	   scalefactor1 = scalefactor2 = scalefactor3 =
      			    scalefactors[stream->get_bits(6)];
		break;

		case 3:
	   scalefactor1 = scalefactors[stream->get_bits(6)];
	   scalefactor2 = scalefactor3 = scalefactors[stream->get_bits(6)];
	   break;
    }
    prepare_sample_reading(header, allocation, &groupingtable,
			    &factor, &codelength, &c, &d);
  }
}


bool SubbandLayer2::read_sampledata(Ibitstream *stream)
{
  if (allocation)
	 if (groupingtable)
	 {
		uint32 samplecode = stream->get_bits(codelength);
		// create requantized samples:
		samplecode += samplecode << 1;
		register real *target = samples;
		register const real *source = groupingtable + samplecode;
		*target++ = *source++;
		*target++ = *source++;
		*target = *source;
		// memcpy (samples, groupingtable + samplecode, 3 * sizeof (real));
	 }
	 else
	 {
		samples[0] = real (stream->get_bits(codelength)) * factor - 1.0f;
		samples[1] = real (stream->get_bits(codelength)) * factor - 1.0f;
		samples[2] = real (stream->get_bits(codelength)) * factor - 1.0f;
	 }

  samplenumber = 0;
  if (++groupnumber == 12)
	 return true;
  else
	 return false;
}


bool SubbandLayer2::put_next_sample (e_channels channels,
												 SynthesisFilter *filter1,
                                     SynthesisFilter *)
{
  if (allocation && channels != right)
  {
	 register real sample = samples[samplenumber];

	 if (!groupingtable)
		sample = (sample + d) * c;
	 if (groupnumber <= 4)
		sample *= scalefactor1;
	 else if (groupnumber <= 8)
		sample *= scalefactor2;
	 else
		sample *= scalefactor3;
	 filter1->input_sample(sample, subbandnumber);
  }

  if (++samplenumber == 3)
	 return true;
  else
	 return false;
}



/******************************/
/*** Intensity Stereo Class ***/
/******************************/

SubbandLayer2IntensityStereo::SubbandLayer2IntensityStereo(uint32 subbandnumber)
: SubbandLayer2(subbandnumber)
{
}


void SubbandLayer2IntensityStereo::read_scalefactor_selection(Ibitstream *stream,
																				  Crc16 *crc)
{
  if (allocation)
  {
	 scfsi = stream->get_bits(2);
	 channel2_scfsi = stream->get_bits(2);
	 if (crc)
	 {
		crc->add_bits(scfsi, 2);

⌨️ 快捷键说明

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