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