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

📄 musicout.c

📁 MPEG 2的音频编码软件。喜欢多媒体的开发人员可以看看。
💻 C
📖 第 1 页 / 共 4 页
字号:
		    frameBits += bs_ext.totbits;
		    if (!sync)
		    {
		       fprintf(stderr, "Extension frame cannot be located, end of input stream\n");
		       exit (1);
		    }

		    while (bs_ext.curpos < bs_ext.totbits)
		       bs_mc.bits[bs_mc.totbits++] = bs_ext.bits[bs_ext.curpos++];
		 }

		 for (i=0; i < channels; i++)
		    for (j=0; j < SBLIMIT; j++)
		       if (I_bit_alloc[0][i][j] > 0)
		          bit_alloc[i][j] = I_bit_alloc[0][i][j];
		       else if (I_bit_alloc[1][i][j] > 0)
		          bit_alloc[i][j] = I_bit_alloc[1][i][j];
		       else if (I_bit_alloc[2][i][j] > 0)
		          bit_alloc[i][j] = I_bit_alloc[2][i][j];
		       else
		          bit_alloc[i][j] = 0;
	      }
	   }
	   else if (info.lay == 2 )
	   {
	      layer_I_frames = 3;
	      bitsPerSlot = 8;
	      samplesPerFrame = 1152;
	      ch_start = 0;
	      channels = stereo;
	      II_decode_bitalloc (&bs_mpg, &fr_ps, bit_alloc, bits_log);
	      II_decode_scale (&bs_mpg, &fr_ps, scfsi, bit_alloc, scale_index, &ch_start, &channels, scfsi_log);

	      if (error_protection)
	      {
		 II_CRC_calc(&fr_ps, bit_alloc, scfsi, &new_crc);
		 if (new_crc != old_crc)
		 {
		    printf(" \n ERROR in LAYER 2 - CRC! \n");
		    crc_error_count++;
		    total_error_count++;
		    recover_CRC_error (*pcm_sample, crc_error_count,
				       &fr_ps, musicout, &sample_frames, channels);
		 }
		 else crc_error_count = 0;
	      }

	      clip = 0;

	      for (i=0;i<12;i++)
	      {
		 II_buffer_sample (&bs_mpg, &fr_ps, (*sample), bit_alloc);
if (!any_log)
{
		 II_dequantize_sample ((*sample), bit_alloc, *fraction, &fr_ps, &i);
		 II_denormalize_sample (*fraction, scale_index, &fr_ps, i>>2, &i);
}
	      }   /* end of for loop */

	      if (mpeg > 1)
	      {
		 while (bs_mpg.curpos < bs_mpg.totbits)
		    bs_mc.bits[bs_mc.totbits++] = bs_mpg.bits[bs_mpg.curpos++];

		 mc_header (&bs_mc, &fr_ps);
		 mc_hdr_to_frps (&fr_ps);

		 bs_mc.totbits -= fr_ps.header->n_ad_bytes * 8;

		 if (fr_ps.header->ext_bit_stream_present)
		 {
		    sync = seek_sync_ext (&bs_ext, &fr_ps);
		    frameBits += bs_ext.totbits;
		    if (!sync)
		    {
		       fprintf(stderr, "Extension frame cannot be located, end of input stream\n");
		       exit (1);
		    }

		    while (bs_ext.curpos < bs_ext.totbits)
		       bs_mc.bits[bs_mc.totbits++] = bs_ext.bits[bs_ext.curpos++];
		 }
	      }
	   }

	   /**********************************************************/
	   /*     	multichannel - decoding    	           */
	   /*             7.07.93 Susanne Ritscher                   */
	   /*            13.10.93 Ralf Schwalbe                      */
	   /*	       30.05.94 Ralf Schwalbe			   */
	   /**********************************************************/

	   if (rate_log)
	     printf ("frame: %5d bitrate: %8.3f kbps\n", frameNum, frameBits * S_freq / samplesPerFrame);
	   else if (mpeg >= 2)
	   {	
	     if ( (frameNum==1) && (fr_ps.header->no_of_multi_lingual_ch>0) )
	     {
	       /*frameNum==1 NOT frameNum==0*/
	       if (fr_ps.header->no_of_multi_lingual_ch>7)
	       {
		 printf("\n\n***Warning. There are %d multilingual channels.\n", fr_ps.header->no_of_multi_lingual_ch);
		 printf    ("            This decoder supports only upto 7 channels.\n\n");
	       }
	       printf("There are %d multilingual channels, coded at ",fr_ps.header->no_of_multi_lingual_ch);
	       if (fr_ps.header->multi_lingual_fs==0) printf("full"); else printf("half");
	       printf(" sampling rate.\n They are outputted in \"%s\".\n",decoded_file_name_ml);
	       if ((musicout_ml = fopen(decoded_file_name_ml, "w+b")) == NULL)
	       {
		 fprintf (stderr, "***Error. Could not create \"%s\".\nExit\n", decoded_file_name_ml);
		 exit (1);
	       }
	       if(need_aiff)
	       {
		 printf("Multilingual file written in AIFF format\n");
		 if (aiff_seek_to_sound_data (musicout_ml) == -1)
		 {
		    fprintf (stderr, "Could not seek to ML PCM sound data in \"%s\".\n",
			    decoded_file_name_ml);
		    exit (1);
		 }  
	       }
	     }

	     mc_channel = fr_ps.mc_channel;
	     crc_error_count_mc = 0;
	     buffer_CRC (&bs_mc, &old_crc);   /* read CRC - check from header */
	     mc_composite_status_info (&bs_mc, &fr_ps, tca_log, dynx_log);
	     
	     if (frameNum == 1) 
	   	if (info.lfe)
		    printf ("mc-channel=%d, MPEG2-ext-length=%d kbit/s lfe-channel present\n",
		    		mc_channel, (int) (info.ext_length * s_freq[info.sampling_frequency] / 144));
 		else
		    printf ("mc-channel=%d, MPEG2-ext-length=%d kbit/s\n",
		    		mc_channel, (int) (info.ext_length * s_freq[info.sampling_frequency] / 144));

	     /* Achtung: fr_ps.jsbound = 27; wird in Abh鋘gikeit von fs gesetzt*/
	     ch_start = stereo;
	     channels = stereo + mc_channel;

	     /* decoding bitallocation's */
	   
	     II_decode_bitalloc_mc (&bs_mc, &fr_ps, bit_alloc, &ch_start, &channels, bits_log);
	     II_decode_scale (&bs_mc, &fr_ps, scfsi, bit_alloc, scale_index, &ch_start, &channels, scfsi_log);

	     /* mandatory CRC check is set */
	     if (crc_check)
	     {
		mc_error_check (&fr_ps, bit_alloc, scfsi, &new_crc, ch_start, channels);
		if (new_crc != old_crc)
		{
		   crc_error_count_mc++;
		   total_error_count_mc++;
		   for (i = 0; i < SBLIMIT; i ++)
		      for (ii = ch_start; ii < channels; ++ii)
			 bit_alloc[ii][i] = 0;
		   printf ("\nERROR in MC-CRC -> mc frame can't be decoded !\n");
		}
		else
		   crc_error_count_mc = 0;
	     }  /* endif crc_check */

	     clip = 0;
	     for (i = 0; i < 12; i++)
	     {
		II_buffer_sample_mc (&bs_mc, &fr_ps, (*sample), bit_alloc, ch_start, channels, i);
if (!any_log)
{
		II_dequantize_sample_mc ((*sample), bit_alloc, *fraction, &fr_ps, ch_start, channels, &i);
		II_denormalize_sample_mc (*fraction, scale_index, &fr_ps, i>>2, ch_start, channels, &i);
}
	     }

	     /* 10/31/95 Ralf Schwalbe LFE */
	     if( info.lfe ) 
	     { 
		if(lfe_init)
		{
		   f = strlen (encoded_file_name) - 4;
		   strcpy (lfe_file_name, encoded_file_name);
		   strcpy (&lfe_file_name[f], DFLT_OPEXT_LFE);
		   if ((lfe = fopen (lfe_file_name, "w+b")) == NULL)
		   {
		      fprintf (stderr, "Could not create \"%s\".\n",lfe_file_name );
		      exit (1);
		   }
		   if (need_aiff)
		   {
		      printf ("LFE file written in AIFF format\n");
		      if (aiff_seek_to_sound_data (lfe) == -1)
		      {
			 fprintf (stderr, "Could not seek to LFE PCM sound data in \"%s\".\n",
				 lfe_file_name);
			 exit (1);
		      }  
		   }	
		}
		lfe_init = 0; /* R.S. only one time */	
		II_lfe_calc(&fr_ps);  
	     }
/*********************************************************************/
/* JMZ 09/03/1995 Multilingual , WtK 7/8/95 */

	     if (info.no_of_multi_lingual_ch>0) 
	     {
		/* SWKim060695 add the condion with 32, 44.1kHz case */
		if (info.sampling_frequency == 1)
		   fr_ps.jsbound = 27;
		else
		   fr_ps.jsbound = 30;

		m = info.no_of_multi_lingual_ch;

		II_decode_bitalloc_ml (&bs_mc, &fr_ps, bit_alloc_ml, &m);
		II_decode_scale_ml (&bs_mc, &fr_ps, scfsi_ml, bit_alloc_ml, scale_index_ml, &m);


		   clip = 0;
		   for (i=0; i< ( (info.multi_lingual_fs==0) ? 12 : 6 ); i++) /* ngr : n_of_granules loop */
		   {
		      II_buffer_sample_ml (&bs_mc, &fr_ps, (*sample_ml), bit_alloc_ml, &m);
if (!any_log)
{
		      II_dequantize_sample_ml ((*sample_ml), bit_alloc_ml, *fraction_ml, &fr_ps, &m, &i);
		      II_denormalize_sample_ml (*fraction_ml, scale_index_ml, &fr_ps,
					      ( (info.multi_lingual_fs==0) ? (i>>2) : (i>>1) ), &m, &i);
}
		      for (k = 0; k < info.no_of_multi_lingual_ch; k++)
			 for (ii = 0; ii < 3; ii++)
			    for (j = 0; j < 32; j++)
			       sym_sample_ml[i][k][ii][j] = (*sample_ml)[k][ii][j];
		   }
	     }

/* JMZ 09/03/1995 Multilingual */
/*********************************************************************/

#ifdef Augmentation_7ch
	     if (mpeg == 3)
	       if (stereo != 2 || fr_ps.header->surround != 2 || fr_ps.header->center == 0)
	       {
		 /* no 3/2 mode */
		 printf ("WARNING: Stream does not contain 5/2 info\n");
		 printf ("         Continue decoding of MPEG2 MC part\n");
		 mpeg = 2;
	       }

	     if (mpeg == 3)
	     {
	       crc_error_count_aug = 0;
	       mc_aug_composite_status_info (&bs_mc, &fr_ps, tca_log, dynx_log);

	       buffer_CRC (&bs_mc, &old_crc);   /* read CRC - check from header */
	       
	       /* Achtung: fr_ps.jsbound = 27; wird in Abh鋘gikeit von fs gesetzt*/
	       ch_start = 5;
	       channels = 7;

	       /* decoding bitallocation's */
	     
	       II_decode_bitalloc_aug (&bs_mc, &fr_ps, bit_alloc, &ch_start, &channels, bits_log);
	       II_decode_scale (&bs_mc, &fr_ps, scfsi, bit_alloc, scale_index, &ch_start, &channels, scfsi_log);

	       /* mandatory CRC check is set */
	       if (crc_check)
	       {
		     mc_aug_error_check(&fr_ps, bit_alloc, scfsi, &new_crc);
		     if (new_crc != old_crc)
		     {
			     crc_error_count_aug++;
			     total_error_count_aug++;
			     for( i = 0; i < SBLIMIT; i ++)
				     for(ii = ch_start; ii < channels; ++ii)
					     bit_alloc[ii][i] = 0;

			     printf("ERROR in MC-AUG-CRC -> mc aug frame can't be decoded !\n");
		     }
		     else
			     crc_error_count_aug = 0;
	       }  /* endif crc_check */

		       clip = 0;
		       for (i=0;i<12;i++)
		       {
			     II_buffer_sample_aug (&bs_mc, &fr_ps, (*sample), bit_alloc, i);
if (!any_log)
{
			     II_dequantize_sample_aug ((*sample), bit_alloc, *fraction, &fr_ps, &i);
			     II_denormalize_sample_aug (*fraction, scale_index, &fr_ps, i>>2, &i);
}
			}
	     }   /* endif mpeg == 3 */
#endif

	     if (info.mc_prediction_on)
		for (k=0; k<2; k++)
		   for (ii=0; ii<8; ii++) 
		   {
		      for (j=0; j<PREDDEL; j++)
			 (*pred_buf)[k][ii][j] = (*pred_buf)[k][ii][j+36];
		      for (j =0; j <3; j++)
			 for (jj=0;jj<12;jj++)
			    (*pred_buf)[k][ii][PREDDEL+j+3*jj] = (*fraction)[k][ii][j][jj];
		   }

	     /* prediction & dematricing MPEG2 part */
if (!any_log)
	     if (crc_error_count_mc == 0)
		dematricing_mc (*fraction, &fr_ps, *pred_buf);

#ifdef Augmentation_7ch
	     if (mpeg == 3)
	     {
if (!any_log)
		if (crc_error_count_aug == 0)
		{
		   dematricing_aug (*fraction, &fr_ps);
		   denormalizing_aug (*fraction, &fr_ps);
		}
	      }
	      else
#endif
	      if (crc_error_count_mc == 0)
		denormalizing_mc (*fraction, &fr_ps, channels);
	   }   /* endif mpeg >= 2 */

if (!any_log)
	   for (jj=0;jj<4*layer_I_frames;jj++)
	      for (k=0; k < channels; k++)
		  for (j =0; j <3; j++)
		     for (ii=0; ii< SBLIMIT; ii++)
			(*fraction_help)[jj][k][j][ii] = (*fraction)[k][ii][j][jj];
if (!any_log)
	   for (i=0;i<4*layer_I_frames;i++)
	   {			  
	      for (j=0;j<3;j++) 
	         for (k=0; k < channels; k++)
		    clip += SubBandSynthesis (&((*fraction_help)[i][k][j][0]), k,
					    &((*pcm_sample)[k][j][0]));
   
	      out_fifo (*pcm_sample, 3, &fr_ps, done, musicout,
				    &sample_frames, channels);
	   }

	/* 31/10/95 Ralf Schwalbe LFE output */
if (!any_log)
	   if (info.lfe) 
	   {

⌨️ 快捷键说明

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