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