tomwalters@0: /* tomwalters@0: Copyright (c) Applied Psychology Unit, Medical Research Council. 1993 tomwalters@0: =========================================================================== tomwalters@0: tomwalters@0: Permission to use, copy, modify, and distribute this software without fee tomwalters@0: is hereby granted for research purposes, provided that this copyright tomwalters@0: notice appears in all copies and in all supporting documentation, and that tomwalters@0: the software is not redistributed for any fee (except for a nominal tomwalters@0: shipping charge). Anyone wanting to incorporate all or part of this tomwalters@0: software in a commercial product must obtain a license from the Medical tomwalters@0: Research Council. tomwalters@0: tomwalters@0: The MRC makes no representations about the suitability of this tomwalters@0: software for any purpose. It is provided "as is" without express or tomwalters@0: implied warranty. tomwalters@0: tomwalters@0: THE MRC DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING tomwalters@0: ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL tomwalters@0: THE A.P.U. BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES tomwalters@0: OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, tomwalters@0: WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, tomwalters@0: ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS tomwalters@0: SOFTWARE. tomwalters@0: */ tomwalters@0: /* napheader.c tomwalters@0: * ---------- tomwalters@0: * tomwalters@0: * The .nap version of header.c tomwalters@0: * tomwalters@0: * M. Akeroyd. 10th June 1993. Revised Winter 1994. tomwalters@0: * tomwalters@0: */ tomwalters@0: tomwalters@0: tomwalters@0: #include tomwalters@0: #include tomwalters@0: #include tomwalters@0: #include "tip.h" tomwalters@0: tomwalters@0: void reset_header_bytes(); tomwalters@0: tomwalters@0: tomwalters@0: extern char progname[MAX_STRING_LENGTH]; tomwalters@0: extern char header[MAX_LINES_HEADER][MAX_LINE_LENGTH]; tomwalters@0: tomwalters@0: extern int verboseflag; tomwalters@0: extern int header_lines; /* number of lines in header */ tomwalters@0: extern int oppositearchflag; /* ON if reading Sun on DEC, or DEC on Sun.*/ tomwalters@0: tomwalters@0: /* .nap parameters */ tomwalters@0: tomwalters@0: extern int no_frames; tomwalters@0: extern int frameheight; /* number of channels */ tomwalters@0: extern int framewidth_samples; /* = 1 */ tomwalters@0: extern int frameshift_samples; /* = 1 */ tomwalters@0: extern int width_win; /* pixels */ tomwalters@0: extern int height_win; /* pixels */ tomwalters@0: extern long samplerate; /* samples per sec */ tomwalters@0: extern int mincf; /* Hz */ tomwalters@0: extern int maxcf; /* Hz */ tomwalters@0: tomwalters@0: tomwalters@0: tomwalters@0: tomwalters@0: int readheader_nap(FILE *inputfp) tomwalters@0: { tomwalters@0: /* Version of 10vi1993 tomwalters@0: */ tomwalters@0: tomwalters@0: char *p_equal=" "; /* pointer to where the '=' is in the headerline */ tomwalters@0: char tempstring[MAX_STRING_LENGTH]; tomwalters@0: tomwalters@0: int bytes_required = 0; /* no. of bytes in header, as in "header_bytes=... tomwalters@0: * This is RETURNed */ tomwalters@0: int bytes_loaded = 0; /* number actually loaded */ tomwalters@0: int counter; tomwalters@0: tomwalters@0: tomwalters@0: tomwalters@0: /* get first line */ tomwalters@0: header_lines = 0; tomwalters@0: fgets(header[0], MAX_LINE_LENGTH, inputfp); tomwalters@0: tomwalters@0: if(strspn(header[0], "header_bytes") == 0) { tomwalters@0: fprintf(stderr, "%s: is the input a AIM file?\n", progname); tomwalters@0: exit(-1);} tomwalters@0: tomwalters@0: /* find out how many bytes there SHOULD be */ tomwalters@0: p_equal = strchr(header[0], '='); tomwalters@0: bytes_required = atoi(++p_equal); tomwalters@0: tomwalters@0: tomwalters@0: /*--------------------------------------------------------------------------*/ tomwalters@0: tomwalters@0: /* loop on remaining lines, saving important information as required */ tomwalters@0: tomwalters@0: while (strncmp(fgets(header[++header_lines], MAX_LINE_LENGTH, inputfp), tomwalters@0: "Version=", 8) != 0) { tomwalters@0: if (strncmp(header[header_lines], "frameheight=", 12) == 0 ) { tomwalters@0: p_equal = strchr(header[header_lines], '='); tomwalters@0: frameheight = atoi(++p_equal); } tomwalters@0: tomwalters@0: if (strncmp(header[header_lines], "framewidth=", 11) == 0 ) { tomwalters@0: p_equal = strchr(header[header_lines], '='); tomwalters@0: framewidth_samples = atoi(++p_equal); } tomwalters@0: tomwalters@0: if (strncmp(header[header_lines], "frames=", 7) == 0 ) { tomwalters@0: p_equal = strchr(header[header_lines], '='); tomwalters@0: no_frames = atoi(++p_equal); } tomwalters@0: tomwalters@0: if (strncmp(header[header_lines], "frameshift=", 11) == 0 ) { tomwalters@0: p_equal = strchr(header[header_lines], '='); tomwalters@0: frameshift_samples = atoi(++p_equal); } tomwalters@0: tomwalters@0: if (strncmp(header[header_lines], "samplerate=", 11) == 0 ) { tomwalters@0: /* For some unknown reason, the samplerate has a "." at the tomwalters@0: * end of it. tomwalters@0: * Well, sometimes. tomwalters@0: */ tomwalters@0: strncpy(tempstring, header[header_lines], tomwalters@0: (strlen(header[header_lines])-0)); tomwalters@0: p_equal = strchr(tempstring, '='); tomwalters@0: samplerate = atol(++p_equal); } tomwalters@0: tomwalters@0: if (strncmp(header[header_lines], "width_win=", 10) == 0 ) { tomwalters@0: p_equal = strchr(header[header_lines], '='); tomwalters@0: width_win = atoi(++p_equal); } tomwalters@0: tomwalters@0: if (strncmp(header[header_lines], "height_win=", 11) == 0 ) { tomwalters@0: p_equal = strchr(header[header_lines], '='); tomwalters@0: height_win = atoi(++p_equal); } tomwalters@0: tomwalters@0: if (strncmp(header[header_lines], "mincf_afb=", 10) == 0 ) { tomwalters@0: p_equal = strchr(header[header_lines], '='); tomwalters@0: mincf = atoi(++p_equal); } tomwalters@0: tomwalters@0: if (strncmp(header[header_lines], "maxcf_afb=", 10) == 0 ) { tomwalters@0: p_equal = strchr(header[header_lines], '='); tomwalters@0: maxcf = atoi(++p_equal); } tomwalters@0: tomwalters@0: } tomwalters@0: tomwalters@0: /*-------------------------------------------------------------------------*/ tomwalters@0: tomwalters@0: /* Test for .nap: both frameshift_samples and framewidth_samples == 1 */ tomwalters@0: if ((framewidth_samples != 1) || (frameshift_samples != 1 )) { tomwalters@0: fprintf(stderr, " %s : is the input a .nap file?\n", progname); tomwalters@0: exit(-1); tomwalters@0: } tomwalters@0: tomwalters@0: /*------------------------------------------------------------------------*/ tomwalters@0: tomwalters@0: /* how many bytes have we loaded ? */ tomwalters@0: for (counter=0; counter<=header_lines; counter++) tomwalters@0: bytes_loaded += strlen(header[counter]); tomwalters@0: tomwalters@0: /* read some more bytes, till we are at the end of the header */ tomwalters@0: for (counter = 1; counter <= (bytes_required - bytes_loaded); counter++) tomwalters@0: fgetc(inputfp); tomwalters@0: tomwalters@0: /* read some more bytes, till we are at the end of the header */ tomwalters@0: for (counter = 1; counter <= (bytes_required - bytes_loaded); counter++) tomwalters@0: fgetc(inputfp); tomwalters@0: tomwalters@0: /* This next bit copied off header.c */ tomwalters@0: tomwalters@0: /* MAA: Winter 1994: Changed this bit to the "-oparch" option */ tomwalters@0: if (oppositearchflag == ON) tomwalters@0: fgetc(inputfp); /* THIS ONE !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/ tomwalters@0: tomwalters@0: return bytes_required; tomwalters@0: } tomwalters@0: tomwalters@0: tomwalters@0: tomwalters@0: tomwalters@0: tomwalters@0: tomwalters@0: tomwalters@0: int fakeheader_sai() tomwalters@0: { tomwalters@0: /* What this code does: tomwalters@0: * tomwalters@0: * It builds a "fake" .sai header, so that a .sai can be output tomwalters@0: * even though a .nap is input. tomwalters@0: * tomwalters@0: * The following bits are copied off the .nap header: tomwalters@0: * samplerate tomwalters@0: * width_win tomwalters@0: * height_win tomwalters@0: * frameheight tomwalters@0: * frameshift (hopefully this is irrelevant) tomwalters@0: * mincf tomwalters@0: * maxcf tomwalters@0: * tomwalters@0: * The following get set anyway, but are reset to the correct values by tomwalters@0: * changeheader(): tomwalters@0: * framewidth tomwalters@0: * framebytes tomwalters@0: * header_bytes tomwalters@0: * frames tomwalters@0: * pwidth tomwalters@0: * nwidth tomwalters@0: * tomwalters@0: * EVERYTHING else is completely fake. The numbers seem to be tomwalters@0: * reasonable: for a histogram graph .sai, though, none of them matter. tomwalters@0: * (Well, I hope not). tomwalters@0: * tomwalters@0: * The date is made up as well. tomwalters@0: */ tomwalters@0: tomwalters@0: int nwidth = -5; tomwalters@0: int pwidth = 20; tomwalters@0: int bytes = 1000; tomwalters@0: int framebytes=150000; tomwalters@0: tomwalters@0: tomwalters@0: /* strcpy(header[0], "header_bytes=\n"); */ tomwalters@0: strcpy(header[1], "llim_sas=1.5c\n"); tomwalters@0: strcpy(header[2], "ulim_sas=24ms\n"); tomwalters@0: strcpy(header[3], "decay_ai=15ms\n"); tomwalters@0: strcpy(header[4], "ltrate_ai=150Hz\n"); tomwalters@0: strcpy(header[5], "utrate_ai=20Hz\n"); tomwalters@0: strcpy(header[6], "ttdecay_ai=10\n"); tomwalters@0: strcpy(header[7], "napdecay_ai=1.25\n"); tomwalters@0: strcpy(header[8], "orig_spd=3.072\n"); tomwalters@0: strcpy(header[9], "zeroline_spd=off\n"); tomwalters@0: /* strcpy(header[10], "nwidth_aid=-5\n"); */ /* see below */ tomwalters@0: /* strcpy(header[11], "pwidth_aid=20\n"); */ /* see below */ tomwalters@0: strcpy(header[12], "frstep_aid=10\n"); tomwalters@0: strcpy(header[13], "frstep_epn=off\n"); tomwalters@0: strcpy(header[14], "downsample=off\n"); tomwalters@0: strcpy(header[15], "tup_idt=8ms\n"); tomwalters@0: strcpy(header[16], "tdown_idt=1\n"); tomwalters@0: strcpy(header[17], "loss_idt=1\n"); tomwalters@0: strcpy(header[18], "vloss_idt=0\n"); tomwalters@0: strcpy(header[19], "igain_idt=1\n"); tomwalters@0: strcpy(header[20], "stages_idt=off\n"); tomwalters@0: strcpy(header[21], "hard_limit=off\n"); tomwalters@0: strcpy(header[22], "meddis=off\n"); tomwalters@0: strcpy(header[23], "times_at=2\n"); tomwalters@0: strcpy(header[24], "reclimit_at=5\n"); tomwalters@0: strcpy(header[25], "frecovery_at=20.\n"); tomwalters@0: strcpy(header[26], "propt2t1_at=0.5\n"); tomwalters@0: strcpy(header[27], "t2recovery_at=0.2\n"); tomwalters@0: strcpy(header[28], "t1recovery_at=0.6\n"); tomwalters@0: strcpy(header[29], "trise_at=10000.\n"); tomwalters@0: strcpy(header[30], "scale_at=100\n"); tomwalters@0: strcpy(header[31], "ltdown_lpf=1\n"); tomwalters@0: strcpy(header[32], "lloss_lpf=1\n"); tomwalters@0: strcpy(header[33], "lvloss_lpf=0\n"); tomwalters@0: strcpy(header[34], "ligain_lpf=1\n"); tomwalters@0: strcpy(header[35], "compress=on\n"); tomwalters@0: strcpy(header[36], "rectify=off\n"); tomwalters@0: strcpy(header[37], "order_gtf=4\n"); tomwalters@0: strcpy(header[38], "phase_gtf=0\n"); tomwalters@0: strcpy(header[39], "gain_gtf=4.\n"); tomwalters@0: strcpy(header[40], "float_gtf=off\n"); tomwalters@0: strcpy(header[41], "audiogram_afb=on\n"); tomwalters@0: strcpy(header[42], "quality_afb=9.265\n"); tomwalters@0: strcpy(header[43], "bwmin_afb=24.7Hz\n"); tomwalters@0: strcpy(header[44], "interp_afb=off\n"); tomwalters@0: strcpy(header[45], "dencf_afb=off\n"); tomwalters@0: /* strcpy(header[46], "maxcf_afb=6000Hz\n"); */ /* see below */ tomwalters@0: /* strcpy(header[47], "mincf_afb=100Hz\n"); */ /* see below */ tomwalters@0: /* strcpy(header[48], "channels_afb=100\n"); */ /* see below */ tomwalters@0: strcpy(header[49], "bits_wave=12\n"); tomwalters@0: strcpy(header[50], "swap_wave=on\n"); tomwalters@0: /* strcpy(header[51], "samplerate=20000\n"); */ /* see below */ tomwalters@0: /* strcpy(header[52], "frames=10\n"); */ /* see below */ tomwalters@0: /* strcpy(header[53], "frameshift=200\n"); */ /* see below */ tomwalters@0: /* strcpy(header[54], "framewidth=500\n"); */ /* see below */ tomwalters@0: /* strcpy(header[55], "frameheight=100\n"); */ /* see below */ tomwalters@0: /* strcpy(header[56], "framebytes=100000\n"); */ /* see below */ tomwalters@0: strcpy(header[57], "type=short\n"); tomwalters@0: strcpy(header[58], "bytemax=255\n"); tomwalters@0: strcpy(header[59], "header=on\n"); tomwalters@0: strcpy(header[60], "animate_ctn=off\n"); tomwalters@0: strcpy(header[61], "erase_ctn=on\n"); tomwalters@0: strcpy(header[62], "downchannel=off\n"); tomwalters@0: strcpy(header[63], "view=landscape\n"); tomwalters@0: strcpy(header[64], "display=on\n"); tomwalters@0: /* strcpy(header[65], "height_win=400\n"); */ /* see below */ tomwalters@0: /* strcpy(header[66], "width_win=540\n"); */ /* see below */ tomwalters@0: strcpy(header[67], "y0_win=center\n"); tomwalters@0: strcpy(header[68], "x0_win=center\n"); tomwalters@0: strcpy(header[69], "Version=\"AICAP Version R6.3 Mon Jan 00 00:00:00 1900\"\n"); tomwalters@0: tomwalters@0: tomwalters@0: tomwalters@0: /* Fill in the values from .nap tomwalters@0: * All the ones with "/* ..." next to are set anyway; they are tomwalters@0: * overwritten with the REAL .sai values in changeheader tomwalters@0: */ tomwalters@0: tomwalters@0: tomwalters@0: sprintf(header[0], "header_bytes=0001000\n"); tomwalters@0: sprintf(header[46], "maxcf_afb=%d\n", maxcf); tomwalters@0: sprintf(header[47], "mincf_afb=%d\n", mincf); tomwalters@0: sprintf(header[51], "samplerate=%d\n", samplerate); tomwalters@0: sprintf(header[52], "frames=%d\n", no_frames); /* */ tomwalters@0: sprintf(header[53], "frameshift=%d\n", frameshift_samples); tomwalters@0: sprintf(header[54], "framewidth=%d\n", framewidth_samples); /* */ tomwalters@0: sprintf(header[48], "channels_afb=%d\n", frameheight); tomwalters@0: sprintf(header[55], "frameheight=%d\n", frameheight); tomwalters@0: sprintf(header[56], "framebytes=%d\n", framebytes); /* */ tomwalters@0: sprintf(header[65], "height_win=%d\n", 400); tomwalters@0: sprintf(header[66], "width_win=%d\n", 540); tomwalters@0: sprintf(header[10], "nwidth_aid=%d\n", nwidth); /* */ tomwalters@0: sprintf(header[11], "pwidth_aid=%d\n", pwidth); /* */ tomwalters@0: tomwalters@0: header_lines=69; tomwalters@0: reset_header_bytes(); tomwalters@0: tomwalters@0: /* RETURN the number of lines */ tomwalters@0: return 69; tomwalters@0: } tomwalters@0: tomwalters@0: tomwalters@0: tomwalters@0: tomwalters@0: /* The End ...............................................................*/ tomwalters@0: /*........................................................................*/