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