tomwalters@0: /* tomwalters@0: edframe.c Edit (ie. partition) AIM output files. tomwalters@0: ---------- tomwalters@0: tomwalters@0: The input file must have a model header. tomwalters@0: tomwalters@0: Usage: edframe [[-]frame=a[-b]] [[-]time=a[-b]] [[-]freq=a[-b]] [file] tomwalters@0: tomwalters@0: Special arguments: tomwalters@0: tomwalters@0: -help Print help on stderr. tomwalters@0: -info Print frame size information on the stdout. tomwalters@0: info=fbank Print channel centre-frequency information for the selected tomwalters@0: range of frequencies on the stdout. (This information is based tomwalters@0: on the filterbank parameters given in the input header). tomwalters@0: tomwalters@0: Each input frame is a matrix with (0,0) in the bottom left. tomwalters@0: The partition, output for each frame, is a sub-matrix indexed by rows a-to-b tomwalters@0: and columns a-to-b inclusive. tomwalters@0: The partition is specified using args: freq=a-b (rows) and time=a-b (cols). tomwalters@0: A single row or col is specified using a single number: freq=a or time=a. tomwalters@0: Rows (channels) are numbered 0,1,...,frameheight-1 -(lowest freq first). tomwalters@0: Cols (samples) are numbered 0,1,...,framewidth-1. tomwalters@0: The strings "min" and "max" can be used as selectors, meaning eg: tomwalters@0: freq=a-max rows a to frameheight-1 tomwalters@0: freq=min-b rows 0 to b tomwalters@0: time=a-max cols a to framewidth-1 tomwalters@0: time=min-b cols 0 to b tomwalters@0: The default selector specifies the whole matrix: tomwalters@0: freq=min-max time=min-max tomwalters@0: tomwalters@0: Expressing time as cols (along the horizontal axis) and frequency as rows tomwalters@0: (up the vertical axis) applies to most gen programs with the exception of tomwalters@0: genwav (where the vertical axis contains just one wave), and the excitation tomwalters@0: patterns genasa, genepn, and gensep (where frequency is measured as cols tomwalters@0: along the horizontal axis). The horizontal dimension is controlled by the tomwalters@0: "freq" parameter for excitation patterns. tomwalters@0: tomwalters@0: The units of the freq selector are Hz or kHz, specifying a range of channels tomwalters@0: in terms of frequency, or if no units are appended, then the selector is tomwalters@0: interpreted as a channel number in the range 0 to frameheight-1. tomwalters@0: When the freq selector is given with frequency units, then the "closest" tomwalters@0: corresponding channel number is used. (This depends upon the parameters tomwalters@0: mincf_afb, maxcf_afb, and dencf_afb as given in the header). tomwalters@0: tomwalters@0: The units of the time selector are s or ms, specifying a range of samples tomwalters@0: in terms of time, (seconds and milliseconds respectively), or if no units tomwalters@0: are appended, then the selector is interpreted as a sample number in the tomwalters@0: range 0 to framewidth-1. tomwalters@0: tomwalters@0: tomwalters@0: When the input consists of a cartoon of multiple frames (eg gensai output) tomwalters@0: then individual frames or subsequences of frames may be selected from the tomwalters@0: input using [[-]frame=a[-b]]. tomwalters@0: Input frames are numbered 0,1,2,...,frames-1 tomwalters@0: frame=a Select just the a'th frame. tomwalters@0: frame=a-b Select frames from the a'th to b'th inclusive. tomwalters@0: The strings "min" and "max" can be used as selectors, meaning eg: tomwalters@0: frame=min Select the first frame. tomwalters@0: frame=max Select the last frame. tomwalters@0: frame=a-max Select frames from the a'th to the last inclusive. tomwalters@0: frame=min-b Select frames from the first to the b'th inclusive. tomwalters@0: The default selector is for all frames, (ie frame=min-max). tomwalters@0: tomwalters@0: The units of the frame selector are s or ms, each specifying a frame which tomwalters@0: is "closest" to the given time, being the frame number which is the greatest tomwalters@0: integer multiple of the framestep (frstep_aid) which does not exceed the tomwalters@0: given time, measured from the start of the input file. tomwalters@0: If no units are appended, then the selector is interpreted as a frame number. tomwalters@0: tomwalters@0: The output frames are preceded by a model header, so that the partition for tomwalters@0: each frame can be plotted using the option "useprevious=on". tomwalters@0: tomwalters@0: The "Header" option controls the output of the modified header. When it is tomwalters@0: set Header=off then a header is not output. tomwalters@0: tomwalters@0: The "Transpose" option is a matrix transpose (swap rows and columns) of the tomwalters@0: output partition of each input frame. tomwalters@0: When a frame partition has a height greater than it's width (ie. cols < rows) tomwalters@0: then setting Transpose=on may provide a preferable display orientation. tomwalters@0: For example, this enables a very narrow (eg. single column) time-slice to be tomwalters@0: plotted horizontally, so that a time-slice of filterbank output may be tomwalters@0: plotted as a spectrum on a horizontal frequency axis. tomwalters@0: tomwalters@0: tomwalters@0: Examples: tomwalters@0: --------- tomwalters@0: tomwalters@0: Edited output may be displayed using the "useprevious" option, for example: tomwalters@0: tomwalters@0: genXXX ... output=stdout file1 | edframe ... > file2.XXX tomwalters@0: genXXX useprevious=on file2 tomwalters@0: tomwalters@0: Note that that file2.XXX must have a different base-name to the genXXX input tomwalters@0: (file1) because genXXX will remove any file1.XXX as a side-effect. tomwalters@0: tomwalters@0: tomwalters@0: Information on the output is printed on the stdout. For example: tomwalters@0: Print size information for gensai output for all frames. tomwalters@0: tomwalters@0: gensai output=stdout ... | edframe -info tomwalters@0: tomwalters@0: Print channel centre-frequency information for genbmm output for the 1kHz tomwalters@0: channel, and then for channel numbers 37 to 50. tomwalters@0: (To print the exact centre-frequency occupied by a given channel). tomwalters@0: tomwalters@0: genbmm output=stdout ... | edframe info=fbank freq=1kHz tomwalters@0: genbmm output=stdout ... | edframe info=fbank freq=37-50 tomwalters@0: tomwalters@0: tomwalters@0: Selecting particular frames from AIM output. tomwalters@0: ------------------------------------------- tomwalters@0: tomwalters@0: 1. Plot gennap output and its transpose. tomwalters@0: tomwalters@0: gennap output=stdout ... | edframe > file1.sai tomwalters@0: gennap output=stdout ... | edframe Tran=on > file2.sai tomwalters@0: gensai useprevious=on file1 tomwalters@0: gensai useprevious=on file2 tomwalters@0: tomwalters@0: 2. Select and plot frame 2 (ie. the 3rd frame) of gensai output. tomwalters@0: tomwalters@0: gensai output=stdout ... | edframe frame=2 > file.sai tomwalters@0: gensai useprevious=on file tomwalters@0: tomwalters@0: 3. Select the frames of gensai output which start between 16ms and 47ms from tomwalters@0: the start of it's input. (When the option frstep_aid=16ms then this would tomwalters@0: select the 2nd and 3rd frames). tomwalters@0: tomwalters@0: gensai output=stdout ... | edframe frame=16ms-47ms > file.sai tomwalters@0: tomwalters@0: 4. Select the 5th to the last frame inclusively of gensai output. tomwalters@0: tomwalters@0: gensai output=stdout ... | edframe frame=4-max > file.sai tomwalters@0: tomwalters@0: 5. Select the first frame of genepn output and plot the spectrum. tomwalters@0: tomwalters@0: genepn output=stdout ... | edframe frame=min > file1.epn tomwalters@0: genepn useprevious=on file1 tomwalters@0: tomwalters@0: tomwalters@0: Editing frames to select particular frequency ranges or channels (ie rows). tomwalters@0: -------------------------------------------------------------------------- tomwalters@0: tomwalters@0: 6. Select and plot the channel with centre-frequency closest to 1kHz from tomwalters@0: gennap output. tomwalters@0: tomwalters@0: gennap output=stdout ... | edframe freq=1kHz > file.nap tomwalters@0: gennap useprevious=on file tomwalters@0: tomwalters@0: 7. Select and plot channel 40 then the channel with the lowest and then tomwalters@0: the highest centre-frequency over all frames of gensai output. tomwalters@0: tomwalters@0: gensai output=stdout ... | edframe freq=40 > file.sai tomwalters@0: gensai useprevious=on file tomwalters@0: tomwalters@0: gensai output=stdout ... | edframe freq=min > file.sai tomwalters@0: gensai useprevious=on file tomwalters@0: tomwalters@0: gensai output=stdout ... | edframe freq=max > file.sai tomwalters@0: gensai useprevious=on file tomwalters@0: tomwalters@0: 8. Select and plot all channels of genbmm output from channel 10 to tomwalters@0: the channel with centre-frequency closest to 1kHz inclusively. tomwalters@0: tomwalters@0: genbmm output=stdout ... | edframe freq=10-1000Hz > file.bmm tomwalters@0: genbmm useprevious=on file tomwalters@0: tomwalters@0: 9. Select and plot a portion of the spectrum from the first frame of genepn tomwalters@0: output between 1kHz and 2kHz. tomwalters@0: Note: frequency controls the horizontal (ie cols) dimension for genepn. tomwalters@0: tomwalters@0: genepn output=stdout ... | edframe frame=min freq=1kHz-2kHz > file.epn tomwalters@0: genepn useprevious=on file tomwalters@0: tomwalters@0: tomwalters@0: Editing frames to select particular time slices (ie cols). tomwalters@0: --------------------------------------------------------- tomwalters@0: tomwalters@0: 10. Plot column (ie sample) 100 of the 3rd frame of gensai output as a row. tomwalters@0: tomwalters@0: gensai output=stdout ... | edframe frame=2 time=100 Tran=on > file.sai tomwalters@0: gensai useprevious=on file tomwalters@0: tomwalters@0: 11. Plot column of sample at 20ms from start of gennap output as a row tomwalters@0: tomwalters@0: gennap output=stdout ... | edframe time=20ms Tran=on > file.nap tomwalters@0: gennap useprevious=on file tomwalters@0: tomwalters@0: 12. Edit a wave to select the stretch between 4ms and 16ms, strip the tomwalters@0: header and plot the resulting wave. tomwalters@0: tomwalters@0: genwav output=stdout ... | edframe time=4ms-16ms Header=off > file tomwalters@0: genwav file tomwalters@0: tomwalters@0: tomwalters@0: Editing frames to select partitions. tomwalters@0: ----------------------------------- tomwalters@0: tomwalters@0: 13. Plot a partition of channels 40 to 44 over the last 5ms (ie near the tomwalters@0: trigger point on the right of the image) of all frames of gensai output. tomwalters@0: Then plot a partition of frequency range 1kHz to 1.5kHz over the first tomwalters@0: 20ms (on the left of the image) of all frames of gensai output. tomwalters@0: tomwalters@0: gensai pwidth=35ms nwidth=0 output=stdout ... | edframe time=30ms-max > file.sai tomwalters@0: gensai useprevious=on file tomwalters@0: gensai output=stdout ... | edframe freq=1kHz-1.5kHz time=min-20ms > file.sai tomwalters@0: gensai useprevious=on file tomwalters@0: tomwalters@0: 14. Plot the highest-frequency channel over the last 20ms of gennap output. tomwalters@0: tomwalters@0: gennap output=stdout ... | edframe freq=max time=20ms-max > file.sai tomwalters@0: gennap useprevious=on file tomwalters@0: tomwalters@0: tomwalters@0: */ tomwalters@0: tomwalters@0: tomwalters@0: #include tomwalters@0: #include tomwalters@0: #include "header.h" tomwalters@0: #include "options.h" tomwalters@0: #include "units.h" tomwalters@0: #include "strmatch.h" tomwalters@0: #include "freqs.c" tomwalters@0: tomwalters@0: char application[] = "Edit AIM output frames. " ; tomwalters@0: tomwalters@0: static char *helpstr, *debugstr, *fstr, *tstr, *cfstr, *infostr, *transtr, *headstr ; tomwalters@0: tomwalters@0: static Options option[] = { tomwalters@0: { "help" , "off" , &helpstr , "help" , DEBUG }, tomwalters@0: { "debug" , "off" , &debugstr , "debugging switch" , DEBUG }, tomwalters@0: { "frame" , "min-max" , &fstr , "select frames inclusively" , VAL }, tomwalters@0: { "time" , "min-max" , &tstr , "time (or sample number) partition" , VAL }, tomwalters@0: { "freq" , "min-max" , &cfstr , "frequency (or channel number) partition" , VAL }, tomwalters@0: { "Transpose" , "off" , &transtr , "transpose each output partition" , SETFLAG }, tomwalters@0: { "Header" , "on" , &headstr , "output header" , SETFLAG }, tomwalters@0: { "info" , "off" , &infostr , "print size and channel centre-frequency information" , SETFLAG }, tomwalters@0: ( char * ) 0 } ; tomwalters@0: tomwalters@0: tomwalters@0: char *limitstr ; tomwalters@0: char *qualstr ; tomwalters@0: char *minstr ; tomwalters@0: char *maxstr ; tomwalters@0: char *denstr ; tomwalters@0: char *chansstr ; tomwalters@0: tomwalters@0: double *frequencies ; tomwalters@0: tomwalters@0: tomwalters@0: int frameheight, framewidth ; /* Parameters read from header */ tomwalters@0: int frames, framebytes ; tomwalters@0: int frstep ; tomwalters@0: int samplerate ; tomwalters@0: tomwalters@0: int applic ; tomwalters@0: int format ; tomwalters@0: int rows, cols, numframes ; tomwalters@0: int Newrows, Newcols, Newnumframes ; tomwalters@0: tomwalters@0: int Newframeheight, Newframewidth ; tomwalters@0: int Newframes, Newframebytes ; tomwalters@0: tomwalters@0: int Transpose ; tomwalters@0: tomwalters@0: tomwalters@0: main(argc, argv) tomwalters@0: int argc ; tomwalters@0: char *argv[] ; tomwalters@0: { tomwalters@0: FILE *fopen(), *fp = (FILE *) 0 ; tomwalters@0: char *header, *Header(); tomwalters@0: char *val1, *val2, *headerstring() ; tomwalters@0: short *frame ; tomwalters@0: int i,j,k, a,b, xa,xb, ya,yb; tomwalters@0: char c, Info=0 ; tomwalters@0: tomwalters@0: fp = openopts( option,argc,argv ) ; tomwalters@0: if ( !isoff( helpstr ) ) tomwalters@0: helpopts( helpstr, argv[0], application, option ) ; tomwalters@0: tomwalters@0: Transpose = ison( transtr ) ; tomwalters@0: tomwalters@0: if ( (header = ReadHeader(fp)) == (char *) 0 ) { tomwalters@0: fprintf(stderr,"edframe: header not found\n"); tomwalters@0: exit(1); tomwalters@0: } tomwalters@0: frameheight = HeaderInt( header, "frameheight" ); tomwalters@0: framewidth = HeaderInt( header, "framewidth" ); tomwalters@0: frames = HeaderInt( header, "frames" ); tomwalters@0: samplerate = HeaderSamplerate( header ); tomwalters@0: tomwalters@0: if ( ( applic = Applic( header) ) < 0 ) { tomwalters@0: fprintf(stderr,"edframe: application name not found in header\n" ) ; tomwalters@0: exit( 1 ) ; tomwalters@0: } tomwalters@0: format = Format( applic ) ; tomwalters@0: frame_to_matrix( format, &rows, &cols, &numframes, frameheight, framewidth, frames ) ; tomwalters@0: framebytes = rows * cols * sizeof(short) ; tomwalters@0: tomwalters@0: if ( format > WAV ) { /* if not genwav */ tomwalters@0: limitstr = headerstring( header, "bwmin_afb" ); tomwalters@0: qualstr = headerstring( header, "quality_afb" ); tomwalters@0: minstr = headerstring( header, "mincf_afb" ); tomwalters@0: maxstr = headerstring( header, "maxcf_afb" ); tomwalters@0: denstr = headerstring( header, "dencf_afb" ); tomwalters@0: chansstr = headerstring( header, "channels_afb" ); tomwalters@0: tomwalters@0: SetErbParameters( to_Hz( limitstr, samplerate ), atof( qualstr ) ) ; tomwalters@0: if( OptionInt( chansstr ) == 0 ) tomwalters@0: frequencies = GenerateCenterFrequencies( to_Hz( minstr, samplerate ), to_Hz( maxstr, samplerate ), atof( denstr ) ) ; tomwalters@0: else tomwalters@0: frequencies = NumberedCenterFrequencies( to_Hz( minstr, samplerate ), to_Hz( maxstr, samplerate ), OptionInt( chansstr ) ) ; tomwalters@0: } tomwalters@0: else frequencies = (double *)0 ; tomwalters@0: tomwalters@0: tomwalters@0: if ( format == SAI ) /* if gensai or genspl */ tomwalters@0: frstep = to_p( headerstring( header, "frstep_aid" ), samplerate ) ; tomwalters@0: else tomwalters@0: frstep = 1 ; tomwalters@0: tomwalters@0: tomwalters@0: /* Get limits on specified number of frames */ tomwalters@0: tomwalters@0: if ( getvals( fstr, &val1, &val2, "-" ) == BADVAL ) { tomwalters@0: fprintf(stderr,"edframe: bad frame selector [%s]\n", fstr ) ; tomwalters@0: exit( 1 ) ; tomwalters@0: } tomwalters@0: if ( ismin( val1 ) ) a = 0 ; tomwalters@0: else if ( ismax( val1 ) ) a = numframes - 1 ; tomwalters@0: else if ( Units( val1 ) ) a = (int)to_p( val1, samplerate ) / frstep ; tomwalters@0: else a = atoi( val1 ) ; tomwalters@0: tomwalters@0: if ( isempty( val2 ) ) b = a ; tomwalters@0: else if ( ismin( val2 ) ) b = 0 ; tomwalters@0: else if ( ismax( val2 ) ) b = numframes - 1 ; tomwalters@0: else if ( Units( val2 ) ) b = (int)to_p( val2, samplerate ) / frstep ; tomwalters@0: else b = atoi( val2 ) ; tomwalters@0: tomwalters@0: if ( ison( debugstr ) ) { tomwalters@0: printf("samplerate=%d val1=[%s] val2=[%s] a=%d b=%d numframes=%d\n", samplerate, val1,val2,a,b,numframes); tomwalters@0: } tomwalters@0: tomwalters@0: if ( a<0 || a>b || b>numframes ) { tomwalters@0: if ( b>numframes ) fprintf(stderr,"edframe: bad frame selector [just %d frames available]\n", numframes ); tomwalters@0: else fprintf(stderr,"edframe: bad frame selector \n" ); tomwalters@0: exit(1); tomwalters@0: } tomwalters@0: tomwalters@0: tomwalters@0: if ( format == EPN ) /* kludge for excitation patterns with horizontal freq axis */ tomwalters@0: swap( &rows, &cols ) ; tomwalters@0: tomwalters@0: tomwalters@0: /* Get limits on specified time (ie samples or cols) */ tomwalters@0: tomwalters@0: if ( getvals( tstr, &val1, &val2, "-" ) == BADVAL ) { tomwalters@0: fprintf(stderr,"edframe: bad time selector [%s]\n", tstr ) ; tomwalters@0: exit( 1 ) ; tomwalters@0: } tomwalters@0: if ( ismin( val1 ) ) xa = 0 ; tomwalters@0: else if ( ismax( val1 ) ) xa = cols-1 ; tomwalters@0: else if ( Units( val1 ) ) xa = to_p( val1, samplerate ) ; tomwalters@0: else xa = atoi( val1 ) ; tomwalters@0: tomwalters@0: if ( isempty( val2 ) ) xb = xa ; tomwalters@0: else if ( ismin( val2 ) ) xb = 0 ; tomwalters@0: else if ( ismax( val2 ) ) xb = cols-1 ; tomwalters@0: else if ( Units( val2 ) ) xb = to_p( val2, samplerate ) ; tomwalters@0: else xb = atoi( val2 ) ; tomwalters@0: tomwalters@0: /* Get limits on specified freqency (ie channels or rows) */ tomwalters@0: tomwalters@0: if ( getvals( cfstr, &val1, &val2, "-" ) == BADVAL ) { tomwalters@0: fprintf(stderr,"edframe: bad frequency selector [%s]\n", cfstr ) ; tomwalters@0: exit( 1 ) ; tomwalters@0: } tomwalters@0: if ( ismin( val1 ) ) ya = 0 ; tomwalters@0: else if ( ismax( val1 ) ) ya = rows-1 ; tomwalters@0: else if ( Units( val1 ) ) ya = closest( to_Hz( val1, samplerate ), frequencies, rows ) ; tomwalters@0: else ya = atoi( val1 ) ; tomwalters@0: tomwalters@0: if ( isempty( val2 ) ) yb = ya ; tomwalters@0: else if ( ismin( val2 ) ) yb = 0 ; tomwalters@0: else if ( ismax( val2 ) ) yb = rows-1 ; tomwalters@0: else if ( Units( val2 ) ) yb = closest( to_Hz( val2, samplerate ), frequencies, rows ) ; tomwalters@0: else yb = atoi( val2 ) ; tomwalters@0: tomwalters@0: tomwalters@0: if ( format == EPN ) { /* excitation patterns have horizontal freq axis */ tomwalters@0: swap( &xa, &ya ) ; tomwalters@0: swap( &xb, &yb ) ; tomwalters@0: swap( &rows, &cols ) ; tomwalters@0: } tomwalters@0: tomwalters@0: if ( ya<0 || yb>=rows || ya>yb || xa<0 || xb>=cols || xa>xb ) { tomwalters@0: fprintf(stderr,"edframe: bad specifiers [xa=%d xb=%d ya=%d yb=%d]\n", xa,xb,ya,yb ) ; tomwalters@0: fprintf(stderr," input frames have %d rows and %d columns \n", rows, cols ) ; tomwalters@0: exit(1); tomwalters@0: } tomwalters@0: tomwalters@0: Newrows = yb - ya + 1 ; tomwalters@0: Newcols = xb - xa + 1 ; tomwalters@0: Newnumframes = b - a + 1 ; tomwalters@0: tomwalters@0: if ( Transpose ) swap( &Newrows, &Newcols ) ; tomwalters@0: tomwalters@0: matrix_to_frame( format, Newrows, Newcols, Newnumframes, &Newframeheight, &Newframewidth, &Newframes ) ; tomwalters@0: Newframebytes = Newframewidth * Newframeheight * sizeof(short) ; tomwalters@0: tomwalters@0: if ( !isoff( infostr ) ) { tomwalters@0: if ( ison( infostr ) ) printinfo() ; tomwalters@0: if ( isstr( infostr, "fbank" ) ) printfbank( xa, xb, ya, yb ) ; tomwalters@0: exit( 0 ) ; tomwalters@0: } tomwalters@0: if ( ison( debugstr ) ) { tomwalters@0: printf( "rows=%d cols=%d numframes=%d\n", rows,cols,numframes); tomwalters@0: printf( "a=%d b=%d ya=%d yb=%d xa=%d xb=%d\n", a,b,ya,yb,xa,xb ) ; tomwalters@0: printf( "Newrows=%d Newcols=%d Newnumframes=%d\n", Newrows,Newcols,Newnumframes); tomwalters@0: printf( "Newframeheight=%d Newframewidth=%d Newframes=%d\n", Newframeheight, Newframewidth, Newframes ) ; tomwalters@0: printf( "framebytes=%d Newframebytes=%d\n", framebytes, Newframebytes ) ; tomwalters@0: exit( 1 ) ; tomwalters@0: } tomwalters@0: tomwalters@0: if ( ison( headstr ) ) tomwalters@0: WriteHeader( Header(header, ya,yb), stdout ); tomwalters@0: tomwalters@0: tomwalters@0: /* Allocate space for framebytes of data */ tomwalters@0: tomwalters@0: if ( (frame = (short *)malloc( framebytes )) == NULL ) { tomwalters@0: fprintf(stderr,"edframe: malloc out of space\n"); tomwalters@0: exit(1); tomwalters@0: } tomwalters@0: tomwalters@0: /* seeks past `a' frames */ tomwalters@0: tomwalters@0: for ( i = 0 ; i < a && fread( frame,framebytes,1,fp ) ; i++ ) tomwalters@0: ; tomwalters@0: tomwalters@0: /* edit frames `a' to `b' */ tomwalters@0: tomwalters@0: if ( Transpose ) { tomwalters@0: tomwalters@0: for ( ; i <= b && fread( frame,framebytes,1,fp ) ; i++ ) { tomwalters@0: tomwalters@0: if ( format == SAI || format == EPN ) tomwalters@0: for ( j=xa ; j<=xb ; j++ ) tomwalters@0: for ( k=ya ; k<=yb ; k++ ) tomwalters@0: fwrite( frame + k*framewidth + j, sizeof(short), 1, stdout ) ; tomwalters@0: else tomwalters@0: for ( j=ya ; j<=yb ; j++ ) tomwalters@0: for ( k=xa ; k<=xb ; k++ ) tomwalters@0: fwrite( frame + k*frameheight + j, sizeof(short), 1, stdout ) ; tomwalters@0: } tomwalters@0: } tomwalters@0: else { /* direct (un-transposed) output */ tomwalters@0: tomwalters@0: for ( ; i <= b && fread( frame,framebytes,1,fp ) ; i++ ) { tomwalters@0: tomwalters@0: if ( format == SAI || format == EPN ) tomwalters@0: for ( j=ya ; j<=yb ; j++ ) tomwalters@0: fwrite( frame + j*framewidth + xa, sizeof(short), Newcols, stdout ) ; tomwalters@0: else tomwalters@0: for ( j=xa ; j<=xb ; j++ ) tomwalters@0: fwrite( frame + j*frameheight + ya, sizeof(short), Newrows, stdout ) ; tomwalters@0: } tomwalters@0: } tomwalters@0: tomwalters@0: fclose(fp); tomwalters@0: tomwalters@0: } tomwalters@0: tomwalters@0: tomwalters@0: /* tomwalters@0: Return an allocated string to the value part of an option in the header tomwalters@0: with the given name. Exit if option not found in header. tomwalters@0: */ tomwalters@0: tomwalters@0: char *headerstring( header, name ) tomwalters@0: char *header, *name ; tomwalters@0: { tomwalters@0: char *valuestr ; tomwalters@0: tomwalters@0: if ( (valuestr = HeaderStringOnly( header, name )) == (char *) 0) { tomwalters@0: fprintf(stderr,"edframe: option %s not found in header\n", name); tomwalters@0: exit( 1 ) ; tomwalters@0: } tomwalters@0: return ( valuestr ) ; tomwalters@0: } tomwalters@0: tomwalters@0: tomwalters@0: int OptionInt( str ) tomwalters@0: char *str ; tomwalters@0: { tomwalters@0: if( strcmp( str, "on" ) == 0 ) tomwalters@0: return( 1 ) ; tomwalters@0: else if( strcmp( str, "Not_used" ) == 0 ) tomwalters@0: return( 0 ) ; tomwalters@0: else tomwalters@0: return( atoi( str ) ) ; tomwalters@0: } tomwalters@0: tomwalters@0: tomwalters@0: /* tomwalters@0: Copy the original nap header to a new sai header, changing in order: tomwalters@0: maxcf_afb tomwalters@0: mincf_afb tomwalters@0: channels_afb tomwalters@0: frames tomwalters@0: framewidth tomwalters@0: frameheight tomwalters@0: framebytes tomwalters@0: view tomwalters@0: Finally, update the new header_bytes, and return the new header. tomwalters@0: */ tomwalters@0: tomwalters@0: char *Header( oldheader, ya,yb ) tomwalters@0: char *oldheader ; tomwalters@0: int ya,yb ; tomwalters@0: { tomwalters@0: char *saiheader; tomwalters@0: char *p0, *p1, *p2, *s, str[64]; tomwalters@0: tomwalters@0: saiheader = (char *)malloc( strlen(oldheader) + 64 ) ; tomwalters@0: tomwalters@0: p0 = saiheader ; tomwalters@0: p1 = oldheader ; tomwalters@0: tomwalters@0: tomwalters@0: if ( format > WAV ) { /* if not genwav */ tomwalters@0: tomwalters@0: /** copy up to maxcf_afb **/ tomwalters@0: tomwalters@0: p2 = HeaderString( oldheader , "maxcf_afb" ) ; tomwalters@0: while( p1 < p2 ) tomwalters@0: *p0++ = *p1++ ; tomwalters@0: tomwalters@0: sprintf(str,"%.2fHz\n", frequencies[yb]); tomwalters@0: for (s = str ; *s != '\n' ; ) tomwalters@0: *p0++ = *s++; tomwalters@0: *p0++ = *s; tomwalters@0: while (*p1 != '\n') tomwalters@0: *p1++; tomwalters@0: *p1++; tomwalters@0: tomwalters@0: tomwalters@0: /** copy up to mincf_afb **/ tomwalters@0: tomwalters@0: p2 = HeaderString( oldheader , "mincf_afb" ) ; tomwalters@0: while( p1 < p2 ) tomwalters@0: *p0++ = *p1++ ; tomwalters@0: tomwalters@0: sprintf(str,"%.2fHz\n", frequencies[ya]); tomwalters@0: for (s = str ; *s != '\n' ; ) tomwalters@0: *p0++ = *s++; tomwalters@0: *p0++ = *s; tomwalters@0: while (*p1 != '\n') tomwalters@0: *p1++; tomwalters@0: *p1++; tomwalters@0: tomwalters@0: tomwalters@0: /** copy up to channels_afb **/ tomwalters@0: tomwalters@0: p2 = HeaderString( oldheader , "channels_afb" ) ; tomwalters@0: while( p1 < p2 ) tomwalters@0: *p0++ = *p1++ ; tomwalters@0: tomwalters@0: sprintf(str,"%d\n", Newframeheight); tomwalters@0: for (s = str ; *s != '\n' ; ) tomwalters@0: *p0++ = *s++; tomwalters@0: *p0++ = *s; tomwalters@0: while (*p1 != '\n') tomwalters@0: *p1++; tomwalters@0: *p1++; tomwalters@0: tomwalters@0: } tomwalters@0: tomwalters@0: /** copy up to frames **/ tomwalters@0: tomwalters@0: p2 = HeaderString( oldheader , "frames" ) ; tomwalters@0: while( p1 < p2 ) tomwalters@0: *p0++ = *p1++ ; tomwalters@0: tomwalters@0: sprintf(str,"%d\n", Newframes); tomwalters@0: for (s = str ; *s != '\n' ; ) tomwalters@0: *p0++ = *s++; tomwalters@0: *p0++ = *s; tomwalters@0: while (*p1 != '\n') tomwalters@0: *p1++; tomwalters@0: *p1++; tomwalters@0: tomwalters@0: tomwalters@0: /** copy up to framewidth **/ tomwalters@0: tomwalters@0: p2 = HeaderString( oldheader , "framewidth" ) ; tomwalters@0: while ( p1 < p2 ) tomwalters@0: *p0++ = *p1++ ; tomwalters@0: tomwalters@0: sprintf(str,"%d\n", Newframewidth); tomwalters@0: for (s = str ; *s != '\n' ; ) tomwalters@0: *p0++ = *s++; tomwalters@0: *p0++ = *s; tomwalters@0: while (*p1 != '\n') tomwalters@0: *p1++; tomwalters@0: *p1++; tomwalters@0: tomwalters@0: tomwalters@0: /** copy up to frameheight **/ tomwalters@0: tomwalters@0: p2 = HeaderString( oldheader , "frameheight" ) ; tomwalters@0: while ( p1 < p2 ) tomwalters@0: *p0++ = *p1++ ; tomwalters@0: tomwalters@0: sprintf(str,"%d\n", Newframeheight); tomwalters@0: for (s = str ; *s != '\n' ; ) tomwalters@0: *p0++ = *s++; tomwalters@0: *p0++ = *s; tomwalters@0: while (*p1 != '\n') tomwalters@0: *p1++; tomwalters@0: *p1++; tomwalters@0: tomwalters@0: tomwalters@0: /** copy up to framebytes **/ tomwalters@0: tomwalters@0: p2 = HeaderString( oldheader , "framebytes" ) ; tomwalters@0: while ( p1 < p2 ) tomwalters@0: *p0++ = *p1++ ; tomwalters@0: tomwalters@0: sprintf(str,"%d\n", Newframebytes); tomwalters@0: for (s = str ; *s != '\n' ; ) tomwalters@0: *p0++ = *s++; tomwalters@0: *p0++ = *s; tomwalters@0: while (*p1 != '\n') tomwalters@0: *p1++; tomwalters@0: *p1++; tomwalters@0: tomwalters@0: tomwalters@0: /** copy rest of header **/ tomwalters@0: tomwalters@0: p2 = HeaderString( oldheader , "Version" ) ; tomwalters@0: while ( p1 < p2 ) tomwalters@0: *p0++ = *p1++ ; tomwalters@0: tomwalters@0: while (*p1 != '\n') tomwalters@0: *p0++ = *p1++ ; tomwalters@0: *p0++ = *p1++ ; tomwalters@0: tomwalters@0: tomwalters@0: /** update header_bytes **/ tomwalters@0: tomwalters@0: sprintf(str, "%0*d", 7, p0-saiheader); tomwalters@0: p0 = HeaderString( saiheader , "header_bytes" ) ; tomwalters@0: s = str; tomwalters@0: while(*p0 != '\n') tomwalters@0: *p0++ = *s++ ; tomwalters@0: tomwalters@0: tomwalters@0: return saiheader; tomwalters@0: } tomwalters@0: tomwalters@0: tomwalters@0: tomwalters@0: tomwalters@0: /* Return the index of the frequency closest to the given "freq" */ tomwalters@0: tomwalters@0: int closest( freq, frequencies, channels ) tomwalters@0: double freq, *frequencies ; tomwalters@0: int channels ; tomwalters@0: { tomwalters@0: int i; tomwalters@0: tomwalters@0: if ( frequencies == (double *)0 ) return 0 ; tomwalters@0: tomwalters@0: for (i=0 ; i WAV ) { /* no filterbank for genwav */ tomwalters@0: if ( format == EPN ) /* freq axis is horiz for epn */ tomwalters@0: for (i=xa ; i<=xb ; i++) tomwalters@0: printf( "channel %2d. %7.2fHz, %4.2fms, %5.2f samples \n", i, frequencies[i], 1000./frequencies[i], (double)samplerate/frequencies[i] ); tomwalters@0: else tomwalters@0: for (i=ya ; i<=yb ; i++) tomwalters@0: printf( "channel %2d. %7.2fHz, %4.2fms, %5.2f samples \n", i, frequencies[i], 1000./frequencies[i], (double)samplerate/frequencies[i] ); tomwalters@0: } tomwalters@0: } tomwalters@0: tomwalters@0: tomwalters@0: /* Swap the values in integer addresses p1 and p2 */ tomwalters@0: tomwalters@0: swap( p1, p2 ) tomwalters@0: int *p1 , *p2 ; tomwalters@0: { tomwalters@0: int tmp ; tomwalters@0: tomwalters@0: tmp = *p1 ; tomwalters@0: *p1 = *p2 ; tomwalters@0: *p2 = tmp ; tomwalters@0: }