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

📄 bs-stats.c

📁 Reference Implementation of G.711 standard and other voice codecs
💻 C
📖 第 1 页 / 共 2 页
字号:
/*                                                         02.Feb.2000 v.1.0   =========================================================================   bs-stats.c   ~~~~~~~~~~   Program Description:   ~~~~~~~~~~~~~~~~~~~~   This example program reports in ASCII format the frame sizes   encountered in an encoded bitstream file and some statistics.   The file containing an encoded speech bitstream can be in the G.192   serial bitstream format (which uses 16-bit softbits), or in the   byte-oriented G.192 format. For this type of verification, the file   cannot be in the compact binary format, nor headerless.   Files in the G.192 format will contain 16-bit, right-aligned   'short' words. The start of a frame is signalled by the synchronism   header, which consists of two shorts: the first word is the frame   synchronism word, 0x6B2z, z=0..F, and the second word contains the   number N of softbits in the frame (i.e., the frame size). After the   synchronism header, comes the frame "payload" that comprise N   shorts equal to 0x007F [an 8-bit softbit representation of the   hardbit '0'], to 0x0081 [an 8-bit softbit representation of the   hardbit '1'], or to 0x0000 [total uncertaintly, in the case of a   frame erasure]. Hence, a frame will occupy N+2 shorts, or 2N+4   bytes. G.192 bitstreams need to be byte-swapped when used across   different platforms that differ in byte-order organization (little   and big endian systems).   The byte-oriented G.192 format is similar to the G.192 format,   except that data is organized in bytes, whereby only the least   significat byte information is preserved. Hence, the frame   syncronism word is represented by the char 0x2z, z=0..F; the   payload will contain bytes 0x7F, 0x81, or 0x00. Byte-oriented G.192   bitstreams do not need byteswapping when using them across   platforms that have different byte-order architectires (i.e. big   and little endian systems). However, the byte-oriented G.192 format   has some important limitations: frame sizes are limited to 255   (soft)bits, and true softbit usage is not recommended since the   syncronism word is no longer unique.   Limitations:   ~~~~~~~~~~~~   This program will not distinguish among different channels that   might be multiplexed in the bitstream file (identified by different   header synchronism values), nor will separate statistics for erased   frames. All data will be consolidated irrespective of different   channel assignment and/or frame erasures.   Usage:   ~~~~~   bs-stats [Options] in_bs bs_info   Where:   in_bs ...... input encoded speech bitstream file   bs_info .... ASCII file where the frame length values found in the                 file are reported, sequencially. Additional stats                printed on the screen can be saved to a file via                redirection of stdin.   Options:   -bs mode ... Mode for bitstream (g192, byte, or bit)   -q ......... Quiet operation   -qq ........ VERY Quiet operation: no ASCII file generated   -? ......... Displays this message   -help ...... Displays a complete help message   Original Author:   ~~~~~~~~~~~~~~~~   Simao Ferraz de Campos Neto   Comsat Laboratories              Tel:    +1-301-428-4516   22300 Comsat Drive               Fax:    +1-301-428-9287   Clarksburg MD 20871 - USA        E-mail: simao.campos@labs.comsat.com   History:   ~~~~~~~~   02.Feb.2000 v.1.0 Created based on eid-xor.c <simao>   ========================================================================= *//* ..... Generic include files ..... */#include "ugstdemo.h"		/* general UGST definitions */#include <stdio.h>		/* Standard I/O Definitions */#include <math.h>#include <stdlib.h>#include <string.h>		/* memset */#include <ctype.h>		/* toupper *//* ..... OS-specific include files ..... */#if defined (unix) && !defined(MSDOS)/*                 ^^^^^^^^^^^^^^^^^^ This strange construction is necessary                                      for DJGPP, because "unix" is defined,				      even it being MSDOS! */#if defined(__ALPHA)#include <unistd.h>		/* for SEEK_... definitions used by fseek() */#else#include <sys/unistd.h>		/* for SEEK_... definitions used by fseek() */#endif#endif/* ..... Module definition files ..... */#include "softbit.h"            /* Soft bit definitions and prototypes *//* ..... Definitions used by the program ..... *//* Generic definitions */#define EID_BUFFER_LENGTH 256#define OUT_RECORD_LENGTH 512#define MAX_FRAME 32767/* Local function prototypes */void display_usage ARGS((int level));/* ************************* AUXILIARY FUNCTIONS ************************* *//*  --------------------------------------------------------------------------  display_usage()  Shows program usage.  History:  ~~~~~~~~  8/Feb/2001  v1.0 Created <simao>  --------------------------------------------------------------------------*/#define P(x) printf xvoid            display_usage (level)int level;{  P(("bs-stats.c - Version 1.0 of 9/Feb/2001\n"));  if (level)  {   P(("\nThis example program reports in ASCII format the frame sizes\n"));  P(("encountered in an encoded bitstream file and some statistics.\n"));  P(("\n"));  P(("The file containing an encoded speech bitstream can be in the G.192\n"));  P(("serial bitstream format (which uses 16-bit softbits), or in the\n"));  P(("byte-oriented G.192 format. For this type of verification, the file\n"));  P(("cannot be in the compact binary format, nor headerless.\n"));  P(("\n"));  P(("Files in the G.192 format will contain 16-bit, right-aligned\n"));  P(("'short' words. The start of a frame is signalled by the synchronism\n"));  P(("header, which consists of two shorts: the first word is the frame\n"));  P(("synchronism word, 0x6B2z, z=0..F, and the second word contains the\n"));  P(("number N of softbits in the frame (i.e., the frame size). After the\n"));  P(("synchronism header, comes the frame \"payload\" that comprise N\n"));  P(("shorts equal to 0x007F [an 8-bit softbit representation of the\n"));  P(("hardbit '0'], to 0x0081 [an 8-bit softbit representation of the\n"));  P(("hardbit '1'], or to 0x0000 [total uncertaintly, in the case of a\n"));  P(("frame erasure]. Hence, a frame will occupy N+2 shorts, or 2N+4\n"));  P(("bytes. G.192 bitstreams need to be byte-swapped when used across\n"));  P(("different platforms that differ in byte-order organization (little\n"));  P(("and big endian systems).\n"));  P(("\n"));  P(("The byte-oriented G.192 format is similar to the G.192 format,\n"));  P(("except that data is organized in bytes, whereby only the least\n"));  P(("significat byte information is preserved. Hence, the frame\n"));  P(("syncronism word is represented by the char 0x2z, z=0..F; the\n"));  P(("payload will contain bytes 0x7F, 0x81, or 0x00. Byte-oriented G.192\n"));  P(("bitstreams do not need byteswapping when using them across\n"));  P(("platforms that have different byte-order architectires (i.e. big\n"));  P(("and little endian systems). However, the byte-oriented G.192 format\n"));  P(("has some important limitations: frame sizes are limited to 255\n"));  P(("(soft)bits, and true softbit usage is not recommended since the\n"));  P(("syncronism word is no longer unique.\n"));  P(("\n"));  P(("Limitations:\n"));  P(("~~~~~~~~~~~~\n"));  P(("\n"));  P(("This program will not distinguish among different channels that\n"));  P(("might be multiplexed in the bitstream file (identified by different\n"));  P(("header synchronism values), nor will separate statistics for erased\n"));  P(("frames. All data will be consolidated irrespective of different\n"));  P(("channel assignment and/or frame erasures.\n"));  P(("\n"));  }  else  {  P((" Reports in ASCII format the frame sizes found in an encoded\n"));  P((" bitstream file and some related statistics. The encoded bitstream\n"));  P((" can be in word- or byte-oriented G.192 format, but cannot be in\n"));  P((" compact or headerless format. This program will report only the\n"));  P((" aggregate frame size information, irrespective of any (possible)\n"));  P((" different channel multiplexing or frame erasures present in the\n"));  P((" bitstream. Try option -help for full help text.\n"));  }  P(("Usage:\n"));  P((" bs-stats [Options] in_bs bs_info\n"));  P(("Where:\n"));  P((" in_bs ...... input encoded speech bitstream file\n"));  P((" bs_info .... ASCII file where the frame length values found in the\n"));  P(("              file are reported, sequencially. Additional stats\n"));  P(("              printed on the screen can be saved to a file via\n"));  P(("              redirection of stdin.\n"));  P(("Options:\n"));  P((" -bs mode ... Mode for bitstream (g192, byte, or bit)\n"));  P((" -q ......... Quiet operation\n"));  P((" -qq ........ VERY Quiet operation: no ASCII file generated\n"));  P((" -? ......... Displays this message\n"));  P((" -help ...... Displays a complete help message\n"));  /* Quit program */  exit(-128);}#undef P/* ....................... End of display_usage() ....................... *//* ************************************************************************* *//* ************************** MAIN_PROGRAM ********************************* *//* ************************************************************************* */int             main (argc, argv)  int             argc;  char           *argv[];{  /* Command line parameters */  char            bs_format = g192;   /* Generic Speech bitstream format */  char            ibs_file[128];      /* Input bitstream file */  char            out_file[128];      /* Output ASCII file */  char            log=1;              /* Flag for en/dis-abling output file */  long            fr_len = 0;         /* Frame length in bits */  long            bs_len;             /* BS frame length, with headers */  long            ori_bs_len, ori_fr_len; /* Frame/BS legth memory */  long            start_frame = 1;     /* Start inserting error from 1st one */  char            sync_header = 1;     /* Flag for input BS */  /* File I/O parameter */  FILE           *Fibs;    /* Pointer to input encoded bitstream file */  FILE           *Fout=0;  /* Pointer to ASCII file with frame sizes */#ifdef DEBUG  FILE *F;#endif  /* Data arrays */  short          *bs;    	       /* Encoded speech bitstream */  short          *payload;             /* Point to payload in bitstream */  /* Aux. variables */  long            no_sizes=-1;   /* No. of diff. frame sizes found in BS */  long            distr[MAX_FRAME]; /* Array with distrib. of frame sizes */  short           offset=0;      /* Where is next frame leng.val. in the BS */  long            max_fr=0;      /* Max. frame length found in bitstream */  long            min_fr=100000; /* Min. frame length found in bitstream */  double          frame_no=0;	       /* Total # of frames in BS */  char            vbr=1;               /* Flag for variable bit rate mode */  long            ibs_sample_len;      /* Size (bytes) of samples in the BS */  char            tmp_type;  long            i;  long            items;	       /* Number of output elements */#if defined(VMS)  char            mrs[15] = "mrs=512";#endif  char            quiet = 0;  /* Pointer to a function */  long            (*read_data)() = read_g192;	/* To read input 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 frame */	start_frame = atol (argv[2]);	/* Move arg{c,v} over the option to the next argument */	argc -= 2;	argv += 2;      }      else if (strcmp (argv[1], "-bs") == 0)      {	/* Define input & output encoded speech bitstream format */

⌨️ 快捷键说明

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