annotate tools/header.c @ 0:5242703e91d3 tip

Initial checkin for AIM92 aimR8.2 (last updated May 1997).
author tomwalters
date Fri, 20 May 2011 15:19:45 +0100
parents
children
rev   line source
tomwalters@0 1 /***************************************************************************
tomwalters@0 2 Utilities for model output headers.
tomwalters@0 3
tomwalters@0 4 A header is an ASCII desciption which summarises the state of
tomwalters@0 5 a process by giving a list of parameter values etc etc..
tomwalters@0 6 Each parameter is described on a separate line, and the header consists
tomwalters@0 7 of several lines of the general form:
tomwalters@0 8
tomwalters@0 9 <ASCII description> = <value>\n
tomwalters@0 10
tomwalters@0 11 For example, the first five lines of the header generated by a command
tomwalters@0 12 line "gensai -header fname" is as follows:
tomwalters@0 13
tomwalters@0 14 header_bytes=0000532
tomwalters@0 15 scale_sai=0.25
tomwalters@0 16 imagedurn_sai=16
tomwalters@0 17 decayrate_sai=10
tomwalters@0 18 cgmdecay=24
tomwalters@0 19 ...
tomwalters@0 20 date=Thu Jan 11 00:19:41 WET 1990\n
tomwalters@0 21 \000
tomwalters@0 22
tomwalters@0 23 This string is written onto the front of the file with padding if
tomwalters@0 24 desired before any data is written. The header can be of any length
tomwalters@0 25 and contain any combination of non null characters. Header items are
tomwalters@0 26 identified by the string on the left of the equals symbol and their
tomwalters@0 27 value is represented by the string on the remainder of that line.
tomwalters@0 28
tomwalters@0 29 The first line is always the HEADER_STRING (ie. header_bytes=....\n)
tomwalters@0 30 which gives the length of the header.
tomwalters@0 31
tomwalters@0 32 Synopsis of utilities:
tomwalters@0 33 ----------------------
tomwalters@0 34
tomwalters@0 35 char *ReadHeader( fp )
tomwalters@0 36 FILE *fp ;
tomwalters@0 37
tomwalters@0 38 WriteHeader(header,fp)
tomwalters@0 39 char *header;
tomwalters@0 40 FILE *fp;
tomwalters@0 41
tomwalters@0 42 char *HeaderString( header, name )
tomwalters@0 43 char *header, *name ;
tomwalters@0 44
tomwalters@0 45 char *HeaderStringOnly( header, name )
tomwalters@0 46 char *header, *name ;
tomwalters@0 47
tomwalters@0 48 double HeaderDouble( header, name )
tomwalters@0 49 char *header, *name ;
tomwalters@0 50
tomwalters@0 51 double HeaderInt( header, name )
tomwalters@0 52 char *header, *name ;
tomwalters@0 53
tomwalters@0 54 void FreeHeader( header )
tomwalters@0 55 char *header ;
tomwalters@0 56
tomwalters@0 57 ReadHeader() reads a header (if it exists ) from the file into
tomwalters@0 58 memory and returns a pointer to the header in memory allocated for
tomwalters@0 59 storing the header. It returns a null pointer if no header is found.
tomwalters@0 60 It leaves the fp pointing to the data which follows the header.
tomwalters@0 61 WriteHeader() writes the given header on the given file stream.
tomwalters@0 62 HeaderString() simply searches through the header for values the user
tomwalters@0 63 requests and returns a pointer to the beginning of the value.
tomwalters@0 64 It returns a null pointer if the required string is not found.
tomwalters@0 65 HeaderStringOnly() returns a pointer to an allocated string that
tomwalters@0 66 contains only the value rather than a pointer to a string that
tomwalters@0 67 includes the all the rest of the header (which is what HeaderString()
tomwalters@0 68 returns). It returns a null pointer if the required string is not found.
tomwalters@0 69 HeaderDouble() converts values to Doubles.
tomwalters@0 70 HeaderInt() converts values to Ints.
tomwalters@0 71 FreeHeader() frees the space allocated for a header by ReadHeader.
tomwalters@0 72
tomwalters@0 73 Example:
tomwalters@0 74 -------
tomwalters@0 75 A simple example of the use of the header utility routines to read the
tomwalters@0 76 sai dimensions from a header would be:
tomwalters@0 77 (This assumes a ".sai" file generated by a command like "gensai -header")
tomwalters@0 78
tomwalters@0 79 #include <stdio.h>
tomwalters@0 80 #include <math.h>
tomwalters@0 81 #include "header.c"
tomwalters@0 82 char *header = ReadHeader(fp); fp is file-pointer to ".sai" file
tomwalters@0 83 int frameheight = HeaderInt(header,"frameheight"); num chans
tomwalters@0 84 int framewidth = HeaderInt(header,"framewidth"); sai duration
tomwalters@0 85
tomwalters@0 86 char *name = "frameheight";
tomwalters@0 87 printf( "%s=%s\n", name, HeaderStringOnly( header, name ) ) ;
tomwalters@0 88
tomwalters@0 89 ****************************************************************************/
tomwalters@0 90
tomwalters@0 91 #include <stdio.h>
tomwalters@0 92 /* #include <strings.h> */
tomwalters@0 93 #include <string.h>
tomwalters@0 94 #include <malloc.h>
tomwalters@0 95 #include "header.h"
tomwalters@0 96 #include "units.h"
tomwalters@0 97
tomwalters@0 98
tomwalters@0 99 /***************************************************************************
tomwalters@0 100 ReadHeader() reads a header (if it exists ) from the file into
tomwalters@0 101 memory and returns a pointer to the header in memory allocated for
tomwalters@0 102 storing the header. It returns a null pointer if no header is found.
tomwalters@0 103 ****************************************************************************/
tomwalters@0 104 char *ReadHeader( fp )
tomwalters@0 105 FILE *fp ;
tomwalters@0 106 {
tomwalters@0 107 static char header_string[] = HEADER_STRING ;
tomwalters@0 108 static char header_start[] = HEADER_START ;
tomwalters@0 109 unsigned header_length ;
tomwalters@0 110 char *header ;
tomwalters@0 111
tomwalters@0 112 if( fread( header_string, sizeof ( *header_string ), STRSIZE( header_string ), fp ) == STRSIZE( header_string )
tomwalters@0 113 && strncmp( header_string, header_start, STRSIZE( header_start ) ) == 0 ) {
tomwalters@0 114
tomwalters@0 115 /* header located - remove carriage return */
tomwalters@0 116
tomwalters@0 117 header_length = atoi( header_string + STRSIZE( header_start ) ) ;
tomwalters@0 118
tomwalters@0 119 header = malloc( header_length ) ;
tomwalters@0 120
tomwalters@0 121 if( header != (char *) 0 ) {
tomwalters@0 122 (void) strcpy( header, header_string ) ;
tomwalters@0 123 (void) fread( header + STRSIZE( header_string ), sizeof ( *header_string ), (int) header_length - STRSIZE( header_string ), fp ) ;
tomwalters@0 124 }
tomwalters@0 125
tomwalters@0 126 return ( header ) ;
tomwalters@0 127 }
tomwalters@0 128 else {
tomwalters@0 129 /* header not present */
tomwalters@0 130
tomwalters@0 131 (void) fseek( fp, 0l, 0 ) ;
tomwalters@0 132
tomwalters@0 133 return ( (char *) 0 ) ;
tomwalters@0 134 }
tomwalters@0 135 }
tomwalters@0 136
tomwalters@0 137 /***************************************************************************
tomwalters@0 138 WriteHeader() writes the given header on the given file stream.
tomwalters@0 139 ****************************************************************************/
tomwalters@0 140 WriteHeader(header,fp)
tomwalters@0 141 char *header;
tomwalters@0 142 FILE *fp;
tomwalters@0 143 {
tomwalters@0 144 int header_length, HeaderInt();
tomwalters@0 145
tomwalters@0 146 header_length = HeaderInt(header,"header_bytes");
tomwalters@0 147 fwrite(header,sizeof(char),header_length,fp);
tomwalters@0 148 }
tomwalters@0 149
tomwalters@0 150
tomwalters@0 151 /***************************************************************************
tomwalters@0 152 HeaderString() simply searches through the header for values the user
tomwalters@0 153 requests and returns a pointer to the begining of the value.
tomwalters@0 154 ****************************************************************************/
tomwalters@0 155 char *HeaderString( header, name )
tomwalters@0 156 char *header, *name ;
tomwalters@0 157 {
tomwalters@0 158 register char *next_line = header ;
tomwalters@0 159 register int name_len = strlen( name ) ;
tomwalters@0 160
tomwalters@0 161 do
tomwalters@0 162 if( strncmp( next_line, name, name_len ) == 0 ) {
tomwalters@0 163
tomwalters@0 164 next_line+=name_len ;
tomwalters@0 165
tomwalters@0 166 if( *next_line++ == '=' )
tomwalters@0 167 return ( next_line ) ;
tomwalters@0 168 }
tomwalters@0 169
tomwalters@0 170 while( ( next_line = strchr( next_line, '\n' ) + 1 ) != (char *) 0 + 1 ) ;
tomwalters@0 171
tomwalters@0 172 return ( (char *) 0 ) ;
tomwalters@0 173 }
tomwalters@0 174
tomwalters@0 175
tomwalters@0 176 /***************************************************************************
tomwalters@0 177 HeaderStringOnly() returns a pointer to an allocated string that
tomwalters@0 178 contains only the value rather than a pointer to a string that
tomwalters@0 179 includes the all the rest of the header which is what HeaderString()
tomwalters@0 180 returns.
tomwalters@0 181 ****************************************************************************/
tomwalters@0 182 char *HeaderStringOnly( header, name )
tomwalters@0 183 char *header, *name ;
tomwalters@0 184 {
tomwalters@0 185 char *value = HeaderString( header, name ) ;
tomwalters@0 186 unsigned value_length ;
tomwalters@0 187
tomwalters@0 188 if( value != (char *) 0 ) {
tomwalters@0 189 value_length = strchr( value, '\n' ) - value ;
tomwalters@0 190 return ( strncpy( malloc( value_length+1 ), value, (int) value_length ) ) ;
tomwalters@0 191 }
tomwalters@0 192 else
tomwalters@0 193 return ( (char *) 0 ) ;
tomwalters@0 194 }
tomwalters@0 195
tomwalters@0 196
tomwalters@0 197 /***************************************************************************
tomwalters@0 198 HeaderStrings() searches through the header for values the user
tomwalters@0 199 requests and returns a pointer to the begining of the value.
tomwalters@0 200 This is a version of HeaderString() which allows abbreviated names,
tomwalters@0 201 return null ptr if not found or ambiguous.
tomwalters@0 202 ****************************************************************************/
tomwalters@0 203 char *HeaderStrings( header, name )
tomwalters@0 204 char *header, *name ;
tomwalters@0 205 {
tomwalters@0 206 register char *next_line = header ;
tomwalters@0 207 register int name_len = strlen( name ) ;
tomwalters@0 208 char *valptr ;
tomwalters@0 209 int count = 0 ;
tomwalters@0 210
tomwalters@0 211 do
tomwalters@0 212 if( strncmp( next_line, name, name_len ) == 0 ) {
tomwalters@0 213
tomwalters@0 214 next_line+=name_len ;
tomwalters@0 215
tomwalters@0 216 if ( ( valptr = strchr( next_line, '=' ) ) != (char *)0 ) {
tomwalters@0 217
tomwalters@0 218 /* return directly if name matches exactly otherwise wait to check ambiguity */
tomwalters@0 219 if ( valptr == next_line ) return ( valptr + 1 ) ;
tomwalters@0 220
tomwalters@0 221 valptr++ ;
tomwalters@0 222 count++ ;
tomwalters@0 223 }
tomwalters@0 224 }
tomwalters@0 225
tomwalters@0 226 while( ( next_line = strchr( next_line, '\n' ) + 1 ) != (char *) 0 + 1 ) ;
tomwalters@0 227
tomwalters@0 228 if( count == 1 )
tomwalters@0 229 return ( valptr ) ;
tomwalters@0 230 else
tomwalters@0 231 return ( (char *) 0 ) ; /* not found or ambiguous */
tomwalters@0 232 }
tomwalters@0 233
tomwalters@0 234
tomwalters@0 235 /***************************************************************************
tomwalters@0 236 HeaderNameString() returns a pointer to an allocated string that
tomwalters@0 237 contains the full name corresponding to the given name, which can be
tomwalters@0 238 given in abbreviated form provided this is unambiguous.
tomwalters@0 239 Return a null ptr if the name is not found or is ambiguous.
tomwalters@0 240 (This is an amalgam of HeaderString() and HeaderStringOnly() which also
tomwalters@0 241 checks for ambiguity)
tomwalters@0 242 ****************************************************************************/
tomwalters@0 243
tomwalters@0 244 char *HeaderNameString( header, name )
tomwalters@0 245 char *header, *name ;
tomwalters@0 246 {
tomwalters@0 247 register char *next_line = header ;
tomwalters@0 248 register int name_len = strlen( name ) ;
tomwalters@0 249 unsigned name_length ;
tomwalters@0 250 char *nameptr ;
tomwalters@0 251 int count = 0 ;
tomwalters@0 252
tomwalters@0 253 do
tomwalters@0 254 if( strncmp( next_line, name, name_len ) == 0 ) {
tomwalters@0 255 if ( strchr( next_line, '=' ) != (char *)0 ) {
tomwalters@0 256 nameptr = next_line ;
tomwalters@0 257
tomwalters@0 258 /* return directly if name matches exactly otherwise wait to check ambiguity */
tomwalters@0 259 if ( name_len == ( name_length = strchr( next_line, '=' ) - next_line ) )
tomwalters@0 260 return ( strncpy( malloc( name_length+1 ), nameptr, (int) name_length ) ) ;
tomwalters@0 261 count++ ;
tomwalters@0 262 }
tomwalters@0 263 }
tomwalters@0 264
tomwalters@0 265 while( ( next_line = strchr( next_line, '\n' ) + 1 ) != (char *) 0 + 1 ) ;
tomwalters@0 266
tomwalters@0 267 if( count == 1 ) {
tomwalters@0 268 name_length = strchr( nameptr, '=' ) - nameptr ;
tomwalters@0 269 return ( strncpy( malloc( name_length+1 ), nameptr, (int) name_length ) ) ;
tomwalters@0 270 }
tomwalters@0 271 else
tomwalters@0 272 return ( (char *) 0 ) ; /* not found or ambiguous */
tomwalters@0 273 }
tomwalters@0 274
tomwalters@0 275
tomwalters@0 276 /***************************************************************************
tomwalters@0 277 HeaderValueString() returns a pointer to an allocated string that
tomwalters@0 278 contains the value corresponding to the given name, which can be given
tomwalters@0 279 in abbreviated form provided this is unambiguous.
tomwalters@0 280 Return a null ptr if the name is not found or is ambiguous.
tomwalters@0 281 (This is an amalgam of HeaderString() and HeaderStringOnly() which also
tomwalters@0 282 checks for ambiguity)
tomwalters@0 283 ****************************************************************************/
tomwalters@0 284
tomwalters@0 285 char *HeaderValueString( header, name )
tomwalters@0 286 char *header, *name ;
tomwalters@0 287 {
tomwalters@0 288 register char *next_line = header ;
tomwalters@0 289 register int name_len = strlen( name ) ;
tomwalters@0 290 unsigned value_length ;
tomwalters@0 291 char *valptr ;
tomwalters@0 292 int count = 0 ;
tomwalters@0 293
tomwalters@0 294 do
tomwalters@0 295 if( strncmp( next_line, name, name_len ) == 0 ) {
tomwalters@0 296
tomwalters@0 297 next_line+=name_len ;
tomwalters@0 298
tomwalters@0 299 if ( ( valptr = strchr( next_line, '=' ) ) != (char *)0 ) {
tomwalters@0 300
tomwalters@0 301 /* return directly if name matches exactly otherwise wait to check ambiguity */
tomwalters@0 302 if ( valptr == next_line ) {
tomwalters@0 303 valptr++ ;
tomwalters@0 304 value_length = strchr( valptr, '\n' ) - valptr ;
tomwalters@0 305 return ( strncpy( malloc( value_length+1 ), valptr, (int) value_length ) ) ;
tomwalters@0 306 }
tomwalters@0 307
tomwalters@0 308 valptr++ ;
tomwalters@0 309 count++ ;
tomwalters@0 310 }
tomwalters@0 311 }
tomwalters@0 312
tomwalters@0 313 while( ( next_line = strchr( next_line, '\n' ) + 1 ) != (char *) 0 + 1 ) ;
tomwalters@0 314
tomwalters@0 315 if( count == 1 ) {
tomwalters@0 316 value_length = strchr( valptr, '\n' ) - valptr ;
tomwalters@0 317 return ( strncpy( malloc( value_length+1 ), valptr, (int) value_length ) ) ;
tomwalters@0 318 }
tomwalters@0 319 else
tomwalters@0 320 return ( (char *) 0 ) ; /* not found or ambiguous */
tomwalters@0 321 }
tomwalters@0 322
tomwalters@0 323
tomwalters@0 324 /***************************************************************************
tomwalters@0 325 HeaderDouble() converts values to Doubles.
tomwalters@0 326 ****************************************************************************/
tomwalters@0 327 double HeaderDouble( header, name )
tomwalters@0 328 char *header, *name ;
tomwalters@0 329 {
tomwalters@0 330 char *valuestr ;
tomwalters@0 331
tomwalters@0 332 if ( (valuestr = HeaderString( header, name )) == (char *) 0) {
tomwalters@0 333 fprintf(stderr,"option %s not found in header\n", name);
tomwalters@0 334 exit(1);
tomwalters@0 335 }
tomwalters@0 336 return ( atof( HeaderString( header, name ) ) ) ;
tomwalters@0 337 }
tomwalters@0 338
tomwalters@0 339
tomwalters@0 340 /***************************************************************************
tomwalters@0 341 HeaderInt() converts values to Ints.
tomwalters@0 342 ****************************************************************************/
tomwalters@0 343 int HeaderInt( header, name )
tomwalters@0 344 char *header, *name ;
tomwalters@0 345 {
tomwalters@0 346 char *valuestr ;
tomwalters@0 347
tomwalters@0 348 if ( (valuestr = HeaderString( header, name )) == (char *) 0) {
tomwalters@0 349 fprintf(stderr,"option %s not found in header\n", name);
tomwalters@0 350 exit(1);
tomwalters@0 351 }
tomwalters@0 352 return ( atoi( valuestr ) ) ;
tomwalters@0 353 }
tomwalters@0 354
tomwalters@0 355
tomwalters@0 356 /***************************************************************************
tomwalters@0 357 HeaderSamplerate() returns the samplerate
tomwalters@0 358 ****************************************************************************/
tomwalters@0 359 HeaderSamplerate( header )
tomwalters@0 360 char *header ;
tomwalters@0 361 {
tomwalters@0 362 char *valuestr ;
tomwalters@0 363
tomwalters@0 364 if ( (valuestr = HeaderStringOnly( header, "samplerate" )) == (char *) 0) {
tomwalters@0 365 fprintf(stderr,"samplerate not found in header\n");
tomwalters@0 366 exit(1);
tomwalters@0 367 }
tomwalters@0 368 return ( (int)to_Hz( valuestr, 1 ) ) ;
tomwalters@0 369 }
tomwalters@0 370
tomwalters@0 371
tomwalters@0 372 /***************************************************************************
tomwalters@0 373 FreeHeader frees the space allocated for a header by ReadHeader
tomwalters@0 374 ****************************************************************************/
tomwalters@0 375 void FreeHeader( header )
tomwalters@0 376 char *header ;
tomwalters@0 377 {
tomwalters@0 378 free( header ) ;
tomwalters@0 379 return ;
tomwalters@0 380 }
tomwalters@0 381
tomwalters@0 382
tomwalters@0 383 /***************************************************************************
tomwalters@0 384 ApplicString() return a ptr to the rest of the header which starts with
tomwalters@0 385 the 3-char application name of the program.
tomwalters@0 386 ***************************************************************************/
tomwalters@0 387
tomwalters@0 388 char *ApplicString( header )
tomwalters@0 389 char *header ;
tomwalters@0 390 {
tomwalters@0 391 char *versionstr, *progname ;
tomwalters@0 392
tomwalters@0 393 if ( ( versionstr = HeaderString( header, "Version" ) ) == (char *)0 )
tomwalters@0 394 return (char *)( 0 ) ; /* version string not found in header */
tomwalters@0 395
tomwalters@0 396 if ( ( progname = strchr( versionstr, '[' ) ) == (char *)0 )
tomwalters@0 397 return (char *)( 0 ) ; /* program name not found in version string */
tomwalters@0 398 if ( strchr( versionstr, ']' ) - ( progname += 4 ) != 3 )
tomwalters@0 399 return (char *)( 0 ) ; /* application name not found in version string */
tomwalters@0 400
tomwalters@0 401 return ( progname ) ;
tomwalters@0 402 }
tomwalters@0 403
tomwalters@0 404
tomwalters@0 405 /***************************************************************************
tomwalters@0 406 Applic() returns the index number to the gen_applics list (see header.h)
tomwalters@0 407 of the application name of the program (the last three letters of its name).
tomwalters@0 408 This is assumed to be delimited by [ ] in the version string in the header.
tomwalters@0 409 Return a -ve number on error.
tomwalters@0 410 ***************************************************************************/
tomwalters@0 411
tomwalters@0 412 Applic( header )
tomwalters@0 413 char *header ;
tomwalters@0 414 {
tomwalters@0 415 char *versionstr, *progname ;
tomwalters@0 416 int i ;
tomwalters@0 417
tomwalters@0 418 if ( ( versionstr = HeaderStringOnly( header, "Version" ) ) == (char *)0 )
tomwalters@0 419 return ( -2 ) ; /* version string not found in header */
tomwalters@0 420
tomwalters@0 421 if ( ( progname = strchr( versionstr, '[' ) ) == (char *)0 )
tomwalters@0 422 return ( -3 ) ; /* program name not found in version string */
tomwalters@0 423 if ( strchr( versionstr, ']' ) - ( progname += 4 ) != 3 )
tomwalters@0 424 return ( -4 ) ; /* application name not found in version string */
tomwalters@0 425 for ( i = 0 ; gen_applics[i] != (char *)0 ; i++ )
tomwalters@0 426 if ( strncmp( gen_applics[i], progname, 3 ) == 0 )
tomwalters@0 427 return i ;
tomwalters@0 428
tomwalters@0 429 return ( -1 ) ; /* application name not found in version string */
tomwalters@0 430 }
tomwalters@0 431
tomwalters@0 432
tomwalters@0 433 /**************************************************************************
tomwalters@0 434
tomwalters@0 435 The table below gives the meaning of the frame parameters for each gen
tomwalters@0 436 program. The frame parameters are frameheight, framewidth, and frames.
tomwalters@0 437 Depending upon the program and the "view", they can mean:
tomwalters@0 438
tomwalters@0 439 chans = number of filterbank channels.
tomwalters@0 440 length = duration in samples.
tomwalters@0 441 num frames = number of cartoon frames.
tomwalters@0 442 pwidth = "positive width" of auditory image.
tomwalters@0 443 nwidth = "negative width" of auditory image.
tomwalters@0 444
tomwalters@0 445 In all cases framebytes = frameheight * framewidth * sizeof(short)
tomwalters@0 446
tomwalters@0 447 The table also shows how the frame parameters relate to the format of the
tomwalters@0 448 display, where each of "num frames" frames of a cartoon is described as a
tomwalters@0 449 matrix of "rows" * "cols". The number of rows describes the vertical direction
tomwalters@0 450 and the number of cols describes the horizontal direction.
tomwalters@0 451
tomwalters@0 452
tomwalters@0 453 gen Frame parameters in header Format of display matrix
tomwalters@0 454 --- ------------------------------------- ----------------------------------
tomwalters@0 455 view height width frames rows cols num frames
tomwalters@0 456 ---- ------ ----- ------ ---- ---- ----------
tomwalters@0 457
tomwalters@0 458 wav wave 1 1 length frameheight frames 1
tomwalters@0 459
tomwalters@0 460 bmm landscape chans 1 length frameheight frames 1
tomwalters@0 461 nap landscape chans 1 length frameheight frames 1
tomwalters@0 462
tomwalters@0 463 sgm greyscale chans 1 length frameheight frames 1
tomwalters@0 464 cgm greyscale chans 1 length frameheight frames 1
tomwalters@0 465 sas greyscale chans 1 length frameheight frames 1
tomwalters@0 466
tomwalters@0 467 asa excitation chans 1 num frames framewidth frameheight frames
tomwalters@0 468 epn excitation chans 1 num frames framewidth frameheight frames
tomwalters@0 469 sep excitation chans 1 num frames framewidth frameheight frames
tomwalters@0 470
tomwalters@0 471 sai landscape chans p+nwidth num frames frameheight framewidth frames
tomwalters@0 472
tomwalters@0 473 spl spiral chans pwidth num frames frameheight framewidth frames
tomwalters@0 474
tomwalters@0 475
tomwalters@0 476 The table below shows the format of the AIM output array for each gen program
tomwalters@0 477 in terms of the frame parameters.
tomwalters@0 478
tomwalters@0 479
tomwalters@0 480 gen Output array format Comment
tomwalters@0 481 --- ---------------------------------- -----------------------------
tomwalters@0 482 wav frames sets of frameheight (=1) array of time samples.
tomwalters@0 483
tomwalters@0 484 -----------------------------
tomwalters@0 485 bmm frames sets of frameheight 2-D array by columns,
tomwalters@0 486 nap frames sets of frameheight with lowest centre-frequency
tomwalters@0 487 first in each column.
tomwalters@0 488 sgm frames sets of frameheight
tomwalters@0 489 cgm frames sets of frameheight
tomwalters@0 490 sas frames sets of frameheight
tomwalters@0 491
tomwalters@0 492 -----------------------------
tomwalters@0 493 asa frameheight sets of framewidth (=1) array of frequency samples.
tomwalters@0 494 epn frameheight sets of framewidth (=1)
tomwalters@0 495 sep frameheight sets of framewidth (=1)
tomwalters@0 496
tomwalters@0 497 -----------------------------
tomwalters@0 498 sai frameheight sets of framewidth 2-D array by rows,
tomwalters@0 499 with lowest centre-frequency
tomwalters@0 500 spl frameheight sets of framewidth row first in each frame.
tomwalters@0 501
tomwalters@0 502
tomwalters@0 503 The gen programs group into five format types each with a particular
tomwalters@0 504 interpretation of it's frame parameters, it's output array format, and it's
tomwalters@0 505 "view". These are defined (in header.h) as:
tomwalters@0 506
tomwalters@0 507 Format gen programs
tomwalters@0 508 ------ --------------
tomwalters@0 509 WAV wav
tomwalters@0 510 NAP bmm, nap
tomwalters@0 511 SGM sgm, cgm, sas
tomwalters@0 512 EPN asa, epn, sep
tomwalters@0 513 SAI sai, spl
tomwalters@0 514
tomwalters@0 515
tomwalters@0 516
tomwalters@0 517
tomwalters@0 518
tomwalters@0 519 ***************************************************************************/
tomwalters@0 520
tomwalters@0 521
tomwalters@0 522
tomwalters@0 523
tomwalters@0 524
tomwalters@0 525 /**************************************************************************
tomwalters@0 526 Format() returns the index number to the gen_formats list (see header.h)
tomwalters@0 527 of the given application number (eg returned by Applic()).
tomwalters@0 528 0 = wave format (array of time points)
tomwalters@0 529 1 = nap format (by columns, lowest centre-frequency first in each column)
tomwalters@0 530 2 = sgm format (by columns, lowest centre-frequency first in each column)
tomwalters@0 531 3 = epn format (array of frequency points per frame)
tomwalters@0 532 4 = sai format (by rows, lowest centre-frequency row first per frame)
tomwalters@0 533 ***************************************************************************/
tomwalters@0 534
tomwalters@0 535 Format( applic )
tomwalters@0 536 int applic ;
tomwalters@0 537 {
tomwalters@0 538 switch ( applic ) {
tomwalters@0 539
tomwalters@0 540 case 0 : return ( 0 ) ;
tomwalters@0 541
tomwalters@0 542 case 1 : case 2 : case 3 :
tomwalters@0 543 case 4 : case 5 : case 6 :
tomwalters@0 544 case 7 : return ( 1 ) ;
tomwalters@0 545
tomwalters@0 546 case 8 : case 9 : case 10: return ( 2 ) ;
tomwalters@0 547
tomwalters@0 548 case 11: case 12: case 13: return ( 3 ) ;
tomwalters@0 549
tomwalters@0 550 case 14: case 15: return ( 4 ) ;
tomwalters@0 551
tomwalters@0 552 default : fprintf( stderr,"unknown application index number\n" ) ;
tomwalters@0 553 exit( 1 ) ;
tomwalters@0 554 }
tomwalters@0 555 }
tomwalters@0 556
tomwalters@0 557
tomwalters@0 558 /**************************************************************************
tomwalters@0 559 frame_to_matrix()
tomwalters@0 560 Given the format number (see: Format(), Applic() and the gen_formats list
tomwalters@0 561 in header.h), and the frameheight, framewidth, and frames,
tomwalters@0 562 return the format of the frames in terms of the number of rows
tomwalters@0 563 (ie. channels) and columns (ie. samples) per frame, and the number of
tomwalters@0 564 such frames, via the given addresses.
tomwalters@0 565 The number of bytes per frame is then = rows * cols * 2.
tomwalters@0 566 ***************************************************************************/
tomwalters@0 567
tomwalters@0 568 frame_to_matrix( format, rows, cols, numframes, frameheight, framewidth, frames )
tomwalters@0 569 int format, *rows, *cols, *numframes, frameheight, framewidth, frames ;
tomwalters@0 570 {
tomwalters@0 571 switch ( format ) {
tomwalters@0 572 case 0 : *rows = 1 ; /* wav format */
tomwalters@0 573 *cols = frames ;
tomwalters@0 574 *numframes = 1 ;
tomwalters@0 575 break ;
tomwalters@0 576
tomwalters@0 577 case 1 : *rows = frameheight ; /* nap format */
tomwalters@0 578 *cols = frames ;
tomwalters@0 579 *numframes = 1 ;
tomwalters@0 580 break ;
tomwalters@0 581
tomwalters@0 582 case 2 : *rows = frameheight ; /* sgm format */
tomwalters@0 583 *cols = frames ;
tomwalters@0 584 *numframes = 1 ;
tomwalters@0 585 break ;
tomwalters@0 586
tomwalters@0 587 case 3 : *rows = 1 ; /* epn format */
tomwalters@0 588 *cols = frameheight ;
tomwalters@0 589 *numframes = frames ;
tomwalters@0 590 break ;
tomwalters@0 591
tomwalters@0 592 case 4 : *rows = frameheight ; /* sai format */
tomwalters@0 593 *cols = framewidth ;
tomwalters@0 594 *numframes = frames ;
tomwalters@0 595 break ;
tomwalters@0 596
tomwalters@0 597 default : fprintf( stderr,"unknown format number\n" ) ;
tomwalters@0 598 exit( 1 ) ;
tomwalters@0 599 }
tomwalters@0 600 }
tomwalters@0 601
tomwalters@0 602
tomwalters@0 603 /**************************************************************************
tomwalters@0 604 matrix_to_frame()
tomwalters@0 605 Inverse of frame_to_matrix().
tomwalters@0 606 Given the format number and the format in terms of the number of rows and
tomwalters@0 607 columns per frame and the number of such frames, return the frameheight,
tomwalters@0 608 framewidth and frames via the given addresses.
tomwalters@0 609 ***************************************************************************/
tomwalters@0 610
tomwalters@0 611 matrix_to_frame( format, rows, cols, numframes, frameheight, framewidth, frames )
tomwalters@0 612 int format, rows, cols, numframes, *frameheight, *framewidth, *frames ;
tomwalters@0 613 {
tomwalters@0 614 switch ( format ) {
tomwalters@0 615 case 0 : *frameheight = 1 ; /* wav format */
tomwalters@0 616 *framewidth = 1 ;
tomwalters@0 617 *frames = cols ;
tomwalters@0 618 break ;
tomwalters@0 619
tomwalters@0 620 case 1 : *frameheight = rows ; /* nap format */
tomwalters@0 621 *framewidth = 1 ;
tomwalters@0 622 *frames = cols ;
tomwalters@0 623 break ;
tomwalters@0 624
tomwalters@0 625 case 2 : *frameheight = rows ; /* sgm format */
tomwalters@0 626 *framewidth = 1 ;
tomwalters@0 627 *frames = cols ;
tomwalters@0 628 break ;
tomwalters@0 629
tomwalters@0 630 case 3 : *frameheight = cols ; /* epn format */
tomwalters@0 631 *framewidth = 1 ;
tomwalters@0 632 *frames = numframes ;
tomwalters@0 633 break ;
tomwalters@0 634
tomwalters@0 635 case 4 : *frameheight = rows ; /* sai format */
tomwalters@0 636 *framewidth = cols ;
tomwalters@0 637 *frames = numframes ;
tomwalters@0 638 break ;
tomwalters@0 639
tomwalters@0 640 default : fprintf( stderr,"unknown format number\n" ) ;
tomwalters@0 641 exit( 1 ) ;
tomwalters@0 642 }
tomwalters@0 643 }
tomwalters@0 644