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

📄 layeriiidecoder.java

📁 JLayer is a library that decodes/plays/converts MPEG 1/2/2.5 Layer 1/2/3 (i.e. MP3) in real time fo
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
	      // System.out.println("x = "+x[0]+" y = "+y[0]);
		}

		// Read count1 area
		h = huffcodetab.ht[si.ch[ch].gr[gr].count1table_select+32];
	    num_bits = br.hsstell();

		while ((num_bits < part2_3_end) && (index < 576)) {

			huffcodetab.huffman_decoder(h, x, y, v, w, br);

	      is_1d[index++] = v[0];
	      is_1d[index++] = w[0];
	      is_1d[index++] = x[0];
	      is_1d[index++] = y[0];
          CheckSumHuff = CheckSumHuff + v[0] + w[0] + x[0] + y[0];
	      // System.out.println("v = "+v[0]+" w = "+w[0]);
	      // System.out.println("x = "+x[0]+" y = "+y[0]);
	      num_bits = br.hsstell();
	   }

		if (num_bits > part2_3_end) {
			br.rewindNbits(num_bits - part2_3_end);
	      index-=4;
	   }

	   num_bits = br.hsstell();

		// Dismiss stuffing bits
		if (num_bits < part2_3_end)
	   	br.hgetbits(part2_3_end - num_bits);

		// Zero out rest

	   if (index < 576)
		   nonzero[ch] = index;
	   else
	   	nonzero[ch] = 576;

	   if (index < 0) index = 0;

	   // may not be necessary
	   for (; index<576; index++)
   		is_1d[index] = 0;
	}

	/**
	 *
	 */
    private void i_stereo_k_values(int is_pos, int io_type, int i)
	{
	   if (is_pos == 0) {
	      k[0][i] = 1.0f;
	      k[1][i] = 1.0f;
	   } else if ((is_pos & 1) != 0) {
			k[0][i] = io[io_type][(is_pos + 1) >>> 1];
	      k[1][i] = 1.0f;
	   } else {
	      k[0][i] = 1.0f;
	      k[1][i] = io[io_type][is_pos >>> 1];
   	   }
	}

	/**
	 *
	 */
	private void dequantize_sample(float xr[][], int ch, int gr)
	{
		gr_info_s gr_info = (si.ch[ch].gr[gr]);
		int  cb=0;
		int  next_cb_boundary;
		int cb_begin = 0;
		int cb_width = 0;
		int  index=0, t_index, j;
	   	float g_gain;
	    float[][] xr_1d = xr;

		// choose correct scalefactor band per block type, initalize boundary

		if ((gr_info.window_switching_flag !=0 ) && (gr_info.block_type == 2) ) {
			if (gr_info.mixed_block_flag != 0)
				next_cb_boundary=sfBandIndex[sfreq].l[1];  // LONG blocks: 0,1,3
			else {
	         cb_width = sfBandIndex[sfreq].s[1];
			   next_cb_boundary = (cb_width << 2) - cb_width;
		 	   cb_begin = 0;
			}
		} else {
			next_cb_boundary=sfBandIndex[sfreq].l[1];  // LONG blocks: 0,1,3
	   }

	   // Compute overall (global) scaling.

		g_gain = (float) Math.pow(2.0 , (0.25 * (gr_info.global_gain - 210.0)));

	  	for (j=0; j<nonzero[ch]; j++)
	  	{
	  	    // Modif E.B 02/22/99
            int reste = j % SSLIMIT;
            int quotien = (int) ((j-reste)/SSLIMIT);
	    	if (is_1d[j] == 0) xr_1d[quotien][reste] = 0.0f;
	        else
	        {
	         int abv = is_1d[j];
	         // Pow Array fix (11/17/04)
	         if (abv < t_43.length)
	         {
				if (is_1d[j] > 0) xr_1d[quotien][reste] = g_gain * t_43[abv];
				else
				{
					if (-abv < t_43.length) xr_1d[quotien][reste] = -g_gain * t_43[-abv];
					else xr_1d[quotien][reste] = -g_gain * (float)Math.pow(-abv, d43);	
				} 
	         }
	         else
	         {
				if (is_1d[j] > 0) xr_1d[quotien][reste] = g_gain * (float)Math.pow(abv, d43);
				else xr_1d[quotien][reste] = -g_gain * (float)Math.pow(-abv, d43);	         	
	         }
	        }
	   }

	   // apply formula per block type
	   for (j=0; j<nonzero[ch]; j++)
	   {
            // Modif E.B 02/22/99
            int reste = j % SSLIMIT;
            int quotien = (int) ((j-reste)/SSLIMIT);

			if (index == next_cb_boundary)  { /* Adjust critical band boundary */
	      	if ((gr_info.window_switching_flag != 0) && (gr_info.block_type == 2)) {
	         	if (gr_info.mixed_block_flag != 0)  {

	            	if (index == sfBandIndex[sfreq].l[8])  {
	                  next_cb_boundary = sfBandIndex[sfreq].s[4];
	                  next_cb_boundary = (next_cb_boundary << 2) -
	                    			           next_cb_boundary;
	                  cb = 3;
	                  cb_width = sfBandIndex[sfreq].s[4] -
	                    			  sfBandIndex[sfreq].s[3];

	                  cb_begin = sfBandIndex[sfreq].s[3];
	                  cb_begin = (cb_begin << 2) - cb_begin;

	               } else if (index < sfBandIndex[sfreq].l[8]) {

	               	next_cb_boundary = sfBandIndex[sfreq].l[(++cb)+1];

	               } else {

	               	next_cb_boundary = sfBandIndex[sfreq].s[(++cb)+1];
	                  next_cb_boundary = (next_cb_boundary << 2) -
	                    				        next_cb_boundary;

	                  cb_begin = sfBandIndex[sfreq].s[cb];
							cb_width = sfBandIndex[sfreq].s[cb+1] -
	                             cb_begin;
	                  cb_begin = (cb_begin << 2) - cb_begin;
	               }

	            } else  {

	               next_cb_boundary = sfBandIndex[sfreq].s[(++cb)+1];
	               next_cb_boundary = (next_cb_boundary << 2) -
	                                  next_cb_boundary;

	               cb_begin = sfBandIndex[sfreq].s[cb];
						cb_width = sfBandIndex[sfreq].s[cb+1] -
	                          cb_begin;
	               cb_begin = (cb_begin << 2) - cb_begin;
	            }

	         } else  { // long blocks

						next_cb_boundary = sfBandIndex[sfreq].l[(++cb)+1];

	         }
	      }

			// Do long/short dependent scaling operations

			if ((gr_info.window_switching_flag !=0)&&
				 (((gr_info.block_type == 2) && (gr_info.mixed_block_flag == 0)) ||
				  ((gr_info.block_type == 2) && (gr_info.mixed_block_flag!=0) && (j >= 36)) ))
	      {

				t_index = (index - cb_begin) / cb_width;
	/*            xr[sb][ss] *= pow(2.0, ((-2.0 * gr_info.subblock_gain[t_index])
	                                    -(0.5 * (1.0 + gr_info.scalefac_scale)
	                                      * scalefac[ch].s[t_index][cb]))); */
				int idx = scalefac[ch].s[t_index][cb]
	           				 << gr_info.scalefac_scale;
	         idx += (gr_info.subblock_gain[t_index] << 2);

				xr_1d[quotien][reste] *= two_to_negative_half_pow[idx];

			} else {   // LONG block types 0,1,3 & 1st 2 subbands of switched blocks
	/*				xr[sb][ss] *= pow(2.0, -0.5 * (1.0+gr_info.scalefac_scale)
														 * (scalefac[ch].l[cb]
														 + gr_info.preflag * pretab[cb])); */
				int idx = scalefac[ch].l[cb];

	   		if (gr_info.preflag != 0)
			   	idx += pretab[cb];

			   idx = idx << gr_info.scalefac_scale;
	         xr_1d[quotien][reste] *= two_to_negative_half_pow[idx];
			}
	      index++;
		}

	   for (j=nonzero[ch]; j<576; j++)
	   {
            // Modif E.B 02/22/99
            int reste = j % SSLIMIT;
            int quotien = (int) ((j-reste)/SSLIMIT);
            if(reste < 0) reste = 0;
            if(quotien < 0) quotien = 0;
	     	xr_1d[quotien][reste] = 0.0f;
	   }

   	   return;
	}

    /**
	 *
	 */
	private void reorder(float xr[][], int ch, int gr)
	{
	   gr_info_s gr_info = (si.ch[ch].gr[gr]);
	   int freq, freq3;
	   int index;
	   int sfb, sfb_start, sfb_lines;
	   int src_line, des_line;
	   float[][] xr_1d = xr;

	   if ((gr_info.window_switching_flag !=0) && (gr_info.block_type == 2)) {

	      for(index=0; index<576; index++)
	         out_1d[index] = 0.0f;

			if (gr_info.mixed_block_flag !=0 ) {
				// NO REORDER FOR LOW 2 SUBBANDS
	            for (index = 0; index < 36; index++)
	            {
                    // Modif E.B 02/22/99
                    int reste = index % SSLIMIT;
                    int quotien = (int) ((index-reste)/SSLIMIT);
	                out_1d[index] = xr_1d[quotien][reste];
	            }
				// REORDERING FOR REST SWITCHED SHORT
				/*for( sfb=3,sfb_start=sfBandIndex[sfreq].s[3],
					 sfb_lines=sfBandIndex[sfreq].s[4] - sfb_start;
					 sfb < 13; sfb++,sfb_start = sfBandIndex[sfreq].s[sfb],
					 sfb_lines = sfBandIndex[sfreq].s[sfb+1] - sfb_start )
					 {*/						   
		 		for( sfb=3; sfb < 13; sfb++)
	            	 {						   
							//System.out.println("sfreq="+sfreq+" sfb="+sfb+" sfBandIndex="+sfBandIndex.length+" sfBandIndex[sfreq].s="+sfBandIndex[sfreq].s.length);
							sfb_start = sfBandIndex[sfreq].s[sfb];
							sfb_lines = sfBandIndex[sfreq].s[sfb+1] - sfb_start;

						   int sfb_start3 = (sfb_start << 2) - sfb_start;

							for(freq=0, freq3=0; freq<sfb_lines;
	                             freq++, freq3+=3) {

								src_line = sfb_start3 + freq;
								des_line = sfb_start3 + freq3;
                                // Modif E.B 02/22/99
                                int reste = src_line % SSLIMIT;
                                int quotien = (int) ((src_line-reste)/SSLIMIT);

								out_1d[des_line] = xr_1d[quotien][reste];
								src_line += sfb_lines;
								des_line++;

								reste = src_line % SSLIMIT;
								quotien = (int) ((src_line-reste)/SSLIMIT);

								out_1d[des_line] = xr_1d[quotien][reste];
								src_line += sfb_lines;
								des_line++;

								reste = src_line % SSLIMIT;
								quotien = (int) ((src_line-reste)/SSLIMIT);

								out_1d[des_line] = xr_1d[quotien][reste];
						   }
	            	  }

			} else {  // pure short
	      	for(index=0;index<576;index++)
	      	{
                int j = reorder_table[sfreq][index];
	            int reste = j % SSLIMIT;
				int quotien = (int) ((j-reste)/SSLIMIT);
	            out_1d[index] = xr_1d[quotien][reste];
	        }
			}
		}
		else {   // long blocks
	      for(index=0; index<576; index++)
	      {
            // Modif E.B 02/22/99
            int reste = index % SSLIMIT;
            int quotien = (int) ((index-reste)/SSLIMIT);
	      	out_1d[index] = xr_1d[quotien][reste];
	      }
		}
	}

	/**
	 *
	 */

	int[] is_pos = new int[576];
	float[] is_ratio = new float[576];

	private void stereo(int gr)
	{
	  int sb, ss;

		if  (channels == 1) { // mono , bypass xr[0][][] to lr[0][][]

			for(sb=0;sb<SBLIMIT;sb++)
				for(ss=0;ss<SSLIMIT;ss+=3) {
					lr[0][sb][ss]   = ro[0][sb][ss];
	            lr[0][sb][ss+1] = ro[0][sb][ss+1];
					lr[0][sb][ss+2] = ro[0][sb][ss+2];
	         }

	   } else {

		gr_info_s gr_info = (si.ch[0].gr[gr]);
	    int mode_ext = header.mode_extension();
		int sfb;
		int i;
	    int lines, temp, temp2;

		boolean ms_stereo = ((header.mode() == Header.JOINT_STEREO) && ((mode_ext & 0x2)!=0));
		boolean i_stereo  = ((header.mode() == Header.JOINT_STEREO) && ((mode_ext & 0x1)!=0));
		boolean lsf = ((header.version() == Header.MPEG2_LSF || header.version() == Header.MPEG25_LSF ));	// SZD

		int io_type = (gr_info.scalefac_compress & 1);

	 	// initialization

	   for (i=0; i<576; i++)
	   {
	   		is_pos[i] = 7;

			is_ratio[i] = 0.0f;
	   }

		if (i_stereo) {
	   	if ((gr_info.window_switching_flag !=0 )&& (gr_info.block_type == 2)) {
	      	if (gr_info.mixed_block_flag != 0) {

	         	 int max_sfb = 0;

					 for (int j=0; j<3; j++) {
	            	 int sfbcnt;
						sfbcnt = 2;
						for( sfb=12; sfb >=3; sfb-- ) {
	               	i = sfBandIndex[sfreq].s[sfb];
							lines = sfBandIndex[sfreq].s[sfb+1] - i;
	                  i = (i << 2) - i + (j+1) * lines - 1;

							while (lines > 0) {
	                  	if (ro[1][i/18][i%18] != 0.0f) {
							// MDM: in java, array access is very slow.
							// Is quicker to compute div and mod values.
						//if (ro[1][ss_div[i]][ss_mod[i]] != 0.0f) {
	                     	sfbcnt = sfb;
									sfb = -10;
									lines = -10;
								}

								lines--;
								i--;

							} // while (lines > 0)

						} // for (sfb=12 ...
						sfb = sfbcnt + 1;

						if (sfb > max_sfb)
							max_sfb = sfb;

						while(sfb < 12) {
	               	temp = sfBandIndex[sfreq].s[sfb];
	               	sb   = sfBandIndex[sfreq].s[sfb+1] - temp;
	                  i    = (temp << 2) - temp + j * sb;

							for ( ; sb > 0; sb--) {
	                  	is_pos[i] = scalefac[1].s[j][sfb];
								if (is_pos[i] != 7)
	                     	if (lsf)

⌨️ 快捷键说明

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