📄 histo.c
字号:
/* ******************************************************************************** * * This material contains proprietary software of Entropic Speech, Inc. * Any reproduction, distribution, or publication without the the prior * written permission of Entropic Speech, Inc. is strictly prohibited. * Any public distribution of copies of this work authorized in writing * by Entropic Speech, Inc. must bear the notice: * * "Copyright (c) 1987 Entropic Speech, Inc.; all rights reserved" * * Program: histo * * Written by: Jim Elliott * * Computes histograms for type and extension fields, and for quantized * power, pulse length, and spectral parameters. * ******************************************************************************** *//* * SCCS program and date keywords. */#ifndef lintstatic char *sccs_id = "@(#)histo.c 1.4 11/24/87 ESI";#endif/* * System include files. */#include <stdio.h>/* * ESPS include files. */#include <esps/esps.h>#include <esps/anafea.h>#include <esps/fea.h>#include <esps/feaqhist.h>#include <esps/feaquant.h>#include "histo.h"/* * Defines. */#define ERROR_EXIT( text ) \{ \ Fprintf( stderr, "histo: %s - exiting\n", text ); \ exit( 1 ); \}#define M_OPT_MSSG "-m: comb_frq, comb_vcg, cont_pwr, cont_spc are only valid choices"#define SYNTAX USAGE( "histo -P param_file -m mode infile.fea outfile.fea" )/* * System functions and variables. */char *strcpy();int getopt(), strcmp();void exit(), perror();extern optind;extern char *optarg;/* * ESPS functions and variables. */char *get_cmd_line();/* ******************************************************************************** * Main program. ******************************************************************************** */main( argc, argv )char *argv[];int argc;{ char *cmd_line, /* String for command line */ *date = "11/24/87", *ifn = NULL, /* Input file name */ *ofn = NULL, /* Output file name */ *pfn = "params", /* Parameter file name */ *version = "1.4"; FILE *ifp = stdin, /* Input file pointer */ *ofp = stdout; /* Output file pointer */ int c, /* For getopt() return */ i, /* Loop variable */ uvced_frmlen, /* Standard unvoiced frame length */ u_lsf_avg[ MAX_ORD ], /* Unvoiced LSF averages */ v_lsf_avg[ MAX_ORD ]; /* Voiced LSF averages */ long order_unvcd, /* Filter order for unvoiced frames */ order_vcd; /* Filter order for voiced frames */ short comb_frq = NO, /* Flag for combining frequency tables */ comb_vcg = NO, /* Flag for combining voicing tables */ cont_pwr = NO, /* Flag for continuous coding of power */ cont_spc = NO, /* Flag for continuous coding of spectrum */ prev_type = NONE, /* Previous frame type */ u_avg[ MAX_ORD ], /* Unvoiced LSF averages */ v_avg[ MAX_ORD ]; /* Voiced LSF averages */ struct anafea *anafea_rec; /* FEA_ANA file record */ struct auxana *auxana_rec; /* Auxiliary index data record */ struct feaqhist *feaqhist_rec; /* FEA_QHIST file record */ struct header *ih, /* Input file header */ *oh; /* Output file header *//* * Histogram arrays: range from -N to +N is converted to range from 0 to * 2*N. Provision is made to store spectral histograms separately, for * voiced/unvoiced frames, and for each spectral parameter. Under certain * options, the histograms are combined before writing to the output file. * * The arrangement of the spectral data is as follows: * * 0: VCF12: (0,1, ... FSZ) * FSZ: VOF12: (0,1, ... FSZ) * ... ... * 8*FSZ: VCF90: (0,1, ... FSZ) * 9*FSZ: VOF90: (0,1, ... FSZ) * VSZ: UCF12: (0,1, ... FSZ) * VSZ+FSZ: UOF12: (0,1, ... FSZ) * ... ... * VSZ+4*FSZ: UCF56: (0,1, ... FSZ) * VSZ+5*FSZ: UOF56: (0,1, ... FSZ) * VSZ+6*FSZ: (unused) */ static int hist_type[ 2*MAX_TYPE+1 ], /* Type field */ hist_ext[ 2*MAX_EXT+1 ], /* Extension field */ hist_len[ 2*MAX_LEN+1 ], /* Pulse length */ hist_pwr[ 2*MAX_PWR+1 ], /* Power */ hist_spec_intra[ 2*VSZ ], /* Intraframe spectrum */ hist_spec_inter[ 2*VSZ ]; /* Interframe spectrum *//* * Read command line and process command line options. */ cmd_line = get_cmd_line( argc, argv ); while ( ( c = getopt( argc, argv, "P:m:" ) ) != EOF ) { switch ( c ) { case 'P': pfn = optarg; break; case 'm': if ( strcmp( optarg, "comb_frq" ) == 0 ) comb_frq = YES; else if ( strcmp( optarg, "comb_vcg" ) == 0 ) comb_vcg = YES; else if ( strcmp( optarg, "cont_pwr" ) == 0 ) cont_pwr = YES; else if ( strcmp( optarg, "cont_spc" ) == 0 ) cont_spc = YES; else { ERROR_EXIT( M_OPT_MSSG ); } break; default: SYNTAX; } }/* * Process file arguments. */ if ( optind < argc ) { ifn = argv[ optind++ ]; if ( strcmp( ifn, "-" ) == 0 ) ifn = "<stdin>"; else TRYOPEN( argv[0], ifn, "r", ifp ); } else { Fprintf( stderr, "histo: No input file specified\n" ); SYNTAX; } if ( optind < argc ) { ofn = argv[ optind++ ]; if ( strcmp( ofn, "-" ) == 0 ) ofn = "<stdout>"; else TRYOPEN( argv[0], ofn, "w", ofp ); } else { Fprintf( stderr, "histo: No output file specified\n" ); SYNTAX; }/* * Read parameter file. */ if ( read_params( pfn, SC_NOCOMMON, NULL ) != 0 ) ERROR_EXIT( "Error reading parameter file" ); (void) getsym_ia( "u_lsf_avg", u_lsf_avg, MAX_ORD ); (void) getsym_ia( "v_lsf_avg", v_lsf_avg, MAX_ORD ); symerr_exit(); for ( i = 0; i < MAX_ORD; i++ ) { u_avg[i] = u_lsf_avg[i]; v_avg[i] = v_lsf_avg[i]; }/* * Read and check values from header of input file. */ if ( ( ih = read_header( ifp ) ) == NULL ) NOTSPS( argv[0], ifn ); if ( ih->common.type != FT_FEA ) ERROR_EXIT( "Input file is not a FEA file" ); if ( ih->hd.fea->fea_type != FEA_ANA ) ERROR_EXIT( "Input file is not FEA_ANA type" ); if ( get_genhd( "lsf_quant", ih ) == NULL || get_genhd( "pitch_quant", ih ) == NULL || get_genhd( "power_quant", ih ) == NULL ) ERROR_EXIT( "Input file is not quantized" );/* * Read and store items from the generic header. */ order_unvcd = *(long *) get_genhd( "order_unvcd", ih ); order_vcd = *(long *) get_genhd( "order_vcd", ih ); uvced_frmlen = *(int *) get_genhd( "uvced_frmlen", ih );/* * Create header for output file. */ oh = new_header( FT_FEA ); add_source_file( oh, ifn, ih ); (void) strcpy( oh->common.prog, "histo" ); (void) strcpy( oh->common.vers, version ); (void) strcpy( oh->common.progdate, date ); add_comment( oh, cmd_line ); oh->common.tag = NO; oh->variable.refer = ifn;/* * Allocate record fields, fill in values of generic header items, and write * output file header. */ if ( init_feaqhist_hd( oh, get_genhd( "lsf_quant", ih ), get_genhd( "pitch_quant", ih ), get_genhd( "power_quant", ih ), u_avg, v_avg ) ) ERROR_EXIT( "Error filling FEA_QHIST header" ); *(short *) get_genhd( "comb_frq", oh ) = comb_frq; *(short *) get_genhd( "comb_vcg", oh ) = comb_vcg; *(short *) get_genhd( "cont_pwr", oh ) = cont_pwr; *(short *) get_genhd( "cont_spc", oh ) = cont_spc; if ( strcmp( get_genhd( "power_quant", ih ), "1.5_dB" ) == 0 ) *(short *) get_genhd( "max_steps", oh ) = *(short *) get_genhd( "max_steps", ih ); else *(short *) get_genhd( "max_steps", oh ) = 0; *(short *) get_genhd( "unvoiced_steps", oh ) = *(short *) get_genhd( "unvoiced_steps", ih ); *(short *) get_genhd( "voiced_steps", oh ) = *(short *) get_genhd( "voiced_steps", ih ); write_header( oh, ofp );/* * Allocate storage for input and output data records. */ anafea_rec = allo_anafea_rec( ih ); auxana_rec = allo_auxana_rec( ih, anafea_rec ); feaqhist_rec = allo_feaqhist_rec( oh );/* * Main program loop. */ while ( get_anafea_rec( anafea_rec, ih, ifp ) != EOF ) { histo_type_ext( anafea_rec, prev_type, uvced_frmlen, hist_type, hist_ext ); histo_power( anafea_rec, auxana_rec, cont_pwr, prev_type, hist_pwr ); histo_length( anafea_rec, auxana_rec, prev_type, hist_len ); histo_spectrum( anafea_rec, auxana_rec, order_vcd, order_unvcd, u_avg, v_avg, cont_spc, prev_type, hist_spec_inter, hist_spec_intra ); prev_type = *anafea_rec->frame_type; }/* * Output histogram results. */ write_histo( hist_type, hist_ext, hist_pwr, hist_len, hist_spec_intra, hist_spec_inter, feaqhist_rec, comb_frq, comb_vcg, cont_spc, oh, ofp ); exit( 0 );}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -