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: tomwalters@0: /* ------------------------------------------------------------------------*/ tomwalters@0: tomwalters@0: /* changeheader.c tomwalters@0: * ---------------- tomwalters@0: * tomwalters@0: * 'fakes' sai & nap headers. tomwalters@0: * tomwalters@0: * M.Akeroyd. Summer 1993. Revised 1994. tomwalters@0: */ tomwalters@0: tomwalters@0: tomwalters@0: #include tomwalters@0: #include tomwalters@0: #include tomwalters@0: #include "tip.h" tomwalters@0: tomwalters@0: tomwalters@0: void reset_header_bytes(); tomwalters@0: void change_framebytes(); 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: 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: extern int greyscaleflag; /* ON or OFF */ tomwalters@0: tomwalters@0: tomwalters@0: tomwalters@0: /* ------------------------------------------------------------------------*/ tomwalters@0: tomwalters@0: tomwalters@0: tomwalters@0: void changeheader(int no_frames, int new_pwidth, int new_nwidth, int framewidth_samples_output) tomwalters@0: { tomwalters@0: /* Reset various values: tomwalters@0: * tomwalters@0: * number of frames -> no_frames tomwalters@0: * pwidth -> new_pwidth tomwalters@0: * nwidth -> new_nwidth tomwalters@0: * framewidth -> (pwidth+nwidth * samplerate). in msecs tomwalters@0: * header_bytes tomwalters@0: * tomwalters@0: */ tomwalters@0: tomwalters@0: int new_header_length = 0; tomwalters@0: int counter; tomwalters@0: char tempstring[MAX_STRING_LENGTH]; tomwalters@0: char tempstring2[MAX_STRING_LENGTH]; tomwalters@0: tomwalters@0: tomwalters@0: /*-------------------------------- */ tomwalters@0: tomwalters@0: for(counter=1; counter<=header_lines; counter++){ tomwalters@0: tomwalters@0: /* frames */ tomwalters@0: if (strncmp(header[counter], "frames=", 7) == 0 ) { tomwalters@0: sprintf(header[counter], "frames=%d\n", no_frames);} tomwalters@0: tomwalters@0: /* pwidth */ tomwalters@0: if (strncmp(header[counter], "pwidth_aid=", 11) == 0 ) tomwalters@0: sprintf(header[counter], "pwidth_aid=%d\n", new_pwidth); tomwalters@0: tomwalters@0: /* nwidth */ tomwalters@0: /* include a gratuitous minus */ tomwalters@0: if (strncmp(header[counter], "nwidth_aid=", 11) == 0 ) tomwalters@0: if (new_nwidth < 0) tomwalters@0: sprintf(header[counter], "nwidth_aid=%d\n", new_nwidth); tomwalters@0: else tomwalters@0: sprintf(header[counter], "nwidth_aid=-%d\n", new_nwidth); tomwalters@0: tomwalters@0: /* framewidth */ tomwalters@0: if (strncmp(header[counter], "framewidth=", 11) == 0 ) tomwalters@0: sprintf(header[counter], "framewidth=%d\n", framewidth_samples_output); tomwalters@0: tomwalters@0: /*view=landscape */ tomwalters@0: if (greyscaleflag == ON) tomwalters@0: if (strncmp(header[counter], "view=landscape", 14) == 0 ) tomwalters@0: sprintf(header[counter], "view=greyscale\n"); tomwalters@0: tomwalters@0: } tomwalters@0: tomwalters@0: /* reset framebytes */ tomwalters@0: change_framebytes(); tomwalters@0: tomwalters@0: /* reset header */ tomwalters@0: reset_header_bytes; tomwalters@0: tomwalters@0: } tomwalters@0: tomwalters@0: tomwalters@0: tomwalters@0: /* ------------------------------------------------------------------------*/ tomwalters@0: tomwalters@0: tomwalters@0: void change_framebytes() tomwalters@0: { tomwalters@0: /* This is seperate beacuse it depends on lots of things tomwalters@0: * framebytes -> frameheight * framewidth *2 (bytes), I hope. tomwalters@0: */ tomwalters@0: tomwalters@0: int counter; tomwalters@0: char *p_equal=" "; /* pointer to where the '=' is in the headerline */ tomwalters@0: char tempstring[MAX_STRING_LENGTH]; tomwalters@0: int local_frameheight = 0; tomwalters@0: int local_framewidth = 0; tomwalters@0: tomwalters@0: /* find out the values */ tomwalters@0: tomwalters@0: for(counter=1; counter<=header_lines; counter++) { tomwalters@0: if (strncmp(header[counter], "frameheight=", 12) == 0 ) { tomwalters@0: p_equal = strchr(header[counter], '='); tomwalters@0: local_frameheight = atoi(++p_equal); } tomwalters@0: if (strncmp(header[counter], "framewidth=", 11) == 0 ) { tomwalters@0: p_equal = strchr(header[counter], '='); tomwalters@0: local_framewidth = atoi(++p_equal); }} tomwalters@0: tomwalters@0: /* put in new value */ tomwalters@0: tomwalters@0: for(counter=1; counter<=header_lines; counter++){ tomwalters@0: if (strncmp(header[counter], "framebytes=", 11) == 0 ) tomwalters@0: sprintf(header[counter], "framebytes=%d\n", (local_framewidth * local_frameheight *2)); tomwalters@0: } tomwalters@0: } tomwalters@0: tomwalters@0: tomwalters@0: tomwalters@0: /* ------------------------------------------------------------------------*/ tomwalters@0: tomwalters@0: tomwalters@0: tomwalters@0: void reset_header_bytes() tomwalters@0: { tomwalters@0: /* What this code does: tomwalters@0: * tomwalters@0: * My latest attempt to get the "header_bytes" field to be set to the tomwalters@0: * right number, well, one that AIM accepts. tomwalters@0: * tomwalters@0: * At the moment, it assumes tomwalters@0: * (1) all headers are an even number of bytes long tomwalters@0: * (2) the field is 7 characters long tomwalters@0: * (3) header_bytes = total length of all strings in header tomwalters@0: + 2 tomwalters@0: * tomwalters@0: */ tomwalters@0: tomwalters@0: int new_header_length = 0; tomwalters@0: int counter; tomwalters@0: char tempstring[MAX_STRING_LENGTH]; tomwalters@0: char tempstring2[MAX_STRING_LENGTH]; tomwalters@0: tomwalters@0: /* find out how many bytes there SHOULD be */ tomwalters@0: for(counter=0; counter<=header_lines; counter++) tomwalters@0: new_header_length = new_header_length + strlen(header[counter]); tomwalters@0: tomwalters@0: /* If this is odd, change to even.*/ tomwalters@0: if ((new_header_length % 2) == 1) tomwalters@0: new_header_length ++; tomwalters@0: tomwalters@0: /* add 2 to it */ tomwalters@0: new_header_length += 2; tomwalters@0: tomwalters@0: /* put lots of zeros on front */ tomwalters@0: sprintf(tempstring, "%d", new_header_length); tomwalters@0: tomwalters@0: /* add enough zero's on front to make it 7 chars long. tomwalters@0: * Since this was the length of the input's field, I don't need to tomwalters@0: * worry about it changing the true length of the header */ tomwalters@0: tomwalters@0: while (strlen(tempstring) != 7 ){ tomwalters@0: strcpy(tempstring2, "0"); tomwalters@0: strcat(tempstring2, tempstring); tomwalters@0: strcpy(tempstring, tempstring2);} tomwalters@0: tomwalters@0: tomwalters@0: /* use this value to reset header_bytes */ tomwalters@0: sprintf(header[0], "header_bytes=%s\n", tempstring); tomwalters@0: tomwalters@0: } tomwalters@0: tomwalters@0: tomwalters@0: tomwalters@0: /* ------------------------------------------------------------------------*/ tomwalters@0: tomwalters@0: tomwalters@0: tomwalters@0: void changeheader_B(int new_mincf, int new_maxcf, int new_channels) tomwalters@0: { tomwalters@0: /* Reset various values: tomwalters@0: * tomwalters@0: * mincf == new_mincf tomwalters@0: * maxcf == new_maxcf tomwalters@0: * channels = framehieght == new_channels tomwalters@0: * tomwalters@0: * NB This assumes "channels=" and "frameheight=" are both set to the tomwalters@0: * same value. I haven't yet seen a .sai in which they are tomwalters@0: * different, but I haven't looked too hard. tomwalters@0: * tomwalters@0: */ tomwalters@0: tomwalters@0: int new_header_length = 0; tomwalters@0: int counter; tomwalters@0: char tempstring[MAX_STRING_LENGTH]; tomwalters@0: char tempstring2[MAX_STRING_LENGTH]; tomwalters@0: tomwalters@0: tomwalters@0: for(counter=1; counter<=header_lines; counter++){ tomwalters@0: tomwalters@0: /* mincf */ tomwalters@0: if (strncmp(header[counter], "mincf_afb=", 10) == 0 ) { tomwalters@0: sprintf(header[counter], "mincf_afb=%d\n", new_mincf);} tomwalters@0: tomwalters@0: /* maxcf */ tomwalters@0: if (strncmp(header[counter], "maxcf_afb=", 10) == 0 ) { tomwalters@0: sprintf(header[counter], "maxcf_afb=%d\n", new_maxcf);} tomwalters@0: tomwalters@0: /* channels */ tomwalters@0: if (strncmp(header[counter], "channels_afb=", 12) == 0 ) { tomwalters@0: sprintf(header[counter], "channels_afb=%d\n", new_channels);} tomwalters@0: tomwalters@0: /* frameheight */ tomwalters@0: if (strncmp(header[counter], "frameheight=", 12) == 0 ) tomwalters@0: sprintf(header[counter], "frameheight=%d\n", new_channels); tomwalters@0: tomwalters@0: } tomwalters@0: tomwalters@0: /* reset framebytes */ tomwalters@0: change_framebytes(); tomwalters@0: tomwalters@0: /* reset header */ tomwalters@0: reset_header_bytes; tomwalters@0: tomwalters@0: } tomwalters@0: tomwalters@0: tomwalters@0: /* The End */ tomwalters@0: /* ------------------------------------------------------------------------*/ tomwalters@0: tomwalters@0: tomwalters@0: tomwalters@0: tomwalters@0: tomwalters@0: tomwalters@0: tomwalters@0: tomwalters@0: