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