📄 firdemo.c
字号:
************************************************************************** ************************************************************************** *** *** *** Test-Program for testing the correct implementation *** *** and to show how to use the programs *** *** *** ************************************************************************** ***************************************************************************/int main(argc, argv) int argc; char *argv[];{/* * ......... Define symbols of type SCD_FIR for each filter ......... */ SCD_FIR *irs_ptr; SCD_FIR *delta_sm_ptr; SCD_FIR *up1_ptr; SCD_FIR *up2_ptr; SCD_FIR *down1_ptr; SCD_FIR *down2_ptr; /* ......... signal arrays ......... */#ifdef STATIC_ALLOCATION short sh_buff[9 * LSEGMAX]; /* 16-bit buffer */ float fl_buff[LSEGMAX]; /* float buffer */ float irs_buff[LSEGMAX]; /* output of irs filter */ float up1_buff[3 * LSEGMAX]; /* output of first upsampling * buffer */ float up2_buff[9 * LSEGMAX]; /* output of second * upsampling buffer */ float down1_buff[9 * LSEGMAX]; /* output of first * downsampling buf. */ float down2_buff[9 * LSEGMAX]; /* output of second * downsampling buf. */#else short *sh_buff; /* 16-bit buffer */ float *fl_buff; /* float buffer */ float *irs_buff; /* output of irs filter */ float *up1_buff; /* output of first upsampling buffer */ float *up2_buff; /* output of second upsampling buffer */ float *down1_buff; /* output of first downsampling buf. */ float *down2_buff; /* output of second downsampling buf. */#endif /* ......... File related variables ......... */ char inpfil[128], outfil[128]; FILE *inpfilptr, *outfilptr; int inp, out;#if defined(VMS) char mrs[15];#endif /* ......... other auxiliary variables ......... */ clock_t t1, t2; /* aux. for CPU-time measurement */ long irs; long delta_sm; long up_1, up_2; long down_1, down_2; long lsegdown1, lsegdown2; long lsegup1, lsegup2; long lsegx, lsegirs, lseg=LSEG0; static long noverflows0 = 0, noverflows1 = 0, noverflows2 = 0, noverflows3 = 0, noverflows4 = 0, noverflows5 = 0; long nsam = 0; long k; int quiet=0, modified_irs=0, half_tilt=0;/* * ......... PRINT INFOS ......... */ printf("%s%s", "*** V2.4 FIR-Up/Down-Sampling ", "and IRS Send Part Filter - 3-Dec-2004 ***\n");/* * ......... PARAMETERS FOR PROCESSING ......... */ /* GETTING OPTIONS */ /* If no pars. are specified, display usage and quit; else, parse args */ if (argc < 2) display_usage(); else { while (argc > 1 && argv[1][0] == '-') if (strcmp(argv[1], "-ht") == 0) { /* Use half-tilt IRS */ half_tilt = 1; /* Update argc/argv to next valid option/argument */ argv++; argc--; } else if (strcmp(argv[1], "-mod") == 0) { /* Use modified IRS, when applicable */ modified_irs = 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 if (strcmp(argv[1], "-lseg") == 0) { /* Set new segment length */ lseg = atoi(argv[2]); /* Move argv over the option to the next argument */ argv+=2; argc-=2; } else if (strcmp(argv[1], "-?") == 0 || strcmp(argv[1], "-help") == 0) { /* Print help */ display_usage(); } else { fprintf(stderr, "ERROR! Invalid option \"%s\" in command line\n\n", argv[1]); display_usage(); } }/* * ......... GETTING PARAMETERS ......... */#ifdef VMS sprintf(mrs, "mrs=%d", 2 * 256);/* mrs definition for VMS */#endif GET_PAR_S(1, "_BIN-File to be filtered: ................ ", inpfil); if ((inpfilptr = fopen(inpfil, RB)) == NULL) HARAKIRI("Error opening input file\n", 1); inp = fileno(inpfilptr); GET_PAR_S(2, "_BIN-Output File: ........................ ", outfil); if ((outfilptr = fopen(outfil, WB)) == NULL) HARAKIRI("Error opening output file\n", 1); out = fileno(outfilptr); GET_PAR_L(3, "_IRS Filter (0, 8, 16, 48): ........ ", irs); if ((irs != 0) && (irs != 8) && (irs != 16) && (irs != 48)) HARAKIRI("wrong IRS filter\n", 1); GET_PAR_L(4, "_Delta-SM filtering (0:skip, 1:apply): ... ", delta_sm); GET_PAR_L(5, "_First Up-Sampling (0, 2, -2, 3): ..... ", up_1); if ((up_1 != 0) && (up_1 != 2) && (up_1 != -2) && (up_1 != 3)) HARAKIRI("wrong upsampling factor\n", 1); GET_PAR_L(6, "_Second Up-Sampling (0, 2, -2, 3): .... ", up_2); if ((up_2 != 0) && (up_2 != 2) && (up_2 != -2) && (up_2 != 3)) HARAKIRI("wrong upsampling factor\n", 1); GET_PAR_L(7, "_First Down-Sampling (0, 2, -2, 3): .... ", down_1); if ((down_1 != 0) && (down_1 != 2) && (down_1 != -2) && (down_1 != 3)) HARAKIRI("wrong downsampling factor\n", 1); GET_PAR_L(8, "_Second Down-Sampling (0, 2, -2, 3): .... ", down_2); if ((down_2 != 0) && (down_2 != 2) && (down_2 != -2) && (down_2 != 3)) HARAKIRI("wrong downsampling factor\n", 1); FIND_PAR_L(9, "_Segment Length for Filtering: ........... ", lseg, lseg); if (lseg > LSEGMAX) { lseg = LSEGMAX; printf("\t\t\t\t(limited to %ld)\n", lseg); }/* * ... Allocate memory ... */ sh_buff = (short *)calloc(9l * lseg, sizeof(short)); fl_buff = (float *)calloc(lseg, sizeof(float)); irs_buff = (float *)calloc(lseg, sizeof(float)); up1_buff = (float *)calloc(3l * lseg, sizeof(float)); up2_buff = (float *)calloc(9l * lseg, sizeof(float)); down1_buff = (float *)calloc(9l * lseg, sizeof(float)); down2_buff = (float *)calloc(9l * lseg, sizeof(float)); if(!(sh_buff && fl_buff && irs_buff && up1_buff && up2_buff && down1_buff && down2_buff)) HARAKIRI("Error allocating memory for sample buffers\n",3); /* * ... Initialize selected FIR-structures for up-/downsampling ... * the types are as follows: * irs: 8 -> irs filter for 8 kHz sampled data * 16 -> (original|modified|half-tilt) irs for 16 kHz sampled data * 48 -> modified irs filter for 48 kHz sampled data * up_1: 2 -> up-sampling filter with factor 1:2 * -2 -> up-sampling filter with factor 1:2 for lin.-ph. band-pass * 3 -> up-sampling filter with factor 1:3 * up_2: 2 -> up-sampling filter with factor 1:2 * -2 -> up-sampling filter with factor 1:2 for lin.-ph. band-pass * 3 -> up-sampling filter with factor 1:3 * down_1: 2 -> down-sampling filter with factor 1:2 * -2 -> down-sampling filter with factor 1:2 for lin.-ph.bnd-pass * 3 -> down-sampling filter with factor 1:3 * down_2: 2 -> down-sampling filter with factor 1:2 * -2 -> down-sampling filter with factor 1:2 for lin.-ph.bnd-pass * 3 -> down-sampling filter with factor 1:3 */ /* Option for IRS-Filter selected? */ if (irs == 8) { /* get pointer to a struct which contains filter coefficients and cleared * state variables for a 8 kHz IRS */ if ((irs_ptr = irs_8khz_init()) == 0) HARAKIRI("irs_8khz initialization failure!\n", 1); /* Inhibit delta-sm: not available for 8kHz */ delta_sm=0; } else if (irs == 16) { /* get pointer to a struct which contains filter coefficients and cleared * state variables for a modified, half-tilt or original 16 kHz IRS */ if (modified_irs) irs_ptr = mod_irs_16khz_init(); else if (half_tilt) irs_ptr = ht_irs_16khz_init(); else irs_ptr = irs_16khz_init(); if (irs_ptr == 0) HARAKIRI("irs16_khz initialization failure!\n", 1); } else if (irs == 48) { /* get pointer to a struct which contains filter coefficients and cleared * state variables for a modified 16 kHz IRS */ if ((irs_ptr = mod_irs_48khz_init()) == 0) HARAKIRI("mod_irs48_khz initialization failure!\n", 1); /* Inhibit delta-sm: not available for 48kHz */ delta_sm=0; } else { irs_ptr = NULL; } /* Check whether to use the Delta-SM filtering */ if (delta_sm) { if (( delta_sm_ptr = delta_sm_16khz_init()) == 0) HARAKIRI("delta_sm initialization failure!\n", 1); } else delta_sm_ptr = NULL; /* First Upsampling Procedure */ if (up_1 == 2) { /* get pointer to a struct which contains filter coefficients and cleared * state variables for a upsampling factor of 2 */ if ((up1_ptr = hq_up_1_to_2_init()) == 0) HARAKIRI("hq_up_1_to_2 initialization failure!\n", 1); } else if (up_1 == -2) { /* get pointer to a struct which contains bpf coefficients and cleared * state variables for a upsampling factor of 2 */ if ((up1_ptr = linear_phase_pb_1_to_2_init()) == 0) HARAKIRI("linear-phase band-pass 1:2 initialization failure!\n", 1); } else if (up_1 == 3) { /* get pointer to a struct which contains filter coefficients and cleared * state variables for a upsampling factor of 3 */ if ((up1_ptr = hq_up_1_to_3_init()) == 0) HARAKIRI("hq_up_1_to_3 initialization failure!\n", 1); } else up1_ptr = NULL; /* Second Upsampling Procedure */ if (up_2 == 2) { /* get pointer to a struct which contains filter coefficients and cleared * state variables for a upsampling factor of 2 */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -