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