?? pcmdemo.c
字號:
/* 30.OCT.94 v1.1 ============================================================================ PCMDEMO.C ~~~~~~~~~ Description: ~~~~~~~~~~~~ Example program for testing the correct implementation of the standard PCM filtering and up/down-sampling module. The test procedure of 3 filtering in series run on the user- specified speech file. After each filtering, the input for the next stage is taken as the output of the previous filter. For each stage, it may be chosen 4 options: no filtering ("short cut"), G712 filtering with no rate change (factor 1:1), or with decimation (factor 2:1), or with interpolation (factor 1:2). Usage: ~~~~~~ $ PCMDEMO ! ---> HELP text is printed to screen or $ PCMDEMO [-options] ifile [ ofile typ1 typ2 typ3 [lseg]] ! (---> filtering is carried out) where: ifile: .. INPUT FILE with short data (binary files) ofile: .. OUTPUT FILE with short data (binary files) typn: ... type of filtering for filtering stage n, n = 1..3: 1_1: input is at 16 kHz, output at 16 kHz 1_2: input is at 8 kHz, output at 16 kHz 2_1: input is at 16 kHz, output at 8 kHz 0 : short cut (no filtering at all!). lseg: ... number of samples per processing block (default is LSEG0=256) Options: ~~~~~~~~ -skip no ... skips saving to file the first `no' processed samples -lseg l .... defines as `l' the number of samples per processing block Compilation: ~~~~~~~~~~~ The test program is implemented for segment-wise filtering. To test the dependency of the segment length, the user must enter a value for the segment length (from 1 ... LSEGMAX). VAX/VMS: $ CC PCMDEMO $ link PCMDEMO $ PCMDEMO :== $pcmdemo_Disk:[pcmdemo_Dir]PCMDEMO $ PCMDEMO ifile ofile 0 1_2 2_1 133 The data from file "ifile" are processed in the following way, being equivalent to the asynchronous filtering needed to simulating the return from digital to analogue domains, and the way back: 1) segments with 133 samples are read from file "ifile" 2) the first filtering just keep the input data as is; 3) the second stage will take the data of the previous stage as sampled at 8 kHz, filter by the std.PCM and upsample to 16 kHz; 4) the output of the second stage is taken as 16 kHz data, which is filtered by the std.PCM filter and down-sampled back to 8 kHz. 5) the output of the third stage is rounded and saved to file `ofile'. Turbo-C, Turbo-C++: > tcc pcmdemo > pcmdemo ifile ofile 1_1 1_1 2_1 1024 The data from file "ifile" are processed in the following way: 1) segments with 1024 samples are read from file "ifile" 2) PCM filtering for 1st stage keeping the rate at 16 kHz; 3) the same for the second; 4) the output of the second step is then filtered and down-sampled (decimated) to 8 kHz. 5) the output of the third filter is then saved to file using rounding. HighC (MetaWare, version R2.32): > hc386 -stack 16384 pcmdemo.c > Run386 pcmdemo ifile ofile 2_1 1_2 0 133 In our test some C-implementations have shown errors, which could be eliminated by increasing the stack size (at compile time). SunC (BSD Unix) # cc -o pcmdemo pcmdemo.c # pcmdemo Original author: ~~~~~~~~~~~~~~~~ Rudolf Hofmann Advanced Development Digital Signal Processing PHILIPS KOMMUNIKATIONS INDUSTRIE AG Kommunikationssysteme Thurn-und-Taxis-Strasse 14 D-8500 Nuernberg 10 (Germany) Phone : +49 911 526-2603 FAX : +49 911 526-3385 EMail : hf@pkinbg.uucp History: ~~~~~~~~ 16.Oct.91 v0.0 Release of beta version to UGST. <hf@pkinbg.uucp> 26.Feb.92 v1.0 (ILS-files removed). <hf@pkinbg.uucp> 18.May.92 v1.1 Use of sh2fl_16bit w/ file normalization. <tdsimao@cpqd.ansp.br> 30.Oct.94 v2.0 Change to encompass splitting of module into subunits ============================================================================*//* * ......... INCLUDES ......... */#include <stdio.h> /* UNIX Standard I/O Definitions */#include <stdlib.h> /* For allocation routine */#include "ugstdemo.h" /* private defines for user interface */#include "ugst-utl.h" /* conversion from float -> short */#include "iirflt.h" /* Standard PCM filtering functions *//* * ......... Definitions for this test program ......... */#define LSEG0 256 /* default segment length for segment-wise filtering */#define LSEGMAX 2048 /* max. number of samples to be proc. *//* ============================================================================ void display_usage (void); ~~~~~~~~~~~~~~~~~~ Description: ~~~~~~~~~~~~ Display usage of this demo program and exit; Return value: ~~~~~~~~~~~~~ Returns the number of longs read. Author: <hf@pkinbg.uucp> ~~~~~~~ History: ~~~~~~~~ 26.Feb.92 v1.0 Release of 1st version <hf@pkinbg.uucp> 30.Oct.94 v2.0 Revamped <simao@ctd.comsat.com> ============================================================================*/#define P(x) printf xvoid display_usage(){ P(("PCMDEMO.C - Version 2.0 of 30/Oct/1994 \n\n")); P((" Run 3 filter in cascade with the G.712 (standard PCM) mask.\n")); P(("For each filter one can select between: \n")); P((" - input signal with sf=16 kHz, output signal with 16 kHz\n")); P((" - input signal with sf= 8 kHz, output signal with 16 kHz\n")); P((" - input signal with sf=16 kHz, output signal with 8 kHz\n")); P((" - short cut \n\n")); P(("Usage:\n")); P(("~~~~~~\n")); P((" $ PCMDEMO ! ---> HELP text is printed to screen\n")); P((" or\n")); P((" $ PCMDEMO [-options] ifile [ ofile typ1 typ2 typ3 [lseg]]\n")); P((" where:\n")); P((" ifile: .. INPUT FILE with short data (binary files)\n")); P((" ofile: .. OUTPUT FILE with short data (binary files)\n")); P((" typn: ... type of filtering for filtering stage n, n = 1..3:\n")); P((" 1_1: input is at 16 kHz, output at 16 kHz\n")); P((" 1_2: input is at 8 kHz, output at 16 kHz\n")); P((" 2_1: input is at 16 kHz, output at 8 kHz\n")); P((" 0 : short cut (no filtering at all!).\n")); P((" lseg: ... number of samples per processing block ")); P(("(default is LSEG0=%d)\n", LSEG0)); P(("\n")); P(("Options:\n")); P(("~~~~~~~~\n")); P((" -skip no ... skips saving to file the first `no' processed samples\n")); P((" -lseg l .... set `l' as the number of samples per processing block\n")); /* Quit program */ exit(-128);}#undef P/* ...................... End of display_usage() ........................... *//* ......................... Begin of main() .............................. *//* ************************************************************************** ************************************************************************** *** *** *** 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_IIR for each filter ......... */ SCD_IIR *typ1_ptr; SCD_IIR *typ2_ptr; SCD_IIR *typ3_ptr; /* ......... signal arrays ......... */ short sh_buff[8 * LSEGMAX]; /* 16-bit buffer */ float fl_buff[LSEGMAX]; /* float buffer */#ifdef STATIC_ALLOCATION float buff1[2 * LSEGMAX]; /* output of 1. filter */ float buff2[4 * LSEGMAX]; /* output of 2. filter */ float buff3[8 * LSEGMAX]; /* output of 3. filter */#else float *buff1; /* output of 1. filter */ float *buff2; /* output of 2. filter */ float *buff3; /* output of 3. filter */#endif /* ......... File related variables ......... */ char inpfil[127], outfil[127]; FILE *inpfilptr, *outfilptr;#if defined(VMS) static char mrs[15] = "mrs=512";#endif /* ......... other auxiliary variables ......... */ clock_t t1, t2; /* aux. for CPU-time measurement */ char typ1[8], typ2[8], typ3[8]; long lseg=LSEG0, lsegx, lseg1, lseg2, lseg3; long noverflows1 = 0, noverflows2 = 0, noverflows3 = 0; long nsam = 0; long k; long skip=0; /* ......... PRINT INFOS ......... */ printf("%s%s", "*** V1.1 DEMO-Program: Standard G.712 Up/Down Sampling ", "Filter 30-Oct-1994 ***\n");/* * ......... PARAMETERS FOR PROCESSING ......... */ /* GETTING OPTIONS */ if (argc < 2) display_usage(); else { while (argc > 1 && argv[1][0] == '-') if (strcmp(argv[1], "-skip") == 0) { /* No reset */ skip = atoi(argv[2]); /* Update argc/argv to next valid option/argument */ argv+=2; argc-=2; } else if (strcmp(argv[1], "-len") == 0) { lseg = atoi(argv[2]); /* If max.seg.length is exceeded, display warning */ if (lseg > LSEGMAX) { lseg = LSEGMAX; fprintf(stderr, "Warning! lseg limited to max of %ld\n", lseg);
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -