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

📄 cvt-head.c

📁 Reference Implementation of G.711 standard and other voice codecs
💻 C
📖 第 1 页 / 共 2 页
字号:
    return "STL92";    break;  case STL96:    return "STL96";    break;  }  return "";}/* ......................... End of cvt_type() ......................... *//* ------------------------------------------------------------------------ *//*                              Main Program                                *//* ------------------------------------------------------------------------ */int main(argc, argv)int argc;char *argv[];{  long            N = 256, N1 = 1, N2 = 0, size, i;  long            fr_len = 256;         /* Frame length in number of bits */  long            items, bitno, cur_blk;  char            bs_type = HAS_HEADER; /* Type for bitstream */  char            bs_format = g192;     /* Format for bitstream */  long            Ninp, Nout;      /* Frame length for input and input files */  short          *bs_inp, *bs_out;	        /* bit-stream data */  char            inpfil[127], outfil[127];  FILE           *Fibs, *Fobs;  long            start_byte, flags_fixed=0;  char            sync_inp=2, sync_out=1, fer=1;  short           overhead_inp = OVERHEAD_STL96;  short           overhead_out = OVERHEAD_STL96;  short           inp_type, out_type;#ifdef VMS  char            mrs[15];	/* for correct mrs in VMS environment */#endif  char quiet=0;  /* Pointer to a function */  long            (*read_data)() = read_g192;	/* To read input bitstream */  long            (*save_data)() = save_g192;	/* To save output bitstream */  /* ......... GET PARAMETERS ......... */  /* Check options */  if (argc < 2)    display_usage(0);  else  {    while (argc > 1 && argv[1][0] == '-')      if (strcmp (argv[1], "-start") == 0)      {	/* Define starting sample for s/p operation */	N1 = atol (argv[2]);	/* Move arg{c,v} over the option to the next argument */	argc -= 2;	argv += 2;      }      else if (strcmp (argv[1], "-frame") == 0)      {	/* Define input & output encoded speech bitstream format */	fr_len = atoi(argv[2]);	/* Move arg{c,v} over the option to the next argument */	argc -= 2;	argv += 2;      }      else if (strcmp (argv[1], "-n") == 0)      {	/* Define number of frames to process */	N2 = atoi(argv[2]);	/* Move arg{c,v} over the option to the next argument */	argc -= 2;	argv += 2;      }      else if (strcmp(argv[1], "-sync") == 0)      {	/* Use sync header to generate output file */	sync_out=1;		/* Update arg[vc] */	argv++;	argc--;      }      else if (strcmp(argv[1], "-nosync") == 0)      {	/* Don't use sync header */	sync_out=0;		/* Update arg[vc] */	argv++;	argc--;      }      else if (strcmp(argv[1], "-nofer") == 0)      {	/* Convert any FER flags (0x6B20) to good frame indicator (0x6B21) */	fer=0;		/* Update arg[vc] */	argv++;	argc--;      }      else if (strcmp(argv[1], "-q") == 0)      {	/* quiet operation - don't print progress flag */	quiet=1;		/* Update arg[vc] */	argv++;	argc--;      }      else if (strcmp(argv[1], "-h") == 0 || strcmp(argv[1], "-?") == 0)      {	/* Display help */	display_usage(0);      }      else if (strstr(argv[1], "-help"))      {	/* Display help */	display_usage(1);      }      else if (strcmp(argv[1], "-") == 0)      {	/* End of option parsing */	break;      }      else      {	fprintf(stderr, "ERROR! Invalid option \"%s\" in command line\n\n",		argv[1]);	display_usage(0);      }  }  /* Read parameters for processing */  GET_PAR_S(1,  "_File to be converted: ....... ", inpfil);  GET_PAR_S(2,  "_Output File: ................ ", outfil);  FIND_PAR_L(3, "_Softbits per frame: ......... ", N, N);  FIND_PAR_L(4, "_Start Frame: ................ ", N1, N1);  FIND_PAR_L(5, "_Frames to process: .......... ", N2, N2);  /* ***** FILE OPERATIONS ***** */#ifdef VMS  sprintf(mrs, "mrs=%d", 512);#endif  /* Open input file */  if ((Fibs = fopen(inpfil, RB)) == NULL)    KILL(inpfil, 2);  /* Open (create) output file */  if ((Fobs = fopen(outfil, WB)) == NULL)    KILL(outfil, 3);  /* Define 1st byte to process */  start_byte = N * (--N1) * sizeof(short);    /* Move file's pointer to 1st desired block */  if (fseek(Fibs, start_byte, 0) < 0l)    KILL(inpfil, 4);  /* ***** DEFINE FRAME SIZES AND FILE TYPES ***** */  /* Gather data about input bitstream */  /* Find the actual frame size for the serial bit stream from the     serial bitstream. If this is a headerless bitstream, assumes that     the frame size is based on the provided block size. */  /* Find the number of words per frame (payload only!),      check whether a sync header was found, and also returns the type      of bitstream (g192, byte, compact) found */  i = check_sync(Fibs, inpfil, &bs_type, &fr_len, &bs_format);  /* If bitstream is not g192, abort */  if (bs_format != g192)    HARAKIRI("Bitstream needs to be in G.192 format. Aborted.\n", 7);  /* If sync info in file differs from the users' provided     input, warns and changes to the value found in file */  if (sync_inp != i)  {    fprintf (stderr, "*** Switching sync of input BS from %d to %ld ***\n",	     sync_inp, i);    sync_inp = i;  }  switch(bs_type)  {  case HAS_HEADER:    /* STL96 -> STL92 conversion */    inp_type = STL96;    out_type = STL92;    /* Define overhead length */    overhead_inp = OVERHEAD_STL96;    overhead_out = OVERHEAD_STL92;    sync_out = 1;    /* Set Ninp to length of payload + header */    Ninp = fr_len + (sync_inp ? overhead_inp : 0);    Nout = fr_len + (sync_out ? overhead_out : 0);    break;  case HAS_FLAG_ONLY:    /* STL92 -> STL96 conversion */    inp_type = STL92;    out_type = STL96;    /* Define overhead length */    overhead_inp = OVERHEAD_STL92;    overhead_out = OVERHEAD_STL96;    sync_out = 2;    /* Set Ninp to length of payload + header */    Ninp = fr_len + (sync_inp ? overhead_inp : 0);    Nout = fr_len + (sync_out ? overhead_out : 0);    break;  case NO_HEADER:    inp_type = raw;    out_type = STL96;    /* If input BS is headerless, any frame size will do; use default */    fr_len = N;    /* Define overhead length */    overhead_inp = 0;    overhead_out = OVERHEAD_STL96;    /* Set Ninp to length of payload + header */    Ninp = fr_len;    Nout = fr_len + overhead_out;    /* In this particular case, force sync header in the output */    sync_inp = 0;    sync_out = 1;    break;  default:    HARAKIRI("Unrecognized bitstream type; check input file\n", 5);  }  /* Print info */  fprintf(stderr, "# Input has  %ld bits/frame %s sync header\n", 	  fr_len, sync_inp?"with":"without");  fprintf(stderr, "# Output has %ld bits/frame %s sync header\n",	  fr_len, sync_out?"with":"without");  /* The following is a hook for future extensions */  switch(bs_format)  {  case g192:    size = sizeof(short);    break;  case byte:    size = sizeof(char);    break;  case compact:    size = sizeof(char);    break;  }  /* *** FINAL INITIALIZATIONS *** */  /* Use the proper data I/O functions; format of output file is the     same as that of the input file */  read_data = bs_format==byte? read_byte              : (bs_format==g192? read_g192 : read_bit_ber);  save_data = bs_format==byte? save_byte              : (bs_format==g192? save_g192 : save_bit);  /* ***** ALLOCATION OF BUFFERS ***** */  /* Allocate memory for input and output buffers */  if ((bs_inp = (short *) calloc(Ninp, sizeof(short))) == NULL)    HARAKIRI("Can't allocate memory for input buffer\n", 10);  if ((bs_out = (short *) calloc(Nout, sizeof(short))) == NULL)    HARAKIRI("Can't allocate memory for output buffer\n", 10);  /* Check if is to process the whole file */  if (N2 == 0)  {    struct stat     st;    stat(inpfil, &st);    N2 = ceil((st.st_size - start_byte) / (double)(Ninp * size));  }  /* ***** PRINT PRELIMINARY INFORMATION ***** */  fprintf(stderr, "# Operation: %s -> %s\n",	  cvt_type(inp_type), cvt_type(out_type));  fprintf(stderr, "# Bitstream format: %s\n", format_str((int)bs_format));  fprintf(stderr, "# Input BS header:  %s\n", sync_inp? "present" : "none");  fprintf(stderr, "# Output BS header: %s\n", sync_out? "present" : "none");  fprintf(stderr, "# Payload/total frame size (input): %ld / %ld\n",	  fr_len, fr_len + (sync_inp ? overhead_inp : 0) );  fprintf(stderr, "# Payload/total frame size (output): %ld / %ld\n",	  fr_len, fr_len + (sync_out ? overhead_out : 0) );  /* ***** CARRY OUT CONVERSION ***** */    /* Move file's pointer to 1st desired block (since the BS probing     has changed the FILE pointer) */  if (fseek(Fibs, start_byte, 0) < 0l)    KILL(inpfil, 4);  /* Inits */  bitno=0;  /* Performs the serial-to-parallel conversion */  for (cur_blk = 0; cur_blk < N2; cur_blk++)  {    if (!quiet)      fprintf(stderr, "\rProcessing block %ld\t", cur_blk+1);    if ((items = read_data (bs_inp, Ninp, Fibs))<0)      KILL(inpfil,5);    /* Treatment */    if (inp_type == STL92) /* out_type is STL96 */    {      /* Copy flag, insert length, copy payload */      bs_out[0]=bs_inp[0];      bs_out[1]=fr_len;      memcpy(&bs_out[2], &bs_inp[1], fr_len * sizeof(short));    }    else if (inp_type == STL96) /* out_type is STL92 */    {      /* Copy flag, skip length, copy payload */      bs_out[0]=bs_inp[0];      memcpy(&bs_out[1], &bs_inp[2], fr_len * sizeof(short));    }    else /* headerless BS; save as STL96 BS */    {      /* Insert flag and length, copy payload */      bs_out[0]= 0x6B21;      bs_out[1]=fr_len;      memcpy(&bs_out[2], bs_inp, fr_len * sizeof(short));    }     /* Replace FER, if selected */    if (!fer && bs_out[0] == 0x6B20)    {      bs_out[0] = 0x6B21;      flags_fixed++;    }    /* Save BS to file */    if ((items = save_data (bs_out, Nout, Fobs))<0)      KILL(outfil,6);    /* Update number of bits processed */    bitno += items - sync_out;  }  /* ***** EXITING ***** */  /* Print info */  fprintf(stderr, "# Bits saved to output file: %ld\n", bitno);  if (!fer)    fprintf(stderr, "# FER flags replaced:        %ld\n", flags_fixed);  /* Release memory */  free(bs_out);   free(bs_inp);  /* And close files! */  fclose(Fobs);  fclose(Fibs);    /* Return OK when not VMS */#ifndef VMS  return(0);#endif}/* ....................... End of main() program ....................... */ 

⌨️ 快捷键说明

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