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

📄 layeriidecoder.java

📁 java for mp3 audio and speech coding
💻 JAVA
📖 第 1 页 / 共 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;
	    }
	  }
	  
	  /**
	   *
	   */
	   protected void prepare_sample_reading(Header header, int allocation,
											 float[][] groupingtable,
	                                         float[] factor, int[] codelength,
	                                         float[] c, float[] d)
	   {
	 	 	int channel_bitrate = header.bitrate_index();
	  		// calculate bitrate per channel:
		  	if (header.mode() != Header.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[0] = table_cd_groupingtables[allocation];
				 factor[0] = table_cd_factor[allocation];
				 codelength[0] = table_cd_codelength[allocation];
				 c[0] = table_cd_c[allocation];
				 d[0] = table_cd_d[allocation];
	 		 }
	 		 else
	 		 {
				 // tables 3-B.2a or 3-B.2b
				 if (subbandnumber <= 2)
				 {
					groupingtable[0] = table_ab1_groupingtables[allocation];
					factor[0] = table_ab1_factor[allocation];
					codelength[0] = table_ab1_codelength[allocation];
	 		     	c[0] = table_ab1_c[allocation];
	 		     	d[0] = table_ab1_d[allocation];
	 		     }
				 else
				 {
	 		     	groupingtable[0] = table_ab234_groupingtables[allocation];
					if (subbandnumber <= 10)
					{
						factor[0] = table_ab2_factor[allocation];
						codelength[0] = table_ab2_codelength[allocation];
						c[0] = table_ab2_c[allocation];
						d[0] = table_ab2_d[allocation];
	 		     	}
	 		     	else if (subbandnumber <= 22)
	 		     	{
						factor[0] = table_ab3_factor[allocation];
						codelength[0] = table_ab3_codelength[allocation];
						c[0] = table_ab3_c[allocation];
						d[0] = table_ab3_d[allocation];
	 		     	}
					else
	 		     	{
						factor[0] = table_ab4_factor[allocation];
						codelength[0] = table_ab4_codelength[allocation];
						c[0] = table_ab4_c[allocation];
						d[0] = table_ab4_d[allocation];
	 		     	}
	 		   	 }
	 		 }   
	   }
					 
	  
	  /**
	   *
	   */
	  public void read_allocation(Bitstream stream, Header header, Crc16 crc)
	  {
		 int length = get_allocationlength(header);
		 allocation = stream.get_bits(length);
		 if (crc != null) 
			 crc.add_bits(allocation, length);  
	  }
	  
	  /**
	   *
	   */
	  public void read_scalefactor_selection (Bitstream stream, Crc16 crc)
	  {
	 	if (allocation != 0)
	 	{
	    	scfsi = stream.get_bits(2);
	    	if (crc != null) crc.add_bits(scfsi, 2);
	    }
	  }

	  /**
	   *
	   */
	  public void read_scalefactor (Bitstream stream, Header header)
	  {
	 	if (allocation != 0)
	 	{
	 	   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);
	  }
	  }
	  
	  /**
	   *
	   */
	  public boolean read_sampledata (Bitstream stream)
	  {
	  	if (allocation != 0)
		 if (groupingtable[0] != null)
		 {
			int samplecode = stream.get_bits(codelength[0]);
			// create requantized samples:
			samplecode += samplecode << 1;
			float[] target = samples;
			float[] source = groupingtable[0];
		    int tmp = 0;
			int temp = 0;
			target[tmp++] = source[samplecode + temp];
			temp++;
			target[tmp++] = source[samplecode + temp];
			temp++;
			target[tmp] = source[samplecode + temp];
			// memcpy (samples, groupingtable + samplecode, 3 * sizeof (real));
		 }
		 else
		 {
			samples[0] = (float) ((stream.get_bits(codelength[0])) * factor[0] - 1.0);
			samples[1] = (float) ((stream.get_bits(codelength[0])) * factor[0] - 1.0);
			samples[2] = (float) ((stream.get_bits(codelength[0])) * factor[0] - 1.0);
		 }

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

	  /**
	   *
	   */
	  public boolean put_next_sample(int channels, SynthesisFilter filter1, SynthesisFilter filter2)
	  {
	    if ((allocation != 0) && (channels != OutputChannels.RIGHT_CHANNEL))
	    {
	  	 float sample = samples[samplenumber];
	  
	  	 if (groupingtable != null)
	  		sample = (sample + d[0]) * c[0];
	  	 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;
	  }
	};
	
	 /**
	  * Class for layer II subbands in joint stereo mode.
	  */
	static class SubbandLayer2IntensityStereo extends SubbandLayer2
	{
	  protected int		 channel2_scfsi;
	  protected float 	 channel2_scalefactor1, channel2_scalefactor2, channel2_scalefactor3;

	  /**
	   * Constructor
	   */
	  public SubbandLayer2IntensityStereo (int subbandnumber)
	  {
	 	super(subbandnumber);
	  }

	  /**
	   *
	   */
	  public void read_allocation(Bitstream stream, Header header, Crc16 crc)
	  {
	    super.read_allocation (stream, header, crc);
	  }
	  
	  /**
	   *
	   */
	  public void read_scalefactor_selection(Bitstream stream, Crc16 crc)
	  {
	    if (allocation != 0)
	    {
	  	 scfsi = stream.get_bits(2);
	  	 channel2_scfsi = stream.get_bits(2);
	  	 if (crc != null)
	  	 {
	  		crc.add_bits(scfsi, 2);
	  		crc.add_bits(channel2_scfsi, 2);
	  	 }
	    }  
	  }
	  
	  /**
	   *
	   */
	  public void read_scalefactor(Bitstream stream, Header header)
	  {
	    if (allocation != 0)
	    {
	  	 super.read_scalefactor(stream, header);
	  	 switch (channel2_scfsi)
	  	 {
	  		case 0:

⌨️ 快捷键说明

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