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