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
|
tomwalters@0
|
26 /* ------------------------------------------------------------------------*/
|
tomwalters@0
|
27
|
tomwalters@0
|
28 /* changeheader.c
|
tomwalters@0
|
29 * ----------------
|
tomwalters@0
|
30 *
|
tomwalters@0
|
31 * 'fakes' sai & nap headers.
|
tomwalters@0
|
32 *
|
tomwalters@0
|
33 * M.Akeroyd. Summer 1993. Revised 1994.
|
tomwalters@0
|
34 */
|
tomwalters@0
|
35
|
tomwalters@0
|
36
|
tomwalters@0
|
37 #include <stdio.h>
|
tomwalters@0
|
38 #include <string.h>
|
tomwalters@0
|
39 #include <stdlib.h>
|
tomwalters@0
|
40 #include "tip.h"
|
tomwalters@0
|
41
|
tomwalters@0
|
42
|
tomwalters@0
|
43 void reset_header_bytes();
|
tomwalters@0
|
44 void change_framebytes();
|
tomwalters@0
|
45
|
tomwalters@0
|
46 extern char progname[MAX_STRING_LENGTH];
|
tomwalters@0
|
47 extern char header[MAX_LINES_HEADER][MAX_LINE_LENGTH];
|
tomwalters@0
|
48
|
tomwalters@0
|
49 extern int verboseflag;
|
tomwalters@0
|
50 extern int header_lines; /* number of lines in header */
|
tomwalters@0
|
51
|
tomwalters@0
|
52
|
tomwalters@0
|
53 /* .nap parameters */
|
tomwalters@0
|
54
|
tomwalters@0
|
55 extern int no_frames;
|
tomwalters@0
|
56 extern int frameheight; /* number of channels */
|
tomwalters@0
|
57 extern int framewidth_samples; /* = 1
|
tomwalters@0
|
58 extern int frameshift_samples; /* = 1 */
|
tomwalters@0
|
59 extern int width_win; /* pixels */
|
tomwalters@0
|
60 extern int height_win; /* pixels */
|
tomwalters@0
|
61 extern long samplerate; /* samples per sec */
|
tomwalters@0
|
62 extern int mincf; /* Hz */
|
tomwalters@0
|
63 extern int maxcf; /* Hz */
|
tomwalters@0
|
64
|
tomwalters@0
|
65 extern int greyscaleflag; /* ON or OFF */
|
tomwalters@0
|
66
|
tomwalters@0
|
67
|
tomwalters@0
|
68
|
tomwalters@0
|
69 /* ------------------------------------------------------------------------*/
|
tomwalters@0
|
70
|
tomwalters@0
|
71
|
tomwalters@0
|
72
|
tomwalters@0
|
73 void changeheader(int no_frames, int new_pwidth, int new_nwidth, int framewidth_samples_output)
|
tomwalters@0
|
74 {
|
tomwalters@0
|
75 /* Reset various values:
|
tomwalters@0
|
76 *
|
tomwalters@0
|
77 * number of frames -> no_frames
|
tomwalters@0
|
78 * pwidth -> new_pwidth
|
tomwalters@0
|
79 * nwidth -> new_nwidth
|
tomwalters@0
|
80 * framewidth -> (pwidth+nwidth * samplerate). in msecs
|
tomwalters@0
|
81 * header_bytes
|
tomwalters@0
|
82 *
|
tomwalters@0
|
83 */
|
tomwalters@0
|
84
|
tomwalters@0
|
85 int new_header_length = 0;
|
tomwalters@0
|
86 int counter;
|
tomwalters@0
|
87 char tempstring[MAX_STRING_LENGTH];
|
tomwalters@0
|
88 char tempstring2[MAX_STRING_LENGTH];
|
tomwalters@0
|
89
|
tomwalters@0
|
90
|
tomwalters@0
|
91 /*-------------------------------- */
|
tomwalters@0
|
92
|
tomwalters@0
|
93 for(counter=1; counter<=header_lines; counter++){
|
tomwalters@0
|
94
|
tomwalters@0
|
95 /* frames */
|
tomwalters@0
|
96 if (strncmp(header[counter], "frames=", 7) == 0 ) {
|
tomwalters@0
|
97 sprintf(header[counter], "frames=%d\n", no_frames);}
|
tomwalters@0
|
98
|
tomwalters@0
|
99 /* pwidth */
|
tomwalters@0
|
100 if (strncmp(header[counter], "pwidth_aid=", 11) == 0 )
|
tomwalters@0
|
101 sprintf(header[counter], "pwidth_aid=%d\n", new_pwidth);
|
tomwalters@0
|
102
|
tomwalters@0
|
103 /* nwidth */
|
tomwalters@0
|
104 /* include a gratuitous minus */
|
tomwalters@0
|
105 if (strncmp(header[counter], "nwidth_aid=", 11) == 0 )
|
tomwalters@0
|
106 if (new_nwidth < 0)
|
tomwalters@0
|
107 sprintf(header[counter], "nwidth_aid=%d\n", new_nwidth);
|
tomwalters@0
|
108 else
|
tomwalters@0
|
109 sprintf(header[counter], "nwidth_aid=-%d\n", new_nwidth);
|
tomwalters@0
|
110
|
tomwalters@0
|
111 /* framewidth */
|
tomwalters@0
|
112 if (strncmp(header[counter], "framewidth=", 11) == 0 )
|
tomwalters@0
|
113 sprintf(header[counter], "framewidth=%d\n", framewidth_samples_output);
|
tomwalters@0
|
114
|
tomwalters@0
|
115 /*view=landscape */
|
tomwalters@0
|
116 if (greyscaleflag == ON)
|
tomwalters@0
|
117 if (strncmp(header[counter], "view=landscape", 14) == 0 )
|
tomwalters@0
|
118 sprintf(header[counter], "view=greyscale\n");
|
tomwalters@0
|
119
|
tomwalters@0
|
120 }
|
tomwalters@0
|
121
|
tomwalters@0
|
122 /* reset framebytes */
|
tomwalters@0
|
123 change_framebytes();
|
tomwalters@0
|
124
|
tomwalters@0
|
125 /* reset header */
|
tomwalters@0
|
126 reset_header_bytes;
|
tomwalters@0
|
127
|
tomwalters@0
|
128 }
|
tomwalters@0
|
129
|
tomwalters@0
|
130
|
tomwalters@0
|
131
|
tomwalters@0
|
132 /* ------------------------------------------------------------------------*/
|
tomwalters@0
|
133
|
tomwalters@0
|
134
|
tomwalters@0
|
135 void change_framebytes()
|
tomwalters@0
|
136 {
|
tomwalters@0
|
137 /* This is seperate beacuse it depends on lots of things
|
tomwalters@0
|
138 * framebytes -> frameheight * framewidth *2 (bytes), I hope.
|
tomwalters@0
|
139 */
|
tomwalters@0
|
140
|
tomwalters@0
|
141 int counter;
|
tomwalters@0
|
142 char *p_equal=" "; /* pointer to where the '=' is in the headerline */
|
tomwalters@0
|
143 char tempstring[MAX_STRING_LENGTH];
|
tomwalters@0
|
144 int local_frameheight = 0;
|
tomwalters@0
|
145 int local_framewidth = 0;
|
tomwalters@0
|
146
|
tomwalters@0
|
147 /* find out the values */
|
tomwalters@0
|
148
|
tomwalters@0
|
149 for(counter=1; counter<=header_lines; counter++) {
|
tomwalters@0
|
150 if (strncmp(header[counter], "frameheight=", 12) == 0 ) {
|
tomwalters@0
|
151 p_equal = strchr(header[counter], '=');
|
tomwalters@0
|
152 local_frameheight = atoi(++p_equal); }
|
tomwalters@0
|
153 if (strncmp(header[counter], "framewidth=", 11) == 0 ) {
|
tomwalters@0
|
154 p_equal = strchr(header[counter], '=');
|
tomwalters@0
|
155 local_framewidth = atoi(++p_equal); }}
|
tomwalters@0
|
156
|
tomwalters@0
|
157 /* put in new value */
|
tomwalters@0
|
158
|
tomwalters@0
|
159 for(counter=1; counter<=header_lines; counter++){
|
tomwalters@0
|
160 if (strncmp(header[counter], "framebytes=", 11) == 0 )
|
tomwalters@0
|
161 sprintf(header[counter], "framebytes=%d\n", (local_framewidth * local_frameheight *2));
|
tomwalters@0
|
162 }
|
tomwalters@0
|
163 }
|
tomwalters@0
|
164
|
tomwalters@0
|
165
|
tomwalters@0
|
166
|
tomwalters@0
|
167 /* ------------------------------------------------------------------------*/
|
tomwalters@0
|
168
|
tomwalters@0
|
169
|
tomwalters@0
|
170
|
tomwalters@0
|
171 void reset_header_bytes()
|
tomwalters@0
|
172 {
|
tomwalters@0
|
173 /* What this code does:
|
tomwalters@0
|
174 *
|
tomwalters@0
|
175 * My latest attempt to get the "header_bytes" field to be set to the
|
tomwalters@0
|
176 * right number, well, one that AIM accepts.
|
tomwalters@0
|
177 *
|
tomwalters@0
|
178 * At the moment, it assumes
|
tomwalters@0
|
179 * (1) all headers are an even number of bytes long
|
tomwalters@0
|
180 * (2) the field is 7 characters long
|
tomwalters@0
|
181 * (3) header_bytes = total length of all strings in header
|
tomwalters@0
|
182 + 2
|
tomwalters@0
|
183 *
|
tomwalters@0
|
184 */
|
tomwalters@0
|
185
|
tomwalters@0
|
186 int new_header_length = 0;
|
tomwalters@0
|
187 int counter;
|
tomwalters@0
|
188 char tempstring[MAX_STRING_LENGTH];
|
tomwalters@0
|
189 char tempstring2[MAX_STRING_LENGTH];
|
tomwalters@0
|
190
|
tomwalters@0
|
191 /* find out how many bytes there SHOULD be */
|
tomwalters@0
|
192 for(counter=0; counter<=header_lines; counter++)
|
tomwalters@0
|
193 new_header_length = new_header_length + strlen(header[counter]);
|
tomwalters@0
|
194
|
tomwalters@0
|
195 /* If this is odd, change to even.*/
|
tomwalters@0
|
196 if ((new_header_length % 2) == 1)
|
tomwalters@0
|
197 new_header_length ++;
|
tomwalters@0
|
198
|
tomwalters@0
|
199 /* add 2 to it */
|
tomwalters@0
|
200 new_header_length += 2;
|
tomwalters@0
|
201
|
tomwalters@0
|
202 /* put lots of zeros on front */
|
tomwalters@0
|
203 sprintf(tempstring, "%d", new_header_length);
|
tomwalters@0
|
204
|
tomwalters@0
|
205 /* add enough zero's on front to make it 7 chars long.
|
tomwalters@0
|
206 * Since this was the length of the input's field, I don't need to
|
tomwalters@0
|
207 * worry about it changing the true length of the header */
|
tomwalters@0
|
208
|
tomwalters@0
|
209 while (strlen(tempstring) != 7 ){
|
tomwalters@0
|
210 strcpy(tempstring2, "0");
|
tomwalters@0
|
211 strcat(tempstring2, tempstring);
|
tomwalters@0
|
212 strcpy(tempstring, tempstring2);}
|
tomwalters@0
|
213
|
tomwalters@0
|
214
|
tomwalters@0
|
215 /* use this value to reset header_bytes */
|
tomwalters@0
|
216 sprintf(header[0], "header_bytes=%s\n", tempstring);
|
tomwalters@0
|
217
|
tomwalters@0
|
218 }
|
tomwalters@0
|
219
|
tomwalters@0
|
220
|
tomwalters@0
|
221
|
tomwalters@0
|
222 /* ------------------------------------------------------------------------*/
|
tomwalters@0
|
223
|
tomwalters@0
|
224
|
tomwalters@0
|
225
|
tomwalters@0
|
226 void changeheader_B(int new_mincf, int new_maxcf, int new_channels)
|
tomwalters@0
|
227 {
|
tomwalters@0
|
228 /* Reset various values:
|
tomwalters@0
|
229 *
|
tomwalters@0
|
230 * mincf == new_mincf
|
tomwalters@0
|
231 * maxcf == new_maxcf
|
tomwalters@0
|
232 * channels = framehieght == new_channels
|
tomwalters@0
|
233 *
|
tomwalters@0
|
234 * NB This assumes "channels=" and "frameheight=" are both set to the
|
tomwalters@0
|
235 * same value. I haven't yet seen a .sai in which they are
|
tomwalters@0
|
236 * different, but I haven't looked too hard.
|
tomwalters@0
|
237 *
|
tomwalters@0
|
238 */
|
tomwalters@0
|
239
|
tomwalters@0
|
240 int new_header_length = 0;
|
tomwalters@0
|
241 int counter;
|
tomwalters@0
|
242 char tempstring[MAX_STRING_LENGTH];
|
tomwalters@0
|
243 char tempstring2[MAX_STRING_LENGTH];
|
tomwalters@0
|
244
|
tomwalters@0
|
245
|
tomwalters@0
|
246 for(counter=1; counter<=header_lines; counter++){
|
tomwalters@0
|
247
|
tomwalters@0
|
248 /* mincf */
|
tomwalters@0
|
249 if (strncmp(header[counter], "mincf_afb=", 10) == 0 ) {
|
tomwalters@0
|
250 sprintf(header[counter], "mincf_afb=%d\n", new_mincf);}
|
tomwalters@0
|
251
|
tomwalters@0
|
252 /* maxcf */
|
tomwalters@0
|
253 if (strncmp(header[counter], "maxcf_afb=", 10) == 0 ) {
|
tomwalters@0
|
254 sprintf(header[counter], "maxcf_afb=%d\n", new_maxcf);}
|
tomwalters@0
|
255
|
tomwalters@0
|
256 /* channels */
|
tomwalters@0
|
257 if (strncmp(header[counter], "channels_afb=", 12) == 0 ) {
|
tomwalters@0
|
258 sprintf(header[counter], "channels_afb=%d\n", new_channels);}
|
tomwalters@0
|
259
|
tomwalters@0
|
260 /* frameheight */
|
tomwalters@0
|
261 if (strncmp(header[counter], "frameheight=", 12) == 0 )
|
tomwalters@0
|
262 sprintf(header[counter], "frameheight=%d\n", new_channels);
|
tomwalters@0
|
263
|
tomwalters@0
|
264 }
|
tomwalters@0
|
265
|
tomwalters@0
|
266 /* reset framebytes */
|
tomwalters@0
|
267 change_framebytes();
|
tomwalters@0
|
268
|
tomwalters@0
|
269 /* reset header */
|
tomwalters@0
|
270 reset_header_bytes;
|
tomwalters@0
|
271
|
tomwalters@0
|
272 }
|
tomwalters@0
|
273
|
tomwalters@0
|
274
|
tomwalters@0
|
275 /* The End */
|
tomwalters@0
|
276 /* ------------------------------------------------------------------------*/
|
tomwalters@0
|
277
|
tomwalters@0
|
278
|
tomwalters@0
|
279
|
tomwalters@0
|
280
|
tomwalters@0
|
281
|
tomwalters@0
|
282
|
tomwalters@0
|
283
|
tomwalters@0
|
284
|
tomwalters@0
|
285
|