comparison 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
comparison
equal deleted inserted replaced
-1:000000000000 0:5242703e91d3
1 /*
2 Copyright (c) Applied Psychology Unit, Medical Research Council. 1993
3 ===========================================================================
4
5 Permission to use, copy, modify, and distribute this software without fee
6 is hereby granted for research purposes, provided that this copyright
7 notice appears in all copies and in all supporting documentation, and that
8 the software is not redistributed for any fee (except for a nominal
9 shipping charge). Anyone wanting to incorporate all or part of this
10 software in a commercial product must obtain a license from the Medical
11 Research Council.
12
13 The MRC makes no representations about the suitability of this
14 software for any purpose. It is provided "as is" without express or
15 implied warranty.
16
17 THE MRC DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
18 ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
19 THE A.P.U. BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES
20 OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
21 WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
22 ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
23 SOFTWARE.
24 */
25 /* napheader.c
26 * ----------
27 *
28 * The .nap version of header.c
29 *
30 * M. Akeroyd. 10th June 1993. Revised Winter 1994.
31 *
32 */
33
34
35 #include <stdio.h>
36 #include <string.h>
37 #include <stdlib.h>
38 #include "tip.h"
39
40 void reset_header_bytes();
41
42
43 extern char progname[MAX_STRING_LENGTH];
44 extern char header[MAX_LINES_HEADER][MAX_LINE_LENGTH];
45
46 extern int verboseflag;
47 extern int header_lines; /* number of lines in header */
48 extern int oppositearchflag; /* ON if reading Sun on DEC, or DEC on Sun.*/
49
50 /* .nap parameters */
51
52 extern int no_frames;
53 extern int frameheight; /* number of channels */
54 extern int framewidth_samples; /* = 1 */
55 extern int frameshift_samples; /* = 1 */
56 extern int width_win; /* pixels */
57 extern int height_win; /* pixels */
58 extern long samplerate; /* samples per sec */
59 extern int mincf; /* Hz */
60 extern int maxcf; /* Hz */
61
62
63
64
65 int readheader_nap(FILE *inputfp)
66 {
67 /* Version of 10vi1993
68 */
69
70 char *p_equal=" "; /* pointer to where the '=' is in the headerline */
71 char tempstring[MAX_STRING_LENGTH];
72
73 int bytes_required = 0; /* no. of bytes in header, as in "header_bytes=...
74 * This is RETURNed */
75 int bytes_loaded = 0; /* number actually loaded */
76 int counter;
77
78
79
80 /* get first line */
81 header_lines = 0;
82 fgets(header[0], MAX_LINE_LENGTH, inputfp);
83
84 if(strspn(header[0], "header_bytes") == 0) {
85 fprintf(stderr, "%s: is the input a AIM file?\n", progname);
86 exit(-1);}
87
88 /* find out how many bytes there SHOULD be */
89 p_equal = strchr(header[0], '=');
90 bytes_required = atoi(++p_equal);
91
92
93 /*--------------------------------------------------------------------------*/
94
95 /* loop on remaining lines, saving important information as required */
96
97 while (strncmp(fgets(header[++header_lines], MAX_LINE_LENGTH, inputfp),
98 "Version=", 8) != 0) {
99 if (strncmp(header[header_lines], "frameheight=", 12) == 0 ) {
100 p_equal = strchr(header[header_lines], '=');
101 frameheight = atoi(++p_equal); }
102
103 if (strncmp(header[header_lines], "framewidth=", 11) == 0 ) {
104 p_equal = strchr(header[header_lines], '=');
105 framewidth_samples = atoi(++p_equal); }
106
107 if (strncmp(header[header_lines], "frames=", 7) == 0 ) {
108 p_equal = strchr(header[header_lines], '=');
109 no_frames = atoi(++p_equal); }
110
111 if (strncmp(header[header_lines], "frameshift=", 11) == 0 ) {
112 p_equal = strchr(header[header_lines], '=');
113 frameshift_samples = atoi(++p_equal); }
114
115 if (strncmp(header[header_lines], "samplerate=", 11) == 0 ) {
116 /* For some unknown reason, the samplerate has a "." at the
117 * end of it.
118 * Well, sometimes.
119 */
120 strncpy(tempstring, header[header_lines],
121 (strlen(header[header_lines])-0));
122 p_equal = strchr(tempstring, '=');
123 samplerate = atol(++p_equal); }
124
125 if (strncmp(header[header_lines], "width_win=", 10) == 0 ) {
126 p_equal = strchr(header[header_lines], '=');
127 width_win = atoi(++p_equal); }
128
129 if (strncmp(header[header_lines], "height_win=", 11) == 0 ) {
130 p_equal = strchr(header[header_lines], '=');
131 height_win = atoi(++p_equal); }
132
133 if (strncmp(header[header_lines], "mincf_afb=", 10) == 0 ) {
134 p_equal = strchr(header[header_lines], '=');
135 mincf = atoi(++p_equal); }
136
137 if (strncmp(header[header_lines], "maxcf_afb=", 10) == 0 ) {
138 p_equal = strchr(header[header_lines], '=');
139 maxcf = atoi(++p_equal); }
140
141 }
142
143 /*-------------------------------------------------------------------------*/
144
145 /* Test for .nap: both frameshift_samples and framewidth_samples == 1 */
146 if ((framewidth_samples != 1) || (frameshift_samples != 1 )) {
147 fprintf(stderr, " %s : is the input a .nap file?\n", progname);
148 exit(-1);
149 }
150
151 /*------------------------------------------------------------------------*/
152
153 /* how many bytes have we loaded ? */
154 for (counter=0; counter<=header_lines; counter++)
155 bytes_loaded += strlen(header[counter]);
156
157 /* read some more bytes, till we are at the end of the header */
158 for (counter = 1; counter <= (bytes_required - bytes_loaded); counter++)
159 fgetc(inputfp);
160
161 /* read some more bytes, till we are at the end of the header */
162 for (counter = 1; counter <= (bytes_required - bytes_loaded); counter++)
163 fgetc(inputfp);
164
165 /* This next bit copied off header.c */
166
167 /* MAA: Winter 1994: Changed this bit to the "-oparch" option */
168 if (oppositearchflag == ON)
169 fgetc(inputfp); /* THIS ONE !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
170
171 return bytes_required;
172 }
173
174
175
176
177
178
179
180 int fakeheader_sai()
181 {
182 /* What this code does:
183 *
184 * It builds a "fake" .sai header, so that a .sai can be output
185 * even though a .nap is input.
186 *
187 * The following bits are copied off the .nap header:
188 * samplerate
189 * width_win
190 * height_win
191 * frameheight
192 * frameshift (hopefully this is irrelevant)
193 * mincf
194 * maxcf
195 *
196 * The following get set anyway, but are reset to the correct values by
197 * changeheader():
198 * framewidth
199 * framebytes
200 * header_bytes
201 * frames
202 * pwidth
203 * nwidth
204 *
205 * EVERYTHING else is completely fake. The numbers seem to be
206 * reasonable: for a histogram graph .sai, though, none of them matter.
207 * (Well, I hope not).
208 *
209 * The date is made up as well.
210 */
211
212 int nwidth = -5;
213 int pwidth = 20;
214 int bytes = 1000;
215 int framebytes=150000;
216
217
218 /* strcpy(header[0], "header_bytes=\n"); */
219 strcpy(header[1], "llim_sas=1.5c\n");
220 strcpy(header[2], "ulim_sas=24ms\n");
221 strcpy(header[3], "decay_ai=15ms\n");
222 strcpy(header[4], "ltrate_ai=150Hz\n");
223 strcpy(header[5], "utrate_ai=20Hz\n");
224 strcpy(header[6], "ttdecay_ai=10\n");
225 strcpy(header[7], "napdecay_ai=1.25\n");
226 strcpy(header[8], "orig_spd=3.072\n");
227 strcpy(header[9], "zeroline_spd=off\n");
228 /* strcpy(header[10], "nwidth_aid=-5\n"); */ /* see below */
229 /* strcpy(header[11], "pwidth_aid=20\n"); */ /* see below */
230 strcpy(header[12], "frstep_aid=10\n");
231 strcpy(header[13], "frstep_epn=off\n");
232 strcpy(header[14], "downsample=off\n");
233 strcpy(header[15], "tup_idt=8ms\n");
234 strcpy(header[16], "tdown_idt=1\n");
235 strcpy(header[17], "loss_idt=1\n");
236 strcpy(header[18], "vloss_idt=0\n");
237 strcpy(header[19], "igain_idt=1\n");
238 strcpy(header[20], "stages_idt=off\n");
239 strcpy(header[21], "hard_limit=off\n");
240 strcpy(header[22], "meddis=off\n");
241 strcpy(header[23], "times_at=2\n");
242 strcpy(header[24], "reclimit_at=5\n");
243 strcpy(header[25], "frecovery_at=20.\n");
244 strcpy(header[26], "propt2t1_at=0.5\n");
245 strcpy(header[27], "t2recovery_at=0.2\n");
246 strcpy(header[28], "t1recovery_at=0.6\n");
247 strcpy(header[29], "trise_at=10000.\n");
248 strcpy(header[30], "scale_at=100\n");
249 strcpy(header[31], "ltdown_lpf=1\n");
250 strcpy(header[32], "lloss_lpf=1\n");
251 strcpy(header[33], "lvloss_lpf=0\n");
252 strcpy(header[34], "ligain_lpf=1\n");
253 strcpy(header[35], "compress=on\n");
254 strcpy(header[36], "rectify=off\n");
255 strcpy(header[37], "order_gtf=4\n");
256 strcpy(header[38], "phase_gtf=0\n");
257 strcpy(header[39], "gain_gtf=4.\n");
258 strcpy(header[40], "float_gtf=off\n");
259 strcpy(header[41], "audiogram_afb=on\n");
260 strcpy(header[42], "quality_afb=9.265\n");
261 strcpy(header[43], "bwmin_afb=24.7Hz\n");
262 strcpy(header[44], "interp_afb=off\n");
263 strcpy(header[45], "dencf_afb=off\n");
264 /* strcpy(header[46], "maxcf_afb=6000Hz\n"); */ /* see below */
265 /* strcpy(header[47], "mincf_afb=100Hz\n"); */ /* see below */
266 /* strcpy(header[48], "channels_afb=100\n"); */ /* see below */
267 strcpy(header[49], "bits_wave=12\n");
268 strcpy(header[50], "swap_wave=on\n");
269 /* strcpy(header[51], "samplerate=20000\n"); */ /* see below */
270 /* strcpy(header[52], "frames=10\n"); */ /* see below */
271 /* strcpy(header[53], "frameshift=200\n"); */ /* see below */
272 /* strcpy(header[54], "framewidth=500\n"); */ /* see below */
273 /* strcpy(header[55], "frameheight=100\n"); */ /* see below */
274 /* strcpy(header[56], "framebytes=100000\n"); */ /* see below */
275 strcpy(header[57], "type=short\n");
276 strcpy(header[58], "bytemax=255\n");
277 strcpy(header[59], "header=on\n");
278 strcpy(header[60], "animate_ctn=off\n");
279 strcpy(header[61], "erase_ctn=on\n");
280 strcpy(header[62], "downchannel=off\n");
281 strcpy(header[63], "view=landscape\n");
282 strcpy(header[64], "display=on\n");
283 /* strcpy(header[65], "height_win=400\n"); */ /* see below */
284 /* strcpy(header[66], "width_win=540\n"); */ /* see below */
285 strcpy(header[67], "y0_win=center\n");
286 strcpy(header[68], "x0_win=center\n");
287 strcpy(header[69], "Version=\"AICAP Version R6.3 Mon Jan 00 00:00:00 1900\"\n");
288
289
290
291 /* Fill in the values from .nap
292 * All the ones with "/* ..." next to are set anyway; they are
293 * overwritten with the REAL .sai values in changeheader
294 */
295
296
297 sprintf(header[0], "header_bytes=0001000\n");
298 sprintf(header[46], "maxcf_afb=%d\n", maxcf);
299 sprintf(header[47], "mincf_afb=%d\n", mincf);
300 sprintf(header[51], "samplerate=%d\n", samplerate);
301 sprintf(header[52], "frames=%d\n", no_frames); /* */
302 sprintf(header[53], "frameshift=%d\n", frameshift_samples);
303 sprintf(header[54], "framewidth=%d\n", framewidth_samples); /* */
304 sprintf(header[48], "channels_afb=%d\n", frameheight);
305 sprintf(header[55], "frameheight=%d\n", frameheight);
306 sprintf(header[56], "framebytes=%d\n", framebytes); /* */
307 sprintf(header[65], "height_win=%d\n", 400);
308 sprintf(header[66], "width_win=%d\n", 540);
309 sprintf(header[10], "nwidth_aid=%d\n", nwidth); /* */
310 sprintf(header[11], "pwidth_aid=%d\n", pwidth); /* */
311
312 header_lines=69;
313 reset_header_bytes();
314
315 /* RETURN the number of lines */
316 return 69;
317 }
318
319
320
321
322 /* The End ...............................................................*/
323 /*........................................................................*/