0
|
1 |
'From Smalltalk/X, Version:2.6.3 on 25-Mar-1993 at 16:32:03'!
|
|
2 |
|
|
3 |
FileStream subclass:#SoundStream
|
|
4 |
instanceVariableNames:'sampleRate numberOfChannels bitsPerSample'
|
|
5 |
classVariableNames:'rampOff'
|
|
6 |
poolDictionaries:''
|
|
7 |
category:'Streams-External'
|
|
8 |
!
|
|
9 |
|
|
10 |
SoundStream comment:'
|
|
11 |
Interface to audio device.
|
|
12 |
Currently works with PD sound-blaster driver and
|
|
13 |
sun audio device. On iris default setup is 8 bit mono
|
|
14 |
so I can play the standard sound files I have here.
|
|
15 |
'!
|
|
16 |
|
|
17 |
%{
|
|
18 |
#ifdef IRIS
|
|
19 |
# include <audio.h>
|
|
20 |
#endif
|
|
21 |
%}
|
|
22 |
|
|
23 |
!SoundStream class methodsFor:'instance creation'!
|
|
24 |
|
|
25 |
reading
|
|
26 |
|newStream|
|
|
27 |
newStream := (self basicNew) initialize.
|
|
28 |
newStream openForReading isNil ifTrue:[^nil].
|
|
29 |
^ newStream
|
|
30 |
|
|
31 |
"SoundStream reading"
|
|
32 |
!
|
|
33 |
|
|
34 |
writing
|
|
35 |
|newStream|
|
|
36 |
|
|
37 |
OperatingSystem getCPUType = '386' ifTrue:[
|
|
38 |
"soundblaster special kludge to avoid click"
|
|
39 |
rampOff isNil ifTrue:[
|
|
40 |
self generateRamp
|
|
41 |
]
|
|
42 |
].
|
|
43 |
newStream := (self basicNew) initialize.
|
|
44 |
newStream openForWriting isNil ifTrue:[^nil].
|
|
45 |
^ newStream
|
|
46 |
|
|
47 |
"SoundStream writing"
|
|
48 |
!
|
|
49 |
|
|
50 |
writing16BitStero
|
|
51 |
"just an example, has never been tried (I also
|
|
52 |
have no samples for this ... leave it as an exercise"
|
|
53 |
|
|
54 |
|newStream|
|
|
55 |
|
|
56 |
OperatingSystem getCPUType = 'irix' ifFalse:[
|
|
57 |
self error:'unsupported audio mode'.
|
|
58 |
^ nil
|
|
59 |
].
|
|
60 |
newStream := (self basicNew) initialize.
|
|
61 |
newStream bitsPerSample:16.
|
|
62 |
newStream numberOfChannels:2.
|
|
63 |
newStream openForWriting isNil ifTrue:[^nil].
|
|
64 |
^ newStream
|
|
65 |
|
|
66 |
"SoundStream writing16BitStereo"
|
|
67 |
! !
|
|
68 |
|
|
69 |
!SoundStream class methodsFor:'default values'!
|
|
70 |
|
|
71 |
defaultSampleRate
|
|
72 |
"minimum, supported by all audio systems"
|
|
73 |
|
|
74 |
^ 8000
|
|
75 |
!
|
|
76 |
|
|
77 |
defaultBitsPerSample
|
|
78 |
"minimum, supported by all audio systems"
|
|
79 |
|
|
80 |
^ 8
|
|
81 |
!
|
|
82 |
|
|
83 |
defaultNumberOfChannels
|
|
84 |
"minimum, supported by all audio systems"
|
|
85 |
|
|
86 |
^ 1
|
|
87 |
!
|
|
88 |
|
|
89 |
defaultMode
|
|
90 |
^ #linear "planned is at least uLaw"
|
|
91 |
!
|
|
92 |
|
|
93 |
blockSize
|
|
94 |
"a good chunk size to read soundstream.
|
|
95 |
Some devices may force a specific size ..."
|
|
96 |
|
|
97 |
^ 2048 "about 1/4 of a second"
|
|
98 |
! !
|
|
99 |
|
|
100 |
!SoundStream class methodsFor:'conversion tables'!
|
|
101 |
|
|
102 |
uLawToLinear:uLawValue
|
|
103 |
"currently unused - but will be"
|
|
104 |
|
|
105 |
^ #(
|
|
106 |
"0 " -32256
|
|
107 |
"1 " -31228
|
|
108 |
"2 " -30200
|
|
109 |
"3 " -29172
|
|
110 |
"4 " -28143
|
|
111 |
"5 " -27115
|
|
112 |
"6 " -26087
|
|
113 |
"7 " -25059
|
|
114 |
"8 " -24031
|
|
115 |
"9 " -23002
|
|
116 |
"10 " -21974
|
|
117 |
"11 " -20946
|
|
118 |
"12 " -19918
|
|
119 |
"13 " -18889
|
|
120 |
"14 " -17861
|
|
121 |
"15 " -16833
|
|
122 |
"16 " -16062
|
|
123 |
"17 " -15548
|
|
124 |
"18 " -15033
|
|
125 |
"19 " -14519
|
|
126 |
"20 " -14005
|
|
127 |
"21 " -13491
|
|
128 |
"22 " -12977
|
|
129 |
"23 " -12463
|
|
130 |
"24 " -11949
|
|
131 |
"25 " -11435
|
|
132 |
"26 " -10920
|
|
133 |
"27 " -10406
|
|
134 |
"28 " -9892
|
|
135 |
"29 " -9378
|
|
136 |
"30 " -8864
|
|
137 |
"31 " -8350
|
|
138 |
"32 " -7964
|
|
139 |
"33 " -7707
|
|
140 |
"34 " -7450
|
|
141 |
"35 " -7193
|
|
142 |
"36 " -6936
|
|
143 |
"37 " -6679
|
|
144 |
"38 " -6422
|
|
145 |
"39 " -6165
|
|
146 |
"40 " -5908
|
|
147 |
"41 " -5651
|
|
148 |
"42 " -5394
|
|
149 |
"43 " -5137
|
|
150 |
"44 " -4880
|
|
151 |
"45 " -4623
|
|
152 |
"46 " -4365
|
|
153 |
"47 " -4108
|
|
154 |
"48 " -3916
|
|
155 |
"49 " -3787
|
|
156 |
"50 " -3659
|
|
157 |
"51 " -3530
|
|
158 |
"52 " -3402
|
|
159 |
"53 " -3273
|
|
160 |
"54 " -3144
|
|
161 |
"55 " -3016
|
|
162 |
"56 " -2887
|
|
163 |
"57 " -2759
|
|
164 |
"58 " -2630
|
|
165 |
"59 " -2502
|
|
166 |
"60 " -2373
|
|
167 |
"61 " -2245
|
|
168 |
"62 " -2116
|
|
169 |
"63 " -1988
|
|
170 |
"64 " -1891
|
|
171 |
"65 " -1827
|
|
172 |
"66 " -1763
|
|
173 |
"67 " -1698
|
|
174 |
"68 " -1634
|
|
175 |
"69 " -1570
|
|
176 |
"70 " -1506
|
|
177 |
"71 " -1441
|
|
178 |
"72 " -1377
|
|
179 |
"73 " -1313
|
|
180 |
"74 " -1249
|
|
181 |
"75 " -1184
|
|
182 |
"76 " -1120
|
|
183 |
"77 " -1056
|
|
184 |
"78 " -992
|
|
185 |
"79 " -927
|
|
186 |
"80 " -879
|
|
187 |
"81 " -847
|
|
188 |
"82 " -815
|
|
189 |
"83 " -783
|
|
190 |
"84 " -751
|
|
191 |
"85 " -718
|
|
192 |
"86 " -686
|
|
193 |
"87 " -654
|
|
194 |
"88 " -622
|
|
195 |
"89 " -590
|
|
196 |
"90 " -558
|
|
197 |
"91 " -526
|
|
198 |
"92 " -494
|
|
199 |
"93 " -461
|
|
200 |
"94 " -429
|
|
201 |
"95 " -397
|
|
202 |
"96 " -373
|
|
203 |
"97 " -357
|
|
204 |
"98 " -341
|
|
205 |
"99 " -325
|
|
206 |
"100" -309
|
|
207 |
"101" -293
|
|
208 |
"102" -277
|
|
209 |
"103" -261
|
|
210 |
"104" -245
|
|
211 |
"105" -228
|
|
212 |
"106" -212
|
|
213 |
"107" -196
|
|
214 |
"108" -180
|
|
215 |
"109" -164
|
|
216 |
"110" -148
|
|
217 |
"111" -132
|
|
218 |
"112" -120
|
|
219 |
"113" -112
|
|
220 |
"114" -104
|
|
221 |
"115" -96
|
|
222 |
"116" -88
|
|
223 |
"117" -80
|
|
224 |
"118" -72
|
|
225 |
"119" -64
|
|
226 |
"120" -56
|
|
227 |
"121" -48
|
|
228 |
"122" -40
|
|
229 |
"123" -32
|
|
230 |
"124" -24
|
|
231 |
"125" -16
|
|
232 |
"126" -8
|
|
233 |
"127" 0
|
|
234 |
"128" 32256
|
|
235 |
"129" 31228
|
|
236 |
"130" 30200
|
|
237 |
"131" 29172
|
|
238 |
"132" 28143
|
|
239 |
"133" 27115
|
|
240 |
"134" 26087
|
|
241 |
"135" 25059
|
|
242 |
"136" 24031
|
|
243 |
"137" 23002
|
|
244 |
"138" 21974
|
|
245 |
"139" 20946
|
|
246 |
"140" 19918
|
|
247 |
"141" 18889
|
|
248 |
"142" 17861
|
|
249 |
"143" 16833
|
|
250 |
"144" 16062
|
|
251 |
"145" 15548
|
|
252 |
"146" 15033
|
|
253 |
"147" 14519
|
|
254 |
"148" 14005
|
|
255 |
"149" 13491
|
|
256 |
"150" 12977
|
|
257 |
"151" 12463
|
|
258 |
"152" 11949
|
|
259 |
"153" 11435
|
|
260 |
"154" 10920
|
|
261 |
"155" 10406
|
|
262 |
"156" 9892
|
|
263 |
"157" 9378
|
|
264 |
"158" 8864
|
|
265 |
"159" 8350
|
|
266 |
"160" 7964
|
|
267 |
"161" 7707
|
|
268 |
"162" 7450
|
|
269 |
"163" 7193
|
|
270 |
"164" 6936
|
|
271 |
"165" 6679
|
|
272 |
"166" 6422
|
|
273 |
"167" 6165
|
|
274 |
"168" 5908
|
|
275 |
"169" 5651
|
|
276 |
"170" 5394
|
|
277 |
"171" 5137
|
|
278 |
"172" 4880
|
|
279 |
"173" 4623
|
|
280 |
"174" 4365
|
|
281 |
"175" 4108
|
|
282 |
"176" 3916
|
|
283 |
"177" 3787
|
|
284 |
"178" 3659
|
|
285 |
"179" 3530
|
|
286 |
"180" 3402
|
|
287 |
"181" 3273
|
|
288 |
"182" 3144
|
|
289 |
"183" 3016
|
|
290 |
"184" 2887
|
|
291 |
"185" 2759
|
|
292 |
"186" 2630
|
|
293 |
"187" 2502
|
|
294 |
"188" 2373
|
|
295 |
"189" 2245
|
|
296 |
"190" 2116
|
|
297 |
"191" 1988
|
|
298 |
"192" 1891
|
|
299 |
"193" 1827
|
|
300 |
"194" 1763
|
|
301 |
"195" 1698
|
|
302 |
"196" 1634
|
|
303 |
"197" 1570
|
|
304 |
"198" 1506
|
|
305 |
"199" 1441
|
|
306 |
"200" 1377
|
|
307 |
"201" 1313
|
|
308 |
"202" 1249
|
|
309 |
"203" 1184
|
|
310 |
"204" 1120
|
|
311 |
"205" 1056
|
|
312 |
"206" 992
|
|
313 |
"207" 927
|
|
314 |
"208" 879
|
|
315 |
"209" 847
|
|
316 |
"210" 815
|
|
317 |
"211" 783
|
|
318 |
"212" 751
|
|
319 |
"213" 718
|
|
320 |
"214" 686
|
|
321 |
"215" 654
|
|
322 |
"216" 622
|
|
323 |
"217" 590
|
|
324 |
"218" 558
|
|
325 |
"219" 526
|
|
326 |
"220" 494
|
|
327 |
"221" 461
|
|
328 |
"222" 429
|
|
329 |
"223" 397
|
|
330 |
"224" 373
|
|
331 |
"225" 357
|
|
332 |
"226" 341
|
|
333 |
"227" 325
|
|
334 |
"228" 309
|
|
335 |
"229" 293
|
|
336 |
"230" 277
|
|
337 |
"231" 261
|
|
338 |
"232" 245
|
|
339 |
"233" 228
|
|
340 |
"234" 212
|
|
341 |
"235" 196
|
|
342 |
"236" 180
|
|
343 |
"237" 164
|
|
344 |
"238" 148
|
|
345 |
"239" 132
|
|
346 |
"240" 120
|
|
347 |
"241" 112
|
|
348 |
"242" 104
|
|
349 |
"243" 96
|
|
350 |
"244" 88
|
|
351 |
"245" 80
|
|
352 |
"246" 72
|
|
353 |
"247" 64
|
|
354 |
"248" 56
|
|
355 |
"249" 48
|
|
356 |
"250" 40
|
|
357 |
"251" 32
|
|
358 |
"252" 24
|
|
359 |
"253" 16
|
|
360 |
"254" 8
|
|
361 |
"255" 0
|
|
362 |
) at:(uLawValue + 1)
|
|
363 |
! !
|
|
364 |
|
|
365 |
!SoundStream class methodsFor:'private'!
|
|
366 |
|
|
367 |
generateRamp
|
|
368 |
"create ramp data (need to be played on soundblaster
|
|
369 |
before closing device to prevent audible click-on/off).
|
|
370 |
This method just fills a buffer with ramp data."
|
|
371 |
|
|
372 |
|size div|
|
|
373 |
|
|
374 |
size := 256.
|
|
375 |
div := size // 128.
|
|
376 |
rampOff := ByteArray new:size.
|
|
377 |
1 to:size do:[:index |
|
|
378 |
rampOff at:index put:(size - index // div)
|
|
379 |
]
|
|
380 |
|
|
381 |
"SoundStream generateRamp"
|
|
382 |
! !
|
|
383 |
|
|
384 |
!SoundStream methodsFor:'mode setting'!
|
|
385 |
|
|
386 |
sampleRate:aNumber
|
|
387 |
"set the sample rate in hertz - on some
|
|
388 |
devices, this is a nop"
|
|
389 |
|
|
390 |
OperatingSystem getCPUType = '386' ifTrue:[
|
|
391 |
"assume sound-blaster device"
|
|
392 |
"set sound blasters sample rate"
|
|
393 |
|
|
394 |
sampleRate := aNumber.
|
|
395 |
self ioctl:1 "DSP_IOCTL_SPEED" with:aNumber
|
|
396 |
].
|
|
397 |
OperatingSystem getOSType = 'sunos' ifTrue:[
|
|
398 |
"audio sample rate is fix"
|
|
399 |
^ self "cannot change"
|
|
400 |
].
|
|
401 |
OperatingSystem getOSType = 'irix' ifTrue:[
|
|
402 |
"could change using ALibrary ...for now, it is fix"
|
|
403 |
sampleRate := aNumber.
|
|
404 |
].
|
|
405 |
!
|
|
406 |
|
|
407 |
sampleRate
|
|
408 |
"return the sample rate"
|
|
409 |
|
|
410 |
^ sampleRate
|
|
411 |
!
|
|
412 |
|
|
413 |
numberOfChannels
|
|
414 |
"return the number of channels (1 or 2; usually 1)"
|
|
415 |
|
|
416 |
^ numberOfChannels
|
|
417 |
!
|
|
418 |
|
|
419 |
numberOfChannels:aNumber
|
|
420 |
"set the number of channels"
|
|
421 |
|
|
422 |
numberOfChannels := aNumber
|
|
423 |
!
|
|
424 |
|
|
425 |
bitsPerSample
|
|
426 |
"return the number of bits per sample - usually 8"
|
|
427 |
|
|
428 |
^ bitsPerSample
|
|
429 |
!
|
|
430 |
|
|
431 |
bitsPerSample:aNumber
|
|
432 |
"set the number of bits per sample"
|
|
433 |
|
|
434 |
bitsPerSample := aNumber
|
|
435 |
! !
|
|
436 |
|
|
437 |
!SoundStream methodsFor:'catching invalid methods'!
|
|
438 |
|
|
439 |
pathName:filename
|
|
440 |
"catch pathname access - its fixed here"
|
|
441 |
|
|
442 |
self shouldNotImplement
|
|
443 |
!
|
|
444 |
|
|
445 |
pathName:filename in:aDirectory
|
|
446 |
"catch pathname access - its fixed here"
|
|
447 |
|
|
448 |
self shouldNotImplement
|
|
449 |
! !
|
|
450 |
|
|
451 |
!SoundStream methodsFor:'private'!
|
|
452 |
|
|
453 |
initialize
|
|
454 |
"initialize for least common mode"
|
|
455 |
|
|
456 |
unBuffered := true.
|
|
457 |
bitsPerSample := 8.
|
|
458 |
numberOfChannels := 1.
|
|
459 |
sampleRate := 8000.
|
|
460 |
|
|
461 |
OperatingSystem getOSType = 'sunos' ifTrue:[
|
|
462 |
pathName := '/dev/audio'.
|
|
463 |
].
|
|
464 |
|
|
465 |
OperatingSystem getOSType = 'irix' ifTrue:[
|
|
466 |
"no device, use special library calls"
|
|
467 |
pathName := nil.
|
|
468 |
].
|
|
469 |
|
|
470 |
OperatingSystem getCPUType = '386' ifTrue:[
|
|
471 |
"this code assumes a PD sound-blaster driver .."
|
|
472 |
pathName := '/dev/sbdsp'
|
|
473 |
]
|
|
474 |
! !
|
|
475 |
|
|
476 |
!SoundStream methodsFor:'redefined'!
|
|
477 |
|
|
478 |
openWithMode:aMode
|
|
479 |
OperatingSystem getOSType = 'irix' ifFalse:[
|
|
480 |
"its a regular file open"
|
|
481 |
^ super openWithMode:aMode
|
|
482 |
].
|
|
483 |
|
|
484 |
((aMode = 'r') or:[aMode = 'w']) ifFalse:[
|
|
485 |
self error:'invalid mode'.
|
|
486 |
^ nil
|
|
487 |
].
|
|
488 |
%{
|
|
489 |
#ifdef IRIS
|
|
490 |
{
|
|
491 |
ALconfig config;
|
|
492 |
ALport p;
|
|
493 |
long params[] = {
|
|
494 |
AL_INPUT_SOURCE, AL_INPUT_MIC,
|
|
495 |
AL_INPUT_RATE, 8000,
|
|
496 |
AL_OUTPUT_RATE, 8000,
|
|
497 |
};
|
|
498 |
|
|
499 |
config = ALnewconfig();
|
|
500 |
if (_INST(numberOfChannels) == _MKSMALLINT(2))
|
|
501 |
ALsetchannels(config, AL_STEREO);
|
|
502 |
else
|
|
503 |
ALsetchannels(config, AL_MONO);
|
|
504 |
if (_INST(bitsPerSample) == _MKSMALLINT(16))
|
|
505 |
ALsetwidth(config, AL_SAMPLE_16);
|
|
506 |
else
|
|
507 |
ALsetwidth(config, AL_SAMPLE_8);
|
|
508 |
|
|
509 |
if (_isSmallInteger(_INST(sampleRate)))
|
|
510 |
params[3] = params[5] = _intVal(_INST(sampleRate));
|
|
511 |
|
|
512 |
ALsetparams(AL_DEFAULT_DEVICE, params, 6);
|
|
513 |
p = ALopenport("smallchat", (char *)_stringVal(aMode), config);
|
|
514 |
if (p) {
|
|
515 |
_INST(filePointer) = _MKSMALLINT((int) p);
|
|
516 |
} else {
|
|
517 |
_INST(filePointer) = nil;
|
|
518 |
RETURN (nil);
|
|
519 |
}
|
|
520 |
_INST(binary) = true;
|
|
521 |
|
|
522 |
ALfreeconfig(config);
|
|
523 |
/*
|
|
524 |
* get the parameters actually installed
|
|
525 |
*/
|
|
526 |
config = ALgetconfig(p);
|
|
527 |
switch (ALgetchannels(config)) {
|
|
528 |
default:
|
|
529 |
/* cannot happen */
|
|
530 |
case AL_MONO:
|
|
531 |
_INST(numberOfChannels) = _MKSMALLINT(1);
|
|
532 |
break;
|
|
533 |
case AL_STEREO:
|
|
534 |
_INST(numberOfChannels) = _MKSMALLINT(2);
|
|
535 |
break;
|
|
536 |
}
|
|
537 |
switch (ALgetwidth(config)) {
|
|
538 |
default:
|
|
539 |
/* cannot happen */
|
|
540 |
case AL_SAMPLE_8:
|
|
541 |
_INST(bitsPerSample) = _MKSMALLINT(8);
|
|
542 |
break;
|
|
543 |
case AL_SAMPLE_16:
|
|
544 |
_INST(bitsPerSample) = _MKSMALLINT(16);
|
|
545 |
break;
|
|
546 |
case AL_SAMPLE_24:
|
|
547 |
_INST(bitsPerSample) = _MKSMALLINT(24);
|
|
548 |
break;
|
|
549 |
}
|
|
550 |
ALgetparams(AL_DEFAULT_DEVICE, params, 6);
|
|
551 |
_INST(sampleRate) = _MKSMALLINT(params[3]);
|
|
552 |
|
|
553 |
ALfreeconfig(config);
|
|
554 |
}
|
|
555 |
#endif
|
|
556 |
%}
|
|
557 |
.
|
|
558 |
^ self
|
|
559 |
!
|
|
560 |
|
|
561 |
close
|
|
562 |
OperatingSystem getOSType = 'irix' ifTrue:[
|
|
563 |
^ self closeFile
|
|
564 |
].
|
|
565 |
|
|
566 |
(mode == #writeonly) ifTrue:[
|
|
567 |
"special handling of close on sound blaster,
|
|
568 |
turn off voice but continue playing a ramp
|
|
569 |
to avoid audible click"
|
|
570 |
|
|
571 |
OperatingSystem getCPUType = '386' ifTrue:[
|
|
572 |
"assume sound-blaster device"
|
|
573 |
self ioctl:2 "DSP_IOCTL_VOICE" with:0.
|
|
574 |
|
|
575 |
"OperatingSystem sleep:3. "
|
|
576 |
"add a ramp to zero to prevent click-off"
|
|
577 |
super nextPutBytes:(rampOff size) from:rampOff
|
|
578 |
]
|
|
579 |
].
|
|
580 |
super close
|
|
581 |
!
|
|
582 |
|
|
583 |
nextPutBytes:count from:anObject startingAt:start
|
|
584 |
"write count bytes from an object starting at index start.
|
|
585 |
return the number of bytes written or nil on error.
|
|
586 |
Redefined, since IRIS audio library cannot be used with stdio.
|
|
587 |
(at least I dont know). Use with ByteArrays only."
|
|
588 |
|
|
589 |
%{
|
|
590 |
#ifdef IRIS
|
|
591 |
{
|
|
592 |
ALport p;
|
|
593 |
int cnt, offs;
|
|
594 |
int objSize;
|
|
595 |
char *cp;
|
|
596 |
|
|
597 |
if (_INST(filePointer) != nil) {
|
|
598 |
if (_INST(mode) != _readonly) {
|
|
599 |
if (_isSmallInteger(count) && _isSmallInteger(start)) {
|
|
600 |
cnt = _intVal(count);
|
|
601 |
offs = _intVal(start) - 1;
|
|
602 |
p = (ALport)(_intVal(_INST(filePointer)));
|
|
603 |
|
|
604 |
/*
|
|
605 |
* compute number of samples
|
|
606 |
*/
|
|
607 |
objSize = _Size(anObject) - OHDR_SIZE;
|
|
608 |
if ( (offs >= 0) && (cnt >= 0) && (objSize >= (cnt + offs)) ) {
|
|
609 |
cp = (char *)_InstPtr(anObject) + OHDR_SIZE + offs;
|
|
610 |
if (_INST(bitsPerSample) == _MKSMALLINT(16))
|
|
611 |
ALwritesamps(p, cp, cnt / 2);
|
|
612 |
else
|
|
613 |
ALwritesamps(p, cp, cnt);
|
|
614 |
RETURN ( _MKSMALLINT(cnt) );
|
|
615 |
}
|
|
616 |
}
|
|
617 |
}
|
|
618 |
}
|
|
619 |
}
|
|
620 |
#endif
|
|
621 |
%}
|
|
622 |
.
|
|
623 |
OperatingSystem getOSType = 'irix' ifFalse:[
|
|
624 |
^ super nextPutBytes:count from:anObject startingAt:start
|
|
625 |
].
|
|
626 |
filePointer isNil ifTrue:[^ self errorNotOpen].
|
|
627 |
(mode == #readonly) ifTrue:[^ self errorReadOnly].
|
|
628 |
self primitiveFailed
|
|
629 |
!
|
|
630 |
|
|
631 |
nextBytes:count into:anObject startingAt:start
|
|
632 |
"read the next count bytes into an object and return the number of
|
|
633 |
bytes read or nil on error.
|
|
634 |
Use with ByteArrays only."
|
|
635 |
|
|
636 |
%{
|
|
637 |
#ifdef IRIS
|
|
638 |
{
|
|
639 |
ALport p;
|
|
640 |
int cnt, offs;
|
|
641 |
int objSize;
|
|
642 |
char *cp;
|
|
643 |
|
|
644 |
if (_INST(filePointer) != nil) {
|
|
645 |
if (_INST(mode) != _writeonly) {
|
|
646 |
if (_isSmallInteger(count) && _isSmallInteger(start)) {
|
|
647 |
cnt = _intVal(count);
|
|
648 |
offs = _intVal(start) - 1;
|
|
649 |
p = (ALport)(_intVal(_INST(filePointer)));
|
|
650 |
objSize = _Size(anObject) - OHDR_SIZE;
|
|
651 |
if ((offs >= 0) && (cnt >= 0) && (objSize >= (cnt + offs))) {
|
|
652 |
cp = (char *)_InstPtr(anObject) + OHDR_SIZE + offs;
|
|
653 |
if (_INST(bitsPerSample) == _MKSMALLINT(16))
|
|
654 |
ALreadsamps(p, cp, cnt / 2);
|
|
655 |
else
|
|
656 |
ALreadsamps(p, cp, cnt);
|
|
657 |
RETURN ( _MKSMALLINT(cnt) );
|
|
658 |
}
|
|
659 |
}
|
|
660 |
}
|
|
661 |
}
|
|
662 |
}
|
|
663 |
#endif
|
|
664 |
%}
|
|
665 |
.
|
|
666 |
OperatingSystem getOSType = 'irix' ifFalse:[
|
|
667 |
^ super nextPutBytes:count from:anObject startingAt:start
|
|
668 |
].
|
|
669 |
filePointer isNil ifTrue:[^ self errorNotOpen].
|
|
670 |
(mode == #writeonly) ifTrue:[^ self errorWriteOnly].
|
|
671 |
self primitiveFailed
|
|
672 |
!
|
|
673 |
|
|
674 |
synchronizeOutput
|
|
675 |
"wait until all sound has been played"
|
|
676 |
|
|
677 |
%{
|
|
678 |
#ifdef IRIS
|
|
679 |
ALport p;
|
|
680 |
|
|
681 |
if (_INST(filePointer) != nil) {
|
|
682 |
p = (ALport)(_intVal(_INST(filePointer)));
|
|
683 |
while (ALgetfilled(p) > 0) {
|
|
684 |
sginap(1);
|
|
685 |
}
|
|
686 |
}
|
|
687 |
#endif
|
|
688 |
%}
|
|
689 |
.
|
|
690 |
OperatingSystem getOSType = 'irix' ifFalse:[
|
|
691 |
"dont know how to wait"
|
|
692 |
].
|
|
693 |
^ self
|
|
694 |
! !
|
|
695 |
|
|
696 |
!SoundStream methodsFor:'instance release'!
|
|
697 |
|
|
698 |
closeFile
|
|
699 |
"a stream has been collected - close the file"
|
|
700 |
|
|
701 |
OperatingSystem getOSType = 'irix' ifFalse:[
|
|
702 |
^ super closeFile
|
|
703 |
].
|
|
704 |
%{
|
|
705 |
#ifdef IRIS
|
|
706 |
ALcloseport( (ALport) (_intVal(_INST(filePointer))) );
|
|
707 |
#endif
|
|
708 |
%}
|
|
709 |
! !
|
|
710 |
|
|
711 |
!SoundStream methodsFor:'sine wave generation'!
|
|
712 |
|
|
713 |
tuneTone
|
|
714 |
|buffer numSamples val|
|
|
715 |
|
|
716 |
"allocate memory for 1sec playing time"
|
|
717 |
numSamples := self sampleRate.
|
|
718 |
buffer := ByteArray new:numSamples.
|
|
719 |
|
|
720 |
"fill it with a sine wave"
|
|
721 |
|
|
722 |
1 to:numSamples do:[:i |
|
|
723 |
val := (440 * 2 * (Float pi) * i / numSamples) sin.
|
|
724 |
val := val * 127 + 128.
|
|
725 |
buffer at:i put:val rounded
|
|
726 |
].
|
|
727 |
|
|
728 |
"play 3 seconds"
|
|
729 |
1 to:3 do:[:s |
|
|
730 |
self nextPutBytes:numSamples from:buffer
|
|
731 |
]
|
|
732 |
|
|
733 |
"SoundStream writing tuneTone synchronizeOutput close"
|
|
734 |
! !
|