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

📄 g727demo.c

📁 Reference Implementation of G.711 standard and other voice codecs
💻 C
📖 第 1 页 / 共 2 页
字号:
	argc -= 2;	argv += 2;      }      else if (strcmp(argv[1], "-enc") == 0)      {	/* Encoder-only operation */	encode = 1;	decode = 0;	/* Move argv over the option to the next argument */	argv++;	argc--;      }      else if (strcmp(argv[1], "-dec") == 0)      {	/*Decoder-only operation */	encode = 0;	decode = 1;	/* Move argv over the option to the next argument */	argv++;	argc--;      }      else if (strcmp(argv[1], "-e_d") == 0)      {	/* Encode-and-decode operation */	encode = 1;	decode = 1;	/* Move argv over the option to the next argument */	argv++;	argc--;      }      else if (strcmp(argv[1], "-law") == 0)      {	/* Define law for operation: A, u, or linear */	law = toupper(argv[2][0]);	/* Move argv over the option to the next argument */	argv+=2;	argc-=2;      }      else if (strcmp(argv[1], "-frame") == 0 ||	       strcmp(argv[1], "-blk") == 0)      {	/* Define Frame size for rate change during operation */        N = atoi(argv[2]);	/* Move argv over the option to the next argument */	argv+=2;	argc-=2;      }      else if (strcmp(argv[1], "-core") == 0)      {	/*Define number of core bits for operation */        nc = atoi(argv[2]);	/* Move argv over the option to the next argument */	argv+=2;	argc-=2;      }      else if (strcmp(argv[1], "-enh") == 0)      {	/*Define number of enhancement bits for operation */        ne =  atoi(argv[2]);	/* Move argv over the option to the next argument */	argv+=2;	argc-=2;      }      else if (strcmp(argv[1], "-q") == 0)      {	/* Don't print progress indicator */	quiet = 1;	/* Move argv over the option to the next argument */	argv++;	argc--;      }      else if (strcmp(argv[1], "-?") == 0 || strstr(argv[1], "-help"))      {	/* Print help */	display_usage();      }      else      {	fprintf(stderr, "ERROR! Invalid option \"%s\" in command line\n\n",		argv[1]);	display_usage();      }  }  /* Now get regular parameters */  GET_PAR_S(1, "_Input File: .................. ", FileIn);  GET_PAR_S(2, "_Output File: ................. ", FileOut);  FIND_PAR_L(3, "_Block Size: .................. ", N, N);  FIND_PAR_L(4, "_Starting Block: .............. ", N1, N1);  FIND_PAR_L(5, "_No. of Blocks: ............... ", N2, N2);  FIND_PAR_C(6, "_Law (A,u): ................... ", law, law);   FIND_PAR_I(7, "_Core bits: ................... ", nc, nc);  FIND_PAR_I(8, "_Enhancement bits: ............ ", ne, ne);  /* INITIALIZATIONS */  /* Check consistency for number of core & enhancement bits */  if (!(2 <= nc && nc <= 4 && ne >= 0 && nc + ne <= 5))  {    fprintf(stderr, "%s: (%d,%d)-Aborted\n",	    "Inconsistent number of core and enhancement bits", nc, ne);    exit(5);  }  /* Compose word length */  wordLen = nc + ne;  /* Find starting byte in file */  start_byte = sizeof(short) * (long) (--N1) * (long) N;  /* Check if is to process the whole file */  if (N2 == 0)  {    struct stat     st;    /* ... find the input file size ... */    stat(FileIn, &st);    N2 = (st.st_size - start_byte) / (N * sizeof(short));  }  /* Define correct data I/O types */  if (encode && decode)   {      inp_type = out_type = (law == '2'? IS_LIN : IS_LOG);  }  else if (encode)       {    inp_type = law == '2'? IS_LIN : IS_LOG;    out_type = IS_ADPCM;  }  else       {    inp_type = IS_ADPCM;    out_type = law == '2'? IS_LIN : IS_LOG;  }  /* Convert law letter to number */  switch (law)  {  case 'A':    law = '1';    break;  case 'U':    law = '0';    break;  case 'L':    law = '2';    break;  default:    HARAKIRI(" Invalid law (A, u, or L)! Aborted...\n", 7);  }  /* Force law to be used *by the ADPCM* to A-law, if input is linear */  if (law=='2')    law='1';  /* Report codec operation mode */  fprintf(stderr, "Operation: %s; Nc=%d; Ne=%d\n",	  encode && decode? "Enc+Dec":	  (encode? "Encode-only": "Decode-only"), nc, ne);/* * ...... MEMORY ALLOCATION ......... */#ifndef STATIC_ALLOCATION  if ((inp_buf = (short *) calloc(N, sizeof(short))) == NULL)      HARAKIRI("Error in memory allocation!\n",1);  if ((out_buf = (short *) calloc(N, sizeof(short))) == NULL)      HARAKIRI("Error in memory allocation!\n",1);  if ((tmp_buf = (short *) calloc(N, sizeof(short))) == NULL)      HARAKIRI("Error in memory allocation!\n",1);#endif/* * ......... FILE PREPARATION ......... */  /* Opening input file; abort if there's any problem */  if ((Fi = fopen(FileIn, RB)) == NULL)    KILL(FileIn, 2);  inp = fileno(Fi);  /* Creates output file */#ifdef VMS  sprintf(mrs, "mrs=%d", 512);#endif  if ((Fo = fopen(FileOut, WB)) == NULL)    KILL(FileOut, 3);  out = fileno(Fo);  /* Move pointer to 1st block of interest */  if (fseek(Fi, start_byte, 0) < 0l)    KILL(FileIn, 4);/* * ......... PROCESSING ACCORDING TO ITU-T G.727 ......... */  /* Reset state variables */  g727_reset(&enc_state);  g727_reset(&dec_state);  /* Process all blocks defined by user */  for (cur_blk = 0; cur_blk < N2; cur_blk++)  {    /* Print progress flag */    if (!quiet)#ifdef DISPLAY_CURRENT_RATE      fprintf(stderr, "%d-", 8 * rate[rate_idx]);#else      fprintf(stderr, "%c\r", funny[cur_blk % 8]);#endif    /* Read a block of samples */    if ((smpno = fread(inp_buf, sizeof(short), N, Fi)) < 0)      KILL(FileIn, 5);    /* Compress linear input samples */    if (inp_type == IS_LIN)    {      /* Compress using A-law */      alaw_compress(smpno, inp_buf, tmp_buf);      /* copy temporary buffer over input buffer */      memcpy(inp_buf, tmp_buf, sizeof(short) * smpno);    }    /* Carry out the desired operation */    if (encode && ! decode)      g727_encode(inp_buf, out_buf, smpno, law, 		  nc, ne, &enc_state);    else if (decode && !encode)      g727_decode(inp_buf, out_buf, smpno, law, 		  nc, ne, &dec_state);    else if (encode && decode)    {      g727_encode(inp_buf, tmp_buf, smpno, law, 		  nc, ne, &enc_state);      g727_decode(tmp_buf, out_buf, smpno, law, 		  nc, ne, &dec_state);    }    /* Expand linear input samples */    if (out_type == IS_LIN)    {      /* Compress using A-law */      alaw_expand(smpno, out_buf, tmp_buf);      /* copy temporary buffer over input buffer */      memcpy(out_buf, tmp_buf, sizeof(short) * smpno);    }    /* Write ADPCM output word */    if ((smpno = fwrite(out_buf, sizeof(short), smpno, Fo)) < 0)      KILL(FileOut, 6);  }/* * ......... FINALIZATIONS ......... */  /* Close input and output files */  fclose(Fi);  fclose(Fo);  /* Exit with success for non-vms systems */#ifndef VMS  return (0);#endif}/* ............................ End of main() ............................. */

⌨️ 快捷键说明

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