fft_filter.c
来自「speech signal process tools」· C语言 代码 · 共 659 行 · 第 1/2 页
C
659 行
/********************************************************** This material contains propriety software of Entropic* Speech, Inc. Any reproduction, distribution, or* publication without 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 1987 Entropic Speech, Inc."** Module Name: fft_filter.c** Written By: Brian Sublett * Modified by David Burton for ESPS 3.0* Modified for FEAFILT by Bill Byrne, 5/24/91** Purpose: This program reads data from an ESPS speech data* file and filters it with an filter of* arbitrary length. The resulting output data* is then printed to another ESPS data file.** Secrets: **********************************************************/static char *sccs_id = "@(#)fft_filter.c 3.18 7/10/98 ESI";/* * System Includes*/# include <stdio.h>/* * ESPS Includes*/# include <esps/esps.h># include <esps/fea.h># include <esps/feasd.h># include <esps/feafilt.h># include <esps/unix.h>/* * Defines*/# define FILNAMSIZE 40 /* Maximum file name size is 40 characters. */# define MAX_FFT_SIZE 16384 /* Maximum FFT taken. */# define SYNTAX USAGE ("filter [-P parfile] [-f filter name] [-F filt_file] \n[-x debug_level] [-i up/down] [-{pr} range] [-z] in_file out_file");/* * ESPS Functions*/void lrange_switch();char *get_cmd_line();void get_fft();void put_sd_recf();void add_genzfunc();double log();int debug_level = 0;main (argc, argv)int argc;char *argv[]; { FILE *fpin = stdin, *fpout = stdout; /*input and output stream pntrs*/ FILE *fpco; /* FILT file stream pointer*/ int i, nsiz, nn, up = 1, down = 1; int co_num = 1; struct feafilt *filt_rec; /*data structure for FEAFILT files*/ char co_source = 'p'; char *in_file = NULL, *out_file = "<stdout>"; /*in & out file name*/ char *filt_file; /* FILT file name*/ char na_name[FILNAMSIZE]; /*holds name of parameter entry for coeffs*/ char nsiz_name[FILNAMSIZE]; /*holds name of param entry for # coeffs.*/ short fflag = NO, interp = NO; long start = 1, nan = LONG_MAX, start_p = 0, end = LONG_MAX; struct header *ih, *oh, *fh = NULL; /* header ptrs for in out and FILT*/ struct zfunc *pzfunc, dummyzfunc; char *param_file = NULL, *filter_name = "filter"; int num_of_files = 0; extern char *optarg; extern optind; char *Version = "3.18"; char *Date = "7/10/98"; register float hr, hi; static float data_real[MAX_FFT_SIZE], data_imag[MAX_FFT_SIZE], filt_coef_real[MAX_FFT_SIZE], filt_coef_imag[MAX_FFT_SIZE], inp[MAX_FFT_SIZE]; /*arrays for fft results*/ float *fptr1, *fptr2; double t; static double temp[MAX_FFT_SIZE]; int N, c, block_size; int range_flag = 0; char *range; int total_pts = 0; /* count total points written */ int fft_size, log_fft_size; int check_common; /* read_params flag */ int Fflag = 0; int zflag = 0; long num_channels; double start_time = 0; double record_freq = 0; short input_field_type; /* input field type */ struct feasd *sdrec; /* pointer to output record *//* Check the command line options. */ while ((c = getopt (argc, argv, "P:f:F:x:i:r:p:z")) != EOF) { switch (c) { case 'P': param_file = optarg; break; case 'f': filter_name = optarg; fflag = YES; break; case 'F': Fflag++; filt_file = optarg; co_source = 'f'; TRYOPEN ("filter", filt_file, "r", fpco); break; case 'x': if (sscanf(optarg,"%d", &debug_level) != 1) { Fprintf (stderr, "Error reading -x arg. Exitting.\n"); exit (1); } if (debug_level != 0 && debug_level != 1) { debug_level = 1; } break; case 'i': if ((nn = sscanf (optarg, "%d/%d", &up, &down)) != 2) { Fprintf (stderr,"fft_filter: interpolation format is up/down\n"); Fprintf (stderr,"fft_filter: nn=%d up=%d down=%d\n", nn, up, down); Fprintf(stderr, "\nfft_filter: -i option not supported yet\n"); exit (1); } if (up < 0 || up > 10) { Fprintf(stderr,"fft_filter: up = %d is illegal.\n", up); exit (1); } if (down < 0 || down > 10) { Fprintf(stderr,"fft_filter: down = %d is illegal.\n", down); exit (1); } interp = YES; break; case 'r': case 'p': range_flag = 1; range = optarg; break; case 'z': zflag++; break; default: USAGE ("filter [-P parfile] [-f filter name] [-F filt_file] \n[-x debug_level] [-{rp} range] [-z] in_file out_file"); } }/* Change the filtername default if -F was used and -f wasn't. */ if (fflag == NO && co_source == 'f') { filter_name = "1"; }/* Get the filenames. *//* * Get the number of filenames on the command line*/ if((num_of_files = argc - optind) > 2){ Fprintf(stderr, "Only two file names allowed\n"); SYNTAX; } if(debug_level > 0) Fprintf(stderr, "fft_filter: num_of_files = %d\n", num_of_files); if(num_of_files == 0){ Fprintf(stderr, "No output filename specified.\n"); SYNTAX; } if(num_of_files == 1){/* * Only output file specified on command line*/ out_file = eopen("fft_filter", argv[optind], "w", NONE, NONE, (struct header **)NULL, &fpout); if (debug_level) { Fprintf (stderr,"Output file is %s\n", out_file); } check_common = SC_CHECK_FILE; } if (num_of_files == 2)/* * Both input and output file names specified on command line*/ { in_file = eopen("fft_filter", argv[optind++], "r", FT_FEA, FEA_SD, &ih, &fpin); if (debug_level) Fprintf (stderr,"fft_filter: Input file is %s\n", in_file); out_file = eopen("fft_filter", argv[optind], "w", NONE, NONE, (struct header **)NULL, &fpout); if (debug_level) { Fprintf (stderr,"fft_filter: Output file is %s\n", out_file); } /* * decide whether to check common */ if(strcmp(in_file, "<stdin>") == 0) check_common = SC_NOCOMMON; else check_common = SC_CHECK_FILE; }/* Read the parameter file. */ if(read_params(param_file, check_common, in_file) == -3){ Fprintf(stderr, "fft_filt: Can't read params file or Common\n"); exit(1); } if(in_file == NULL){ if(symtype("filename") == ST_UNDEF){ Fprintf(stderr, "fft_filter: No input file on command line or in Common\n"); exit(1); } in_file = eopen("fft_filter", getsym_s("filename"), "r", FT_FEA, FEA_SD, &ih, &fpin); if(debug_level > 0) Fprintf(stderr, "fft_filter: Input file name from common is %s\n", in_file); }/* * abort if mulichannel or complex*/ if((num_channels = get_fea_siz("samples", ih,(short *) NULL, (long **) NULL)) != 1){ Fprintf(stderr, "fft_filter: Multichannel data not supported yet - exiting.\n"); exit(1); } if(is_field_complex(ih, "samples") == YES) { Fprintf(stderr, "fft_filter: Complex data not supported - exiting.\n"); exit(1); } input_field_type = get_fea_type( "samples", ih); if (debug_level) switch( input_field_type ) { case DOUBLE: Fprintf(stderr, "Input field type: double\n"); break; case FLOAT: Fprintf(stderr, "Input field type: float\n"); break; case LONG: Fprintf(stderr, "Input field type: long\n"); break; case SHORT: Fprintf(stderr, "Input field type: short\n"); break; case BYTE: Fprintf(stderr, "Input field type: byte\n"); break; default: Fprintf(stderr, "Input field type unrecognized\n"); exit(1); break; } /* Create the output header. */ oh = new_header (FT_FEA); add_comment(oh, get_cmd_line(argc, argv)); add_source_file (oh, in_file, ih); Strcpy (oh->common.prog, "fft_filter"); Strcpy (oh->common.vers, Version); Strcpy (oh->common.progdate, Date); if((record_freq = get_genhd_val("record_freq", ih, (double)0.)) == 0){ Fprintf(stderr,"fft_filter: Input file record_freq == 0 - exiting.\n"); exit(1); } if((init_feasd_hd(oh, input_field_type, (int) 1, &start_time, (int) 0, record_freq)) != 0){ Fprintf(stderr, "fft_filter: Couldn't allocate input fea_sd header - exiting\n"); exit(1); } /* * Get range info, if not on command line */ if (!range_flag){ if(symtype("start") == ST_UNDEF){ if(debug_level > 0)
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?