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

📄 pcmdemo.c

📁 Reference Implementation of G.711 standard and other voice codecs
💻 C
📖 第 1 页 / 共 2 页
字号:
	}	/* Update argc/argv to next valid option/argument */	argv+=2;	argc-=2;      }      else if (strcmp(argv[1], "-?") == 0 || strcmp(argv[1], "-help") == 0)      {	/* Print help */	display_usage();      }      else      {	fprintf(stderr, "ERROR! Invalid option \"%s\" in command line\n\n",		argv[1]);	display_usage();      }  }  /* ......... GETTING PARAMETERS ......... */  /* ......... GETTING PARAMETERS ......... */  GET_PAR_S(1, "_BIN-File to be processed: ............... ", inpfil);  if ((inpfilptr = fopen(inpfil, RB)) == NULL)    HARAKIRI("\n   Error opening input file", 1);  GET_PAR_S(2, "_BIN-Output File: ........................ ", outfil);  if ((outfilptr = fopen(outfil, WB)) == NULL)    HARAKIRI("\n   Error opening output file", 1);  GET_PAR_S(3, "_type of filter 1: ....................... ", typ1);  if ((strcmp(typ1, "0") != 0) && (strcmp(typ1, "1_1") != 0) &&      (strcmp(typ1, "1_2") != 0) && (strcmp(typ1, "2_1") != 0))    HARAKIRI("\n   undefined filter type (use 0, 1_1, 1_2 or 2_1)", 1);  GET_PAR_S(4, "_type of filter 2: ....................... ", typ2);  if ((strcmp(typ2, "0") != 0) && (strcmp(typ2, "1_1") != 0) &&      (strcmp(typ2, "1_2") != 0) && (strcmp(typ2, "2_1") != 0))    HARAKIRI("\n   undefined filter type (use 0, 1_1, 1_2 or 2_1)", 1);  GET_PAR_S(5, "_type of filter 3: ....................... ", typ3);  if ((strcmp(typ3, "0") != 0) && (strcmp(typ3, "1_1") != 0) &&      (strcmp(typ3, "1_2") != 0) && (strcmp(typ3, "2_1") != 0))    HARAKIRI("\n   undefined filter type (use 0, 1_1, 1_2 or 2_1)", 1);  FIND_PAR_L(6, "_Segment Length for Filtering: ........... ", lseg, lseg);  if (lseg > LSEGMAX)  {    /* If max.seg.length is exceeded, display warning */    lseg = LSEGMAX;    printf("\t\t\t\t(limited to %ld)\n", lseg);  }/*   * ... ALLOCATE MEMORY FOR INTERMEDIATE AND FINAL DATA ...   */   if ((buff1 = (float *) calloc((long)(2*lseg), sizeof(float)))==NULL)     HARAKIRI("Error allocating memory for 1st filtering step\n", 3);   if ((buff2 = (float *) calloc((long)(4*lseg), sizeof(float)))==NULL)     HARAKIRI("Error allocating memory for 2nd filtering step\n", 3);   if ((buff3 = (float *) calloc((long)(8*lseg), sizeof(float)))==NULL)     HARAKIRI("Error allocating memory for 3rd filtering step\n", 3);/*   * ... INITIALIZE SELECTED IIR-STRUCTURES FOR UP-/DOWNSAMPLING ...   *       the types are as follows:   *          1_1 : standard PCM with 16 kHz, no rate change (1:1)   *          1_2 : standard PCM with 16 kHz, upsampling factor of 1:2   *          2_1 : standard PCM with 16 kHz, downsampling factor of 2:1   *       the return value is a pointer to filter coefficients and   *       cleared state variables   */  /* ... for Filter #1 */  if (strcmp(typ1, "1_1") == 0)  {    if ((typ1_ptr = stdpcm_16khz_init()) == 0)      HARAKIRI("Filter 1: initialization failure stdpcm_16khz_init()", 1);  }  else if (strcmp(typ1, "1_2") == 0)  {    if ((typ1_ptr = stdpcm_1_to_2_init()) == 0)      HARAKIRI("Filter 1: initialization failure stdpcm_1_to_2_init()", 1);  }  else if (strcmp(typ1, "2_1") == 0)  {    if ((typ1_ptr = stdpcm_2_to_1_init()) == 0)      HARAKIRI("Filter 1: initialization failure stdpcm_2_to_1_init()", 1);  }  else    typ1_ptr = (SCD_IIR *) NULL;  /* Init.the pointer to NULL */  /* ... for Filter #2: */  if (strcmp(typ2, "1_1") == 0)  {    if ((typ2_ptr = stdpcm_16khz_init()) == 0)      HARAKIRI("Filter 2: initialization failure stdpcm_16khz_init()", 1);  }  else if (strcmp(typ2, "1_2") == 0)  {    if ((typ2_ptr = stdpcm_1_to_2_init()) == 0)      HARAKIRI("Filter 2: initialization failure stdpcm_1_to_2_init()", 1);  }  else if (strcmp(typ2, "2_1") == 0)  {    if ((typ2_ptr = stdpcm_2_to_1_init()) == 0)      HARAKIRI("Filter 2: initialization failure stdpcm_2_to_1_init()", 1);  }  else    typ2_ptr = (SCD_IIR *) NULL;  /* ... for Filter #3: */  if (strcmp(typ3, "1_1") == 0)  {    if ((typ3_ptr = stdpcm_16khz_init()) == 0)      HARAKIRI("Filter 3: initialization failure stdpcm_16khz_init()", 1);  }  else if (strcmp(typ3, "1_2") == 0)  {    if ((typ3_ptr = stdpcm_1_to_2_init()) == 0)      HARAKIRI("Filter 3: initialization failure stdpcm_1_to_2_init()", 1);  }  else if (strcmp(typ3, "2_1") == 0)  {    if ((typ3_ptr = stdpcm_2_to_1_init()) == 0)      HARAKIRI("Filter 3: initialization failure stdpcm_2_to_1_init()", 1);  }  else    typ3_ptr = (SCD_IIR *) NULL;/*   * ......... CARRY OUT FILTERING .........   */  /* measure CPU-time */  t1 = clock();  lsegx = lseg;  while (lsegx == lseg)  {    /* Read input buffer */    lsegx = fread(sh_buff, sizeof(short), lseg, inpfilptr);    /* convert short data to float in normalized range */    sh2fl_16bit(lsegx, sh_buff, fl_buff, 1);/*   * WHAT TO DO IN FILTERING STAGE 1?   */    if (strcmp(typ1, "0") == 0)	  /* No filtering; so, ... */    {      /* ...copy input buffer to second step's buffer */      for (k = 0; k < lsegx; k++)	buff1[k] = fl_buff[k];      /* ... and return no. of output samples */      lseg1 = lsegx;    }    else    {      /* Standard PCM filtering */      lseg1 =			  /* Returned: number of output samples */	stdpcm_kernel(		  /* standard PCM filter */		      lsegx,	  /* In   : number of input samples */		      fl_buff,	  /* In   : array with input samples */		      typ1_ptr,	  /* InOut: pointer to IIR struct */		      buff1	  /* Out  : array with output samples */	);      /* Convert to integer for testing overflows -- do not save! */      noverflows1 += fl2sh_16bit(lseg1, buff1, sh_buff, (int) 1);    }/*   * WHAT TO DO IN FILTERING STAGE 2?   */    if (strcmp(typ2, "0") == 0)	  /* No filtering; so, ... */    {      /* ... copy input buffer to third step's buffer */      for (k = 0; k < lseg1; k++)	buff2[k] = buff1[k];      /* ... and return number of output samples */      lseg2 = lseg1;    }    else    {      /* Standard PCM filtering */      lseg2 =			  /* Returned: number of output samples */	stdpcm_kernel(		  /* standard PCM filter */		      lseg1,	  /* In   : number of input samples */		      buff1,	  /* In   : array with input samples */		      typ2_ptr,	  /* InOut: pointer to IIR struct */		      buff2	  /* Out  : array with output samples */	);      /* Convert to Integer for testing overflows -- do not save! */      noverflows2 += fl2sh_16bit(lseg2, buff2, sh_buff, (int) 1);    }/*   * WHAT TO DO IN FILTERING STAGE 3?   */    if (strcmp(typ3, "0") == 0)	  /* No filtering; so ... */    {      /* ... copy input buffer to output buffer */      for (k = 0; k < lseg2; k++)	buff3[k] = buff2[k];      /* ... and return number of output samples */      lseg3 = lseg2;    }    else    {      /* Standard PCM filtering */      lseg3 =			  /* Returned: number of output samples */	stdpcm_kernel(		  /* standard PCM filter */		      lseg2,	  /* In   : number of input samples */		      buff2,	  /* In   : array with input samples */		      typ3_ptr,	  /* InOut: pointer to IIR struct */		      buff3	  /* Out  : array with output samples */	);    }/*  * ......... CONVERTION FROM FLOAT TO SHORT with rounding .........  *                      (now saves the data!)  */    noverflows3 += fl2sh_16bit(lseg3, buff3, sh_buff, (int) 1);/*  * ......... WRITE SAMPLES TO OUTPUT FILE .........  */    /* Skip samples if requested */    if (lseg1 > skip)    {      /* Write samples to output file */      nsam += fwrite(&sh_buff[skip], sizeof(short), (lseg3-skip), outfilptr);      skip = 0;    }    else      skip -= lseg1;/*    nsam += fwrite(sh_buff, sizeof(short), lseg3, outfilptr);*/  }/*   * ......... FINALIZATIONS .........   */  /* Print time statistics - Include file I/O! */  t2 = clock();  printf("\nDONE: %f sec CPU-time for %ld generated samples\n",	 (t2 - t1) / (double) CLOCKS_PER_SEC, nsam);  /* Print overflow statistics */  if (noverflows1 == 0 && noverflows2 == 0 && noverflows3 == 0)    printf("      no overflows occurred\n");  else  {    printf("\t Overflows - filter 1: %ld\n", noverflows1);    printf("\t           - filter 2: %ld\n", noverflows2);    printf("\t           - filter 3: %ld\n", noverflows3);  }  /* Release memory allocated to IIR structures */  if (typ3_ptr != (SCD_IIR *) NULL)    stdpcm_free(typ3_ptr);  if (typ2_ptr != (SCD_IIR *) NULL)    stdpcm_free(typ2_ptr);  if (typ1_ptr != (SCD_IIR *) NULL)    stdpcm_free(typ1_ptr);#ifndef STATIC_ALLOCATION  /* Free memory of data vectors */  free(buff3);  free(buff2);  free(buff1);#endif  /* Close files */  fclose(outfilptr);  fclose(inpfilptr);#ifndef VMS  return 0;#endif}/* ......................... End of main() ......................... */

⌨️ 快捷键说明

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