📄 dec-patt.c
字号:
#ifdef COMPILE_ME/* This file is just an scheleton *//* ..... 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! */#include <sys/unistd.h> /* for SEEK_... definitions used by fseek() */#endif/* ..... Module definition files ..... */#include "eid.h" /* EID functions */#include "eid_io.h" /* EID I/O functions *//* ..... Definitions used by the program ..... *//* Operating modes */enum BS_types {byte, g192, compact};enum BS_types {BER, FER};/* Definitions for byte mode (defs for G192-mode are in eid_io.h) */#define BYTE_ZERO (char)0X7F#define BYTE_ONE (char)0X81#define BYTE_SYNC (char)0x21#define BYTE_FER (char)0x20/* Other definitions */#define EID_BUFFER_LENGTH 256#define OUT_RECORD_LENGTH 512/* ------------------------------------------------------------------------- long read_g192 (short *patt, long n, FILE *F); ~~~~~~~~~~~~~~ Read a G.192-compliant 16-bit serial bitstream error pattern. Parameter: ~~~~~~~~~~ patt .... G.192 array with the softbits representing the bit error/frame erasure pattern n ....... number of softbits in the pattern F ....... pointer to FILE where the pattern should be readd Return value: ~~~~~~~~~~~~~ Returns a long with the number of shorts softbits from file. On error, returns -1. Original author: <simao.campos@comsat.com> ~~~~~~~~~~~~~~~~ History: ~~~~~~~~ 13.Aug.97 v.1.0 Created. ------------------------------------------------------------------------- */long read_g192(patt, n, F)short *patt;long n;FILE *F;{ long i; /* Read words from file */ i=fread(patt, sizeof(short), n, F); /* Return no.of samples read or error */ return(ferror(F)? -1l : i);}/* ....................... End of read_g192() ....................... *//* --------------------------------------------------------------------------- char *format_str (int fmt); ~~~~~~~~~~~~~~~~~ Function to return a string with the description of the current bitstream format (g192, byte, or bit). Parameters: fmt ... integer with the bitstream format Returned value: ~~~~~~~~~~~~~~~ Returns a pointer to the format string, or a NULL pointer if fmt is invalid. Original author: <simao.campos@comsat.com> ~~~~~~~~~~~~~~~~ History: ~~~~~~~~ 21.Aug.97 v1.00 created ---------------------------------------------------------------------------*/char *format_str(fmt)int fmt;{ switch(fmt) { case byte: return "byte"; break; case g192: return "g192"; break; case compact: return "bit"; break; } return "";}/* ....................... End of format_str() ....................... */ /* -------------------------------------------------------------------------- char check_eid_format (FILE *F, char *file, char *type); ~~~~~~~~~~~~~~~~~~~~~ Function that checks the format (g192, byte, bit) in a given bitstream, and tries to guess the type of data (bit stream or frame erasure pattern) Parameter: ~~~~~~~~~~ F ...... FILE * structure to file to be checked file ... name of file to be checked type ... pointer to guessed data type (FER or BER) in file Returned value: ~~~~~~~~~~~~~~~ Returns the data format (g192, byte, bit) found in file. Original author: <simao.campos@comsat.com> ~~~~~~~~~~~~~~~~ History: ~~~~~~~~ 15.Aug.97 v.1.0 Created. -------------------------------------------------------------------------- */char check_eid_format(F, file, type)FILE *F;char *file;char *type;{ short word; char ret_val; /* Get a 16-bit word from the file */ fread(&word, sizeof(short), 1, F); /* Use some heuristics to determine what type of file is this */ switch((unsigned)word) { case 0x7F7F: case 0x7F81: case 0x817F: case 0x8181: /* Byte-oriented G.192 bitstream */ *type = BER; ret_val = byte; break; case 0x2020: case 0x2021: case 0x2120: case 0x2121: /* Byte-oriented G.192 syncs */ *type = FER; ret_val = byte; break; case 0x007F: case 0x0081: /* G.192 bitstream in natural order */ *type = BER; ret_val = g192; break; case 0x6B21: case 0x6B20: /* G.192 sync header in natural order */ *type = FER; ret_val = g192; break; case 0x7F00: case 0x8100: case 0x216B: case 0x206B: /* G.192 format that needs to be byte-swapped */ fprintf(stderr, "File %s needs to be byte-swapped! Aborted.\n", file); exit(8); default: /* Assuming it is compact bit mode */ *type = nil; /* Not possible to infer type for binary format! */ ret_val = compact; } /* Final check to see if the input bitstream is a byte-oriented G.192 bitstream. In this case, the first byte is 0x2n (n=0..F) and the second byte must be the frame length */ if ((((unsigned)word>>8) & 0xF0) == 0x20) { *type = FER; ret_val = byte; } /* Rewind file & and return format identifier */ fseek(F, 0l, SEEK_SET); return(ret_val);}/* ...................... End of check_eid_format() ...................... */int main (argc, argv) int argc; char *argv[];{ /* Command line parameters */ char format = g192; /* BS format: g192, byte, bit */ char type = FER; /* BS type: BER or FER */ double ber_master, ber_new; /* File I/O parameter */ char master_ep[128]; /* Master error pattern file */ char new_ep[128]; /* New error pattern file */ FILE *Fi, *Fo; long smpno=0, start_frame=1; /* EID-related variables */ long fr_len = 256; char sync_header = 1; /* Data arrays */ short *master, *new; /* Bit error buffer */ /* Aux. variables */ double FER; /* frame erasure rate */ double BER; /* bit error rate */ double BER_gamma = 0.0; /* burst factors; NOT NEEDED */ double FER_gamma = 0.0; /* burst factors; NOT NEEDED */ double ber1; /* returns values from BER_generator */ double disturb_master; /* # of distorted bits/frames */ double proc_master; /* # of processed bits/frames */ double generated; /* # of generated bits/frames */ double percentage; double tolerance = -1; /* Tolerance for actual rates; disabled */ char percent = '%'; long i, j, k, iteraction = 0; long items; /* Number of output elements */ long itot; long index;#if defined(VMS) char mrs[15] = "mrs=512";#endif char quiet = 0, reset = 0, save_format = byte; /* Pointer to a function */ long (*read_patt)() = read_g192; /* To read master EP */ long (*save_patt)() = save_g192; /* To save new EP */ /* ......... GET PARAMETERS ......... */ /* Check options */ if (argc < 2) display_usage (); else { while (argc > 1 && argv[1][0] == '-') if (strcmp (argv[1], "-start") == 0) { /* Define starting sample/frame for error insertion */ 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], "-n") == 0) { /* Define number of samples to extract */ smpno = atoi (argv[2]); /* Move arg{c,v} over the option to the next argument */ argc -= 2; argv += 2; } else if (strcmp (argv[1], "-tol") == 0) { /* Define number of samples to extract */ tolerance = atof (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], "-ber") == 0 || strcmp (argv[1], "-BER") == 0) { /* BS type */ bs_type = BER; /* Move arg{c,v} over the option to the next argument */ argc--; argv++; } else if (strcmp (argv[1], "-fer") == 0 || strcmp (argv[1], "-FER") == 0) { /* BS type */ bs_type = FER; /* Move arg{c,v} over the option to the next argument */ argc--; argv++; } else if (strcmp (argv[1], "-g192") == 0) { /* Save bitstream as a G.192-compliant serial bitstream */ save_format = g192; save_patt = save_g192; /* Move arg{c,v} over the option to the next argument */ argc--; argv++; } else if (strcmp (argv[1], "-byte") == 0)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -