-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.c
316 lines (269 loc) · 6.62 KB
/
script.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
/*
* Lyon's Cochlear Model, The Program
* Malcolm Slaney
* Advanced Technology Group
* Apple Computer, Inc.
* malcolm@apple.com
* November 1988
*
* This program implements a model of acoustic propagation and detection
* in the human cochlea. This model was first described by Richard F.
* Lyon. Please see
* Malcolm Slaney, "Lyon's Cochlear Model, the Mathematica
* Notebook," Apple Technical Report #13, 1988
* for more information. This report is available from the Apple
* Corporate Library.
*
* Warranty Information
* Even though Apple has reviewed this software, Apple makes no warranty
* or representation, either express or implied, with respect to this
* software, its quality, accuracy, merchantability, or fitness for a
* particular purpose. As a result, this software is provided "as is,"
* and you, its user, are assuming the entire risk as to its quality
* and accuracy.
*
* Copyright (c) 1988-1989 by Apple Computer, Inc
* All Rights Reserved.
*
* $Header: script.c,v 2.2 90/11/06 20:54:53 malcolm Exp $
*
* $Log: script.c,v $
* Revision 2.2 90/11/06 20:54:53 malcolm
* Changed copyright messsage.
*
* Revision 2.1 89/11/09 23:16:35 malcolm
* Rewrote video starting condition (when starting in the middle.)
*
* Revision 2.0 89/07/25 18:58:55 malcolm
* Completely debugged and tested version on the following machines (roughly
* in order of performance):
* Cray, Stellar, SGI, Sun-4, Sequent Balance, Sun-3, VAX, Macintosh under
* both MPW and LightSpeed C.
*
*
*/
static char *RCSid = "$Header: script.c,v 2.2 90/11/06 20:54:53 malcolm Exp $";
#include <stdio.h>
#include "complex.h"
#include "filter.h"
#include "ear.h"
#define IMPULSE_HEIGHT .0001
main(argc,argv)
int argc;
char **argv;
{
int i;
FILE *ofp;
progname = *argv;
while(argv++ , --argc){
if (**argv == '?')
syntax();
if(( **argv=='-' || **argv=='+')&& argv[0][1]) {
ProcessOption(*argv);
}else {
ProcessArgument(*argv);
}
}
inittimers();
Animation2();
}
Animation1()
{
register int i;
int one = 1, two = 2, three = 3, four = 4, Channel;
float Output[MaxN], *Sound, GETAGC();
float *Data, *ReadInputFile();
UseDifference = 0;
DecimationFactor = 1;
if (ImpulseInput){
DataLength = 512;
Data = (float *)calloc(DataLength, sizeof(*Data));
Data[0] = IMPULSE_HEIGHT;
} else {
float *Signal;
Signal = ReadInputFile(ifn, &sample_rate, &DataLength);
Data = (float *) malloc(3*DataLength*sizeof(*Data));
for (i=0;i<DataLength;i++)
Data[i] = Data[i+DataLength] = Data[i+2*DataLength] =
Signal[i];
DataLength *= 3;
}
ChangeDecimationParameters();
ChangeAgcParams();
DesignEarFilters();
#ifdef MINUSG
CPUs = 1;
#endif /* MINUSG */
#ifdef CRAY
if (CPUs > 1 && (UseUltra || cfn) ){
printf("Getting %d cpus.\n", CPUs);
GETCPUS(&CPUs);
}
#endif /* CRAY */
/*
AgcStage1Tau = AgcStage2Tau = AgcStage3Tau = AgcStage4Tau = 1000000;
*/
if (printflag){
PrintStats();
}
Sound = (float *)malloc(DataLength*sizeof(*Data));
for (i=0;i<DataLength;i++){
SystemCursor();
SampleNumber = i;
starttimer(10);
EARSTEP(&Data[i], Output);
endtimer(10);
Channel = (i*EarLength)/DataLength+1;
Sound[i] = Output[Channel] ;
}
WriteADCFile(ofn, sample_rate, DataLength, Sound);
printtimers();
}
#define Between(a,b,c) ((a > b && a < c) || (a < b && a > c))
Median(Data,Length)
float *Data;
int Length;
{
register int i;
register float a, b, c, save;
save = Data[0];
for (i=1;i<Length-1;i++){
a = Data[i-1];
b = Data[i];
c = Data[i+1];
Data[i-1] = save;
if (Between(a,b,c))
save = a;
else if (Between(c,a,b))
save = c;
else
save = b;
}
}
Animation2()
{
int LineCount = 0;
int CorrelationLineCount = 0, CorrelationPictureCount = 0;
int CorrelationOutputSize;
float *CorrelationOutput = NULL, *CorrelationZero = NULL;
float *Data, *ReadInputFile();
register int i;
float Output[MaxN], SamplesPerFrame, SamplesToNextFrame;
cfn = ofn = "";
UseUltra = 1;
TauFactor= 1;
DecimationFactor= 1;
CorrelationLags = 512;
Normalization = .5;
EarQ = 4;
EarStepFactor = .125;
if (ImpulseInput){
DataLength = 512;
Data = (float *)calloc(DataLength, sizeof(*Data));
Data[0] = IMPULSE_HEIGHT;
} else {
Data = ReadInputFile(ifn, &sample_rate, &DataLength);
}
ChangeDecimationParameters();
ChangeAgcParams();
DesignEarFilters();
#ifdef MINUSG
CPUs = 1;
#endif /* MINUSG */
#ifdef CRAY
if (CPUs > 1 && (UseUltra || cfn) ){
printf("Getting %d cpus.\n", CPUs);
GETCPUS(&CPUs);
}
#endif /* CRAY */
if (printflag){
PrintStats();
}
InitCorrelation(EarLength-2, 2*CorrelationLags);
CorrelationOutputSize = (EarLength + 10) *
CorrelationLags;
CorrelationOutput = (float *)
malloc(CorrelationOutputSize*
sizeof(CorrelationOutput[0]));
if (!CorrelationOutput){
fprintf(stderr,
"%s: Couldn't get %d bytes for correlation output.\n",
"Correlation Animation", CorrelationOutputSize);
exit(2);
}
SamplesPerFrame = sample_rate/29.985;
SamplesToNextFrame = SamplesPerFrame;
printf("sample_rate is %g, SamplesPerFrame is %g.\n",
sample_rate, SamplesPerFrame);
OpenConnection("dumbo");
SendCommandToRemote("setenv WF_RECDEV diaq");
for (i=0;i<DataLength;i++){
SampleNumber = i;
starttimer(10);
EARSTEP(&Data[i], Output);
endtimer(10);
SendInputToCorrelation(Output+2);
SamplesToNextFrame--;
if (SamplesToNextFrame < 0){
extern int FrameNumber;
SamplesToNextFrame += SamplesPerFrame;
EarCorrelation(CorrelationOutput,
CorrelationLags);
if (SampleNumber/sample_rate > -1.0)
RecordVideo();
else
printf("Skipping frame %d.\n",FrameNumber++);
CorrelationPictureCount++;
}
}
printtimers();
}
int FrameNumber = 0;
RecordVideo(){
int i;
extern int errno;
FILE *fp;
#ifdef OLD
i = system("/usr/ucb/remsh dumbo 'setenv WF_RECDEV diaq;/usr/local/wave/bin/record'");
/*
i = system("/usr/ucb/remsh dumbo 'date'");
*/
if (i){
printf("%d: system returns %d (errno is %d).\n",FrameNumber,
i,errno);
exit(1);
} else {
printf("Finished frame %d.\n", FrameNumber);
}
WaitForFrameBuffer();
#endif OLD
SendCommandToRemote("/usr/local/wave/bin/record");
fp = fopen(".frame","w");
if (fp){
fprintf(fp,"%d\n", FrameNumber);
fclose(fp);
}
FrameNumber++;
/*
char Buffer[512];
int i;
printf("Recording a frame.....");
clearerr(stdin);
i = fgets(Buffer,512,stdin);
printf("fgets got *%d*\n",i);
*/
}
#define WAITFILE "/tmp/stopanimation"
WaitForFrameBuffer(){
FILE *fp;
fp = fopen(WAITFILE,"r");
if (fp){
fclose(fp);
printf("Found %s....waiting.\n", WAITFILE);
while (fp = fopen(WAITFILE,"r")){
fclose(fp);
sleep(1);
}
printf("Resuming animation.\n");
}
}