tomwalters@0: /*************************************************************************** tomwalters@0: Utilities for model output headers. tomwalters@0: tomwalters@0: A header is an ASCII desciption which summarises the state of tomwalters@0: a process by giving a list of parameter values etc etc.. tomwalters@0: Each parameter is described on a separate line, and the header consists tomwalters@0: of several lines of the general form: tomwalters@0: tomwalters@0: = \n tomwalters@0: tomwalters@0: For example, the first five lines of the header generated by a command tomwalters@0: line "gensai -header fname" is as follows: tomwalters@0: tomwalters@0: header_bytes=0000532 tomwalters@0: scale_sai=0.25 tomwalters@0: imagedurn_sai=16 tomwalters@0: decayrate_sai=10 tomwalters@0: cgmdecay=24 tomwalters@0: ... tomwalters@0: date=Thu Jan 11 00:19:41 WET 1990\n tomwalters@0: \000 tomwalters@0: tomwalters@0: This string is written onto the front of the file with padding if tomwalters@0: desired before any data is written. The header can be of any length tomwalters@0: and contain any combination of non null characters. Header items are tomwalters@0: identified by the string on the left of the equals symbol and their tomwalters@0: value is represented by the string on the remainder of that line. tomwalters@0: tomwalters@0: The first line is always the HEADER_STRING (ie. header_bytes=....\n) tomwalters@0: which gives the length of the header. tomwalters@0: tomwalters@0: Synopsis of utilities: tomwalters@0: ---------------------- tomwalters@0: tomwalters@0: char *ReadHeader( fp ) tomwalters@0: FILE *fp ; tomwalters@0: tomwalters@0: WriteHeader(header,fp) tomwalters@0: char *header; tomwalters@0: FILE *fp; tomwalters@0: tomwalters@0: char *HeaderString( header, name ) tomwalters@0: char *header, *name ; tomwalters@0: tomwalters@0: char *HeaderStringOnly( header, name ) tomwalters@0: char *header, *name ; tomwalters@0: tomwalters@0: double HeaderDouble( header, name ) tomwalters@0: char *header, *name ; tomwalters@0: tomwalters@0: double HeaderInt( header, name ) tomwalters@0: char *header, *name ; tomwalters@0: tomwalters@0: void FreeHeader( header ) tomwalters@0: char *header ; tomwalters@0: tomwalters@0: ReadHeader() reads a header (if it exists ) from the file into tomwalters@0: memory and returns a pointer to the header in memory allocated for tomwalters@0: storing the header. It returns a null pointer if no header is found. tomwalters@0: It leaves the fp pointing to the data which follows the header. tomwalters@0: WriteHeader() writes the given header on the given file stream. tomwalters@0: HeaderString() simply searches through the header for values the user tomwalters@0: requests and returns a pointer to the beginning of the value. tomwalters@0: It returns a null pointer if the required string is not found. tomwalters@0: HeaderStringOnly() returns a pointer to an allocated string that tomwalters@0: contains only the value rather than a pointer to a string that tomwalters@0: includes the all the rest of the header (which is what HeaderString() tomwalters@0: returns). It returns a null pointer if the required string is not found. tomwalters@0: HeaderDouble() converts values to Doubles. tomwalters@0: HeaderInt() converts values to Ints. tomwalters@0: FreeHeader() frees the space allocated for a header by ReadHeader. tomwalters@0: tomwalters@0: Example: tomwalters@0: ------- tomwalters@0: A simple example of the use of the header utility routines to read the tomwalters@0: sai dimensions from a header would be: tomwalters@0: (This assumes a ".sai" file generated by a command like "gensai -header") tomwalters@0: tomwalters@0: #include tomwalters@0: #include tomwalters@0: #include "header.c" tomwalters@0: char *header = ReadHeader(fp); fp is file-pointer to ".sai" file tomwalters@0: int frameheight = HeaderInt(header,"frameheight"); num chans tomwalters@0: int framewidth = HeaderInt(header,"framewidth"); sai duration tomwalters@0: tomwalters@0: char *name = "frameheight"; tomwalters@0: printf( "%s=%s\n", name, HeaderStringOnly( header, name ) ) ; tomwalters@0: tomwalters@0: ****************************************************************************/ tomwalters@0: tomwalters@0: #include tomwalters@0: /* #include */ tomwalters@0: #include tomwalters@0: #include tomwalters@0: #include "header.h" tomwalters@0: #include "units.h" tomwalters@0: tomwalters@0: tomwalters@0: /*************************************************************************** tomwalters@0: ReadHeader() reads a header (if it exists ) from the file into tomwalters@0: memory and returns a pointer to the header in memory allocated for tomwalters@0: storing the header. It returns a null pointer if no header is found. tomwalters@0: ****************************************************************************/ tomwalters@0: char *ReadHeader( fp ) tomwalters@0: FILE *fp ; tomwalters@0: { tomwalters@0: static char header_string[] = HEADER_STRING ; tomwalters@0: static char header_start[] = HEADER_START ; tomwalters@0: unsigned header_length ; tomwalters@0: char *header ; tomwalters@0: tomwalters@0: if( fread( header_string, sizeof ( *header_string ), STRSIZE( header_string ), fp ) == STRSIZE( header_string ) tomwalters@0: && strncmp( header_string, header_start, STRSIZE( header_start ) ) == 0 ) { tomwalters@0: tomwalters@0: /* header located - remove carriage return */ tomwalters@0: tomwalters@0: header_length = atoi( header_string + STRSIZE( header_start ) ) ; tomwalters@0: tomwalters@0: header = malloc( header_length ) ; tomwalters@0: tomwalters@0: if( header != (char *) 0 ) { tomwalters@0: (void) strcpy( header, header_string ) ; tomwalters@0: (void) fread( header + STRSIZE( header_string ), sizeof ( *header_string ), (int) header_length - STRSIZE( header_string ), fp ) ; tomwalters@0: } tomwalters@0: tomwalters@0: return ( header ) ; tomwalters@0: } tomwalters@0: else { tomwalters@0: /* header not present */ tomwalters@0: tomwalters@0: (void) fseek( fp, 0l, 0 ) ; tomwalters@0: tomwalters@0: return ( (char *) 0 ) ; tomwalters@0: } tomwalters@0: } tomwalters@0: tomwalters@0: /*************************************************************************** tomwalters@0: WriteHeader() writes the given header on the given file stream. tomwalters@0: ****************************************************************************/ tomwalters@0: WriteHeader(header,fp) tomwalters@0: char *header; tomwalters@0: FILE *fp; tomwalters@0: { tomwalters@0: int header_length, HeaderInt(); tomwalters@0: tomwalters@0: header_length = HeaderInt(header,"header_bytes"); tomwalters@0: fwrite(header,sizeof(char),header_length,fp); tomwalters@0: } tomwalters@0: tomwalters@0: tomwalters@0: /*************************************************************************** tomwalters@0: HeaderString() simply searches through the header for values the user tomwalters@0: requests and returns a pointer to the begining of the value. tomwalters@0: ****************************************************************************/ tomwalters@0: char *HeaderString( header, name ) tomwalters@0: char *header, *name ; tomwalters@0: { tomwalters@0: register char *next_line = header ; tomwalters@0: register int name_len = strlen( name ) ; tomwalters@0: tomwalters@0: do tomwalters@0: if( strncmp( next_line, name, name_len ) == 0 ) { tomwalters@0: tomwalters@0: next_line+=name_len ; tomwalters@0: tomwalters@0: if( *next_line++ == '=' ) tomwalters@0: return ( next_line ) ; tomwalters@0: } tomwalters@0: tomwalters@0: while( ( next_line = strchr( next_line, '\n' ) + 1 ) != (char *) 0 + 1 ) ; tomwalters@0: tomwalters@0: return ( (char *) 0 ) ; tomwalters@0: } tomwalters@0: tomwalters@0: tomwalters@0: /*************************************************************************** tomwalters@0: HeaderStringOnly() returns a pointer to an allocated string that tomwalters@0: contains only the value rather than a pointer to a string that tomwalters@0: includes the all the rest of the header which is what HeaderString() tomwalters@0: returns. tomwalters@0: ****************************************************************************/ tomwalters@0: char *HeaderStringOnly( header, name ) tomwalters@0: char *header, *name ; tomwalters@0: { tomwalters@0: char *value = HeaderString( header, name ) ; tomwalters@0: unsigned value_length ; tomwalters@0: tomwalters@0: if( value != (char *) 0 ) { tomwalters@0: value_length = strchr( value, '\n' ) - value ; tomwalters@0: return ( strncpy( malloc( value_length+1 ), value, (int) value_length ) ) ; tomwalters@0: } tomwalters@0: else tomwalters@0: return ( (char *) 0 ) ; tomwalters@0: } tomwalters@0: tomwalters@0: tomwalters@0: /*************************************************************************** tomwalters@0: HeaderStrings() searches through the header for values the user tomwalters@0: requests and returns a pointer to the begining of the value. tomwalters@0: This is a version of HeaderString() which allows abbreviated names, tomwalters@0: return null ptr if not found or ambiguous. tomwalters@0: ****************************************************************************/ tomwalters@0: char *HeaderStrings( header, name ) tomwalters@0: char *header, *name ; tomwalters@0: { tomwalters@0: register char *next_line = header ; tomwalters@0: register int name_len = strlen( name ) ; tomwalters@0: char *valptr ; tomwalters@0: int count = 0 ; tomwalters@0: tomwalters@0: do tomwalters@0: if( strncmp( next_line, name, name_len ) == 0 ) { tomwalters@0: tomwalters@0: next_line+=name_len ; tomwalters@0: tomwalters@0: if ( ( valptr = strchr( next_line, '=' ) ) != (char *)0 ) { tomwalters@0: tomwalters@0: /* return directly if name matches exactly otherwise wait to check ambiguity */ tomwalters@0: if ( valptr == next_line ) return ( valptr + 1 ) ; tomwalters@0: tomwalters@0: valptr++ ; tomwalters@0: count++ ; tomwalters@0: } tomwalters@0: } tomwalters@0: tomwalters@0: while( ( next_line = strchr( next_line, '\n' ) + 1 ) != (char *) 0 + 1 ) ; tomwalters@0: tomwalters@0: if( count == 1 ) tomwalters@0: return ( valptr ) ; tomwalters@0: else tomwalters@0: return ( (char *) 0 ) ; /* not found or ambiguous */ tomwalters@0: } tomwalters@0: tomwalters@0: tomwalters@0: /*************************************************************************** tomwalters@0: HeaderNameString() returns a pointer to an allocated string that tomwalters@0: contains the full name corresponding to the given name, which can be tomwalters@0: given in abbreviated form provided this is unambiguous. tomwalters@0: Return a null ptr if the name is not found or is ambiguous. tomwalters@0: (This is an amalgam of HeaderString() and HeaderStringOnly() which also tomwalters@0: checks for ambiguity) tomwalters@0: ****************************************************************************/ tomwalters@0: tomwalters@0: char *HeaderNameString( header, name ) tomwalters@0: char *header, *name ; tomwalters@0: { tomwalters@0: register char *next_line = header ; tomwalters@0: register int name_len = strlen( name ) ; tomwalters@0: unsigned name_length ; tomwalters@0: char *nameptr ; tomwalters@0: int count = 0 ; tomwalters@0: tomwalters@0: do tomwalters@0: if( strncmp( next_line, name, name_len ) == 0 ) { tomwalters@0: if ( strchr( next_line, '=' ) != (char *)0 ) { tomwalters@0: nameptr = next_line ; tomwalters@0: tomwalters@0: /* return directly if name matches exactly otherwise wait to check ambiguity */ tomwalters@0: if ( name_len == ( name_length = strchr( next_line, '=' ) - next_line ) ) tomwalters@0: return ( strncpy( malloc( name_length+1 ), nameptr, (int) name_length ) ) ; tomwalters@0: count++ ; tomwalters@0: } tomwalters@0: } tomwalters@0: tomwalters@0: while( ( next_line = strchr( next_line, '\n' ) + 1 ) != (char *) 0 + 1 ) ; tomwalters@0: tomwalters@0: if( count == 1 ) { tomwalters@0: name_length = strchr( nameptr, '=' ) - nameptr ; tomwalters@0: return ( strncpy( malloc( name_length+1 ), nameptr, (int) name_length ) ) ; tomwalters@0: } tomwalters@0: else tomwalters@0: return ( (char *) 0 ) ; /* not found or ambiguous */ tomwalters@0: } tomwalters@0: tomwalters@0: tomwalters@0: /*************************************************************************** tomwalters@0: HeaderValueString() returns a pointer to an allocated string that tomwalters@0: contains the value corresponding to the given name, which can be given tomwalters@0: in abbreviated form provided this is unambiguous. tomwalters@0: Return a null ptr if the name is not found or is ambiguous. tomwalters@0: (This is an amalgam of HeaderString() and HeaderStringOnly() which also tomwalters@0: checks for ambiguity) tomwalters@0: ****************************************************************************/ tomwalters@0: tomwalters@0: char *HeaderValueString( header, name ) tomwalters@0: char *header, *name ; tomwalters@0: { tomwalters@0: register char *next_line = header ; tomwalters@0: register int name_len = strlen( name ) ; tomwalters@0: unsigned value_length ; tomwalters@0: char *valptr ; tomwalters@0: int count = 0 ; tomwalters@0: tomwalters@0: do tomwalters@0: if( strncmp( next_line, name, name_len ) == 0 ) { tomwalters@0: tomwalters@0: next_line+=name_len ; tomwalters@0: tomwalters@0: if ( ( valptr = strchr( next_line, '=' ) ) != (char *)0 ) { tomwalters@0: tomwalters@0: /* return directly if name matches exactly otherwise wait to check ambiguity */ tomwalters@0: if ( valptr == next_line ) { tomwalters@0: valptr++ ; tomwalters@0: value_length = strchr( valptr, '\n' ) - valptr ; tomwalters@0: return ( strncpy( malloc( value_length+1 ), valptr, (int) value_length ) ) ; tomwalters@0: } tomwalters@0: tomwalters@0: valptr++ ; tomwalters@0: count++ ; tomwalters@0: } tomwalters@0: } tomwalters@0: tomwalters@0: while( ( next_line = strchr( next_line, '\n' ) + 1 ) != (char *) 0 + 1 ) ; tomwalters@0: tomwalters@0: if( count == 1 ) { tomwalters@0: value_length = strchr( valptr, '\n' ) - valptr ; tomwalters@0: return ( strncpy( malloc( value_length+1 ), valptr, (int) value_length ) ) ; tomwalters@0: } tomwalters@0: else tomwalters@0: return ( (char *) 0 ) ; /* not found or ambiguous */ tomwalters@0: } tomwalters@0: tomwalters@0: tomwalters@0: /*************************************************************************** tomwalters@0: HeaderDouble() converts values to Doubles. tomwalters@0: ****************************************************************************/ tomwalters@0: double HeaderDouble( header, name ) tomwalters@0: char *header, *name ; tomwalters@0: { tomwalters@0: char *valuestr ; tomwalters@0: tomwalters@0: if ( (valuestr = HeaderString( header, name )) == (char *) 0) { tomwalters@0: fprintf(stderr,"option %s not found in header\n", name); tomwalters@0: exit(1); tomwalters@0: } tomwalters@0: return ( atof( HeaderString( header, name ) ) ) ; tomwalters@0: } tomwalters@0: tomwalters@0: tomwalters@0: /*************************************************************************** tomwalters@0: HeaderInt() converts values to Ints. tomwalters@0: ****************************************************************************/ tomwalters@0: int HeaderInt( header, name ) tomwalters@0: char *header, *name ; tomwalters@0: { tomwalters@0: char *valuestr ; tomwalters@0: tomwalters@0: if ( (valuestr = HeaderString( header, name )) == (char *) 0) { tomwalters@0: fprintf(stderr,"option %s not found in header\n", name); tomwalters@0: exit(1); tomwalters@0: } tomwalters@0: return ( atoi( valuestr ) ) ; tomwalters@0: } tomwalters@0: tomwalters@0: tomwalters@0: /*************************************************************************** tomwalters@0: HeaderSamplerate() returns the samplerate tomwalters@0: ****************************************************************************/ tomwalters@0: HeaderSamplerate( header ) tomwalters@0: char *header ; tomwalters@0: { tomwalters@0: char *valuestr ; tomwalters@0: tomwalters@0: if ( (valuestr = HeaderStringOnly( header, "samplerate" )) == (char *) 0) { tomwalters@0: fprintf(stderr,"samplerate not found in header\n"); tomwalters@0: exit(1); tomwalters@0: } tomwalters@0: return ( (int)to_Hz( valuestr, 1 ) ) ; tomwalters@0: } tomwalters@0: tomwalters@0: tomwalters@0: /*************************************************************************** tomwalters@0: FreeHeader frees the space allocated for a header by ReadHeader tomwalters@0: ****************************************************************************/ tomwalters@0: void FreeHeader( header ) tomwalters@0: char *header ; tomwalters@0: { tomwalters@0: free( header ) ; tomwalters@0: return ; tomwalters@0: } tomwalters@0: tomwalters@0: tomwalters@0: /*************************************************************************** tomwalters@0: ApplicString() return a ptr to the rest of the header which starts with tomwalters@0: the 3-char application name of the program. tomwalters@0: ***************************************************************************/ tomwalters@0: tomwalters@0: char *ApplicString( header ) tomwalters@0: char *header ; tomwalters@0: { tomwalters@0: char *versionstr, *progname ; tomwalters@0: tomwalters@0: if ( ( versionstr = HeaderString( header, "Version" ) ) == (char *)0 ) tomwalters@0: return (char *)( 0 ) ; /* version string not found in header */ tomwalters@0: tomwalters@0: if ( ( progname = strchr( versionstr, '[' ) ) == (char *)0 ) tomwalters@0: return (char *)( 0 ) ; /* program name not found in version string */ tomwalters@0: if ( strchr( versionstr, ']' ) - ( progname += 4 ) != 3 ) tomwalters@0: return (char *)( 0 ) ; /* application name not found in version string */ tomwalters@0: tomwalters@0: return ( progname ) ; tomwalters@0: } tomwalters@0: tomwalters@0: tomwalters@0: /*************************************************************************** tomwalters@0: Applic() returns the index number to the gen_applics list (see header.h) tomwalters@0: of the application name of the program (the last three letters of its name). tomwalters@0: This is assumed to be delimited by [ ] in the version string in the header. tomwalters@0: Return a -ve number on error. tomwalters@0: ***************************************************************************/ tomwalters@0: tomwalters@0: Applic( header ) tomwalters@0: char *header ; tomwalters@0: { tomwalters@0: char *versionstr, *progname ; tomwalters@0: int i ; tomwalters@0: tomwalters@0: if ( ( versionstr = HeaderStringOnly( header, "Version" ) ) == (char *)0 ) tomwalters@0: return ( -2 ) ; /* version string not found in header */ tomwalters@0: tomwalters@0: if ( ( progname = strchr( versionstr, '[' ) ) == (char *)0 ) tomwalters@0: return ( -3 ) ; /* program name not found in version string */ tomwalters@0: if ( strchr( versionstr, ']' ) - ( progname += 4 ) != 3 ) tomwalters@0: return ( -4 ) ; /* application name not found in version string */ tomwalters@0: for ( i = 0 ; gen_applics[i] != (char *)0 ; i++ ) tomwalters@0: if ( strncmp( gen_applics[i], progname, 3 ) == 0 ) tomwalters@0: return i ; tomwalters@0: tomwalters@0: return ( -1 ) ; /* application name not found in version string */ tomwalters@0: } tomwalters@0: tomwalters@0: tomwalters@0: /************************************************************************** tomwalters@0: tomwalters@0: The table below gives the meaning of the frame parameters for each gen tomwalters@0: program. The frame parameters are frameheight, framewidth, and frames. tomwalters@0: Depending upon the program and the "view", they can mean: tomwalters@0: tomwalters@0: chans = number of filterbank channels. tomwalters@0: length = duration in samples. tomwalters@0: num frames = number of cartoon frames. tomwalters@0: pwidth = "positive width" of auditory image. tomwalters@0: nwidth = "negative width" of auditory image. tomwalters@0: tomwalters@0: In all cases framebytes = frameheight * framewidth * sizeof(short) tomwalters@0: tomwalters@0: The table also shows how the frame parameters relate to the format of the tomwalters@0: display, where each of "num frames" frames of a cartoon is described as a tomwalters@0: matrix of "rows" * "cols". The number of rows describes the vertical direction tomwalters@0: and the number of cols describes the horizontal direction. tomwalters@0: tomwalters@0: tomwalters@0: gen Frame parameters in header Format of display matrix tomwalters@0: --- ------------------------------------- ---------------------------------- tomwalters@0: view height width frames rows cols num frames tomwalters@0: ---- ------ ----- ------ ---- ---- ---------- tomwalters@0: tomwalters@0: wav wave 1 1 length frameheight frames 1 tomwalters@0: tomwalters@0: bmm landscape chans 1 length frameheight frames 1 tomwalters@0: nap landscape chans 1 length frameheight frames 1 tomwalters@0: tomwalters@0: sgm greyscale chans 1 length frameheight frames 1 tomwalters@0: cgm greyscale chans 1 length frameheight frames 1 tomwalters@0: sas greyscale chans 1 length frameheight frames 1 tomwalters@0: tomwalters@0: asa excitation chans 1 num frames framewidth frameheight frames tomwalters@0: epn excitation chans 1 num frames framewidth frameheight frames tomwalters@0: sep excitation chans 1 num frames framewidth frameheight frames tomwalters@0: tomwalters@0: sai landscape chans p+nwidth num frames frameheight framewidth frames tomwalters@0: tomwalters@0: spl spiral chans pwidth num frames frameheight framewidth frames tomwalters@0: tomwalters@0: tomwalters@0: The table below shows the format of the AIM output array for each gen program tomwalters@0: in terms of the frame parameters. tomwalters@0: tomwalters@0: tomwalters@0: gen Output array format Comment tomwalters@0: --- ---------------------------------- ----------------------------- tomwalters@0: wav frames sets of frameheight (=1) array of time samples. tomwalters@0: tomwalters@0: ----------------------------- tomwalters@0: bmm frames sets of frameheight 2-D array by columns, tomwalters@0: nap frames sets of frameheight with lowest centre-frequency tomwalters@0: first in each column. tomwalters@0: sgm frames sets of frameheight tomwalters@0: cgm frames sets of frameheight tomwalters@0: sas frames sets of frameheight tomwalters@0: tomwalters@0: ----------------------------- tomwalters@0: asa frameheight sets of framewidth (=1) array of frequency samples. tomwalters@0: epn frameheight sets of framewidth (=1) tomwalters@0: sep frameheight sets of framewidth (=1) tomwalters@0: tomwalters@0: ----------------------------- tomwalters@0: sai frameheight sets of framewidth 2-D array by rows, tomwalters@0: with lowest centre-frequency tomwalters@0: spl frameheight sets of framewidth row first in each frame. tomwalters@0: tomwalters@0: tomwalters@0: The gen programs group into five format types each with a particular tomwalters@0: interpretation of it's frame parameters, it's output array format, and it's tomwalters@0: "view". These are defined (in header.h) as: tomwalters@0: tomwalters@0: Format gen programs tomwalters@0: ------ -------------- tomwalters@0: WAV wav tomwalters@0: NAP bmm, nap tomwalters@0: SGM sgm, cgm, sas tomwalters@0: EPN asa, epn, sep tomwalters@0: SAI sai, spl tomwalters@0: tomwalters@0: tomwalters@0: tomwalters@0: tomwalters@0: tomwalters@0: ***************************************************************************/ tomwalters@0: tomwalters@0: tomwalters@0: tomwalters@0: tomwalters@0: tomwalters@0: /************************************************************************** tomwalters@0: Format() returns the index number to the gen_formats list (see header.h) tomwalters@0: of the given application number (eg returned by Applic()). tomwalters@0: 0 = wave format (array of time points) tomwalters@0: 1 = nap format (by columns, lowest centre-frequency first in each column) tomwalters@0: 2 = sgm format (by columns, lowest centre-frequency first in each column) tomwalters@0: 3 = epn format (array of frequency points per frame) tomwalters@0: 4 = sai format (by rows, lowest centre-frequency row first per frame) tomwalters@0: ***************************************************************************/ tomwalters@0: tomwalters@0: Format( applic ) tomwalters@0: int applic ; tomwalters@0: { tomwalters@0: switch ( applic ) { tomwalters@0: tomwalters@0: case 0 : return ( 0 ) ; tomwalters@0: tomwalters@0: case 1 : case 2 : case 3 : tomwalters@0: case 4 : case 5 : case 6 : tomwalters@0: case 7 : return ( 1 ) ; tomwalters@0: tomwalters@0: case 8 : case 9 : case 10: return ( 2 ) ; tomwalters@0: tomwalters@0: case 11: case 12: case 13: return ( 3 ) ; tomwalters@0: tomwalters@0: case 14: case 15: return ( 4 ) ; tomwalters@0: tomwalters@0: default : fprintf( stderr,"unknown application index number\n" ) ; tomwalters@0: exit( 1 ) ; tomwalters@0: } tomwalters@0: } tomwalters@0: tomwalters@0: tomwalters@0: /************************************************************************** tomwalters@0: frame_to_matrix() tomwalters@0: Given the format number (see: Format(), Applic() and the gen_formats list tomwalters@0: in header.h), and the frameheight, framewidth, and frames, tomwalters@0: return the format of the frames in terms of the number of rows tomwalters@0: (ie. channels) and columns (ie. samples) per frame, and the number of tomwalters@0: such frames, via the given addresses. tomwalters@0: The number of bytes per frame is then = rows * cols * 2. tomwalters@0: ***************************************************************************/ tomwalters@0: tomwalters@0: frame_to_matrix( format, rows, cols, numframes, frameheight, framewidth, frames ) tomwalters@0: int format, *rows, *cols, *numframes, frameheight, framewidth, frames ; tomwalters@0: { tomwalters@0: switch ( format ) { tomwalters@0: case 0 : *rows = 1 ; /* wav format */ tomwalters@0: *cols = frames ; tomwalters@0: *numframes = 1 ; tomwalters@0: break ; tomwalters@0: tomwalters@0: case 1 : *rows = frameheight ; /* nap format */ tomwalters@0: *cols = frames ; tomwalters@0: *numframes = 1 ; tomwalters@0: break ; tomwalters@0: tomwalters@0: case 2 : *rows = frameheight ; /* sgm format */ tomwalters@0: *cols = frames ; tomwalters@0: *numframes = 1 ; tomwalters@0: break ; tomwalters@0: tomwalters@0: case 3 : *rows = 1 ; /* epn format */ tomwalters@0: *cols = frameheight ; tomwalters@0: *numframes = frames ; tomwalters@0: break ; tomwalters@0: tomwalters@0: case 4 : *rows = frameheight ; /* sai format */ tomwalters@0: *cols = framewidth ; tomwalters@0: *numframes = frames ; tomwalters@0: break ; tomwalters@0: tomwalters@0: default : fprintf( stderr,"unknown format number\n" ) ; tomwalters@0: exit( 1 ) ; tomwalters@0: } tomwalters@0: } tomwalters@0: tomwalters@0: tomwalters@0: /************************************************************************** tomwalters@0: matrix_to_frame() tomwalters@0: Inverse of frame_to_matrix(). tomwalters@0: Given the format number and the format in terms of the number of rows and tomwalters@0: columns per frame and the number of such frames, return the frameheight, tomwalters@0: framewidth and frames via the given addresses. tomwalters@0: ***************************************************************************/ tomwalters@0: tomwalters@0: matrix_to_frame( format, rows, cols, numframes, frameheight, framewidth, frames ) tomwalters@0: int format, rows, cols, numframes, *frameheight, *framewidth, *frames ; tomwalters@0: { tomwalters@0: switch ( format ) { tomwalters@0: case 0 : *frameheight = 1 ; /* wav format */ tomwalters@0: *framewidth = 1 ; tomwalters@0: *frames = cols ; tomwalters@0: break ; tomwalters@0: tomwalters@0: case 1 : *frameheight = rows ; /* nap format */ tomwalters@0: *framewidth = 1 ; tomwalters@0: *frames = cols ; tomwalters@0: break ; tomwalters@0: tomwalters@0: case 2 : *frameheight = rows ; /* sgm format */ tomwalters@0: *framewidth = 1 ; tomwalters@0: *frames = cols ; tomwalters@0: break ; tomwalters@0: tomwalters@0: case 3 : *frameheight = cols ; /* epn format */ tomwalters@0: *framewidth = 1 ; tomwalters@0: *frames = numframes ; tomwalters@0: break ; tomwalters@0: tomwalters@0: case 4 : *frameheight = rows ; /* sai format */ tomwalters@0: *framewidth = cols ; tomwalters@0: *frames = numframes ; tomwalters@0: break ; tomwalters@0: tomwalters@0: default : fprintf( stderr,"unknown format number\n" ) ; tomwalters@0: exit( 1 ) ; tomwalters@0: } tomwalters@0: } tomwalters@0: