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