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