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