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

📄 vselp.c

📁 Reference Implementation of G.711 standard and other voice codecs
💻 C
📖 第 1 页 / 共 2 页
字号:
/**************************************************************************                (C) Copyright 1990, Motorola Inc., U.S.A.Note:  Reproduction and use for the development of North American digital       cellular standards or development of digital speech coding       standards within the International Telecommunications Union -       Telecommunications Standardization Sector is authorized by Motorola        Inc.  No other use is intended or authorized.       The availability of this material does not provide any license       by implication, estoppel, or otherwise under any patent rights       of Motorola Inc. or others covering any use of the contents       herein.       Any copies or derivative works must incude this and all other       proprietary notices.       Permision has been granted to include this software in ITU-T       Software Tool Library, for the only purpose of helping the       development of new ITU standards.Systems Research LaboratoriesChicago Corporate Research and Development CenterMotorola Inc.************************************************************************* *//*  -------------------------------------------------------------------------  vselp.c  ~~~~~~~  C Language Version of the IS54 VSELP Speech Coder. Reference  implementation carried out by Motorola.  Original author: Matt Hartman  Adapted to ITU-TSS Software Tool Library by: Simao F.Campos Neto  Usage:  vselp [-urf urffile] [-bin obsfile] [-hex obsfile] [-log logfile]        [-nolog] [-pf] [enc] [-dec]        srcfile decfile logfile obsfile, OR (WHEN -enc USED)        srcfile ibsfile logfile,         OR (WHEN -dec USED)        srcfile decfile logfile          (DEFAULT)  where:  srcfile ........ name of input file  decfile ........ name of output, decoded file [ignored for encode_only mode]  ibsfile ........ input bitstream file [ignored for encode_only|encode+decode]  logfile ........ log file name  obsfile ........ bitstream gen'd for srcfile [only w/encode_only|encode+decode]  Options:  -urf urffile ... use the user's response file "urffile"  -bin ........... coded bitstream should be saved to a binary file   -hex ........... coded bstream should be saved to an ascii hex file [default]  -log logfile ... log of processing results is to be saved in file "logfile"  -nolog ......... do not log results  -enc ........... run encoder only [default: run encode + decode]  -dec ........... run decoder only [default: run encode + decode]  -pf ............ use post-filter in decoder  History:  08/May/90 v.1.0  Created <Matt Hartman>  20/Mar/94 v.1.1  Adapted to UGST format <simao@cpqd.ansp.br>  08/Feb/95 v.1.2  Fixed error in self-documentation and help message                   <simao@ctd.comsat.com>  22/Feb/96 v.1.2  Adapted code for operation in a DEC Alpha/APX (after                    STEGMANN, FI/DBP Telekom) -------------------------------------------------------------------------*//* Include files */#include "vselp.h"#include "ugstdemo.h"#include "vparams.h"#ifdef __TURBOC__unsigned        _stklen = 50000;/* Set Stack Size for Turbo C */#endif#ifdef VMS#undef WT#define WT "w" /* Plain write file definition for fopen() in VMS */#endif/* Global vars for communication with other routines */int             apply_postfilter, encode_only, decode_only;/* ------------------------------------------------------------------------ */long swap_byte(shPtr, n)short *shPtr;long n;{  short *s_Ptr;  short register tmp;  long register count;    for (count=0; count<n; count++)  {    tmp = (*shPtr << 8) + ((*shPtr >> 8) & 0x00ff);    *shPtr++ = tmp;  }  return((long)count);}/* ......................... End of swap_byte() ............................ *//* ------------------------------------------------------------------------ */void initState(){  T_NEW.k = (FTYPE *) calloc(14 * NP, sizeof(FTYPE));	/* Note: it is  */  T_NEW.a = T_NEW.k + NP;	/* necessary that these coef sets be */  T_NEW.widen = T_NEW.a + NP;	/* stored sequentially. DONT REARRANGE. */  T_OLD.k = T_NEW.widen + NP;	/* Note: it is necessary that these */  T_OLD.a = T_OLD.k + NP;	/* coef sets be stored sequentially. */  T_OLD.widen = T_OLD.a + NP;	/* DONT REARRANGE. */  R_NEW.k = T_OLD.widen + NP;	/* Note: it is necessary that these */  R_NEW.a = R_NEW.k + NP;	/* coef sets be stored sequentially. */  R_NEW.widen = R_NEW.a + NP;	/* DONT REARRANGE. */  R_NEW.sst = R_NEW.widen + NP;  R_OLD.k = R_NEW.sst + NP;	/* Note: it is necessary that these */  R_OLD.a = R_OLD.k + NP;	/* coef sets be stored sequentially. */  R_OLD.widen = R_OLD.a + NP;	/* DONT REARRANGE. */  R_OLD.sst = R_OLD.widen + NP;}/* ......................... End of initState() ............................ *//* ------------------------------------------------------------------------ */#define P(x) printf xvoid            display_usage(){  P(("  vselp: version 1.10 of 14/Mar/1994 \n\n"));  P(("  C Language Version of the IS54 VSELP Speech Coder. Reference\n"));  P(("  implementation carried out by Motorola adapted to ITU-T Software\n"));  P(("  Tool Library by Simao F. Campos Neto\n"));  P(("\n"));  P(("  Original author: Matt Hartman\n"));  P(("\n"));  P(("\n"));  P(("  Usage:\n"));  P(("  vselp [-urf urffile] [-bin obsfile] [-hex obsfile] [-log logfile] [-nolog]\n"));  P(("        [-nolog] [-pf] [-enc] [-dec]\n"));  P(("        srcfile decfile logfile obsfile, OR (WHEN -enc USED)\n"));  P(("        srcfile ibsfile logfile,         OR (WHEN -dec USED)\n"));  P(("        srcfile decfile logfile          (DEFAULT)\n\n"));  P(("  where:\n"));  P(("  srcfile ........ name of input file\n"));  P(("  decfile ........ name of output, decoded file [ignored for encode_only mode]\n"));  P(("  ibsfile ........ input bitstream file [ignored for encode_only|encode+decode]\n"));  P(("  logfile ........ log file name\n"));  P(("  obsfile ........ bstream gen'd for srcfile [only w/encode_only|encode+decode]\n"));  P(("  Options:\n"));  P(("  -urf urffile ... use the user's response file \"urffile\"\n"));  P(("  -bin ........... coded bitstream should be saved to a binary file\n"));  P(("  -hex ........... coded bstream should be saved to an ascii hex file [default]\n"));  P(("  -log logfile ... log of processing results is to be saved in file \"logfile\"\n"));  P(("  -nolog ......... do not log results\n"));  P(("  -enc ........... run encoder only [default: run encode + decode]\n"));  P(("  -dec ........... run decoder only [default: run encode + decode]\n"));  P(("  -pf ............ use post-filter in decoder\n"));  P(("\n"));  /* Quit program */  exit(-128);}#undef P/* .......................... end of displau_usage() ......................... *//*-------------------------------------------------------------------------*//* main program*/int             main(argc, argv)  int             argc;  char           *argv[];{  /* Main's automatic variables */  FTYPE          *coefBuf;	/* Points to memory allocated for T_NEW,				 * T_OLD, R_NEW, and R_OLD coefficient				 * storage */  FTYPE           RQ_HOLD;	/* Temporary storage for the R0q value to use				 * in the middle subframe on the receive side */  FTYPE           RQ_TMP;	/* R0q value that gets passed to RES_ENG() */  FTYPE           inScale = 1.0 / 32768.0;	/* Scale factor used to						 * convert  integer input						 * samples to floating point						 * fractions */  int             us;		/* Unstable flag returned by INTERPOLATE(),				 * determines whether another RS will need to				 * be calculated */  short          *shBuf;	/* points to beginning of short I/O buffer */  FILE           *fpprm;	/* points to parameter set-up file (if given) */  FTYPE          *tmpPtr, *tmpPtr2, *endPtr, f1;  int             i, numRead;  short          *shPtr;  long		(*get_codes)(), (*put_codes)();  long            bs_read = 0, bs_saved = 0;  char            use_user_resp_file = 0;	/* Don't use user's response						 * file */  char            InpFile[120], OutFile[100], LogFile[100], PackedFile[100];#ifdef VMS  char mrs[15];  short *zero_vector;  long zero_values,lwrite;  #endif  /* Diagnostic variables for debugging */  int             finalCnt;  /* Progress indication */  static char     quiet, funny[9] = "|/-\\|/-\\";  /* SETTING DEFAULT OPTIONS */  decode_only = 0;		/* run encoder and decoder */  encode_only = 0;  packedStream = 1;		/* generate HEX-packed bitstreams */  performMeas = 1;		/* calculate performance measures */  makeLog = 1;  apply_postfilter = 0;  quiet = 0;  finalCnt = 0;			/* always process the complete file */  fpin = fpout = fpcode = fplog = fpstream = NULL;#ifdef VMS  sprintf (mrs, "mrs=%d", 512);#endif  /* GETTING OPTIONS */  if (argc < 2)    display_usage();  else  {    while (argc > 1 && argv[1][0] == '-')      if (strcmp(argv[1], "-urf") == 0)      {	/* User response file */	use_user_resp_file = 1;	fpprm = fopen(argv[2], "r");	getParams(fpprm);	fclose(fpprm);	/* Update argc/argv to next valid option/argument */	argv += 2;	argc -= 2;      }      else if (strcmp(argv[1], "-dec") == 0)      {	/* Run only the decoder */	decode_only = 1;	/* Move argv over the option to the next argument */	argv++;	argc--;      }      else if (strcmp(argv[1], "-enc") == 0)      {	/* Run only the encoder */	encode_only = 1;	/* Move argv over the option to the next argument */	argv++;	argc--;      }      else if (strcmp(argv[1], "-bin") == 0)      {	/* Save bitstream as an binary, 16-bit-word oriented file */	packedStream = 0;	/* Move argv over the option to the next argument */	argv++;	argc--;      }      else if (strcmp(argv[1], "-hex") == 0)      {	/* Save bitstream as an ascii HEXadecimal file */	packedStream = 1;	/* Move argv over the option to the next argument */	argv++;	argc--;      }      else if (strcmp(argv[1], "-log") == 0)      {	/* Do create log file (default) */	makeLog = 1;	/* Scan log file name */	strcpy(LogFile, argv[2]);	if ((fplog = fopen(argv[2], "w")) == NULL)	  HARAKIRI("ERROR creating log file\n", 2);	/* Move argv over the option to the next argument */	argv += 2;	argc -= 2;      }      else if (strcmp(argv[1], "-nolog") == 0)      {	/* Don't create log file */	makeLog = 0;	fplog = stderr;	/* Move argv over the option to the next argument */	argv++;	argc--;      }      else if (strcmp(argv[1], "-pf") == 0)      {	/* Apply post-filtering in the decoder */	apply_postfilter = 1;	/* Move argv over the option to the next argument */	argv++;	argc--;      }      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      {	fprintf(stderr, "ERROR! Invalid option \"%s\" in command line\n\n",		argv[1]);	display_usage();      }  }  /* WELCOME! */  fprintf(stderr, "***************************************************************\n");  fprintf(stderr, "\n           (C) Copyright 1990, Motorola Inc., U.S.A.\n\n");  fprintf(stderr, "***************************************************************\n");  /* Get values for calculated parameters */  /* Three choices: */  /*  - enc+dec:  read inp-lin-file out-lin-file logfile */  /*  - enc-only: read inp-lin-file out-bitstream-file logfile */  /*  - dec-only: read inp-bitstream-file out-lin-file logfile */  if (!use_user_resp_file)  {    i = 1;    if (!decode_only && fpin == NULL)    {      GET_PAR_S(i, "Input speech file: ........ ", InpFile);      if ((fpin = fopen(InpFile, RB)) == NULL)	KILL(InpFile, 2);      i++;    }    if (decode_only && fpstream == NULL)    {      GET_PAR_S(i, "Input bit-stream file: .... ", InpFile);      i++;      if (packedStream)      {         if ((fpstream = fopen(InpFile, "r")) == NULL)	  HARAKIRI("Error opening code file\n", 2);      }      else      {        if ((fpstream = fopen(InpFile, RB)) == NULL)	  HARAKIRI("Error opening code file\n", 2);      }    }    if (encode_only && fpstream == NULL)    {      GET_PAR_S(i, "Output bit-stream file: ... ", OutFile);      i++;

⌨️ 快捷键说明

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