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