author | Claus Gittinger <cg@exept.de> |
Mon, 21 Dec 1998 12:43:58 +0100 | |
changeset 712 | 9e853d04f52b |
parent 614 | 565ea4308322 |
child 713 | 85912db3ad19 |
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 |
|
712 | 14 |
instanceVariableNames:'sampleRate numberOfChannels bitsPerSample audioFormat |
15 |
alPort |
|
16 |
pDirectSound pDSBuffer cbBufOffset cbBufSize' |
|
595 | 17 |
classVariableNames:'UnsupportedOperationSignal' |
259 | 18 |
poolDictionaries:'' |
19 |
category:'Streams-External' |
|
0 | 20 |
! |
21 |
||
121
606a3ccd3682
linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents:
112
diff
changeset
|
22 |
!SoundStream primitiveDefinitions! |
606a3ccd3682
linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents:
112
diff
changeset
|
23 |
%{ |
606a3ccd3682
linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents:
112
diff
changeset
|
24 |
#ifdef IRIS |
606a3ccd3682
linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents:
112
diff
changeset
|
25 |
# ifndef IRIX5 |
606a3ccd3682
linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents:
112
diff
changeset
|
26 |
# define IRIS_AUDIO |
606a3ccd3682
linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents:
112
diff
changeset
|
27 |
# endif |
606a3ccd3682
linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents:
112
diff
changeset
|
28 |
#endif |
606a3ccd3682
linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents:
112
diff
changeset
|
29 |
|
606a3ccd3682
linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents:
112
diff
changeset
|
30 |
#ifdef IRIS_AUDIO |
606a3ccd3682
linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents:
112
diff
changeset
|
31 |
# include <audio.h> |
712 | 32 |
# define __ALportVal(o) (ALport)(__externalAddressVal(o)) |
121
606a3ccd3682
linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents:
112
diff
changeset
|
33 |
#endif |
592 | 34 |
|
35 |
#ifdef LINUX |
|
594 | 36 |
# define DEV_AUDIO |
37 |
# include <sys/soundcard.h> |
|
38 |
#endif |
|
39 |
||
40 |
#if defined(sunos) || defined(solaris) |
|
41 |
# define DEV_AUDIO |
|
42 |
#endif |
|
43 |
||
44 |
#ifdef DEV_AUDIO |
|
593 | 45 |
# include <stdio.h> |
592 | 46 |
#endif |
712 | 47 |
|
48 |
#ifdef WIN32 |
|
49 |
||
50 |
# define _WIN32 |
|
51 |
||
52 |
# undef INT |
|
53 |
# undef Array |
|
54 |
# undef Number |
|
55 |
# undef Method |
|
56 |
# undef Point |
|
57 |
# undef Rectangle |
|
58 |
# undef Block |
|
59 |
# undef String |
|
60 |
# undef Message |
|
61 |
# undef Object |
|
62 |
# undef Context |
|
63 |
||
64 |
/* # include <stdarg.h> /* */ |
|
65 |
# include <stdio.h> /* */ |
|
66 |
# include <windows.h> |
|
67 |
# define CINTERFACE |
|
68 |
# include "dsound.h" |
|
69 |
||
70 |
# ifdef __DEF_Array |
|
71 |
# define Array __DEF_Array |
|
72 |
# endif |
|
73 |
# ifdef __DEF_Number |
|
74 |
# define Number __DEF_Number |
|
75 |
# endif |
|
76 |
# ifdef __DEF_Method |
|
77 |
# define Method __DEF_Method |
|
78 |
# endif |
|
79 |
# ifdef __DEF_Point |
|
80 |
# define Point __DEF_Point |
|
81 |
# endif |
|
82 |
# ifdef __DEF_Block |
|
83 |
# define Block __DEF_Block |
|
84 |
# endif |
|
85 |
# ifdef __DEF_String |
|
86 |
# define String __DEF_String |
|
87 |
# endif |
|
88 |
# ifdef __DEF_Message |
|
89 |
# define Message __DEF_Message |
|
90 |
# endif |
|
91 |
# ifdef __DEF_Object |
|
92 |
# define Object __DEF_Object |
|
93 |
# endif |
|
94 |
# ifdef __DEF_Context |
|
95 |
# define Context __DEF_Context |
|
96 |
# endif |
|
97 |
||
98 |
# define INT int |
|
99 |
||
100 |
# define __DirectSoundVal(o) (LPDIRECTSOUND)(__externalAddressVal(o)) |
|
101 |
# define __DSBufferVal(o) (LPDIRECTSOUNDBUFFER)(__externalAddressVal(o)) |
|
102 |
||
103 |
# define RT_BUFFER_SIZE 4096 |
|
104 |
# define NBUFS 4 |
|
105 |
||
106 |
#endif |
|
107 |
||
121
606a3ccd3682
linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents:
112
diff
changeset
|
108 |
%} |
606a3ccd3682
linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents:
112
diff
changeset
|
109 |
! ! |
606a3ccd3682
linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents:
112
diff
changeset
|
110 |
|
28 | 111 |
!SoundStream class methodsFor:'documentation'! |
112 |
||
31 | 113 |
copyright |
114 |
" |
|
115 |
COPYRIGHT (c) 1993 by Claus Gittinger |
|
45 | 116 |
All Rights Reserved |
31 | 117 |
|
118 |
This software is furnished under a license and may be used |
|
119 |
only in accordance with the terms of that license and with the |
|
120 |
inclusion of the above copyright notice. This software may not |
|
121 |
be provided or otherwise made available to, or used by, any |
|
122 |
other person. No title to or ownership of the software is |
|
123 |
hereby transferred. |
|
124 |
" |
|
125 |
! |
|
126 |
||
28 | 127 |
documentation |
128 |
" |
|
592 | 129 |
Preliminary (unfinished) interface to audio device. |
593 | 130 |
Currently works with LINUXs or SUNs /dev/audio driver and |
592 | 131 |
IRIX (indy). |
593 | 132 |
On iris, the default setup is for 8 bit mono |
28 | 133 |
so I can play the standard sound files I have here. |
134 |
It needs much more work, for stereo, different sampling rates etc. |
|
135 |
||
592 | 136 |
This is an experimental class - its interface & implementation |
137 |
may change in the future. |
|
138 |
||
259 | 139 |
[author:] |
277
ab17540f022a
oops - your last checkin was garbage
Claus Gittinger <cg@exept.de>
parents:
274
diff
changeset
|
140 |
Claus Gittinger |
28 | 141 |
" |
152 | 142 |
! ! |
45 | 143 |
|
595 | 144 |
!SoundStream class methodsFor:'initialization'! |
145 |
||
146 |
initialize |
|
147 |
UnsupportedOperationSignal isNil ifTrue:[ |
|
712 | 148 |
UnsupportedOperationSignal := StreamErrorSignal newSignalMayProceed:false. |
149 |
UnsupportedOperationSignal nameClass:self message:#unsupportedOperationSignal. |
|
150 |
UnsupportedOperationSignal notifierString:'unsupported operation'. |
|
595 | 151 |
] |
152 |
! ! |
|
153 |
||
0 | 154 |
!SoundStream class methodsFor:'instance creation'! |
155 |
||
156 |
reading |
|
593 | 157 |
"create and return a new soundStream for reading (i.e. recording)" |
158 |
||
0 | 159 |
|newStream| |
160 |
newStream := (self basicNew) initialize. |
|
161 |
newStream openForReading isNil ifTrue:[^nil]. |
|
593 | 162 |
newStream buffered:false. |
163 |
newStream binary. |
|
0 | 164 |
^ newStream |
165 |
||
166 |
"SoundStream reading" |
|
593 | 167 |
|
168 |
"Modified: / 12.12.1997 / 16:51:56 / cg" |
|
0 | 169 |
! |
170 |
||
171 |
writing |
|
593 | 172 |
"create and return a new soundStream for writing (i.e. playback)" |
173 |
||
0 | 174 |
|newStream| |
175 |
||
176 |
newStream := (self basicNew) initialize. |
|
177 |
newStream openForWriting isNil ifTrue:[^nil]. |
|
593 | 178 |
newStream buffered:false. |
179 |
newStream binary. |
|
0 | 180 |
^ newStream |
181 |
||
121
606a3ccd3682
linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents:
112
diff
changeset
|
182 |
" |
606a3ccd3682
linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents:
112
diff
changeset
|
183 |
SoundStream writing |
606a3ccd3682
linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents:
112
diff
changeset
|
184 |
" |
606a3ccd3682
linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents:
112
diff
changeset
|
185 |
|
593 | 186 |
"Created: / 17.11.1995 / 17:25:42 / cg" |
187 |
"Modified: / 12.12.1997 / 16:51:38 / cg" |
|
0 | 188 |
! |
189 |
||
712 | 190 |
writing16BitStereo |
0 | 191 |
"just an example, has never been tried (I also |
592 | 192 |
have no samples for this ... leave it as an exercise)" |
0 | 193 |
|
194 |
|newStream| |
|
195 |
||
593 | 196 |
OperatingSystem getCPUType ~= 'irix' ifTrue:[ |
45 | 197 |
self error:'unsupported audio mode'. |
198 |
^ nil |
|
0 | 199 |
]. |
200 |
newStream := (self basicNew) initialize. |
|
593 | 201 |
newStream buffered:false. |
202 |
newStream binary. |
|
0 | 203 |
newStream bitsPerSample:16. |
204 |
newStream numberOfChannels:2. |
|
205 |
newStream openForWriting isNil ifTrue:[^nil]. |
|
206 |
^ newStream |
|
207 |
||
208 |
"SoundStream writing16BitStereo" |
|
593 | 209 |
|
210 |
"Modified: / 12.12.1997 / 16:51:49 / cg" |
|
0 | 211 |
! ! |
212 |
||
596 | 213 |
!SoundStream class methodsFor:'Signal constants'! |
214 |
||
215 |
unsupportedOperationSignal |
|
216 |
^ UnsupportedOperationSignal |
|
217 |
! ! |
|
218 |
||
592 | 219 |
!SoundStream class methodsFor:'conversion helpers'! |
0 | 220 |
|
596 | 221 |
linear16ToUlaw:a16bitSignedValue |
222 |
"given a 16it signed value, encode into uLaw byte" |
|
223 |
||
224 |
|absVal sign exp mantissa byte| |
|
225 |
||
226 |
%{ |
|
227 |
/* |
|
228 |
* so heavily used when playing sounds ... |
|
229 |
* made it a primitive. |
|
230 |
*/ |
|
231 |
if (__isSmallInteger(a16bitSignedValue)) { |
|
232 |
int __sign = 0; |
|
233 |
int __absVal = __intVal(a16bitSignedValue); |
|
234 |
int __exp, __mantissa, __byte; |
|
235 |
static char __uLawExp[] = |
|
236 |
{ |
|
237 |
0,1,2,2,3,3,3,3,4,4,4,4,4,4,4,4, |
|
238 |
5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5, |
|
239 |
6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6, |
|
240 |
6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6, |
|
241 |
7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, |
|
242 |
7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, |
|
243 |
7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, |
|
244 |
7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7 |
|
245 |
}; |
|
246 |
||
247 |
if (__absVal < 0) { |
|
248 |
if (__absVal <= -32256) { |
|
249 |
RETURN (__MKSMALLINT(0)); |
|
250 |
} |
|
251 |
__absVal = -__absVal; |
|
252 |
__sign = 0x80; |
|
253 |
} else { |
|
254 |
if (__absVal >= 32256) { |
|
255 |
RETURN (__MKSMALLINT(128)); |
|
256 |
} |
|
257 |
} |
|
258 |
||
259 |
__exp = __uLawExp[__absVal >> 8]; |
|
260 |
__mantissa = (__absVal >> (__exp+3)) & 0xF; |
|
261 |
__byte = ~(__sign | (__exp<<4) | __mantissa) & 0xFF; |
|
262 |
RETURN (__MKSMALLINT(__byte)); |
|
263 |
} |
|
264 |
%}. |
|
265 |
"/ |
|
266 |
"/ fallback for non-integral argument |
|
267 |
"/ |
|
712 | 268 |
a16bitSignedValue isInteger ifFalse:[ |
269 |
^ self uLawToLinear16:a16bitSignedValue asInteger |
|
596 | 270 |
]. |
712 | 271 |
^ 0 |
596 | 272 |
|
273 |
" |
|
274 |
SoundStream uLawToLinear16:(SoundStream linear16ToUlaw:0) |
|
275 |
SoundStream uLawToLinear16:(SoundStream linear16ToUlaw:32256) |
|
276 |
SoundStream uLawToLinear16:(SoundStream linear16ToUlaw:-32256) |
|
277 |
SoundStream uLawToLinear16:(SoundStream linear16ToUlaw:32767) |
|
278 |
SoundStream uLawToLinear16:(SoundStream linear16ToUlaw:-32767) |
|
279 |
SoundStream uLawToLinear16:(SoundStream linear16ToUlaw:100) |
|
280 |
SoundStream uLawToLinear16:(SoundStream linear16ToUlaw:-100) |
|
281 |
SoundStream uLawToLinear16:(SoundStream linear16ToUlaw:104) |
|
282 |
SoundStream uLawToLinear16:(SoundStream linear16ToUlaw:-104) |
|
283 |
" |
|
284 |
||
285 |
"Modified: / 9.12.1997 / 16:46:24 / cg" |
|
286 |
! |
|
287 |
||
592 | 288 |
uLawToLinear16:uLawValue |
289 |
"given a uLaw byte, return the decoded signed 16bit value. |
|
290 |
Currently unused - but will be" |
|
0 | 291 |
|
292 |
^ #( |
|
45 | 293 |
"0 " -32256 |
294 |
"1 " -31228 |
|
295 |
"2 " -30200 |
|
296 |
"3 " -29172 |
|
297 |
"4 " -28143 |
|
298 |
"5 " -27115 |
|
299 |
"6 " -26087 |
|
300 |
"7 " -25059 |
|
301 |
"8 " -24031 |
|
302 |
"9 " -23002 |
|
303 |
"10 " -21974 |
|
304 |
"11 " -20946 |
|
305 |
"12 " -19918 |
|
306 |
"13 " -18889 |
|
307 |
"14 " -17861 |
|
308 |
"15 " -16833 |
|
309 |
"16 " -16062 |
|
310 |
"17 " -15548 |
|
311 |
"18 " -15033 |
|
312 |
"19 " -14519 |
|
313 |
"20 " -14005 |
|
314 |
"21 " -13491 |
|
315 |
"22 " -12977 |
|
316 |
"23 " -12463 |
|
317 |
"24 " -11949 |
|
318 |
"25 " -11435 |
|
319 |
"26 " -10920 |
|
320 |
"27 " -10406 |
|
321 |
"28 " -9892 |
|
322 |
"29 " -9378 |
|
323 |
"30 " -8864 |
|
324 |
"31 " -8350 |
|
325 |
"32 " -7964 |
|
326 |
"33 " -7707 |
|
327 |
"34 " -7450 |
|
328 |
"35 " -7193 |
|
329 |
"36 " -6936 |
|
330 |
"37 " -6679 |
|
331 |
"38 " -6422 |
|
332 |
"39 " -6165 |
|
333 |
"40 " -5908 |
|
334 |
"41 " -5651 |
|
335 |
"42 " -5394 |
|
336 |
"43 " -5137 |
|
337 |
"44 " -4880 |
|
338 |
"45 " -4623 |
|
339 |
"46 " -4365 |
|
340 |
"47 " -4108 |
|
341 |
"48 " -3916 |
|
342 |
"49 " -3787 |
|
343 |
"50 " -3659 |
|
344 |
"51 " -3530 |
|
345 |
"52 " -3402 |
|
346 |
"53 " -3273 |
|
347 |
"54 " -3144 |
|
348 |
"55 " -3016 |
|
349 |
"56 " -2887 |
|
350 |
"57 " -2759 |
|
351 |
"58 " -2630 |
|
352 |
"59 " -2502 |
|
353 |
"60 " -2373 |
|
354 |
"61 " -2245 |
|
355 |
"62 " -2116 |
|
356 |
"63 " -1988 |
|
357 |
"64 " -1891 |
|
358 |
"65 " -1827 |
|
359 |
"66 " -1763 |
|
360 |
"67 " -1698 |
|
361 |
"68 " -1634 |
|
362 |
"69 " -1570 |
|
363 |
"70 " -1506 |
|
364 |
"71 " -1441 |
|
365 |
"72 " -1377 |
|
366 |
"73 " -1313 |
|
367 |
"74 " -1249 |
|
368 |
"75 " -1184 |
|
369 |
"76 " -1120 |
|
370 |
"77 " -1056 |
|
371 |
"78 " -992 |
|
372 |
"79 " -927 |
|
373 |
"80 " -879 |
|
374 |
"81 " -847 |
|
375 |
"82 " -815 |
|
376 |
"83 " -783 |
|
377 |
"84 " -751 |
|
378 |
"85 " -718 |
|
379 |
"86 " -686 |
|
380 |
"87 " -654 |
|
381 |
"88 " -622 |
|
382 |
"89 " -590 |
|
383 |
"90 " -558 |
|
384 |
"91 " -526 |
|
385 |
"92 " -494 |
|
386 |
"93 " -461 |
|
387 |
"94 " -429 |
|
388 |
"95 " -397 |
|
389 |
"96 " -373 |
|
390 |
"97 " -357 |
|
391 |
"98 " -341 |
|
392 |
"99 " -325 |
|
393 |
"100" -309 |
|
394 |
"101" -293 |
|
395 |
"102" -277 |
|
396 |
"103" -261 |
|
397 |
"104" -245 |
|
398 |
"105" -228 |
|
399 |
"106" -212 |
|
400 |
"107" -196 |
|
401 |
"108" -180 |
|
402 |
"109" -164 |
|
403 |
"110" -148 |
|
404 |
"111" -132 |
|
405 |
"112" -120 |
|
406 |
"113" -112 |
|
407 |
"114" -104 |
|
408 |
"115" -96 |
|
409 |
"116" -88 |
|
410 |
"117" -80 |
|
411 |
"118" -72 |
|
412 |
"119" -64 |
|
413 |
"120" -56 |
|
414 |
"121" -48 |
|
415 |
"122" -40 |
|
416 |
"123" -32 |
|
417 |
"124" -24 |
|
418 |
"125" -16 |
|
419 |
"126" -8 |
|
420 |
"127" 0 |
|
421 |
"128" 32256 |
|
422 |
"129" 31228 |
|
423 |
"130" 30200 |
|
424 |
"131" 29172 |
|
425 |
"132" 28143 |
|
426 |
"133" 27115 |
|
427 |
"134" 26087 |
|
428 |
"135" 25059 |
|
429 |
"136" 24031 |
|
430 |
"137" 23002 |
|
431 |
"138" 21974 |
|
432 |
"139" 20946 |
|
433 |
"140" 19918 |
|
434 |
"141" 18889 |
|
435 |
"142" 17861 |
|
436 |
"143" 16833 |
|
437 |
"144" 16062 |
|
438 |
"145" 15548 |
|
439 |
"146" 15033 |
|
440 |
"147" 14519 |
|
441 |
"148" 14005 |
|
442 |
"149" 13491 |
|
443 |
"150" 12977 |
|
444 |
"151" 12463 |
|
445 |
"152" 11949 |
|
446 |
"153" 11435 |
|
447 |
"154" 10920 |
|
448 |
"155" 10406 |
|
449 |
"156" 9892 |
|
450 |
"157" 9378 |
|
451 |
"158" 8864 |
|
452 |
"159" 8350 |
|
453 |
"160" 7964 |
|
454 |
"161" 7707 |
|
455 |
"162" 7450 |
|
456 |
"163" 7193 |
|
457 |
"164" 6936 |
|
458 |
"165" 6679 |
|
459 |
"166" 6422 |
|
460 |
"167" 6165 |
|
461 |
"168" 5908 |
|
462 |
"169" 5651 |
|
463 |
"170" 5394 |
|
464 |
"171" 5137 |
|
465 |
"172" 4880 |
|
466 |
"173" 4623 |
|
467 |
"174" 4365 |
|
468 |
"175" 4108 |
|
469 |
"176" 3916 |
|
470 |
"177" 3787 |
|
471 |
"178" 3659 |
|
472 |
"179" 3530 |
|
473 |
"180" 3402 |
|
474 |
"181" 3273 |
|
475 |
"182" 3144 |
|
476 |
"183" 3016 |
|
477 |
"184" 2887 |
|
478 |
"185" 2759 |
|
479 |
"186" 2630 |
|
480 |
"187" 2502 |
|
481 |
"188" 2373 |
|
482 |
"189" 2245 |
|
483 |
"190" 2116 |
|
484 |
"191" 1988 |
|
485 |
"192" 1891 |
|
486 |
"193" 1827 |
|
487 |
"194" 1763 |
|
488 |
"195" 1698 |
|
489 |
"196" 1634 |
|
490 |
"197" 1570 |
|
491 |
"198" 1506 |
|
492 |
"199" 1441 |
|
493 |
"200" 1377 |
|
494 |
"201" 1313 |
|
495 |
"202" 1249 |
|
496 |
"203" 1184 |
|
497 |
"204" 1120 |
|
498 |
"205" 1056 |
|
499 |
"206" 992 |
|
500 |
"207" 927 |
|
501 |
"208" 879 |
|
502 |
"209" 847 |
|
503 |
"210" 815 |
|
504 |
"211" 783 |
|
505 |
"212" 751 |
|
506 |
"213" 718 |
|
507 |
"214" 686 |
|
508 |
"215" 654 |
|
509 |
"216" 622 |
|
510 |
"217" 590 |
|
511 |
"218" 558 |
|
512 |
"219" 526 |
|
513 |
"220" 494 |
|
514 |
"221" 461 |
|
515 |
"222" 429 |
|
516 |
"223" 397 |
|
517 |
"224" 373 |
|
518 |
"225" 357 |
|
519 |
"226" 341 |
|
520 |
"227" 325 |
|
521 |
"228" 309 |
|
522 |
"229" 293 |
|
523 |
"230" 277 |
|
524 |
"231" 261 |
|
525 |
"232" 245 |
|
526 |
"233" 228 |
|
527 |
"234" 212 |
|
528 |
"235" 196 |
|
529 |
"236" 180 |
|
530 |
"237" 164 |
|
531 |
"238" 148 |
|
532 |
"239" 132 |
|
533 |
"240" 120 |
|
534 |
"241" 112 |
|
535 |
"242" 104 |
|
536 |
"243" 96 |
|
537 |
"244" 88 |
|
538 |
"245" 80 |
|
539 |
"246" 72 |
|
540 |
"247" 64 |
|
541 |
"248" 56 |
|
542 |
"249" 48 |
|
543 |
"250" 40 |
|
544 |
"251" 32 |
|
545 |
"252" 24 |
|
546 |
"253" 16 |
|
547 |
"254" 8 |
|
548 |
"255" 0 |
|
0 | 549 |
) at:(uLawValue + 1) |
592 | 550 |
|
551 |
"Modified: / 9.12.1997 / 16:34:17 / cg" |
|
0 | 552 |
! ! |
553 |
||
121
606a3ccd3682
linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents:
112
diff
changeset
|
554 |
!SoundStream class methodsFor:'default values'! |
606a3ccd3682
linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents:
112
diff
changeset
|
555 |
|
596 | 556 |
defaultAudioFormat |
712 | 557 |
OperatingSystem getOSType = 'win32' ifTrue:[ |
558 |
^ #S16 |
|
559 |
]. |
|
596 | 560 |
^ #U8 |
561 |
! |
|
562 |
||
121
606a3ccd3682
linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents:
112
diff
changeset
|
563 |
defaultBitsPerSample |
606a3ccd3682
linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents:
112
diff
changeset
|
564 |
"minimum, supported by all audio systems" |
606a3ccd3682
linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents:
112
diff
changeset
|
565 |
|
712 | 566 |
OperatingSystem getOSType = 'win32' ifTrue:[ |
567 |
^ 16 |
|
568 |
]. |
|
121
606a3ccd3682
linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents:
112
diff
changeset
|
569 |
^ 8 |
606a3ccd3682
linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents:
112
diff
changeset
|
570 |
! |
606a3ccd3682
linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents:
112
diff
changeset
|
571 |
|
606a3ccd3682
linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents:
112
diff
changeset
|
572 |
defaultNumberOfChannels |
606a3ccd3682
linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents:
112
diff
changeset
|
573 |
"minimum, supported by all audio systems" |
606a3ccd3682
linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents:
112
diff
changeset
|
574 |
|
606a3ccd3682
linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents:
112
diff
changeset
|
575 |
^ 1 |
606a3ccd3682
linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents:
112
diff
changeset
|
576 |
! |
606a3ccd3682
linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents:
112
diff
changeset
|
577 |
|
606a3ccd3682
linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents:
112
diff
changeset
|
578 |
defaultSampleRate |
606a3ccd3682
linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents:
112
diff
changeset
|
579 |
"minimum, supported by all audio systems" |
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 |
^ 8000 |
606a3ccd3682
linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents:
112
diff
changeset
|
582 |
! ! |
606a3ccd3682
linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents:
112
diff
changeset
|
583 |
|
606a3ccd3682
linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents:
112
diff
changeset
|
584 |
!SoundStream class methodsFor:'playing'! |
606a3ccd3682
linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents:
112
diff
changeset
|
585 |
|
606a3ccd3682
linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents:
112
diff
changeset
|
586 |
playSoundFile:aFilename |
593 | 587 |
"play a soundFile" |
588 |
||
121
606a3ccd3682
linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents:
112
diff
changeset
|
589 |
|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
|
590 |
|
606a3ccd3682
linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents:
112
diff
changeset
|
591 |
inStream := aFilename asFilename readStream. |
606a3ccd3682
linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents:
112
diff
changeset
|
592 |
inStream isNil ifTrue:[^ self]. |
606a3ccd3682
linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents:
112
diff
changeset
|
593 |
|
606a3ccd3682
linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents:
112
diff
changeset
|
594 |
soundStream := self writing. |
606a3ccd3682
linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents:
112
diff
changeset
|
595 |
soundStream isNil ifTrue:[^ self]. |
606a3ccd3682
linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents:
112
diff
changeset
|
596 |
soundStream buffered:false. |
606a3ccd3682
linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents:
112
diff
changeset
|
597 |
|
606a3ccd3682
linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents:
112
diff
changeset
|
598 |
startTime := AbsoluteTime now. |
606a3ccd3682
linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents:
112
diff
changeset
|
599 |
totalCount := 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 |
buffer := ByteArray new:4096. |
606a3ccd3682
linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents:
112
diff
changeset
|
602 |
[(count := inStream nextBytesInto:buffer) > 0] whileTrue:[ |
277
ab17540f022a
oops - your last checkin was garbage
Claus Gittinger <cg@exept.de>
parents:
274
diff
changeset
|
603 |
totalCount := totalCount + count. |
ab17540f022a
oops - your last checkin was garbage
Claus Gittinger <cg@exept.de>
parents:
274
diff
changeset
|
604 |
soundStream nextPutBytes:count from:buffer. |
121
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 |
|
606a3ccd3682
linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents:
112
diff
changeset
|
607 |
inStream close. |
606a3ccd3682
linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents:
112
diff
changeset
|
608 |
soundStream commit. |
606a3ccd3682
linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents:
112
diff
changeset
|
609 |
|
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 |
"/ 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
|
612 |
"/ |
606a3ccd3682
linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents:
112
diff
changeset
|
613 |
playTime := totalCount / soundStream sampleRate. |
606a3ccd3682
linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents:
112
diff
changeset
|
614 |
delayedTime := (AbsoluteTime now - startTime). |
606a3ccd3682
linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents:
112
diff
changeset
|
615 |
waitTime := playTime - delayedTime + 0.1. |
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 |
(Delay forSeconds:waitTime) wait. |
606a3ccd3682
linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents:
112
diff
changeset
|
618 |
|
606a3ccd3682
linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents:
112
diff
changeset
|
619 |
soundStream close. |
606a3ccd3682
linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents:
112
diff
changeset
|
620 |
|
606a3ccd3682
linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents:
112
diff
changeset
|
621 |
" |
606a3ccd3682
linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents:
112
diff
changeset
|
622 |
SoundStream playSoundFile:'/usr/local/lib/sounds/laugh.snd' |
606a3ccd3682
linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents:
112
diff
changeset
|
623 |
SoundStream playSoundFile:'/usr/local/lib/sounds/spacemusic.snd' |
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 |
|
606a3ccd3682
linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents:
112
diff
changeset
|
626 |
"Created: 17.11.1995 / 17:25:30 / cg" |
606a3ccd3682
linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents:
112
diff
changeset
|
627 |
"Modified: 17.11.1995 / 17:45:40 / cg" |
606a3ccd3682
linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents:
112
diff
changeset
|
628 |
! ! |
606a3ccd3682
linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents:
112
diff
changeset
|
629 |
|
596 | 630 |
!SoundStream methodsFor:'catching invalid methods'! |
631 |
||
632 |
pathName:filename |
|
633 |
"catch pathname access - its fixed here" |
|
634 |
||
635 |
self shouldNotImplement |
|
636 |
! |
|
637 |
||
638 |
pathName:filename in:aDirectory |
|
639 |
"catch pathname access - its fixed here" |
|
640 |
||
641 |
self shouldNotImplement |
|
642 |
! ! |
|
643 |
||
644 |
!SoundStream methodsFor:'mode setting'! |
|
645 |
||
646 |
bitsPerSample |
|
647 |
"return the number of bits per sample - usually 8" |
|
648 |
||
649 |
^ bitsPerSample |
|
650 |
! |
|
651 |
||
652 |
bitsPerSample:aNumber |
|
653 |
"set the number of bits per sample" |
|
654 |
||
655 |
bitsPerSample := aNumber |
|
656 |
! |
|
657 |
||
658 |
numberOfChannels |
|
659 |
"return the number of channels (1 or 2; usually 1)" |
|
660 |
||
661 |
^ numberOfChannels |
|
662 |
! |
|
663 |
||
664 |
numberOfChannels:aNumber |
|
665 |
"set the number of channels" |
|
666 |
||
667 |
numberOfChannels := aNumber |
|
668 |
! |
|
669 |
||
670 |
sampleRate |
|
671 |
"return the sample rate" |
|
672 |
||
673 |
^ sampleRate |
|
674 |
! |
|
675 |
||
676 |
sampleRate:aNumber |
|
677 |
"set the sample rate in hertz - on some |
|
678 |
devices, this is a nop" |
|
679 |
||
680 |
self setSampleRate:aNumber. |
|
681 |
! ! |
|
682 |
||
592 | 683 |
!SoundStream methodsFor:'private'! |
684 |
||
593 | 685 |
dumpSettings |
686 |
"debugging interface - dump the current settings" |
|
687 |
||
595 | 688 |
|fd blockSize speed channels stereo| |
592 | 689 |
|
690 |
fd := self fileDescriptor. |
|
691 |
fd isNil ifTrue:[ |
|
712 | 692 |
self error. |
693 |
^ nil |
|
592 | 694 |
]. |
695 |
%{ |
|
696 |
int f = __intVal(fd); |
|
697 |
int __blockSize = -1; |
|
698 |
int __speed = 0; |
|
699 |
int __stereo = 0; |
|
700 |
int __channels = 0; |
|
701 |
||
594 | 702 |
#if defined(DEV_AUDIO) |
595 | 703 |
channels = __MKSMALLINT(1); |
704 |
stereo = __MKSMALLINT(0); |
|
705 |
speed = __MKSMALLINT(8000); |
|
712 | 706 |
|
707 |
# if defined(SNDCTL_DSP_GETBLKSIZE) |
|
708 |
if (ioctl(f, SNDCTL_DSP_GETBLKSIZE, &__blockSize) >= 0) { |
|
709 |
blockSize = __MKSMALLINT(__blockSize); |
|
710 |
} |
|
711 |
# endif |
|
712 |
# if defined(SNDCTL_DSP_CHANNELS) |
|
713 |
if (ioctl(f, SNDCTL_DSP_CHANNELS, &__channels) >= 0) { |
|
714 |
channels = __MKSMALLINT(__channels); |
|
715 |
} |
|
716 |
# endif |
|
717 |
# if defined(SNDCTL_DSP_STEREO) |
|
718 |
if (ioctl(f, SNDCTL_DSP_STEREO, &__stereo) >= 0) { |
|
719 |
stereo = __MKSMALLINT(__stereo); |
|
720 |
} |
|
721 |
# endif |
|
722 |
# if defined(SNDCTL_DSP_SPEED) |
|
723 |
if (ioctl(f, SNDCTL_DSP_SPEED, &__speed) >= 0) { |
|
724 |
speed = __MKSMALLINT(__speed); |
|
725 |
} |
|
726 |
# endif |
|
594 | 727 |
#endif /* DEV_AUDIO */ |
592 | 728 |
%}. |
729 |
blockSize notNil ifTrue:[ |
|
712 | 730 |
Transcript show:'blockSize: '; showCR:blockSize |
592 | 731 |
]. |
732 |
speed notNil ifTrue:[ |
|
712 | 733 |
Transcript show:'speed: '; showCR:speed |
592 | 734 |
]. |
735 |
channels notNil ifTrue:[ |
|
712 | 736 |
Transcript show:'channels: '; showCR:channels |
592 | 737 |
]. |
738 |
stereo notNil ifTrue:[ |
|
712 | 739 |
Transcript show:'stereo: '; showCR:stereo |
592 | 740 |
]. |
741 |
||
593 | 742 |
Transcript show:'audioFormats: '; showCR:(self supportedAudioFormats). |
592 | 743 |
|
744 |
" |
|
593 | 745 |
self writing dumpSettings; close |
746 |
" |
|
747 |
! |
|
748 |
||
596 | 749 |
initialize |
750 |
"initialize for least common mode" |
|
593 | 751 |
|
596 | 752 |
buffered := false. |
712 | 753 |
bitsPerSample := self class defaultBitsPerSample. |
754 |
audioFormat := self class defaultAudioFormat. |
|
755 |
numberOfChannels := self class defaultNumberOfChannels. |
|
756 |
sampleRate := self class defaultSampleRate. |
|
757 |
pathName := nil. |
|
595 | 758 |
|
712 | 759 |
OperatingSystem getOSType ~= 'win32' ifTrue:[ |
760 |
'/dev/audio' asFilename exists ifTrue:[ |
|
761 |
"/ |
|
762 |
"/ sunos or linux |
|
763 |
"/ |
|
764 |
pathName := '/dev/audio'. |
|
765 |
]. |
|
595 | 766 |
]. |
593 | 767 |
|
596 | 768 |
"Created: 17.11.1995 / 17:28:14 / cg" |
592 | 769 |
! |
770 |
||
771 |
resetSoundCard |
|
593 | 772 |
"debugging interface - reset the soundCard" |
773 |
||
592 | 774 |
|fd| |
775 |
||
712 | 776 |
filePointer notNil ifTrue:[ |
777 |
fd := self fileDescriptor. |
|
778 |
fd isNil ifTrue:[ |
|
779 |
self error. |
|
780 |
^ nil |
|
781 |
] |
|
592 | 782 |
]. |
783 |
%{ |
|
784 |
int f = __intVal(fd); |
|
785 |
int __dummy; |
|
786 |
||
712 | 787 |
#if defined(DEV_AUDIO) |
788 |
if (__isSmallInteger(fd)) { |
|
614
565ea4308322
make it compilable on elder linux's
Claus Gittinger <cg@exept.de>
parents:
598
diff
changeset
|
789 |
# if defined(SNDCTL_DSP_RESET) |
712 | 790 |
if (ioctl(f, SNDCTL_DSP_RESET, &__dummy) >= 0) { |
791 |
RETURN (self); |
|
792 |
} |
|
793 |
# endif |
|
592 | 794 |
} |
795 |
#endif |
|
796 |
%}. |
|
595 | 797 |
^ UnsupportedOperationSignal raise |
592 | 798 |
|
799 |
" |
|
593 | 800 |
self writing resetSoundCard; dumpSettings; close |
592 | 801 |
" |
802 |
! |
|
803 |
||
804 |
setAudioFormat:aSymbol |
|
593 | 805 |
"set the format of the audio data as specified by aSymbol. |
806 |
Returns true if sucessfull - may fail with some formats on many sound devices." |
|
807 |
||
592 | 808 |
|fd| |
809 |
||
712 | 810 |
filePointer notNil ifTrue:[ |
811 |
fd := self fileDescriptor. |
|
812 |
fd isNil ifTrue:[ |
|
813 |
self error. |
|
814 |
^ nil |
|
815 |
] |
|
592 | 816 |
]. |
817 |
%{ |
|
818 |
int f = __intVal(fd); |
|
597 | 819 |
int __fmt = 0, __fmtWant; |
593 | 820 |
union { |
712 | 821 |
unsigned short us; |
822 |
unsigned char ub[2]; |
|
593 | 823 |
} u; |
597 | 824 |
OBJ sym = aSymbol; |
592 | 825 |
|
712 | 826 |
#if defined(DEV_AUDIO) |
827 |
if (__isSmallInteger(fd)) { |
|
828 |
if (__isSymbol(sym)) { |
|
829 |
if (sym == @symbol(U16)) { |
|
830 |
u.us = 0x1234; |
|
831 |
if (u.ub[0] == 0x34) { |
|
597 | 832 |
/* printf("U16_LE\n"); */ |
712 | 833 |
sym = @symbol(U16_LE); |
834 |
} else { |
|
597 | 835 |
/* printf("U16_BE\n"); */ |
712 | 836 |
sym = @symbol(U16_BE); |
837 |
} |
|
838 |
} else if (sym == @symbol(S16)) { |
|
839 |
u.us = 0x1234; |
|
840 |
if (u.ub[0] == 0x34) { |
|
597 | 841 |
/* printf("S16_LE\n"); */ |
712 | 842 |
sym = @symbol(S16_LE); |
843 |
} else { |
|
597 | 844 |
/* printf("S16_BE\n"); */ |
712 | 845 |
sym = @symbol(S16_BE); |
846 |
} |
|
847 |
} |
|
593 | 848 |
|
712 | 849 |
if (0) { |
850 |
#ifdef AFMT_MU_LAW |
|
851 |
} else if (sym == @symbol(MU_LAW)) { |
|
852 |
__fmt = AFMT_MU_LAW; |
|
853 |
#endif |
|
854 |
#ifdef AFMT_A_LAW |
|
855 |
} else if (sym == @symbol(A_LAW)) { |
|
856 |
__fmt = AFMT_A_LAW; |
|
857 |
#endif |
|
858 |
#ifdef AFMT_IMA_ADPCM |
|
859 |
} else if (sym == @symbol(IMA_ADPCM)) { |
|
860 |
__fmt = AFMT_IMA_ADPCM; |
|
861 |
#endif |
|
862 |
#ifdef AFMT_U8 |
|
863 |
} else if (sym == @symbol(U8)) { |
|
864 |
__fmt = AFMT_U8; |
|
865 |
#endif |
|
866 |
#ifdef AFMT_S8 |
|
867 |
} else if (sym == @symbol(S8)) { |
|
868 |
__fmt = AFMT_S8; |
|
869 |
#endif |
|
870 |
#ifdef AFMT_U16_LE |
|
871 |
} else if (sym == @symbol(U16_LE)) { |
|
872 |
__fmt = AFMT_U16_LE; |
|
873 |
#endif |
|
874 |
#ifdef AFMT_U16_BE |
|
875 |
} else if (sym == @symbol(U16_BE)) { |
|
876 |
__fmt = AFMT_U16_BE; |
|
877 |
#endif |
|
878 |
#ifdef AFMT_S16_LE |
|
879 |
} else if (sym == @symbol(S16_LE)) { |
|
880 |
__fmt = AFMT_S16_LE; |
|
881 |
#endif |
|
882 |
#ifdef AFMT_S16_BE |
|
883 |
} else if (sym == @symbol(S16_BE)) { |
|
884 |
__fmt = AFMT_S16_BE; |
|
885 |
#endif |
|
886 |
#ifdef AFMT_MPEG |
|
887 |
} else if (sym == @symbol(MPEG)) { |
|
888 |
__fmt = AFMT_MPEG; |
|
889 |
#endif |
|
890 |
} else { |
|
891 |
fprintf(stderr, "bad format: %s\n", __stringVal(sym)); |
|
892 |
goto bad; |
|
893 |
} |
|
894 |
} |
|
895 |
||
896 |
__fmtWant = __fmt; |
|
897 |
||
898 |
#ifdef SNDCTL_DSP_SETFMT |
|
899 |
if (ioctl(f, SNDCTL_DSP_SETFMT, &__fmt) >= 0) { |
|
900 |
if (__fmt == __fmtWant) { |
|
901 |
__INST(audioFormat) = sym; |
|
902 |
RETURN (self); |
|
903 |
} else { |
|
904 |
/* fprintf(stderr, "want: %x; got: %x\n", __fmtWant, __fmt); */ |
|
905 |
} |
|
906 |
} else { |
|
907 |
/* fprintf(stderr, "got err-return from setFmp %x\n", __fmt); */ |
|
908 |
} |
|
909 |
#endif /* SNDCTL_DSP_SETFMT */ |
|
910 |
||
911 |
bad: ; |
|
592 | 912 |
} |
712 | 913 |
#endif /* DEV_AUDIO */ |
614
565ea4308322
make it compilable on elder linux's
Claus Gittinger <cg@exept.de>
parents:
598
diff
changeset
|
914 |
|
592 | 915 |
%}. |
597 | 916 |
^ UnsupportedOperationSignal raise |
592 | 917 |
|
918 |
" |
|
919 |
self writing setAudioFormat:#'MU_LAW'; close |
|
597 | 920 |
self writing setAudioFormat:#'U8'; dumpSettings; close |
921 |
self writing setAudioFormat:#'MPEG'; dumpSettings; close |
|
592 | 922 |
" |
593 | 923 |
! |
924 |
||
925 |
setChannels:nChannels |
|
926 |
"set the number of channels (1 -> mono; 2 -> stereo). |
|
927 |
Returns true if sucessfull - may fail with many sound devices." |
|
928 |
||
929 |
|fd| |
|
930 |
||
712 | 931 |
filePointer notNil ifTrue:[ |
932 |
fd := self fileDescriptor. |
|
933 |
fd isNil ifTrue:[ |
|
934 |
self error. |
|
935 |
^ nil |
|
936 |
] |
|
593 | 937 |
]. |
938 |
%{ |
|
939 |
int f = __intVal(fd); |
|
940 |
int __nCh = 0; |
|
941 |
||
712 | 942 |
#if defined(DEV_AUDIO) && defined(SOUND_PCM_WRITE_CHANNELS) |
943 |
if (__isSmallInteger(fd) && __isSmallInteger(nChannels)) { |
|
593 | 944 |
__nCh = __intVal(nChannels); |
945 |
if (ioctl(f, SOUND_PCM_WRITE_CHANNELS, &__nCh) >= 0) { |
|
946 |
__INST(numberOfChannels) = nChannels; |
|
595 | 947 |
RETURN (self); |
593 | 948 |
} |
949 |
} |
|
950 |
#endif |
|
951 |
%}. |
|
595 | 952 |
^ UnsupportedOperationSignal raise |
593 | 953 |
|
954 |
" |
|
955 |
self writing setChannels:2; dumpSettings; close |
|
956 |
self writing setChannels:2; setSampleRate:10000; dumpSettings; close |
|
957 |
self writing setChannels:2; setSampleRate:40000; dumpSettings; close |
|
958 |
" |
|
959 |
! |
|
960 |
||
961 |
setFragmentSize:blockSize |
|
962 |
"set the soundDrivers fragmentSize. |
|
963 |
Returns true if sucessfull - may fail with many sound devices." |
|
964 |
||
965 |
|fd| |
|
966 |
||
712 | 967 |
filePointer notNil ifTrue:[ |
968 |
fd := self fileDescriptor. |
|
969 |
fd isNil ifTrue:[ |
|
970 |
self error. |
|
971 |
^ nil |
|
972 |
] |
|
593 | 973 |
]. |
974 |
%{ |
|
975 |
int f = __intVal(fd); |
|
976 |
int __blockSize = 0; |
|
977 |
||
712 | 978 |
#if defined(DEV_AUDIO) && defined(SNDCTL_DSP_SETFRAGMENT) |
979 |
if (__isSmallInteger(fd) && __isSmallInteger(blockSize)) { |
|
593 | 980 |
__blockSize = __intVal(blockSize); |
981 |
if (ioctl(f, SNDCTL_DSP_SETFRAGMENT, &__blockSize) >= 0) { |
|
982 |
/* __INST(blockSize) = blockSize; */ |
|
595 | 983 |
RETURN (self); |
593 | 984 |
} |
985 |
} |
|
986 |
#endif |
|
987 |
%}. |
|
595 | 988 |
^ UnsupportedOperationSignal raise |
593 | 989 |
! |
990 |
||
991 |
setSampleRate:hz |
|
992 |
"set the sample rate. |
|
993 |
Returns true if sucessfull - may fail with many sound devices." |
|
994 |
||
995 |
|fd| |
|
996 |
||
712 | 997 |
filePointer notNil ifTrue:[ |
998 |
fd := self fileDescriptor. |
|
999 |
fd isNil ifTrue:[ |
|
1000 |
self error. |
|
1001 |
^ nil |
|
1002 |
] |
|
593 | 1003 |
]. |
1004 |
%{ |
|
1005 |
int f = __intVal(fd); |
|
1006 |
int __rate = 0; |
|
1007 |
int __rateWant; |
|
1008 |
||
712 | 1009 |
#if defined(DEV_AUDIO) && defined(SOUND_PCM_WRITE_RATE) |
1010 |
if (__isSmallInteger(fd) && __isSmallInteger(hz)) { |
|
593 | 1011 |
__rate = __rateWant = __intVal(hz); |
1012 |
if (ioctl(f, SOUND_PCM_WRITE_RATE, &__rate) >= 0) { |
|
1013 |
if (__rate != __rateWant) { |
|
1014 |
fprintf(stderr, "SoundStream [warning]: actual rate is %d\n", __rate); |
|
1015 |
hz = __MKSMALLINT(__rate); |
|
1016 |
} |
|
1017 |
__INST(sampleRate) = hz; |
|
595 | 1018 |
RETURN (self); |
593 | 1019 |
} |
1020 |
} |
|
1021 |
#endif |
|
1022 |
%}. |
|
595 | 1023 |
^ UnsupportedOperationSignal raise |
593 | 1024 |
|
1025 |
" |
|
1026 |
self writing setSampleRate:10000; dumpSettings; close |
|
1027 |
self writing setSampleRate:1000; dumpSettings; close |
|
1028 |
" |
|
121
606a3ccd3682
linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents:
112
diff
changeset
|
1029 |
! |
606a3ccd3682
linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents:
112
diff
changeset
|
1030 |
|
596 | 1031 |
supportedAudioFormats |
1032 |
"return a collection of supported audio formats. |
|
1033 |
returned symbols are: |
|
1034 |
U8 unsigned 8bit samples |
|
1035 |
S8 signed 8bit samples |
|
1036 |
MU_LAW u-law encoded 8bit samples |
|
1037 |
A_LAW a-law encoded 8bit samples |
|
1038 |
IMA_ADPCM adpcm encoded |
|
1039 |
U16 unsigned 16bit samples |
|
1040 |
U16_LE unsigned 16bit big endian samples |
|
1041 |
U16_BE unsigned 16bit big endian samples |
|
1042 |
S16 signed 16bit little endian samples |
|
1043 |
S16_LE signed 16bit little endian samples |
|
1044 |
S16_BE signed 16bit big endian samples |
|
1045 |
MPEG audio mpeg encoded |
|
712 | 1046 |
PCM pcm |
596 | 1047 |
" |
121
606a3ccd3682
linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents:
112
diff
changeset
|
1048 |
|
596 | 1049 |
|fd audioFormatMask |
1050 |
supportedFormats |
|
1051 |
supports_MU_LAW supports_A_LAW |
|
1052 |
supports_IMA_ADPCM supports_U8 |
|
1053 |
supports_S16_LE supports_S16_BE |
|
1054 |
supports_S8 supports_U16_LE |
|
712 | 1055 |
supports_U16_BE supports_MPEG supports_PCM| |
121
606a3ccd3682
linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents:
112
diff
changeset
|
1056 |
|
596 | 1057 |
fd := self fileDescriptor. |
1058 |
fd isNil ifTrue:[ |
|
1059 |
self error. |
|
1060 |
^ nil |
|
1061 |
]. |
|
1062 |
%{ |
|
1063 |
int f = __intVal(fd); |
|
1064 |
int __audioFormatMask = 0; |
|
1065 |
||
1066 |
#if defined(DEV_AUDIO) |
|
712 | 1067 |
supports_MU_LAW = true; |
1068 |
||
1069 |
# if defined(SNDCTL_DSP_GETFMTS) |
|
596 | 1070 |
if (ioctl(f, SNDCTL_DSP_GETFMTS, &__audioFormatMask) >= 0) { |
1071 |
audioFormatMask = __MKSMALLINT(__audioFormatMask); |
|
121
606a3ccd3682
linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents:
112
diff
changeset
|
1072 |
|
712 | 1073 |
# ifdef AFMT_MU_LAW |
596 | 1074 |
supports_MU_LAW = (__audioFormatMask & AFMT_MU_LAW) ? true : false; |
712 | 1075 |
# endif |
1076 |
# ifdef AFMT_A_LAW |
|
596 | 1077 |
supports_A_LAW = (__audioFormatMask & AFMT_A_LAW) ? true : false; |
712 | 1078 |
# endif |
1079 |
# ifdef AFMT_IMA_ADPCM |
|
596 | 1080 |
supports_IMA_ADPCM = (__audioFormatMask & AFMT_IMA_ADPCM) ? true : false; |
712 | 1081 |
# endif |
1082 |
# ifdef AFMT_U8 |
|
596 | 1083 |
supports_U8 = (__audioFormatMask & AFMT_U8) ? true : false; |
712 | 1084 |
# endif |
1085 |
# ifdef AFMT_S16_LE |
|
596 | 1086 |
supports_S16_LE = (__audioFormatMask & AFMT_S16_LE) ? true : false; |
712 | 1087 |
# endif |
1088 |
# ifdef AFMT_S16_BE |
|
596 | 1089 |
supports_S16_BE = (__audioFormatMask & AFMT_S16_BE) ? true : false; |
712 | 1090 |
# endif |
1091 |
# ifdef AFMT_S8 |
|
596 | 1092 |
supports_S8 = (__audioFormatMask & AFMT_S8) ? true : false; |
712 | 1093 |
# endif |
1094 |
# ifdef AFMT_U16_LE |
|
596 | 1095 |
supports_U16_LE = (__audioFormatMask & AFMT_U16_LE) ? true : false; |
712 | 1096 |
# endif |
1097 |
# ifdef AFMT_U16_BE |
|
596 | 1098 |
supports_U16_BE = (__audioFormatMask & AFMT_U16_BE) ? true : false; |
712 | 1099 |
# endif |
1100 |
# ifdef AFMT_MPEG |
|
596 | 1101 |
supports_MPEG = (__audioFormatMask & AFMT_MPEG) ? true : false; |
712 | 1102 |
# endif |
596 | 1103 |
} |
1104 |
# endif |
|
0 | 1105 |
|
596 | 1106 |
#endif /* DEV_AUDIO */ |
0 | 1107 |
|
596 | 1108 |
#ifdef IRIS_AUDIO |
1109 |
supports_U8 = true; |
|
1110 |
supports_U16_BE = true; |
|
1111 |
#endif |
|
0 | 1112 |
|
712 | 1113 |
#ifdef WIN32 |
1114 |
supports_S16_LE = true; |
|
1115 |
#endif |
|
1116 |
||
596 | 1117 |
%}. |
1118 |
supportedFormats := IdentitySet new. |
|
1119 |
supports_MU_LAW ifTrue:[ |
|
1120 |
supportedFormats add:#'MU_LAW' |
|
1121 |
]. |
|
1122 |
supports_A_LAW ifTrue:[ |
|
1123 |
supportedFormats add:#'A_LAW' |
|
1124 |
]. |
|
1125 |
supports_IMA_ADPCM ifTrue:[ |
|
1126 |
supportedFormats add:#'IMA_ADPCM' |
|
1127 |
]. |
|
1128 |
supports_S8 ifTrue:[ |
|
1129 |
supportedFormats add:#'S8' |
|
1130 |
]. |
|
1131 |
supports_U8 ifTrue:[ |
|
1132 |
supportedFormats add:#'U8' |
|
0 | 1133 |
]. |
596 | 1134 |
supports_S16_LE ifTrue:[ |
1135 |
supportedFormats add:#'S16_LE'. |
|
1136 |
supportedFormats add:#'S16'. |
|
1137 |
]. |
|
1138 |
supports_S16_BE ifTrue:[ |
|
1139 |
supportedFormats add:#'S16_BE'. |
|
1140 |
supportedFormats add:#'S16'. |
|
1141 |
]. |
|
1142 |
supports_U16_LE ifTrue:[ |
|
1143 |
supportedFormats add:#'U16_LE'. |
|
1144 |
supportedFormats add:#'U16'. |
|
1145 |
]. |
|
1146 |
supports_U16_BE ifTrue:[ |
|
1147 |
supportedFormats add:#'U16_BE'. |
|
1148 |
supportedFormats add:#'U16'. |
|
1149 |
]. |
|
1150 |
supports_MPEG ifTrue:[ |
|
1151 |
supportedFormats add:#'MPEG' |
|
1152 |
]. |
|
1153 |
^ supportedFormats. |
|
0 | 1154 |
|
596 | 1155 |
" |
1156 |
|s formats| |
|
0 | 1157 |
|
596 | 1158 |
s := self writing. |
1159 |
formats := s supportedAudioFormats. |
|
1160 |
s close. |
|
1161 |
formats |
|
1162 |
" |
|
0 | 1163 |
! ! |
1164 |
||
1165 |
!SoundStream methodsFor:'redefined'! |
|
1166 |
||
712 | 1167 |
XXclose |
121
606a3ccd3682
linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents:
112
diff
changeset
|
1168 |
OperatingSystem getOSType = 'irix' ifTrue:[ |
277
ab17540f022a
oops - your last checkin was garbage
Claus Gittinger <cg@exept.de>
parents:
274
diff
changeset
|
1169 |
^ self closeFile |
121
606a3ccd3682
linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents:
112
diff
changeset
|
1170 |
]. |
712 | 1171 |
OperatingSystem getOSType = 'win32' ifTrue:[ |
1172 |
^ self closeFile |
|
1173 |
]. |
|
121
606a3ccd3682
linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents:
112
diff
changeset
|
1174 |
|
606a3ccd3682
linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents:
112
diff
changeset
|
1175 |
super close |
606a3ccd3682
linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents:
112
diff
changeset
|
1176 |
|
606a3ccd3682
linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents:
112
diff
changeset
|
1177 |
"Created: 17.11.1995 / 17:27:26 / cg" |
606a3ccd3682
linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents:
112
diff
changeset
|
1178 |
"Modified: 17.11.1995 / 17:47:13 / cg" |
606a3ccd3682
linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents:
112
diff
changeset
|
1179 |
! |
606a3ccd3682
linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents:
112
diff
changeset
|
1180 |
|
593 | 1181 |
closeFile |
1182 |
"a stream has been collected - close the file" |
|
1183 |
||
594 | 1184 |
%{ |
593 | 1185 |
#ifdef IRIS_AUDIO |
595 | 1186 |
OBJ port; |
1187 |
||
712 | 1188 |
if ((port = __INST(alPort)) != nil) { |
1189 |
__INST(alPort) = nil; |
|
1190 |
ALcloseport(__ALportVal(port)); |
|
1191 |
} |
|
1192 |
RETURN (self); |
|
1193 |
#endif |
|
1194 |
||
1195 |
#ifdef WIN32 |
|
1196 |
OBJ oDirectSound, oDSBuffer; |
|
1197 |
LPDIRECTSOUND t_pDirectSound; |
|
1198 |
LPDIRECTSOUNDBUFFER t_pDSBuffer; |
|
1199 |
||
1200 |
if ((oDSBuffer = __INST(pDSBuffer)) != nil) { |
|
1201 |
__INST(pDSBuffer) = nil; |
|
1202 |
t_pDSBuffer = __DSBufferVal(oDSBuffer); |
|
1203 |
if (t_pDSBuffer) { |
|
1204 |
IDirectSoundBuffer_Stop(t_pDSBuffer); |
|
1205 |
IDirectSoundBuffer_Release(t_pDSBuffer); |
|
1206 |
} |
|
1207 |
} |
|
1208 |
if ((oDirectSound = __INST(pDirectSound)) != nil) { |
|
1209 |
__INST(pDirectSound) = nil; |
|
1210 |
t_pDirectSound = __DirectSoundVal(oDirectSound); |
|
1211 |
if (t_pDirectSound) { |
|
1212 |
IDirectSound_Release(t_pDirectSound); |
|
1213 |
} |
|
595 | 1214 |
} |
1215 |
RETURN (self); |
|
593 | 1216 |
#endif |
595 | 1217 |
|
594 | 1218 |
#if defined(DEV_AUDIO) |
1219 |
OBJ fp; |
|
1220 |
int fd; |
|
1221 |
FILE *f; |
|
593 | 1222 |
|
594 | 1223 |
if ((fp = __INST(filePointer)) != nil) { |
1224 |
f = __FILEVal(fp); |
|
1225 |
__INST(filePointer) = nil; |
|
1226 |
# ifdef LINUX |
|
1227 |
sigsetmask(~0); |
|
1228 |
# endif |
|
1229 |
if (__INST(buffered) == true) { |
|
1230 |
fflush(f); |
|
1231 |
fclose(f); |
|
1232 |
} else { |
|
1233 |
fd = fileno(f); |
|
1234 |
close(fd); |
|
1235 |
fclose(f); |
|
593 | 1236 |
} |
594 | 1237 |
# ifdef LINUX |
1238 |
sigsetmask(0); |
|
1239 |
# endif |
|
1240 |
} |
|
595 | 1241 |
RETURN (self); |
594 | 1242 |
#endif /* DEV_AUDIO */ |
595 | 1243 |
%}. |
1244 |
^ super closeFile |
|
593 | 1245 |
! |
1246 |
||
274
f45bd0d6ea31
Rename synchronizeOutput --> flush.
Stefan Vogel <sv@exept.de>
parents:
259
diff
changeset
|
1247 |
flush |
f45bd0d6ea31
Rename synchronizeOutput --> flush.
Stefan Vogel <sv@exept.de>
parents:
259
diff
changeset
|
1248 |
"wait until all sound has been played" |
f45bd0d6ea31
Rename synchronizeOutput --> flush.
Stefan Vogel <sv@exept.de>
parents:
259
diff
changeset
|
1249 |
|
593 | 1250 |
|fd| |
1251 |
||
1252 |
fd := self fileDescriptor. |
|
274
f45bd0d6ea31
Rename synchronizeOutput --> flush.
Stefan Vogel <sv@exept.de>
parents:
259
diff
changeset
|
1253 |
%{ |
f45bd0d6ea31
Rename synchronizeOutput --> flush.
Stefan Vogel <sv@exept.de>
parents:
259
diff
changeset
|
1254 |
#ifdef IRIS_AUDIO |
712 | 1255 |
OPJ port; |
277
ab17540f022a
oops - your last checkin was garbage
Claus Gittinger <cg@exept.de>
parents:
274
diff
changeset
|
1256 |
ALport p; |
274
f45bd0d6ea31
Rename synchronizeOutput --> flush.
Stefan Vogel <sv@exept.de>
parents:
259
diff
changeset
|
1257 |
|
712 | 1258 |
if ((port = __INST(alPort)) != nil) { |
1259 |
p = __ALportVal(port); |
|
592 | 1260 |
while (ALgetfilled(p) > 0) { |
1261 |
sginap(1); |
|
1262 |
} |
|
277
ab17540f022a
oops - your last checkin was garbage
Claus Gittinger <cg@exept.de>
parents:
274
diff
changeset
|
1263 |
} |
353 | 1264 |
RETURN(self); |
277
ab17540f022a
oops - your last checkin was garbage
Claus Gittinger <cg@exept.de>
parents:
274
diff
changeset
|
1265 |
#endif |
593 | 1266 |
|
712 | 1267 |
#if defined(DEV_AUDIO) |
593 | 1268 |
if (__isSmallInteger(fd)) { |
1269 |
int f = __intVal(fd); |
|
1270 |
/* ... */ |
|
1271 |
} |
|
1272 |
#endif |
|
1273 |
%}. |
|
353 | 1274 |
"dont know how to wait on non-iris systems" |
277
ab17540f022a
oops - your last checkin was garbage
Claus Gittinger <cg@exept.de>
parents:
274
diff
changeset
|
1275 |
^ self |
ab17540f022a
oops - your last checkin was garbage
Claus Gittinger <cg@exept.de>
parents:
274
diff
changeset
|
1276 |
! |
274
f45bd0d6ea31
Rename synchronizeOutput --> flush.
Stefan Vogel <sv@exept.de>
parents:
259
diff
changeset
|
1277 |
|
712 | 1278 |
isOpen |
1279 |
alPort notNil ifTrue:[^ true]. |
|
1280 |
pDirectSound notNil ifTrue:[^ true]. |
|
1281 |
^ filePointer notNil |
|
1282 |
! |
|
1283 |
||
121
606a3ccd3682
linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents:
112
diff
changeset
|
1284 |
nextBytes:count into:anObject startingAt:start |
606a3ccd3682
linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents:
112
diff
changeset
|
1285 |
"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
|
1286 |
bytes read or nil on error. |
606a3ccd3682
linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents:
112
diff
changeset
|
1287 |
Use with ByteArrays only." |
606a3ccd3682
linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents:
112
diff
changeset
|
1288 |
|
606a3ccd3682
linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents:
112
diff
changeset
|
1289 |
%{ |
606a3ccd3682
linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents:
112
diff
changeset
|
1290 |
#ifdef IRIS_AUDIO |
606a3ccd3682
linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents:
112
diff
changeset
|
1291 |
{ |
712 | 1292 |
OBJ port; |
121
606a3ccd3682
linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents:
112
diff
changeset
|
1293 |
ALport p; |
712 | 1294 |
int cnt, offs, nSamp; |
277
ab17540f022a
oops - your last checkin was garbage
Claus Gittinger <cg@exept.de>
parents:
274
diff
changeset
|
1295 |
int objSize; |
ab17540f022a
oops - your last checkin was garbage
Claus Gittinger <cg@exept.de>
parents:
274
diff
changeset
|
1296 |
char *cp; |
ab17540f022a
oops - your last checkin was garbage
Claus Gittinger <cg@exept.de>
parents:
274
diff
changeset
|
1297 |
|
712 | 1298 |
if ((port = __INST(alPort)) != nil) { |
277
ab17540f022a
oops - your last checkin was garbage
Claus Gittinger <cg@exept.de>
parents:
274
diff
changeset
|
1299 |
if (__INST(mode) != _writeonly) { |
ab17540f022a
oops - your last checkin was garbage
Claus Gittinger <cg@exept.de>
parents:
274
diff
changeset
|
1300 |
if (__bothSmallInteger(count, start)) { |
712 | 1301 |
cnt = __intVal(count); |
1302 |
offs = __intVal(start) - 1; |
|
1303 |
p = __ALportVal(port); |
|
277
ab17540f022a
oops - your last checkin was garbage
Claus Gittinger <cg@exept.de>
parents:
274
diff
changeset
|
1304 |
objSize = _Size(anObject) - OHDR_SIZE; |
ab17540f022a
oops - your last checkin was garbage
Claus Gittinger <cg@exept.de>
parents:
274
diff
changeset
|
1305 |
if ((offs >= 0) && (cnt >= 0) && (objSize >= (cnt + offs))) { |
ab17540f022a
oops - your last checkin was garbage
Claus Gittinger <cg@exept.de>
parents:
274
diff
changeset
|
1306 |
cp = (char *)__InstPtr(anObject) + OHDR_SIZE + offs; |
ab17540f022a
oops - your last checkin was garbage
Claus Gittinger <cg@exept.de>
parents:
274
diff
changeset
|
1307 |
if (__INST(bitsPerSample) == __MKSMALLINT(16)) |
712 | 1308 |
nSamp = cnt / 2; |
277
ab17540f022a
oops - your last checkin was garbage
Claus Gittinger <cg@exept.de>
parents:
274
diff
changeset
|
1309 |
else |
712 | 1310 |
nSamp = cnt; |
1311 |
ALreadsamps(p, cp, nSamp); |
|
277
ab17540f022a
oops - your last checkin was garbage
Claus Gittinger <cg@exept.de>
parents:
274
diff
changeset
|
1312 |
RETURN ( __MKSMALLINT(cnt) ); |
ab17540f022a
oops - your last checkin was garbage
Claus Gittinger <cg@exept.de>
parents:
274
diff
changeset
|
1313 |
} |
ab17540f022a
oops - your last checkin was garbage
Claus Gittinger <cg@exept.de>
parents:
274
diff
changeset
|
1314 |
} |
ab17540f022a
oops - your last checkin was garbage
Claus Gittinger <cg@exept.de>
parents:
274
diff
changeset
|
1315 |
} |
ab17540f022a
oops - your last checkin was garbage
Claus Gittinger <cg@exept.de>
parents:
274
diff
changeset
|
1316 |
} |
ab17540f022a
oops - your last checkin was garbage
Claus Gittinger <cg@exept.de>
parents:
274
diff
changeset
|
1317 |
} |
ab17540f022a
oops - your last checkin was garbage
Claus Gittinger <cg@exept.de>
parents:
274
diff
changeset
|
1318 |
#endif |
593 | 1319 |
%}. |
277
ab17540f022a
oops - your last checkin was garbage
Claus Gittinger <cg@exept.de>
parents:
274
diff
changeset
|
1320 |
OperatingSystem getOSType = 'irix' ifFalse:[ |
712 | 1321 |
OperatingSystem getOSType = 'win32' ifFalse:[ |
1322 |
^ super nextPutBytes:count from:anObject startingAt:start |
|
1323 |
]. |
|
277
ab17540f022a
oops - your last checkin was garbage
Claus Gittinger <cg@exept.de>
parents:
274
diff
changeset
|
1324 |
]. |
ab17540f022a
oops - your last checkin was garbage
Claus Gittinger <cg@exept.de>
parents:
274
diff
changeset
|
1325 |
filePointer isNil ifTrue:[^ self errorNotOpen]. |
ab17540f022a
oops - your last checkin was garbage
Claus Gittinger <cg@exept.de>
parents:
274
diff
changeset
|
1326 |
(mode == #writeonly) ifTrue:[^ self errorWriteOnly]. |
ab17540f022a
oops - your last checkin was garbage
Claus Gittinger <cg@exept.de>
parents:
274
diff
changeset
|
1327 |
self primitiveFailed |
ab17540f022a
oops - your last checkin was garbage
Claus Gittinger <cg@exept.de>
parents:
274
diff
changeset
|
1328 |
! |
121
606a3ccd3682
linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents:
112
diff
changeset
|
1329 |
|
606a3ccd3682
linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents:
112
diff
changeset
|
1330 |
nextPutBytes:count from:anObject startingAt:start |
606a3ccd3682
linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents:
112
diff
changeset
|
1331 |
"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
|
1332 |
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
|
1333 |
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
|
1334 |
(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
|
1335 |
|
277
ab17540f022a
oops - your last checkin was garbage
Claus Gittinger <cg@exept.de>
parents:
274
diff
changeset
|
1336 |
%{ |
ab17540f022a
oops - your last checkin was garbage
Claus Gittinger <cg@exept.de>
parents:
274
diff
changeset
|
1337 |
#ifdef IRIS_AUDIO |
ab17540f022a
oops - your last checkin was garbage
Claus Gittinger <cg@exept.de>
parents:
274
diff
changeset
|
1338 |
{ |
712 | 1339 |
OBJ port; |
277
ab17540f022a
oops - your last checkin was garbage
Claus Gittinger <cg@exept.de>
parents:
274
diff
changeset
|
1340 |
ALport p; |
712 | 1341 |
int cnt, offs, nSamp; |
277
ab17540f022a
oops - your last checkin was garbage
Claus Gittinger <cg@exept.de>
parents:
274
diff
changeset
|
1342 |
int objSize; |
ab17540f022a
oops - your last checkin was garbage
Claus Gittinger <cg@exept.de>
parents:
274
diff
changeset
|
1343 |
char *cp; |
ab17540f022a
oops - your last checkin was garbage
Claus Gittinger <cg@exept.de>
parents:
274
diff
changeset
|
1344 |
|
712 | 1345 |
if ((port = __INST(alPort)) != nil) { |
593 | 1346 |
if (__INST(mode) != @symbol(readonly)) { |
277
ab17540f022a
oops - your last checkin was garbage
Claus Gittinger <cg@exept.de>
parents:
274
diff
changeset
|
1347 |
if (__bothSmallInteger(count, start)) { |
712 | 1348 |
cnt = __intVal(count); |
1349 |
offs = __intVal(start) - 1; |
|
1350 |
p = __ALportVal(port); |
|
277
ab17540f022a
oops - your last checkin was garbage
Claus Gittinger <cg@exept.de>
parents:
274
diff
changeset
|
1351 |
|
ab17540f022a
oops - your last checkin was garbage
Claus Gittinger <cg@exept.de>
parents:
274
diff
changeset
|
1352 |
/* |
ab17540f022a
oops - your last checkin was garbage
Claus Gittinger <cg@exept.de>
parents:
274
diff
changeset
|
1353 |
* compute number of samples |
ab17540f022a
oops - your last checkin was garbage
Claus Gittinger <cg@exept.de>
parents:
274
diff
changeset
|
1354 |
*/ |
ab17540f022a
oops - your last checkin was garbage
Claus Gittinger <cg@exept.de>
parents:
274
diff
changeset
|
1355 |
objSize = _Size(anObject) - OHDR_SIZE; |
ab17540f022a
oops - your last checkin was garbage
Claus Gittinger <cg@exept.de>
parents:
274
diff
changeset
|
1356 |
if ( (offs >= 0) && (cnt >= 0) && (objSize >= (cnt + offs)) ) { |
ab17540f022a
oops - your last checkin was garbage
Claus Gittinger <cg@exept.de>
parents:
274
diff
changeset
|
1357 |
cp = (char *)__InstPtr(anObject) + OHDR_SIZE + offs; |
ab17540f022a
oops - your last checkin was garbage
Claus Gittinger <cg@exept.de>
parents:
274
diff
changeset
|
1358 |
if (__INST(bitsPerSample) == __MKSMALLINT(16)) |
712 | 1359 |
nSamp = cnt / 2; |
277
ab17540f022a
oops - your last checkin was garbage
Claus Gittinger <cg@exept.de>
parents:
274
diff
changeset
|
1360 |
else |
712 | 1361 |
nSamp = cnt; |
1362 |
ALwritesamps(p, cp, cnt); |
|
593 | 1363 |
RETURN ( count ); |
277
ab17540f022a
oops - your last checkin was garbage
Claus Gittinger <cg@exept.de>
parents:
274
diff
changeset
|
1364 |
} |
ab17540f022a
oops - your last checkin was garbage
Claus Gittinger <cg@exept.de>
parents:
274
diff
changeset
|
1365 |
} |
ab17540f022a
oops - your last checkin was garbage
Claus Gittinger <cg@exept.de>
parents:
274
diff
changeset
|
1366 |
} |
ab17540f022a
oops - your last checkin was garbage
Claus Gittinger <cg@exept.de>
parents:
274
diff
changeset
|
1367 |
} |
ab17540f022a
oops - your last checkin was garbage
Claus Gittinger <cg@exept.de>
parents:
274
diff
changeset
|
1368 |
} |
712 | 1369 |
#endif /* SGI_AUDIO */ |
1370 |
||
1371 |
#ifdef WIN32 |
|
1372 |
{ |
|
1373 |
HRESULT hr; |
|
1374 |
DWORD status; |
|
1375 |
LPVOID lpbuf1 = NULL; |
|
1376 |
LPVOID lpbuf2 = NULL; |
|
1377 |
DWORD dwsize1 = 0; |
|
1378 |
DWORD dwsize2 = 0; |
|
1379 |
DWORD playPos, safePos, endWrite; |
|
1380 |
DWORD millis; |
|
1381 |
OBJ oDirectSound, oDSBuffer; |
|
1382 |
LPDIRECTSOUND t_pDirectSound = (LPDIRECTSOUND)0; |
|
1383 |
LPDIRECTSOUNDBUFFER t_pDSBuffer = (LPDIRECTSOUNDBUFFER)0; |
|
1384 |
int t_cbBufOffset, t_cbBufSize; |
|
1385 |
short *buf; |
|
1386 |
int cnt, offs; |
|
1387 |
||
1388 |
if ((oDSBuffer = __INST(pDSBuffer)) != nil) { |
|
1389 |
t_pDSBuffer = __DSBufferVal(oDSBuffer); |
|
1390 |
} |
|
1391 |
if ((oDirectSound = __INST(pDirectSound)) != nil) { |
|
1392 |
t_pDirectSound = __DirectSoundVal(oDirectSound); |
|
1393 |
} |
|
1394 |
||
1395 |
if (!t_pDSBuffer || !t_pDirectSound) { |
|
1396 |
RETURN (0); |
|
1397 |
} |
|
1398 |
t_cbBufOffset = __intVal(__INST(cbBufOffset)); |
|
1399 |
t_cbBufSize = __intVal(__INST(cbBufSize)); |
|
1400 |
||
1401 |
cnt = __intVal(count); |
|
1402 |
offs = __intVal(start) - 1; |
|
1403 |
buf = (short *)__InstPtr(anObject) + OHDR_SIZE + offs; |
|
1404 |
||
1405 |
// Should be playing, right? |
|
1406 |
hr = IDirectSoundBuffer_GetStatus(t_pDSBuffer, &status ); |
|
1407 |
if (!(status && DSBSTATUS_PLAYING)) { |
|
1408 |
printf("Buffer not playing!\n"); |
|
1409 |
} |
|
1410 |
||
1411 |
// Sleep until we have enough room in buffer. |
|
1412 |
hr = IDirectSoundBuffer_GetCurrentPosition(t_pDSBuffer, &playPos, &safePos ); |
|
1413 |
if( hr != DS_OK ) { |
|
1414 |
RETURN (0); |
|
1415 |
} |
|
1416 |
if( playPos < t_cbBufOffset ) playPos += t_cbBufSize; |
|
1417 |
||
1418 |
endWrite = t_cbBufOffset + RT_BUFFER_SIZE * sizeof(short); |
|
1419 |
while ( playPos < endWrite ) { |
|
1420 |
// Calculate number of milliseconds until we will have room, as |
|
1421 |
// time = distance * (milliseconds/second) / ((bytes/sample) * (samples/second)), |
|
1422 |
// rounded up. |
|
1423 |
millis = (DWORD) (1.0 + ((endWrite - playPos) * 1000.0) / ( sizeof(short) * __intVal(__INST(sampleRate)))); |
|
1424 |
||
1425 |
// Sleep for that long |
|
1426 |
Sleep( millis ); |
|
1427 |
||
1428 |
// Wake up, find out where we are now |
|
1429 |
hr = IDirectSoundBuffer_GetCurrentPosition(t_pDSBuffer, &playPos, &safePos ); |
|
1430 |
if( hr != DS_OK ) { |
|
1431 |
RETURN (0); |
|
1432 |
} |
|
1433 |
if( playPos < t_cbBufOffset ) playPos += t_cbBufSize; // unwrap offset |
|
1434 |
} |
|
1435 |
||
1436 |
// Lock free space in the DS |
|
1437 |
hr = IDirectSoundBuffer_Lock(t_pDSBuffer, t_cbBufOffset, RT_BUFFER_SIZE * sizeof(short), &lpbuf1, &dwsize1, &lpbuf2, &dwsize2, 0); |
|
1438 |
if (hr == DS_OK) { |
|
1439 |
// Copy the buffer into the DS |
|
1440 |
CopyMemory(lpbuf1, buf, dwsize1); |
|
1441 |
if(NULL != lpbuf2) CopyMemory(lpbuf2, buf+dwsize1, dwsize2); |
|
1442 |
||
1443 |
// Update our buffer offset and unlock sound buffer |
|
1444 |
t_cbBufOffset = (t_cbBufOffset + dwsize1 + dwsize2) % t_cbBufSize; |
|
1445 |
IDirectSoundBuffer_Unlock(t_pDSBuffer, lpbuf1, dwsize1, lpbuf2, dwsize2); |
|
1446 |
} |
|
1447 |
__INST(cbBufOffset) = __MKSMALLINT(t_cbBufOffset); |
|
1448 |
||
1449 |
RETURN (0); |
|
1450 |
} |
|
1451 |
#endif /* WIN32 */ |
|
593 | 1452 |
|
594 | 1453 |
#if defined(DEV_AUDIO) |
593 | 1454 |
/* |
1455 |
* redefine to work around a bug in the linux sound driver; |
|
1456 |
* if a write is interrupted (EINTR), it is not defined, how many |
|
1457 |
* bytes have been written to the device. |
|
1458 |
* I.e. a retry of the write may lead to ever-playing without ever |
|
1459 |
* finishing. |
|
1460 |
* |
|
1461 |
* As a workaround, disable signals here to prevent the write from |
|
1462 |
* being interrupted. |
|
1463 |
*/ |
|
1464 |
int cnt, offs, objSize, n; |
|
1465 |
char *cp; |
|
1466 |
OBJ fp; |
|
1467 |
FILE *f; |
|
1468 |
int fd; |
|
1469 |
||
1470 |
if ((fp = __INST(filePointer)) != nil) { |
|
1471 |
f = __FILEVal(fp); |
|
1472 |
if (__INST(mode) != @symbol(readonly)) { |
|
1473 |
if (__bothSmallInteger(count, start)) { |
|
712 | 1474 |
cnt = __intVal(count); |
1475 |
offs = __intVal(start) - 1; |
|
277
ab17540f022a
oops - your last checkin was garbage
Claus Gittinger <cg@exept.de>
parents:
274
diff
changeset
|
1476 |
|
593 | 1477 |
objSize = _Size(anObject) - OHDR_SIZE; |
1478 |
if ( (offs >= 0) && (cnt >= 0) && (objSize >= (cnt + offs)) ) { |
|
598 | 1479 |
do { |
712 | 1480 |
cp = (char *)__InstPtr(anObject) + OHDR_SIZE + offs; |
593 | 1481 |
|
1482 |
n = cnt; |
|
1483 |
if (n > 4096) n = 4096; |
|
598 | 1484 |
# ifdef LINUX |
712 | 1485 |
sigsetmask(~0); |
598 | 1486 |
# endif |
593 | 1487 |
if (__INST(buffered) == true) { |
1488 |
n = fwrite(cp, 1, n, f); |
|
1489 |
} else { |
|
1490 |
fd = fileno(f); |
|
1491 |
n = write(fd, cp, n); |
|
1492 |
} |
|
598 | 1493 |
# ifdef LINUX |
712 | 1494 |
sigsetmask(0); |
598 | 1495 |
# endif |
1496 |
__BEGIN_INTERRUPTABLE__ |
|
1497 |
__END_INTERRUPTABLE__ |
|
593 | 1498 |
if (n > 0) { |
598 | 1499 |
offs += n; |
593 | 1500 |
cnt -= n; |
1501 |
} |
|
1502 |
} while (cnt); |
|
1503 |
} |
|
1504 |
RETURN (count); |
|
1505 |
} |
|
1506 |
} |
|
1507 |
} |
|
1508 |
#endif |
|
1509 |
||
1510 |
%}. |
|
1511 |
^ super nextPutBytes:count from:anObject startingAt:start |
|
277
ab17540f022a
oops - your last checkin was garbage
Claus Gittinger <cg@exept.de>
parents:
274
diff
changeset
|
1512 |
! |
121
606a3ccd3682
linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents:
112
diff
changeset
|
1513 |
|
712 | 1514 |
openForReading |
1515 |
|rslt| |
|
1516 |
||
1517 |
mode := #readonly. |
|
1518 |
didWrite := false. |
|
1519 |
(rslt := self openWithMode:ReadMode) notNil ifTrue:[ |
|
1520 |
Lobby register:self |
|
1521 |
]. |
|
1522 |
^ rslt |
|
1523 |
! |
|
1524 |
||
596 | 1525 |
openForWriting |
1526 |
"open the file writeonly. |
|
1527 |
If the file does not exist its an error, return nil; |
|
1528 |
otherwise return the receiver." |
|
1529 |
||
712 | 1530 |
|rslt| |
1531 |
||
596 | 1532 |
mode := #writeonly. |
1533 |
didWrite := true. |
|
712 | 1534 |
(rslt := self openWithMode:WriteMode) notNil ifTrue:[ |
1535 |
Lobby register:self |
|
1536 |
]. |
|
1537 |
^ rslt |
|
596 | 1538 |
|
1539 |
"Created: / 15.12.1997 / 13:13:56 / cg" |
|
1540 |
! |
|
1541 |
||
0 | 1542 |
openWithMode:aMode |
1543 |
%{ |
|
36 | 1544 |
#ifdef IRIS_AUDIO |
0 | 1545 |
{ |
1546 |
ALconfig config; |
|
1547 |
ALport p; |
|
1548 |
long params[] = { |
|
45 | 1549 |
AL_INPUT_SOURCE, AL_INPUT_MIC, |
1550 |
AL_INPUT_RATE, 8000, |
|
1551 |
AL_OUTPUT_RATE, 8000, |
|
0 | 1552 |
}; |
1553 |
||
1554 |
config = ALnewconfig(); |
|
217 | 1555 |
if (__INST(numberOfChannels) == __MKSMALLINT(2)) |
45 | 1556 |
ALsetchannels(config, AL_STEREO); |
0 | 1557 |
else |
277
ab17540f022a
oops - your last checkin was garbage
Claus Gittinger <cg@exept.de>
parents:
274
diff
changeset
|
1558 |
ALsetchannels(config, AL_MONO); |
ab17540f022a
oops - your last checkin was garbage
Claus Gittinger <cg@exept.de>
parents:
274
diff
changeset
|
1559 |
if (__INST(bitsPerSample) == __MKSMALLINT(16)) |
ab17540f022a
oops - your last checkin was garbage
Claus Gittinger <cg@exept.de>
parents:
274
diff
changeset
|
1560 |
ALsetwidth(config, AL_SAMPLE_16); |
ab17540f022a
oops - your last checkin was garbage
Claus Gittinger <cg@exept.de>
parents:
274
diff
changeset
|
1561 |
else |
ab17540f022a
oops - your last checkin was garbage
Claus Gittinger <cg@exept.de>
parents:
274
diff
changeset
|
1562 |
ALsetwidth(config, AL_SAMPLE_8); |
ab17540f022a
oops - your last checkin was garbage
Claus Gittinger <cg@exept.de>
parents:
274
diff
changeset
|
1563 |
|
ab17540f022a
oops - your last checkin was garbage
Claus Gittinger <cg@exept.de>
parents:
274
diff
changeset
|
1564 |
if (__isSmallInteger(__INST(sampleRate))) |
712 | 1565 |
params[3] = params[5] = __intVal(__INST(sampleRate)); |
0 | 1566 |
|
277
ab17540f022a
oops - your last checkin was garbage
Claus Gittinger <cg@exept.de>
parents:
274
diff
changeset
|
1567 |
ALsetparams(AL_DEFAULT_DEVICE, params, 6); |
ab17540f022a
oops - your last checkin was garbage
Claus Gittinger <cg@exept.de>
parents:
274
diff
changeset
|
1568 |
p = ALopenport("smallchat", (char *)_stringVal(aMode), config); |
ab17540f022a
oops - your last checkin was garbage
Claus Gittinger <cg@exept.de>
parents:
274
diff
changeset
|
1569 |
if (p) { |
712 | 1570 |
OBJ t; |
1571 |
||
1572 |
__INST(alPort) = t = __MKEXTERNALADDRESS(p); __STORE(self, t); |
|
277
ab17540f022a
oops - your last checkin was garbage
Claus Gittinger <cg@exept.de>
parents:
274
diff
changeset
|
1573 |
} else { |
712 | 1574 |
__INST(alPort) = nil; |
277
ab17540f022a
oops - your last checkin was garbage
Claus Gittinger <cg@exept.de>
parents:
274
diff
changeset
|
1575 |
RETURN (nil); |
ab17540f022a
oops - your last checkin was garbage
Claus Gittinger <cg@exept.de>
parents:
274
diff
changeset
|
1576 |
} |
ab17540f022a
oops - your last checkin was garbage
Claus Gittinger <cg@exept.de>
parents:
274
diff
changeset
|
1577 |
__INST(binary) = true; |
0 | 1578 |
|
277
ab17540f022a
oops - your last checkin was garbage
Claus Gittinger <cg@exept.de>
parents:
274
diff
changeset
|
1579 |
ALfreeconfig(config); |
ab17540f022a
oops - your last checkin was garbage
Claus Gittinger <cg@exept.de>
parents:
274
diff
changeset
|
1580 |
/* |
ab17540f022a
oops - your last checkin was garbage
Claus Gittinger <cg@exept.de>
parents:
274
diff
changeset
|
1581 |
* get the parameters actually installed |
ab17540f022a
oops - your last checkin was garbage
Claus Gittinger <cg@exept.de>
parents:
274
diff
changeset
|
1582 |
*/ |
ab17540f022a
oops - your last checkin was garbage
Claus Gittinger <cg@exept.de>
parents:
274
diff
changeset
|
1583 |
config = ALgetconfig(p); |
ab17540f022a
oops - your last checkin was garbage
Claus Gittinger <cg@exept.de>
parents:
274
diff
changeset
|
1584 |
switch (ALgetchannels(config)) { |
ab17540f022a
oops - your last checkin was garbage
Claus Gittinger <cg@exept.de>
parents:
274
diff
changeset
|
1585 |
default: |
ab17540f022a
oops - your last checkin was garbage
Claus Gittinger <cg@exept.de>
parents:
274
diff
changeset
|
1586 |
/* cannot happen */ |
ab17540f022a
oops - your last checkin was garbage
Claus Gittinger <cg@exept.de>
parents:
274
diff
changeset
|
1587 |
case AL_MONO: |
ab17540f022a
oops - your last checkin was garbage
Claus Gittinger <cg@exept.de>
parents:
274
diff
changeset
|
1588 |
__INST(numberOfChannels) = __MKSMALLINT(1); |
ab17540f022a
oops - your last checkin was garbage
Claus Gittinger <cg@exept.de>
parents:
274
diff
changeset
|
1589 |
break; |
ab17540f022a
oops - your last checkin was garbage
Claus Gittinger <cg@exept.de>
parents:
274
diff
changeset
|
1590 |
case AL_STEREO: |
ab17540f022a
oops - your last checkin was garbage
Claus Gittinger <cg@exept.de>
parents:
274
diff
changeset
|
1591 |
__INST(numberOfChannels) = __MKSMALLINT(2); |
ab17540f022a
oops - your last checkin was garbage
Claus Gittinger <cg@exept.de>
parents:
274
diff
changeset
|
1592 |
break; |
ab17540f022a
oops - your last checkin was garbage
Claus Gittinger <cg@exept.de>
parents:
274
diff
changeset
|
1593 |
} |
ab17540f022a
oops - your last checkin was garbage
Claus Gittinger <cg@exept.de>
parents:
274
diff
changeset
|
1594 |
switch (ALgetwidth(config)) { |
ab17540f022a
oops - your last checkin was garbage
Claus Gittinger <cg@exept.de>
parents:
274
diff
changeset
|
1595 |
default: |
ab17540f022a
oops - your last checkin was garbage
Claus Gittinger <cg@exept.de>
parents:
274
diff
changeset
|
1596 |
/* cannot happen */ |
ab17540f022a
oops - your last checkin was garbage
Claus Gittinger <cg@exept.de>
parents:
274
diff
changeset
|
1597 |
case AL_SAMPLE_8: |
ab17540f022a
oops - your last checkin was garbage
Claus Gittinger <cg@exept.de>
parents:
274
diff
changeset
|
1598 |
__INST(bitsPerSample) = __MKSMALLINT(8); |
ab17540f022a
oops - your last checkin was garbage
Claus Gittinger <cg@exept.de>
parents:
274
diff
changeset
|
1599 |
break; |
ab17540f022a
oops - your last checkin was garbage
Claus Gittinger <cg@exept.de>
parents:
274
diff
changeset
|
1600 |
case AL_SAMPLE_16: |
ab17540f022a
oops - your last checkin was garbage
Claus Gittinger <cg@exept.de>
parents:
274
diff
changeset
|
1601 |
__INST(bitsPerSample) = __MKSMALLINT(16); |
ab17540f022a
oops - your last checkin was garbage
Claus Gittinger <cg@exept.de>
parents:
274
diff
changeset
|
1602 |
break; |
ab17540f022a
oops - your last checkin was garbage
Claus Gittinger <cg@exept.de>
parents:
274
diff
changeset
|
1603 |
case AL_SAMPLE_24: |
ab17540f022a
oops - your last checkin was garbage
Claus Gittinger <cg@exept.de>
parents:
274
diff
changeset
|
1604 |
__INST(bitsPerSample) = __MKSMALLINT(24); |
ab17540f022a
oops - your last checkin was garbage
Claus Gittinger <cg@exept.de>
parents:
274
diff
changeset
|
1605 |
break; |
ab17540f022a
oops - your last checkin was garbage
Claus Gittinger <cg@exept.de>
parents:
274
diff
changeset
|
1606 |
} |
ab17540f022a
oops - your last checkin was garbage
Claus Gittinger <cg@exept.de>
parents:
274
diff
changeset
|
1607 |
ALgetparams(AL_DEFAULT_DEVICE, params, 6); |
ab17540f022a
oops - your last checkin was garbage
Claus Gittinger <cg@exept.de>
parents:
274
diff
changeset
|
1608 |
__INST(sampleRate) = __MKSMALLINT(params[3]); |
0 | 1609 |
|
277
ab17540f022a
oops - your last checkin was garbage
Claus Gittinger <cg@exept.de>
parents:
274
diff
changeset
|
1610 |
ALfreeconfig(config); |
594 | 1611 |
RETURN (self); |
277
ab17540f022a
oops - your last checkin was garbage
Claus Gittinger <cg@exept.de>
parents:
274
diff
changeset
|
1612 |
} |
712 | 1613 |
#endif /* SGI_AUDIO */ |
1614 |
||
1615 |
#ifdef WIN32 |
|
1616 |
{ |
|
1617 |
HRESULT result; |
|
1618 |
LPDIRECTSOUND t_pDirectSound; |
|
1619 |
LPDIRECTSOUNDBUFFER t_pDSBuffer, t_pDSPrimeBuffer; |
|
1620 |
WAVEFORMATEX wfFormat; |
|
1621 |
DSBUFFERDESC dsbdDesc, primarydsbDesc; |
|
1622 |
BYTE *pDSBuffData; |
|
1623 |
int t_cbBufSize; |
|
1624 |
int dwDataLen; |
|
1625 |
||
1626 |
/* Create the DS object */ |
|
1627 |
if ((result = DirectSoundCreate(NULL, &t_pDirectSound, NULL)) != DS_OK) { |
|
1628 |
fprintf(stderr,"SoundStream: Cannot open default sound device!!\n"); |
|
1629 |
RETURN (nil); |
|
1630 |
} |
|
1631 |
||
1632 |
/* Define the wave format structure */ |
|
1633 |
wfFormat.wFormatTag = WAVE_FORMAT_PCM; |
|
1634 |
wfFormat.nChannels = __intVal(__INST(numberOfChannels)); |
|
1635 |
wfFormat.nSamplesPerSec = __intVal(__INST(sampleRate)); |
|
1636 |
wfFormat.wBitsPerSample = __intVal(__INST(bitsPerSample)); |
|
1637 |
wfFormat.nBlockAlign = wfFormat.nChannels * wfFormat.wBitsPerSample / 8; |
|
1638 |
wfFormat.nAvgBytesPerSec = wfFormat.nSamplesPerSec * wfFormat.nBlockAlign; |
|
1639 |
wfFormat.cbSize = 0; |
|
1640 |
#if 0 |
|
1641 |
/* Setup the primary DS buffer description */ |
|
1642 |
ZeroMemory(&primarydsbDesc, sizeof(DSBUFFERDESC)); |
|
1643 |
primarydsbDesc.dwSize = sizeof(DSBUFFERDESC); |
|
1644 |
primarydsbDesc.dwFlags = DSBCAPS_PRIMARYBUFFER; |
|
1645 |
primarydsbDesc.dwBufferBytes = 0; |
|
1646 |
primarydsbDesc.lpwfxFormat = NULL; |
|
1647 |
||
1648 |
/* Create the primary DS buffer */ |
|
1649 |
if ((result = IDirectSound_CreateSoundBuffer(t_pDirectSound, &primarydsbDesc, |
|
1650 |
&t_pDSPrimeBuffer, NULL)) != DS_OK) { |
|
1651 |
fprintf(stderr,"SoundStream: Cannot get the primary DS buffer address!\n"); |
|
1652 |
IDirectSound_Release(t_pDirectSound); |
|
1653 |
RETURN (nil); |
|
1654 |
} |
|
1655 |
||
1656 |
/* Set the primary DS buffer sound format. We have to do this because |
|
1657 |
the default primary buffer is 8-bit, 22kHz! */ |
|
1658 |
if ((result = IDirectSoundBuffer_SetFormat(t_pDSPrimeBuffer, &wfFormat)) != DS_OK) { |
|
1659 |
fprintf(stderr,"SoundStream: Cannot set the primary DS buffer to proper sound format (%x) (%d)!\n", result, result); |
|
1660 |
IDirectSoundBuffer_Stop(t_pDSPrimeBuffer); |
|
1661 |
IDirectSoundBuffer_Release(t_pDSPrimeBuffer); |
|
1662 |
IDirectSound_Release(t_pDirectSound); |
|
1663 |
RETURN (nil); |
|
1664 |
} |
|
277
ab17540f022a
oops - your last checkin was garbage
Claus Gittinger <cg@exept.de>
parents:
274
diff
changeset
|
1665 |
#endif |
712 | 1666 |
|
1667 |
/* Setup the secondary DS buffer description */ |
|
1668 |
t_cbBufSize = RT_BUFFER_SIZE * sizeof(short) * NBUFS; |
|
1669 |
__INST(cbBufSize) = __MKSMALLINT(t_cbBufSize); |
|
1670 |
||
1671 |
ZeroMemory(&dsbdDesc, sizeof(DSBUFFERDESC)); |
|
1672 |
dsbdDesc.dwSize = sizeof(DSBUFFERDESC); |
|
1673 |
dsbdDesc.dwFlags = DSBCAPS_GLOBALFOCUS; |
|
1674 |
dsbdDesc.dwBufferBytes = t_cbBufSize; |
|
1675 |
dsbdDesc.lpwfxFormat = &wfFormat; |
|
1676 |
||
1677 |
/* Create the secondary DS buffer */ |
|
1678 |
if ((result = IDirectSound_CreateSoundBuffer(t_pDirectSound, &dsbdDesc, &t_pDSBuffer, NULL)) != DS_OK) { |
|
1679 |
fprintf(stderr,"SoundStream: couldn't create sound buffer!\n"); |
|
1680 |
IDirectSoundBuffer_Stop(t_pDSPrimeBuffer); |
|
1681 |
IDirectSoundBuffer_Release(t_pDSPrimeBuffer); |
|
1682 |
IDirectSound_Release(t_pDirectSound); |
|
1683 |
RETURN (nil); |
|
1684 |
} |
|
1685 |
||
1686 |
/* Lock the DS buffer */ |
|
1687 |
if ((result = IDirectSoundBuffer_Lock(t_pDSBuffer, 0, t_cbBufSize, (LPLPVOID)&pDSBuffData, |
|
1688 |
&dwDataLen, NULL, NULL, 0)) != DS_OK) { |
|
1689 |
fprintf(stderr,"SoundStream: couldn't lock sound buffer!\n"); |
|
1690 |
IDirectSoundBuffer_Stop(t_pDSBuffer); |
|
1691 |
IDirectSoundBuffer_Stop(t_pDSPrimeBuffer); |
|
1692 |
IDirectSoundBuffer_Release(t_pDSPrimeBuffer); |
|
1693 |
IDirectSound_Release(t_pDirectSound); |
|
1694 |
RETURN (nil); |
|
1695 |
} |
|
1696 |
||
1697 |
/* Zero the DS buffer */ |
|
1698 |
ZeroMemory(pDSBuffData, dwDataLen); |
|
1699 |
||
1700 |
/* Unlock the DS buffer */ |
|
1701 |
if ((result = IDirectSoundBuffer_Unlock(t_pDSBuffer, pDSBuffData, dwDataLen, NULL, 0)) != DS_OK) { |
|
1702 |
fprintf(stderr,"SoundStream: couldn't unlock sound buffer!\n"); |
|
1703 |
IDirectSoundBuffer_Stop(t_pDSBuffer); |
|
1704 |
IDirectSoundBuffer_Stop(t_pDSPrimeBuffer); |
|
1705 |
IDirectSoundBuffer_Release(t_pDSPrimeBuffer); |
|
1706 |
IDirectSound_Release(t_pDirectSound); |
|
1707 |
RETURN (nil); |
|
1708 |
} |
|
1709 |
||
1710 |
__INST(cbBufOffset) = __MKSMALLINT(0); // reset last write position to start of buffer |
|
1711 |
||
1712 |
/* Start the buffer playback */ |
|
1713 |
if ((result = IDirectSoundBuffer_Play(t_pDSBuffer, 0, 0, DSBPLAY_LOOPING ) != DS_OK)) { |
|
1714 |
fprintf(stderr,"SoundStream: couldn't play sound buffer!\n"); |
|
1715 |
IDirectSoundBuffer_Stop(t_pDSBuffer); |
|
1716 |
IDirectSoundBuffer_Stop(t_pDSPrimeBuffer); |
|
1717 |
IDirectSoundBuffer_Release(t_pDSPrimeBuffer); |
|
1718 |
IDirectSound_Release(t_pDirectSound); |
|
1719 |
RETURN (nil); |
|
1720 |
} |
|
1721 |
||
1722 |
{ |
|
1723 |
OBJ t; |
|
1724 |
||
1725 |
__INST(pDSBuffer) = t = __MKEXTERNALADDRESS(t_pDSBuffer); __STORE(self, t); |
|
1726 |
__INST(pDirectSound) = t = __MKEXTERNALADDRESS(t_pDirectSound); __STORE(self, t); |
|
1727 |
} |
|
1728 |
RETURN (self); |
|
1729 |
} |
|
1730 |
#endif /* WIN32 */ |
|
1731 |
||
593 | 1732 |
%}. |
594 | 1733 |
"its a regular file open (i.e. /dev/audio) " |
1734 |
^ super openWithMode:aMode |
|
277
ab17540f022a
oops - your last checkin was garbage
Claus Gittinger <cg@exept.de>
parents:
274
diff
changeset
|
1735 |
! ! |
0 | 1736 |
|
1737 |
!SoundStream methodsFor:'sine wave generation'! |
|
1738 |
||
596 | 1739 |
tuneTone |
1740 |
self tuneTone:440 |
|
1741 |
||
1742 |
" |
|
1743 |
SoundStream writing tuneTone; close |
|
1744 |
SoundStream writing setSampleRate:4000; tuneTone; close |
|
1745 |
SoundStream writing setSampleRate:8000; tuneTone; close |
|
1746 |
SoundStream writing setSampleRate:10000; tuneTone; close |
|
1747 |
SoundStream writing setSampleRate:20000; tuneTone; close |
|
1748 |
SoundStream writing setSampleRate:40000; tuneTone; close |
|
1749 |
SoundStream writing setSampleRate:20000; dumpSettings; close |
|
1750 |
" |
|
1751 |
||
1752 |
"Modified: / 12.12.1997 / 20:34:42 / cg" |
|
1753 |
! |
|
1754 |
||
597 | 1755 |
tuneTone16:freq |
1756 |
"output some tone for 3 seconds in S16 audioFormat - a test method" |
|
1757 |
||
1758 |
|buffer numSamples val scale oldFormat| |
|
1759 |
||
1760 |
"allocate memory for 1sec playing time" |
|
1761 |
numSamples := self sampleRate. |
|
1762 |
buffer := WordArray new:numSamples. |
|
1763 |
||
1764 |
"fill it with a sine wave" |
|
1765 |
||
1766 |
scale := freq * 2 * (Float pi). |
|
1767 |
1 to:numSamples do:[:i | |
|
712 | 1768 |
val := (scale * i / numSamples) sin. |
1769 |
val := (val * 16r7FFF) rounded bitAnd:16rFFFF. |
|
1770 |
buffer at:i put:val |
|
597 | 1771 |
]. |
1772 |
||
1773 |
oldFormat := audioFormat. |
|
1774 |
self setAudioFormat:#S16. |
|
1775 |
1 to:3 do:[:s | |
|
712 | 1776 |
self nextPutBytes:(numSamples*2) from:buffer startingAt:1 |
597 | 1777 |
]. |
1778 |
self setAudioFormat:oldFormat. |
|
1779 |
||
1780 |
"of course, the frequency should be below half the |
|
1781 |
sampleRate - hear below ... |
|
1782 |
||
1783 |
SoundStream writing setSampleRate:4000; tuneTone16:440; close |
|
1784 |
SoundStream writing setSampleRate:8000; tuneTone16:440; close |
|
1785 |
SoundStream writing setSampleRate:10000; tuneTone16:440; close |
|
1786 |
SoundStream writing setSampleRate:20000; tuneTone16:440; close |
|
1787 |
SoundStream writing setSampleRate:40000; tuneTone16:440; close |
|
1788 |
" |
|
1789 |
||
1790 |
"Modified: / 15.12.1997 / 13:46:57 / cg" |
|
1791 |
! |
|
1792 |
||
593 | 1793 |
tuneTone:freq |
597 | 1794 |
"output some tone for 3 seconds in U8 audioFormat - a test method" |
1795 |
||
593 | 1796 |
|buffer numSamples val scale oldFormat| |
0 | 1797 |
|
1798 |
"allocate memory for 1sec playing time" |
|
1799 |
numSamples := self sampleRate. |
|
1800 |
buffer := ByteArray new:numSamples. |
|
1801 |
||
1802 |
"fill it with a sine wave" |
|
1803 |
||
593 | 1804 |
scale := freq * 2 * (Float pi). |
0 | 1805 |
1 to:numSamples do:[:i | |
712 | 1806 |
val := (scale * i / numSamples) sin. |
1807 |
val := (val * 127 + 128) rounded. |
|
1808 |
buffer at:i put:val |
|
0 | 1809 |
]. |
1810 |
||
593 | 1811 |
oldFormat := audioFormat. |
1812 |
self setAudioFormat:#U8. |
|
0 | 1813 |
1 to:3 do:[:s | |
712 | 1814 |
self nextPutBytes:numSamples from:buffer startingAt:1 |
593 | 1815 |
]. |
1816 |
self setAudioFormat:oldFormat. |
|
1817 |
||
1818 |
"of course, the frequency should be below half the |
|
1819 |
sampleRate - hear below ... |
|
0 | 1820 |
|
593 | 1821 |
SoundStream writing tuneTone; close |
1822 |
SoundStream writing setSampleRate:4000; tuneTone:440; close |
|
1823 |
SoundStream writing setSampleRate:4000; tuneTone:2000; close |
|
1824 |
SoundStream writing setSampleRate:8000; tuneTone:440; close |
|
1825 |
SoundStream writing setSampleRate:8000; tuneTone:2000; close |
|
1826 |
SoundStream writing setSampleRate:8000; tuneTone:4000; close |
|
1827 |
SoundStream writing setSampleRate:10000; tuneTone:440; close |
|
1828 |
SoundStream writing setSampleRate:10000; tuneTone:2000; close |
|
1829 |
SoundStream writing setSampleRate:10000; tuneTone:4000; close |
|
1830 |
SoundStream writing setSampleRate:20000; tuneTone:440; close |
|
1831 |
SoundStream writing setSampleRate:20000; tuneTone:2000; close |
|
1832 |
SoundStream writing setSampleRate:20000; tuneTone:4000; close |
|
1833 |
SoundStream writing setSampleRate:20000; tuneTone:8000; close |
|
1834 |
SoundStream writing setSampleRate:40000; tuneTone:440; close |
|
1835 |
SoundStream writing setSampleRate:40000; tuneTone:2000; close |
|
1836 |
SoundStream writing setSampleRate:40000; tuneTone:4000; close |
|
1837 |
SoundStream writing setSampleRate:40000; tuneTone:8000; close |
|
1838 |
SoundStream writing setSampleRate:40000; tuneTone:10000; close |
|
1839 |
" |
|
1840 |
||
597 | 1841 |
"Modified: / 15.12.1997 / 13:43:05 / cg" |
1842 |
! |
|
1843 |
||
1844 |
tuneToneMU:freq |
|
1845 |
"output some tone for 3 seconds in MU_LAW audioFormat - a test method" |
|
1846 |
||
1847 |
|buffer numSamples val scale oldFormat| |
|
1848 |
||
1849 |
"allocate memory for 1sec playing time" |
|
1850 |
numSamples := self sampleRate. |
|
1851 |
buffer := ByteArray new:numSamples. |
|
1852 |
||
1853 |
"fill it with a sine wave" |
|
1854 |
||
1855 |
scale := freq * 2 * (Float pi). |
|
1856 |
1 to:numSamples do:[:i | |
|
712 | 1857 |
val := (scale * i / numSamples) sin. |
1858 |
val := (val * 16r7FFF) rounded. |
|
1859 |
buffer at:i put:(self class linear16ToUlaw:val) |
|
597 | 1860 |
]. |
1861 |
||
1862 |
oldFormat := audioFormat. |
|
1863 |
self setAudioFormat:#MU_LAW. |
|
1864 |
1 to:3 do:[:s | |
|
712 | 1865 |
self nextPutBytes:numSamples from:buffer startingAt:1 |
597 | 1866 |
]. |
1867 |
self setAudioFormat:oldFormat. |
|
1868 |
||
1869 |
"of course, the frequency should be below half the |
|
1870 |
sampleRate - hear below ... |
|
1871 |
||
1872 |
SoundStream writing setSampleRate:8000; tuneToneMU:440; close |
|
1873 |
SoundStream writing setSampleRate:10000; tuneToneMU:440; close |
|
1874 |
SoundStream writing setSampleRate:20000; tuneToneMU:440; close |
|
1875 |
SoundStream writing setSampleRate:40000; tuneToneMU:440; close |
|
1876 |
" |
|
1877 |
||
1878 |
"Modified: / 15.12.1997 / 13:46:19 / cg" |
|
0 | 1879 |
! ! |
121
606a3ccd3682
linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents:
112
diff
changeset
|
1880 |
|
152 | 1881 |
!SoundStream class methodsFor:'documentation'! |
1882 |
||
1883 |
version |
|
712 | 1884 |
^ '$Header: /cvs/stx/stx/libbasic2/Attic/SoundStr.st,v 1.34 1998-12-21 11:43:58 cg Exp $'! ! |
596 | 1885 |
SoundStream initialize! |