14实验六MPEG音频编码实验

一、MPEG-1 Audio LayerII编码器原理

在这里插入图片描述

1.1 基本思想

分析信号,去掉不能被感知的部分【声音压缩算法可以确立这种特性的模型来取消更多的冗余数据】

◼ 通过子带分析滤波器组使信号具有高的时间分辨率,确保在短暂冲击信号情况下,编码的声音信号具有足够高的质量。
◼ 又可以使信号通过FFT运算具有高的频率分辨率,因为掩蔽阈值是从功率谱密度推出来的。
◼ 在低频子带中,为了保护音调和共振峰的结构,就要求用较小的量化阶、较多的量化级数,即分配较多的位数来表示样本值。而话音中的摩擦音和类似噪声的声音,通常出现在高频子带中,对它分配较少的位数。

1.2 心理声学模型

1.2.1听觉阈值

听觉系统中存在一个听觉阈值电平,低于这个电平的声音信号就听不到
在这里插入图片描述
◼ 听觉阈值的大小随声音频率的改变而改变。
◼ 一个人是否听到声音取决于声音的频率,以及声音的幅度是否高于这种频率下的听觉阈值。

1.2.2频域掩蔽

听觉阈值电平是自适应的,会随听到的不同频率声音而发生变化
在这里插入图片描述如果有多个频率成分的复杂信号存在,那么频谱的总掩蔽阈值与频率的关系取决于各掩蔽音的强度、频率和它们之间的距离。

掩蔽声对被掩蔽声的掩蔽效应,取决于两者的频率与强度的关系。

掩蔽言语声和短声等宽频谱信号,则常用白噪声。因此,在听觉诱发反应测试中,往往在健侧耳施加白噪声作为掩蔽噪声。

1.3 临界频带

临界频带是指当某个纯音被以它为中心频率、且具有一定带宽的连续噪声所掩蔽时,如果该纯音刚好被听到时的功率等于这一频带内的噪声功率,这个带宽为临界频带宽度。

◼ 研究窄带噪声对纯音掩蔽量的规律时被发现的
➢ 使噪声的中心频率等于信号频率,只改变噪声的带宽同时保持噪声的功率谱密度不变,测试纯音听阈随掩蔽噪声带宽变化的特性
➢ 纯音的听阈随掩蔽噪声带宽的增大而增大,在带宽增大到某一特定值之后听阈保持恒定不变。

◼ 通常认为从20Hz到16kHz有25个临界频带,单位为bark,1 Bark = 一个临界频带的宽度
在这里插入图片描述

1.4 人耳听觉系统

人类听觉系统大致等效于一个信号通过一组并联的不同中心频率的带通滤波器

➢ 中心频率与信号频率相同的滤波器具有最大响应;中心频率偏离信号频率较多的滤波器不会产生响应。
➢ 在0Hz到20KHz频率范围内由25个重叠的带通滤波器组成的滤波器组。
➢ 听音者在噪声中听某一纯音信号时,只启用中心频率与信号频率相同的那个听觉滤波器,纯音信号通过该滤波器,而噪声信号只有通带范围内的部分信号能通过,通带以外的频率成分则被抑制,只有通过该滤波器的噪声才对掩蔽起作用。
➢ 聆听复音时启动多个听觉滤波器。听觉能够计算各滤波器输出端的信噪比。当信噪比达到或者超过听阈因子时,即可听到该频率成分。
在这里插入图片描述

1.5掩蔽效果的加和

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

二、MPEG音频压缩

在这里插入图片描述
输入声音信号经过一个多相滤波器组,变换到多个子带,同时经过“心理声学模型”计算以频率为自变量的噪声掩蔽阈值。量化和编码部分用信掩比SMR决定分配给子带信号的量化位数,使量化噪声<掩蔽阈值。最后通过数据帧包装 将量化的子带样本和其它数据按照规定的帧格式组装成比特数据流。

2.1多相滤波器组,用来分割子带

划分子带的方法有两种:线性划分和非线性划分
➢ 线性划分可能一个子带覆盖好几个临界频带,以Layer 1为例,先分成32个相等的子带。
在这里插入图片描述

2.2量化和编码 – 比例因子的取值和编码

对各个子带每12个样点进行一次比例因子计算。先定出12个样点中绝对值的最大值。查比例因子表中比这个最大值大的最小值作为比例因子。用6比特表示。
◆第2层的一帧对应36个子带样值,是第1层的三倍,原则上要传三个比例因子。为了降低比例因子的传输码率,采用了利用人耳时域掩蔽特性的编码策略。
◆每帧中每个子带的三个比例因子被一起考虑,划分成特定的几种模式。根据这些模式,1个、2个或3个比例因子和比例因子选择信息(每子带2比特)一起被传送。如果一个比例因子和下一个只有很小的差别,就只传送大的一个,这种情况对于稳态信号经常出现。
◆使用这一算法后,和第1层相比,第2层传输的比例因子平均减少了2个,即传输码率由22.5Kb/s降低到了7.5Kb/s。

◼ 在调整到固定的码率之前
➢ 先确定可用于样值编码的有效比特数
➢ 这个数值取决于比例因子、比例因子选择信息、比特分配信息以及辅助数据所需比特数
◼ 比特分配的过程
➢ 对每个子带计算掩蔽-噪声比MNR,信噪比SNR–信掩比SMR,即:MNR = SNR–SMR
在这里插入图片描述
◼ 比特分配的过程
➢ 使整个一帧和每个子带的总噪声-掩蔽比最小。这是一个循环过程,每一次循环使获益最大的子带的量化级别增加一级,当然所用比特数不能超过一帧所能提供的最大数目
➢ 第1层一帧用4比特给每个子带的比特分配信息编码;而第2层只在低频段用4比特,高频段则用2比特

2.3数据帧包装

◼码流结构的设计
➢ 有利于使用低复杂性和少延时的解码器,编码后的声音信号包含多个短且恒定间隔的切入点。
➢ 编码数据允许在编码码流中插入整数倍的切入点,以利记录、播放和编辑短的声音序列,并能精确指定编辑点。
在这里插入图片描述

三、实验步骤

1.文件开头定义宏和变量

#define FRAME_TRACE 1
FILE* output;

2.打印音频信息

void print_config (frame_info * frame, int *psy, char *inPath,
		   char *outPath)
{
  frame_header *header = frame->header;

  if (glopts.verbosity == 0)
    return;

  fprintf (stderr, "--------------------------------------------\n");
  fprintf (stderr, "Input File : '%s'   %.1f kHz\n",
	   (strcmp (inPath, "-") ? inPath : "stdin"),
	   s_freq[header->version][header->sampling_frequency]);
  fprintf (stderr, "Output File: '%s'\n",
	   (strcmp (outPath, "-") ? outPath : "stdout"));
  fprintf (stderr, "%d kbps ", bitrate[header->version][header->bitrate_index]);
  fprintf (stderr, "%s ", version_names[header->version]);
  if (header->mode != MPG_MD_JOINT_STEREO)
    fprintf (stderr, "Layer II %s Psycho model=%d  (Mode_Extension=%d)\n",
	     mode_names[header->mode], *psy, header->mode_ext);
  else
    fprintf (stderr, "Layer II %s Psy model %d \n", mode_names[header->mode],
	     *psy);

  fprintf (stderr, "[De-emph:%s\tCopyright:%s\tOriginal:%s\tCRC:%s]\n",
	   ((header->emphasis) ? "On" : "Off"),
	   ((header->copyright) ? "Yes" : "No"),
	   ((header->original) ? "Yes" : "No"),
	   ((header->error_protection) ? "On" : "Off"));

  fprintf (stderr, "[Padding:%s\tByte-swap:%s\tChanswap:%s\tDAB:%s]\n",
	   ((glopts.usepadbit) ? "Normal" : "Off"),
	   ((glopts.byteswap) ? "On" : "Off"),
	   ((glopts.channelswap) ? "On" : "Off"),
	   ((glopts.dab) ? "On" : "Off"));

  if (glopts.vbr == TRUE)
    fprintf (stderr, "VBR Enabled. Using MNR boost of %f\n", glopts.vbrlevel);
  fprintf(stderr,"ATH adjustment %f\n",glopts.athlevel);

  fprintf (stderr, "--------------------------------------------\n");
  #if FRAME_TRACE
  FILE* output;
  output = fopen("output.txt", "a");
  fprintf(output, "========== 基本信息 ==========\n");
  fprintf(output, "输入文件:%s\n", inPath);
  fprintf(output, "输出文件:%s\n", outPath);
  fprintf(output, "采样频率:%.1f kHz\n", s_freq[header->version][header->sampling_frequency]);
  fprintf(output, "输出文件码率:%d kbps\n", bitrate[header->version][header->bitrate_index]);
  fclose(output);
#endif // FRAME_TRACE

}

3.修改主函数

int main (int argc, char **argv)
{
  typedef double SBS[2][3][SCALE_BLOCK][SBLIMIT];
  SBS *sb_sample;
  typedef double JSBS[3][SCALE_BLOCK][SBLIMIT];
  JSBS *j_sample;
  typedef double IN[2][HAN_SIZE];
  IN *win_que;
  typedef unsigned int SUB[2][3][SCALE_BLOCK][SBLIMIT];
  SUB *subband;

  frame_info frame;
  frame_header header;
  char original_file_name[MAX_NAME_SIZE];
  char encoded_file_name[MAX_NAME_SIZE];
  short **win_buf;
  static short buffer[2][1152];
  static unsigned int bit_alloc[2][SBLIMIT], scfsi[2][SBLIMIT];
  static unsigned int scalar[2][3][SBLIMIT], j_scale[3][SBLIMIT];
  static double smr[2][SBLIMIT], lgmin[2][SBLIMIT], max_sc[2][SBLIMIT];
  // FLOAT snr32[32];
  short sam[2][1344];		/* was [1056]; */
  int model, nch, error_protection;
  static unsigned int crc;
  int sb, ch, adb;
  unsigned long frameBits, sentBits = 0;
  unsigned long num_samples;
  int lg_frame;
  int i;

  /* Used to keep the SNR values for the fast/quick psy models */
  static FLOAT smrdef[2][32];

  static int psycount = 0;
  extern int minimum;

  time_t start_time, end_time;
  int total_time;

  sb_sample = (SBS *) mem_alloc (sizeof (SBS), "sb_sample");
  j_sample = (JSBS *) mem_alloc (sizeof (JSBS), "j_sample");
  win_que = (IN *) mem_alloc (sizeof (IN), "Win_que");
  subband = (SUB *) mem_alloc (sizeof (SUB), "subband");
  win_buf = (short **) mem_alloc (sizeof (short *) * 2, "win_buf");

  /* clear buffers */
  memset ((char *) buffer, 0, sizeof (buffer));
  memset ((char *) bit_alloc, 0, sizeof (bit_alloc));
  memset ((char *) scalar, 0, sizeof (scalar));
  memset ((char *) j_scale, 0, sizeof (j_scale));
  memset ((char *) scfsi, 0, sizeof (scfsi));
  memset ((char *) smr, 0, sizeof (smr));
  memset ((char *) lgmin, 0, sizeof (lgmin));
  memset ((char *) max_sc, 0, sizeof (max_sc));
  //memset ((char *) snr32, 0, sizeof (snr32));
  memset ((char *) sam, 0, sizeof (sam));

  global_init ();
  
  header.extension = 0;
  frame.header = &header;
  frame.tab_num = -1;		/* no table loaded */
  frame.alloc = NULL;
  header.version = MPEG_AUDIO_ID;	/* Default: MPEG-1 */

  total_time = 0;

  time(&start_time);     

  programName = argv[0];
  if (argc == 1)		/* no command-line args */
    short_usage ();
  else
    parse_args (argc, argv, &frame, &model, &num_samples, original_file_name,
		encoded_file_name);
  print_config (&frame, &model, original_file_name, encoded_file_name);

  /* this will load the alloc tables and do some other stuff */
  hdr_to_frps (&frame);
  nch = frame.nch;
  error_protection = header.error_protection;



  while (get_audio (musicin, buffer, num_samples, nch, &header) > 0) {
    if (glopts.verbosity > 1)
      if (++frameNum % 10 == 0)
	fprintf (stderr, "[%4u]\r", frameNum);
    fflush (stderr);
    win_buf[0] = &buffer[0][0];
    win_buf[1] = &buffer[1][0];

    adb = available_bits (&header, &glopts);
    lg_frame = adb / 8;
    if (header.dab_extension) {
      /* in 24 kHz we always have 4 bytes */
      if (header.sampling_frequency == 1)
	header.dab_extension = 4;
/* You must have one frame in memory if you are in DAB mode                 */
/* in conformity of the norme ETS 300 401 http://www.etsi.org               */
      /* see bitstream.c            */
      if (frameNum == 1)
	minimum = lg_frame + MINIMUM;
      adb -= header.dab_extension * 8 + header.dab_length * 8 + 16;
    }

    {
      int gr, bl, ch;
      /* New polyphase filter
	 Combines windowing and filtering. Ricardo Feb'03 */
      for( gr = 0; gr < 3; gr++ )
	for ( bl = 0; bl < 12; bl++ )
	  for ( ch = 0; ch < nch; ch++ )
	    WindowFilterSubband( &buffer[ch][gr * 12 * 32 + 32 * bl], ch,
				 &(*sb_sample)[ch][gr][bl][0] );
    }

#ifdef REFERENCECODE
    {
      /* Old code. left here for reference */
      int gr, bl, ch;
      for (gr = 0; gr < 3; gr++)
	for (bl = 0; bl < SCALE_BLOCK; bl++)
	  for (ch = 0; ch < nch; ch++) {
	    window_subband (&win_buf[ch], &(*win_que)[ch][0], ch);
	    filter_subband (&(*win_que)[ch][0], &(*sb_sample)[ch][gr][bl][0]);
	  }
    }
#endif


#ifdef NEWENCODE
    scalefactor_calc_new(*sb_sample, scalar, nch, frame.sblimit);
    find_sf_max (scalar, &frame, max_sc);
    if (frame.actual_mode == MPG_MD_JOINT_STEREO) {
      /* this way we calculate more mono than we need */
      /* but it is cheap */
      combine_LR_new (*sb_sample, *j_sample, frame.sblimit);
      scalefactor_calc_new (j_sample, &j_scale, 1, frame.sblimit);
    }
#else
    scale_factor_calc (*sb_sample, scalar, nch, frame.sblimit);
    pick_scale (scalar, &frame, max_sc);
#if FRAME_TRACE
	//FILE* output;
	output = fopen("output.txt", "a");
	if (frameNum == 2) {
		fprintf(output, "声道数:%d\n", nch);
		fprintf(output, "目前观测第 %d 帧\n", frameNum);
		fprintf(output, "本帧比特预算:%d bits\n", adb);
		fprintf(output, "\n");
		/* 比例因子 */
		fprintf(output, "========== 比例因子 ==========\n");
		for (ch = 0; ch < nch; ch++)	// 每个声道单独输出
		{
			fprintf(output, "------ 声道%2d ------\n", ch + 1);
			for (sb = 0; sb < frame.sblimit; sb++)	// 每个子带
			{
				int gr = 0;
				fprintf(output, "子带[%2d]:\t", sb + 1);
				for ( gr = 0; gr < 3; gr++) {
					fprintf(output, "%2d\t", scalar[ch][gr][sb]);
				}
				fprintf(output, "\n");
			}
		}
		fprintf(output, "\n");

		/* 比特分配表 */
		fprintf(output, "========== 比特分配表 ==========\n");  //输出比特分配结果
		for (ch = 0; ch < nch; ch++) {
			fprintf(output, "------ 声道%2d ------\n", ch + 1); //按声道分配
			for (sb = 0; sb < frame.sblimit; sb++) {
				fprintf(output, "子带[%2d]:\t%2d\n", sb + 1, bit_alloc[ch][sb]);
			}
			fprintf(output, "\n");
		}
	}
	fclose(output);
#endif // FRAME_TRACE
    if (frame.actual_mode == MPG_MD_JOINT_STEREO) {
      /* this way we calculate more mono than we need */
      /* but it is cheap */
      combine_LR (*sb_sample, *j_sample, frame.sblimit);
      scale_factor_calc (j_sample, &j_scale, 1, frame.sblimit);
    }
#endif



    if ((glopts.quickmode == TRUE) && (++psycount % glopts.quickcount != 0)) {
      /* We're using quick mode, so we're only calculating the model every
         'quickcount' frames. Otherwise, just copy the old ones across */
      for (ch = 0; ch < nch; ch++) {
	for (sb = 0; sb < SBLIMIT; sb++)
	  smr[ch][sb] = smrdef[ch][sb];
      }
    } else {
      /* calculate the psymodel */
      switch (model) {
      case -1:
	psycho_n1 (smr, nch);
	break;
      case 0:	/* Psy Model A */
	psycho_0 (smr, nch, scalar, (FLOAT) s_freq[header.version][header.sampling_frequency] * 1000);	
	break;
      case 1:
	psycho_1 (buffer, max_sc, smr, &frame);
	break;
      case 2:
	for (ch = 0; ch < nch; ch++) {
	  psycho_2 (&buffer[ch][0], &sam[ch][0], ch, &smr[ch][0], //snr32,
		     (FLOAT) s_freq[header.version][header.sampling_frequency] *
		     1000, &glopts);
	}
	break;
      case 3:
	/* Modified psy model 1 */
	psycho_3 (buffer, max_sc, smr, &frame, &glopts);
	break;
      case 4:
	/* Modified Psycho Model 2 */
	for (ch = 0; ch < nch; ch++) {
	  psycho_4 (&buffer[ch][0], &sam[ch][0], ch, &smr[ch][0], // snr32,
		     (FLOAT) s_freq[header.version][header.sampling_frequency] *
		     1000, &glopts);
	}
	break;	
      case 5:
	/* Model 5 comparse model 1 and 3 */
	psycho_1 (buffer, max_sc, smr, &frame);
	fprintf(stdout,"1 ");
	smr_dump(smr,nch);
	psycho_3 (buffer, max_sc, smr, &frame, &glopts);
	fprintf(stdout,"3 ");
	smr_dump(smr,nch);
	break;
      case 6:
	/* Model 6 compares model 2 and 4 */
	for (ch = 0; ch < nch; ch++) 
	  psycho_2 (&buffer[ch][0], &sam[ch][0], ch, &smr[ch][0], //snr32,
		    (FLOAT) s_freq[header.version][header.sampling_frequency] *
		    1000, &glopts);
	fprintf(stdout,"2 ");
	smr_dump(smr,nch);
	for (ch = 0; ch < nch; ch++) 
	  psycho_4 (&buffer[ch][0], &sam[ch][0], ch, &smr[ch][0], // snr32,
		     (FLOAT) s_freq[header.version][header.sampling_frequency] *
		     1000, &glopts);
	fprintf(stdout,"4 ");
	smr_dump(smr,nch);
	break;
      case 7:
	fprintf(stdout,"Frame: %i\n",frameNum);
	/* Dump the SMRs for all models */	
	psycho_1 (buffer, max_sc, smr, &frame);
	fprintf(stdout,"1");
	smr_dump(smr, nch);
	psycho_3 (buffer, max_sc, smr, &frame, &glopts);
	fprintf(stdout,"3");
	smr_dump(smr,nch);
	for (ch = 0; ch < nch; ch++) 
	  psycho_2 (&buffer[ch][0], &sam[ch][0], ch, &smr[ch][0], //snr32,
		    (FLOAT) s_freq[header.version][header.sampling_frequency] *
		    1000, &glopts);
	fprintf(stdout,"2");
	smr_dump(smr,nch);
	for (ch = 0; ch < nch; ch++) 
	  psycho_4 (&buffer[ch][0], &sam[ch][0], ch, &smr[ch][0], // snr32,
		     (FLOAT) s_freq[header.version][header.sampling_frequency] *
		     1000, &glopts);
	fprintf(stdout,"4");
	smr_dump(smr,nch);
	break;
      case 8:
	/* Compare 0 and 4 */	
	psycho_n1 (smr, nch);
	fprintf(stdout,"0");
	smr_dump(smr,nch);

	for (ch = 0; ch < nch; ch++) 
	  psycho_4 (&buffer[ch][0], &sam[ch][0], ch, &smr[ch][0], // snr32,
		     (FLOAT) s_freq[header.version][header.sampling_frequency] *
		     1000, &glopts);
	fprintf(stdout,"4");
	smr_dump(smr,nch);
	break;
      default:
	fprintf (stderr, "Invalid psy model specification: %i\n", model);
	exit (0);
      }

      if (glopts.quickmode == TRUE)
	/* copy the smr values and reuse them later */
	for (ch = 0; ch < nch; ch++) {
	  for (sb = 0; sb < SBLIMIT; sb++)
	    smrdef[ch][sb] = smr[ch][sb];
	}

      if (glopts.verbosity > 4) 
	smr_dump(smr, nch);
     
      


    }

#ifdef NEWENCODE
    sf_transmission_pattern (scalar, scfsi, &frame);
    main_bit_allocation_new (smr, scfsi, bit_alloc, &adb, &frame, &glopts);
    //main_bit_allocation (smr, scfsi, bit_alloc, &adb, &frame, &glopts);

    if (error_protection)
      CRC_calc (&frame, bit_alloc, scfsi, &crc);

    write_header (&frame, &bs);
    //encode_info (&frame, &bs);
    if (error_protection)
      putbits (&bs, crc, 16);
    write_bit_alloc (bit_alloc, &frame, &bs);
    //encode_bit_alloc (bit_alloc, &frame, &bs);
    write_scalefactors(bit_alloc, scfsi, scalar, &frame, &bs);
    //encode_scale (bit_alloc, scfsi, scalar, &frame, &bs);
    subband_quantization_new (scalar, *sb_sample, j_scale, *j_sample, bit_alloc,
    			  *subband, &frame);
    //subband_quantization (scalar, *sb_sample, j_scale, *j_sample, bit_alloc,
    //	  *subband, &frame);
    write_samples_new(*subband, bit_alloc, &frame, &bs);
    //sample_encoding (*subband, bit_alloc, &frame, &bs);
#else
    transmission_pattern (scalar, scfsi, &frame);
    main_bit_allocation (smr, scfsi, bit_alloc, &adb, &frame, &glopts);
    if (error_protection)
      CRC_calc (&frame, bit_alloc, scfsi, &crc);
    encode_info (&frame, &bs);
    if (error_protection)
      encode_CRC (crc, &bs);
    encode_bit_alloc (bit_alloc, &frame, &bs);
    encode_scale (bit_alloc, scfsi, scalar, &frame, &bs);
    subband_quantization (scalar, *sb_sample, j_scale, *j_sample, bit_alloc,
			  *subband, &frame);
    sample_encoding (*subband, bit_alloc, &frame, &bs);
#endif


    /* If not all the bits were used, write out a stack of zeros */
    for (i = 0; i < adb; i++)
      put1bit (&bs, 0);
    if (header.dab_extension) {
      /* Reserve some bytes for X-PAD in DAB mode */
      putbits (&bs, 0, header.dab_length * 8);
      
      for (i = header.dab_extension - 1; i >= 0; i--) {
	CRC_calcDAB (&frame, bit_alloc, scfsi, scalar, &crc, i);
	/* this crc is for the previous frame in DAB mode  */
	if (bs.buf_byte_idx + lg_frame < bs.buf_size)
	  bs.buf[bs.buf_byte_idx + lg_frame] = crc;
	/* reserved 2 bytes for F-PAD in DAB mode  */
	putbits (&bs, crc, 8);
      }
      putbits (&bs, 0, 16);
    }

    frameBits = sstell (&bs) - sentBits;

    if (frameBits % 8) {	/* a program failure */
      fprintf (stderr, "Sent %ld bits = %ld slots plus %ld\n", frameBits,
	       frameBits / 8, frameBits % 8);
      fprintf (stderr, "If you are reading this, the program is broken\n");
      fprintf (stderr, "email [mfc at NOTplanckenerg.com] without the NOT\n");
      fprintf (stderr, "with the command line arguments and other info\n");
      exit (0);
    }

    sentBits += frameBits;
  }

  close_bit_stream_w (&bs);

  if ((glopts.verbosity > 1) && (glopts.vbr == TRUE)) {
    int i;
#ifdef NEWENCODE
    extern int vbrstats_new[15];
#else
    extern int vbrstats[15];
#endif
    fprintf (stdout, "VBR stats:\n");
    for (i = 1; i < 15; i++)
      fprintf (stdout, "%4i ", bitrate[header.version][i]);
    fprintf (stdout, "\n");
    for (i = 1; i < 15; i++)
#ifdef NEWENCODE
      fprintf (stdout,"%4i ",vbrstats_new[i]);
#else
      fprintf (stdout, "%4i ", vbrstats[i]);
#endif
    fprintf (stdout, "\n");
  }

  fprintf (stderr,
	   "Avg slots/frame = %.3f; b/smp = %.2f; bitrate = %.3f kbps\n",
	   (FLOAT) sentBits / (frameNum * 8),
	   (FLOAT) sentBits / (frameNum * 1152),
	   (FLOAT) sentBits / (frameNum * 1152) *
	   s_freq[header.version][header.sampling_frequency]);

  if (fclose (musicin) != 0) {
    fprintf (stderr, "Could not close \"%s\".\n", original_file_name);
    exit (2);
  }

  fprintf (stderr, "\nDone\n");

  time(&end_time);
  total_time = end_time - start_time;
  printf("total time is %d\n", total_time);
  
  exit (0);
}

四、实验结果

1.音乐文件

(1)命令参数调整

在这里插入图片描述

(2)调试结果

在这里插入图片描述

(3)生成结果

在这里插入图片描述

========== 基本信息 ==========
输入文件:music.wav
输出文件:music.mp2
采样频率:22.1 kHz
输出文件码率:96 kbps
声道数:2
目前观测第 2 帧
本帧比特预算:5016 bits

========== 比例因子 ==========
------ 声道 1 ------
子带[ 1]:	63	63	63	
子带[ 2]:	63	63	63	
子带[ 3]:	63	63	63	
子带[ 4]:	63	63	63	
子带[ 5]:	63	63	63	
子带[ 6]:	63	63	63	
子带[ 7]:	63	63	63	
子带[ 8]:	63	63	63	
子带[ 9]:	63	63	63	
子带[10]:	63	63	63	
子带[11]:	63	63	63	
子带[12]:	63	63	63	
子带[13]:	63	63	63	
子带[14]:	63	63	63	
子带[15]:	63	63	63	
子带[16]:	63	63	63	
子带[17]:	63	63	63	
子带[18]:	63	63	63	
子带[19]:	63	63	63	
子带[20]:	63	63	63	
子带[21]:	63	63	63	
子带[22]:	63	63	63	
子带[23]:	63	63	63	
子带[24]:	63	63	63	
子带[25]:	63	63	63	
子带[26]:	63	63	63	
子带[27]:	63	63	63	
子带[28]:	63	63	63	
子带[29]:	63	63	63	
子带[30]:	63	63	63	
------ 声道 2 ------
子带[ 1]:	63	63	63	
子带[ 2]:	63	63	63	
子带[ 3]:	63	63	63	
子带[ 4]:	63	63	63	
子带[ 5]:	63	63	63	
子带[ 6]:	63	63	63	
子带[ 7]:	63	63	63	
子带[ 8]:	63	63	63	
子带[ 9]:	63	63	63	
子带[10]:	63	63	63	
子带[11]:	63	63	63	
子带[12]:	63	63	63	
子带[13]:	63	63	63	
子带[14]:	63	63	63	
子带[15]:	63	63	63	
子带[16]:	63	63	63	
子带[17]:	63	63	63	
子带[18]:	63	63	63	
子带[19]:	63	63	63	
子带[20]:	63	63	63	
子带[21]:	63	63	63	
子带[22]:	63	63	63	
子带[23]:	63	63	63	
子带[24]:	63	63	63	
子带[25]:	63	63	63	
子带[26]:	63	63	63	
子带[27]:	63	63	63	
子带[28]:	63	63	63	
子带[29]:	63	63	63	
子带[30]:	63	63	63	

========== 比特分配表 ==========
------ 声道 1 ------
子带[ 1]:	 0
子带[ 2]:	 1
子带[ 3]:	 1
子带[ 4]:	 1
子带[ 5]:	 2
子带[ 6]:	 2
子带[ 7]:	 3
子带[ 8]:	 3
子带[ 9]:	 3
子带[10]:	 3
子带[11]:	 3
子带[12]:	 3
子带[13]:	 3
子带[14]:	 2
子带[15]:	 2
子带[16]:	 2
子带[17]:	 2
子带[18]:	 2
子带[19]:	 1
子带[20]:	 1
子带[21]:	 1
子带[22]:	 1
子带[23]:	 1
子带[24]:	 1
子带[25]:	 1
子带[26]:	 1
子带[27]:	 1
子带[28]:	 1
子带[29]:	 0
子带[30]:	 0

------ 声道 2 ------
子带[ 1]:	 0
子带[ 2]:	 1
子带[ 3]:	 1
子带[ 4]:	 1
子带[ 5]:	 2
子带[ 6]:	 2
子带[ 7]:	 2
子带[ 8]:	 3
子带[ 9]:	 3
子带[10]:	 3
子带[11]:	 3
子带[12]:	 3
子带[13]:	 3
子带[14]:	 2
子带[15]:	 2
子带[16]:	 2
子带[17]:	 2
子带[18]:	 2
子带[19]:	 1
子带[20]:	 1
子带[21]:	 1
子带[22]:	 1
子带[23]:	 1
子带[24]:	 1
子带[25]:	 1
子带[26]:	 1
子带[27]:	 1
子带[28]:	 1
子带[29]:	 0
子带[30]:	 0


2.噪声文件

(1)命令参数调整

在这里插入图片描述

(2)调试结果

在这里插入图片描述

(3)生成结果

在这里插入图片描述

========== 基本信息 ==========
输入文件:noise.wav
输出文件:noise.mp2
采样频率:22.1 kHz
输出文件码率:96 kbps
声道数:1
目前观测第 2 帧
本帧比特预算:5016 bits

========== 比例因子 ==========
------ 声道 1 ------
子带[ 1]:	18	10	12	
子带[ 2]:	38	19	17	
子带[ 3]:	37	22	18	
子带[ 4]:	35	22	19	
子带[ 5]:	38	22	21	
子带[ 6]:	36	21	22	
子带[ 7]:	38	18	21	
子带[ 8]:	37	22	22	
子带[ 9]:	38	17	18	
子带[10]:	38	18	21	
子带[11]:	38	13	14	
子带[12]:	40	 4	 7	
子带[13]:	37	12	15	
子带[14]:	38	14	17	
子带[15]:	39	16	18	
子带[16]:	41	19	21	
子带[17]:	39	19	23	
子带[18]:	42	24	24	
子带[19]:	38	21	23	
子带[20]:	42	24	22	
子带[21]:	41	24	19	
子带[22]:	42	21	19	
子带[23]:	39	13	15	
子带[24]:	40	10	11	
子带[25]:	41	16	17	
子带[26]:	42	19	21	
子带[27]:	44	23	22	
子带[28]:	41	24	26	
子带[29]:	45	26	25	
子带[30]:	44	29	31	

========== 比特分配表 ==========
------ 声道 1 ------
子带[ 1]:	 8
子带[ 2]:	 7
子带[ 3]:	 6
子带[ 4]:	 6
子带[ 5]:	 5
子带[ 6]:	 5
子带[ 7]:	 5
子带[ 8]:	 5
子带[ 9]:	 4
子带[10]:	 5
子带[11]:	 4
子带[12]:	 3
子带[13]:	 3
子带[14]:	 3
子带[15]:	 3
子带[16]:	 3
子带[17]:	 3
子带[18]:	 3
子带[19]:	 3
子带[20]:	 3
子带[21]:	 3
子带[22]:	 3
子带[23]:	 3
子带[24]:	 3
子带[25]:	 3
子带[26]:	 3
子带[27]:	 3
子带[28]:	 3
子带[29]:	 3
子带[30]:	 3

3.音乐+噪声文件

(1)命令参数调整

在这里插入图片描述

(2)调试结果

在这里插入图片描述

(3)生成结果

在这里插入图片描述

========== 基本信息 ==========
输入文件:music+noise.wav
输出文件:music+noise.mp2
采样频率:22.1 kHz
输出文件码率:96 kbps
声道数:2
目前观测第 2 帧
本帧比特预算:5016 bits

========== 比例因子 ==========
------ 声道 1 ------
子带[ 1]:	63	63	63	
子带[ 2]:	63	63	63	
子带[ 3]:	63	63	63	
子带[ 4]:	63	63	63	
子带[ 5]:	63	63	63	
子带[ 6]:	63	63	63	
子带[ 7]:	63	63	63	
子带[ 8]:	63	63	63	
子带[ 9]:	63	63	63	
子带[10]:	63	63	63	
子带[11]:	63	63	63	
子带[12]:	63	63	63	
子带[13]:	63	63	63	
子带[14]:	63	63	63	
子带[15]:	63	63	63	
子带[16]:	63	63	63	
子带[17]:	63	63	63	
子带[18]:	63	63	63	
子带[19]:	63	63	63	
子带[20]:	63	63	63	
子带[21]:	63	63	63	
子带[22]:	63	63	63	
子带[23]:	63	63	63	
子带[24]:	63	63	63	
子带[25]:	63	63	63	
子带[26]:	63	63	63	
子带[27]:	63	63	63	
子带[28]:	63	63	63	
子带[29]:	63	63	63	
子带[30]:	63	63	63	
------ 声道 2 ------
子带[ 1]:	63	63	63	
子带[ 2]:	63	63	63	
子带[ 3]:	63	63	63	
子带[ 4]:	63	63	63	
子带[ 5]:	63	63	63	
子带[ 6]:	63	63	63	
子带[ 7]:	63	63	63	
子带[ 8]:	63	63	63	
子带[ 9]:	63	63	63	
子带[10]:	63	63	63	
子带[11]:	63	63	63	
子带[12]:	63	63	63	
子带[13]:	63	63	63	
子带[14]:	63	63	63	
子带[15]:	63	63	63	
子带[16]:	63	63	63	
子带[17]:	63	63	63	
子带[18]:	63	63	63	
子带[19]:	63	63	63	
子带[20]:	63	63	63	
子带[21]:	63	63	63	
子带[22]:	63	63	63	
子带[23]:	63	63	63	
子带[24]:	63	63	63	
子带[25]:	63	63	63	
子带[26]:	63	63	63	
子带[27]:	63	63	63	
子带[28]:	63	63	63	
子带[29]:	63	63	63	
子带[30]:	63	63	63	

========== 比特分配表 ==========
------ 声道 1 ------
子带[ 1]:	 4
子带[ 2]:	 5
子带[ 3]:	 4
子带[ 4]:	 4
子带[ 5]:	 3
子带[ 6]:	 3
子带[ 7]:	 3
子带[ 8]:	 3
子带[ 9]:	 3
子带[10]:	 2
子带[11]:	 3
子带[12]:	 3
子带[13]:	 3
子带[14]:	 2
子带[15]:	 2
子带[16]:	 3
子带[17]:	 3
子带[18]:	 3
子带[19]:	 3
子带[20]:	 2
子带[21]:	 2
子带[22]:	 2
子带[23]:	 3
子带[24]:	 3
子带[25]:	 1
子带[26]:	 2
子带[27]:	 1
子带[28]:	 2
子带[29]:	 2
子带[30]:	 3

------ 声道 2 ------
子带[ 1]:	 4
子带[ 2]:	 5
子带[ 3]:	 4
子带[ 4]:	 4
子带[ 5]:	 3
子带[ 6]:	 3
子带[ 7]:	 3
子带[ 8]:	 3
子带[ 9]:	 3
子带[10]:	 2
子带[11]:	 3
子带[12]:	 3
子带[13]:	 3
子带[14]:	 2
子带[15]:	 2
子带[16]:	 3
子带[17]:	 3
子带[18]:	 3
子带[19]:	 3
子带[20]:	 2
子带[21]:	 2
子带[22]:	 2
子带[23]:	 3
子带[24]:	 3
子带[25]:	 1
子带[26]:	 2
子带[27]:	 1
子带[28]:	 2
子带[29]:	 2
子带[30]:	 3


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值