author | Claus Gittinger <cg@exept.de> |
Sat, 02 May 2020 21:40:13 +0200 | |
changeset 5476 | 7355a4b11cb6 |
parent 5468 | e9da15c1a36c |
permissions | -rw-r--r-- |
5424 | 1 |
"{ Encoding: utf8 }" |
2 |
||
4 | 3 |
" |
4 |
COPYRIGHT (c) 1993 by Claus Gittinger |
|
5429 | 5 |
All Rights Reserved |
4 | 6 |
|
7 |
This software is furnished under a license and may be used |
|
8 |
only in accordance with the terms of that license and with the |
|
9 |
inclusion of the above copyright notice. This software may not |
|
10 |
be provided or otherwise made available to, or used by, any |
|
11 |
other person. No title to or ownership of the software is |
|
12 |
hereby transferred. |
|
13 |
" |
|
918 | 14 |
"{ Package: 'stx:libbasic2' }" |
15 |
||
3482 | 16 |
"{ NameSpace: Smalltalk }" |
17 |
||
0 | 18 |
FileStream subclass:#SoundStream |
5447 | 19 |
instanceVariableNames:'sampleRate numberOfChannels bitsPerSample audioFormat handle1 |
20 |
handle2 bufferOffset bufferSize lastErrorString fragmentSize |
|
21 |
openMode openAttributes' |
|
22 |
classVariableNames:'IsInitialized UnsupportedOperationSignal ConcreteClass' |
|
23 |
poolDictionaries:'' |
|
24 |
category:'Streams-External' |
|
0 | 25 |
! |
26 |
||
5402 | 27 |
SoundStream subclass:#DevAudio |
5447 | 28 |
instanceVariableNames:'' |
29 |
classVariableNames:'' |
|
30 |
poolDictionaries:'' |
|
31 |
privateIn:SoundStream |
|
5402 | 32 |
! |
33 |
||
34 |
SoundStream subclass:#IRISAudio |
|
5447 | 35 |
instanceVariableNames:'' |
36 |
classVariableNames:'' |
|
37 |
poolDictionaries:'' |
|
38 |
privateIn:SoundStream |
|
5402 | 39 |
! |
40 |
||
5421 | 41 |
SoundStream subclass:#JackAudio |
5447 | 42 |
instanceVariableNames:'' |
43 |
classVariableNames:'' |
|
44 |
poolDictionaries:'' |
|
45 |
privateIn:SoundStream |
|
5421 | 46 |
! |
47 |
||
5402 | 48 |
SoundStream subclass:#PortAudio |
5447 | 49 |
instanceVariableNames:'' |
50 |
classVariableNames:'' |
|
51 |
poolDictionaries:'' |
|
52 |
privateIn:SoundStream |
|
5402 | 53 |
! |
54 |
||
55 |
SoundStream subclass:#Win32DirectSound |
|
5447 | 56 |
instanceVariableNames:'' |
57 |
classVariableNames:'' |
|
58 |
poolDictionaries:'' |
|
59 |
privateIn:SoundStream |
|
5402 | 60 |
! |
61 |
||
62 |
SoundStream subclass:#Win32WaveSound |
|
5447 | 63 |
instanceVariableNames:'' |
64 |
classVariableNames:'' |
|
65 |
poolDictionaries:'' |
|
66 |
privateIn:SoundStream |
|
5402 | 67 |
! |
68 |
||
121
606a3ccd3682
linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents:
112
diff
changeset
|
69 |
!SoundStream primitiveDefinitions! |
606a3ccd3682
linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents:
112
diff
changeset
|
70 |
%{ |
725 | 71 |
|
2818 | 72 |
#include "stxOSDefs.h" |
73 |
||
5421 | 74 |
#ifndef NO_SOUND |
75 |
||
76 |
# ifdef __win32__ |
|
5405 | 77 |
# define xxxSUPPORT_WIN32_DIRECTSOUND |
5406 | 78 |
# ifndef SUPPORT_WIN32_WAVESOUND |
79 |
# define SUPPORT_WIN32_WAVESOUND |
|
80 |
# endif |
|
5421 | 81 |
# endif /* __win32__ */ |
82 |
||
83 |
# ifdef __iris__ |
|
84 |
# ifndef IRIX5 |
|
85 |
# ifndef SUPPORT_IRIS_AUDIO |
|
86 |
# define SUPPORT_IRIS_AUDIO |
|
5406 | 87 |
# endif |
5400 | 88 |
# endif |
5421 | 89 |
# endif // __iris__ |
90 |
||
91 |
# ifndef SUPPORT_IRIS_AUDIO |
|
92 |
# ifndef SUPPORT_ALSA_AUDIO |
|
93 |
# ifdef LINUX |
|
94 |
# ifndef SUPPORT_DEV_AUDIO |
|
95 |
# define SUPPORT_DEV_AUDIO |
|
96 |
# endif |
|
97 |
# endif // LINUX |
|
1583 | 98 |
# endif |
5421 | 99 |
# endif // SUPPORT_IRIS_AUDIO |
100 |
||
101 |
# ifdef __osx__ |
|
102 |
# ifndef SUPPORT_PORTAUDIO |
|
5468 | 103 |
# define xxxSUPPORT_PORTAUDIO // def comes from config file |
5421 | 104 |
# endif |
105 |
# endif // __osx__ |
|
106 |
||
107 |
#endif /* NO_SOUND */ |
|
1583 | 108 |
|
5405 | 109 |
#ifdef SUPPORT_IRIS_AUDIO |
1583 | 110 |
# include <audio.h> |
111 |
# define __ALportVal(o) (ALport)(__externalAddressVal(o)) |
|
112 |
# define alPort handle1 |
|
113 |
#endif |
|
114 |
||
5405 | 115 |
#ifdef SUPPORT_ALSA_AUDIO |
1583 | 116 |
# ifdef LINUX |
117 |
# include <alsa/asoundlib.h> |
|
118 |
# define MAX_NR_OF_CHANNELS 8 |
|
119 |
# define DEBUG_SOUND |
|
120 |
# define readHandle handle1 |
|
121 |
# define writeHandle handle2 |
|
121
606a3ccd3682
linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents:
112
diff
changeset
|
122 |
# endif |
606a3ccd3682
linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents:
112
diff
changeset
|
123 |
#endif |
606a3ccd3682
linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents:
112
diff
changeset
|
124 |
|
5405 | 125 |
#ifdef SUPPORT_DEV_AUDIO |
1583 | 126 |
# ifdef LINUX |
127 |
# include <stdio.h> |
|
5426 | 128 |
# include <errno.h> |
129 |
# include <signal.h> |
|
130 |
# include <sys/ioctl.h> |
|
1583 | 131 |
# include <sys/soundcard.h> |
132 |
# define DEV_AUDIO_DEFAULT_FREQ (8000) |
|
133 |
# define DEV_AUDIO_DEFAULT_BUFFERSIZE (16384) |
|
134 |
# endif |
|
592 | 135 |
|
1583 | 136 |
# ifdef FREEBSD |
137 |
# include <stdio.h> |
|
138 |
# include <sys/time.h> |
|
139 |
# include <sys/ioctl.h> |
|
140 |
# include <machine/pcaudioio.h> |
|
141 |
# define DEV_AUDIO_DEFAULT_FREQ (8000) |
|
142 |
# define DEV_AUDIO_DEFAULT_BUFFERSIZE (16384) |
|
143 |
# endif |
|
594 | 144 |
|
1583 | 145 |
# if defined(sunos) || defined(solaris) |
146 |
# include <stdio.h> |
|
147 |
# ifdef solaris |
|
148 |
# include <sys/audioio.h> |
|
149 |
# else |
|
150 |
# include <sun/audioio.h> |
|
151 |
# endif |
|
152 |
# define DEV_AUDIO_DEFAULT_FREQ (8000) |
|
153 |
# define DEV_AUDIO_DEFAULT_BUFFERSIZE (16384) |
|
724 | 154 |
# endif |
155 |
||
1583 | 156 |
# if defined(hpux) |
157 |
# include <stdio.h> |
|
158 |
# include <sys/ioctl.h> |
|
159 |
# include <sys/inode.h> |
|
160 |
# include <sys/audio.h> |
|
161 |
# include <sys/time.h> |
|
162 |
# include <unistd.h> |
|
163 |
# define DEV_AUDIO_DEFAULT_FREQ (22050) |
|
164 |
# define DEV_AUDIO_DEFAULT_BUFFERSIZE (16384) |
|
165 |
# endif |
|
5405 | 166 |
#endif /* SUPPORT_DEV_AUDIO */ |
167 |
||
168 |
#ifdef SUPPORT_PORTAUDIO |
|
5400 | 169 |
// # include "pthread.h" |
170 |
# include "portaudio.h" |
|
171 |
# define PORTAUDIO_DEFAULT_FREQ (44100) |
|
172 |
# define PORTAUDIO_DEFAULT_BUFFERSIZE (16384) |
|
173 |
||
174 |
# define xINITLOCK(lk) { pthread_mutex_init(&(lk), NULL); } |
|
175 |
# define xRELEASELOCK(lk) { pthread_mutex_destroy(&(lk)); } |
|
176 |
# define xLOCK(lk) { pthread_mutex_lock(&(lk)); } |
|
177 |
# define xUNLOCK(lk) { pthread_mutex_unlock(&(lk)); } |
|
178 |
# define xMUTEX pthread_mutex_t |
|
179 |
||
180 |
# define INITLOCK(lk) { (lk) = 0; } |
|
181 |
# define RELEASELOCK(lk) { (lk) = 0; } |
|
182 |
# define LOCK(lk) { while ((lk)) ; (lk) = 1; } |
|
183 |
# define UNLOCK(lk) { (lk) = 0; } |
|
184 |
# define MUTEX int |
|
185 |
||
5405 | 186 |
#endif // SUPPORT_PORTAUDIO |
720 | 187 |
|
5421 | 188 |
#ifdef SUPPORT_JACKAUDIO |
189 |
# include "jack/jack.h" |
|
190 |
#endif // SUPPORT_JACKAUDIO |
|
191 |
||
3846 | 192 |
#ifdef __win32__ |
712 | 193 |
# define _WIN32 |
194 |
||
195 |
# undef INT |
|
196 |
# undef Array |
|
197 |
# undef Number |
|
198 |
# undef Method |
|
199 |
# undef Point |
|
200 |
# undef Rectangle |
|
201 |
# undef Block |
|
202 |
# undef String |
|
203 |
# undef Message |
|
204 |
# undef Object |
|
205 |
# undef Context |
|
753 | 206 |
# undef Time |
207 |
# undef Date |
|
1853
b9c4a09bfc6a
Fix name clashes with windows header files
Stefan Vogel <sv@exept.de>
parents:
1839
diff
changeset
|
208 |
# undef Process |
b9c4a09bfc6a
Fix name clashes with windows header files
Stefan Vogel <sv@exept.de>
parents:
1839
diff
changeset
|
209 |
# undef Processor |
861 | 210 |
# undef Set |
211 |
# undef Signal |
|
212 |
# undef Delay |
|
712 | 213 |
|
214 |
/* # include <stdarg.h> /* */ |
|
215 |
# include <stdio.h> /* */ |
|
216 |
# include <windows.h> |
|
721 | 217 |
|
5405 | 218 |
# ifdef SUPPORT_WIN32_DIRECTSOUND |
721 | 219 |
# define CINTERFACE |
220 |
# include "dsound.h" |
|
221 |
# define __DirectSoundVal(o) (LPDIRECTSOUND)(__externalAddressVal(o)) |
|
222 |
# define __DSBufferVal(o) (LPDIRECTSOUNDBUFFER)(__externalAddressVal(o)) |
|
223 |
||
224 |
# define RT_BUFFER_SIZE 4096 |
|
225 |
# define NBUFS 4 |
|
226 |
||
227 |
# define pDirectSound handle1 |
|
228 |
# define pDSBuffer handle2 |
|
229 |
||
230 |
# else /* USE WAVE... */ |
|
5405 | 231 |
# ifdef SUPPORT_WIN32_WAVESOUND |
2818 | 232 |
# define __WaveHandleVal(o) (HWAVEOUT)(__externalAddressVal(o)) |
233 |
# define MAXBUF 10 /* Maximum number of buffers */ |
|
234 |
# define DATALEN 2048 /* Size of wave data buffer */ |
|
721 | 235 |
|
236 |
struct buf { |
|
237 |
WAVEHDR hdr; /* Wave data header */ |
|
722 | 238 |
char data[DATALEN]; /* Actual wave data */ |
721 | 239 |
struct buf *next; /* Next buffer in free list */ |
240 |
}; |
|
241 |
||
722 | 242 |
static struct buf *free_list = NULL; /* List of available buffers */ |
243 |
static CRITICAL_SECTION free_list_lock; |
|
244 |
static int free_buffers = 0; /* Number of buffers in free list */ |
|
245 |
static int total_buffers = 0; /* Total number of buffers allocated */ |
|
246 |
static HANDLE free_buffer_event; /* Automatic-reset event triggered whenever */ |
|
721 | 247 |
|
2818 | 248 |
# define waveHandle handle1 |
721 | 249 |
|
5405 | 250 |
# endif /* SUPPORT_WIN32_WAVESOUND */ |
251 |
# endif /* SUPPORT_WIN32_DIRECTSOUND */ |
|
712 | 252 |
|
253 |
# ifdef __DEF_Array |
|
254 |
# define Array __DEF_Array |
|
255 |
# endif |
|
256 |
# ifdef __DEF_Number |
|
257 |
# define Number __DEF_Number |
|
258 |
# endif |
|
259 |
# ifdef __DEF_Method |
|
260 |
# define Method __DEF_Method |
|
261 |
# endif |
|
262 |
# ifdef __DEF_Point |
|
263 |
# define Point __DEF_Point |
|
264 |
# endif |
|
265 |
# ifdef __DEF_Block |
|
266 |
# define Block __DEF_Block |
|
267 |
# endif |
|
268 |
# ifdef __DEF_String |
|
269 |
# define String __DEF_String |
|
270 |
# endif |
|
271 |
# ifdef __DEF_Message |
|
272 |
# define Message __DEF_Message |
|
273 |
# endif |
|
274 |
# ifdef __DEF_Object |
|
275 |
# define Object __DEF_Object |
|
276 |
# endif |
|
277 |
# ifdef __DEF_Context |
|
278 |
# define Context __DEF_Context |
|
279 |
# endif |
|
753 | 280 |
# ifdef __DEF_Time |
281 |
# define Time __DEF_Time |
|
282 |
# endif |
|
283 |
# ifdef __DEF_Date |
|
284 |
# define Date __DEF_Date |
|
285 |
# endif |
|
1853
b9c4a09bfc6a
Fix name clashes with windows header files
Stefan Vogel <sv@exept.de>
parents:
1839
diff
changeset
|
286 |
#ifdef __DEF_Process |
b9c4a09bfc6a
Fix name clashes with windows header files
Stefan Vogel <sv@exept.de>
parents:
1839
diff
changeset
|
287 |
# define Process __DEF_Process |
b9c4a09bfc6a
Fix name clashes with windows header files
Stefan Vogel <sv@exept.de>
parents:
1839
diff
changeset
|
288 |
#endif |
b9c4a09bfc6a
Fix name clashes with windows header files
Stefan Vogel <sv@exept.de>
parents:
1839
diff
changeset
|
289 |
#ifdef __DEF_Processor |
b9c4a09bfc6a
Fix name clashes with windows header files
Stefan Vogel <sv@exept.de>
parents:
1839
diff
changeset
|
290 |
# define Processor __DEF_Processor |
b9c4a09bfc6a
Fix name clashes with windows header files
Stefan Vogel <sv@exept.de>
parents:
1839
diff
changeset
|
291 |
#endif |
861 | 292 |
#ifdef __DEF_Set |
293 |
# define Set __DEF_Set |
|
294 |
#endif |
|
295 |
#ifdef __DEF_Signal |
|
296 |
# define Signal __DEF_Signal |
|
297 |
#endif |
|
298 |
#ifdef __DEF_Delay |
|
299 |
# define Delay __DEF_Delay |
|
300 |
#endif |
|
753 | 301 |
|
3000 | 302 |
# define INT STX_INT |
303 |
# define UINT STX_UINT |
|
712 | 304 |
|
3846 | 305 |
#endif /* __win32__ */ |
712 | 306 |
|
1583 | 307 |
#ifdef DEBUG_SOUND |
1839 | 308 |
# define DPRINTF(x) console_printf x |
1583 | 309 |
#else |
310 |
# define DPRINTF(x) /* as nothing */ |
|
311 |
#endif |
|
312 |
||
121
606a3ccd3682
linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents:
112
diff
changeset
|
313 |
%} |
606a3ccd3682
linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents:
112
diff
changeset
|
314 |
! ! |
606a3ccd3682
linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents:
112
diff
changeset
|
315 |
|
5421 | 316 |
!SoundStream primitiveVariables! |
317 |
%{ |
|
318 |
static int DEBUGGING = 0; |
|
319 |
%} |
|
320 |
! ! |
|
321 |
||
721 | 322 |
!SoundStream primitiveFunctions! |
323 |
%{ |
|
5400 | 324 |
|
5405 | 325 |
#ifdef SUPPORT_WIN32_WAVESOUND |
5400 | 326 |
|
327 |
/* |
|
328 |
* This routine will be called by windows when audio is needed. |
|
329 |
* It may called at interrupt level and by a separate thread, so don't do anything |
|
330 |
* that could mess up the system like calling malloc() or free(). |
|
331 |
*/ |
|
1556
8a78c9a5a8f7
STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents:
1480
diff
changeset
|
332 |
static void CALLBACK |
3000 | 333 |
waveCallBack(HWAVE waveHandle, UINT msg, DWORD_PTR inst, DWORD_PTR p1, DWORD_PTR p2) |
721 | 334 |
{ |
335 |
if (msg == MM_WOM_DONE) { |
|
5429 | 336 |
struct buf *bp = (struct buf *)p1; |
337 |
||
338 |
EnterCriticalSection(&free_list_lock); |
|
339 |
bp->next = free_list; |
|
340 |
free_list = bp; |
|
341 |
free_buffers++; |
|
342 |
SetEvent(free_buffer_event); |
|
343 |
LeaveCriticalSection(&free_list_lock); |
|
721 | 344 |
} |
345 |
} |
|
346 |
||
5405 | 347 |
#endif /* SUPPORT_WIN32_WAVESOUND */ |
348 |
||
349 |
#ifdef SUPPORT_PORTAUDIO |
|
5400 | 350 |
|
351 |
struct paBuffer { |
|
352 |
void* sampleData; |
|
353 |
int bufferSize; |
|
354 |
struct paBuffer* nextBuffer; |
|
355 |
}; |
|
356 |
||
357 |
struct paStreamData { |
|
358 |
PaStream *stream; |
|
359 |
MUTEX lock; |
|
360 |
int readOffset; |
|
361 |
int bytesPerSample; // bytesPerSample (1, 2 or 4) |
|
362 |
int nChannels; // num channels (1 or 2) |
|
363 |
int hasFinished; |
|
364 |
struct paBuffer* currentBuffer; |
|
365 |
struct paBuffer* lastBuffer; |
|
366 |
struct paBuffer* freeList; |
|
367 |
}; |
|
368 |
||
369 |
/* |
|
370 |
* This routine will be called by the PortAudio engine when audio is needed. |
|
5421 | 371 |
* It may called at interrupt level on some machines, so don't do anything |
5400 | 372 |
* that could mess up the system like calling malloc() or free(). |
373 |
*/ |
|
374 |
static int |
|
375 |
paCallback( const void *inputBuffer, void *outputBuffer, |
|
5429 | 376 |
unsigned long framesPerBuffer, |
377 |
const PaStreamCallbackTimeInfo* timeInfo, |
|
378 |
PaStreamCallbackFlags statusFlags, |
|
379 |
void *userData ) |
|
5400 | 380 |
{ |
5421 | 381 |
struct paStreamData *streamData = (struct paStreamData *)userData; |
382 |
struct paBuffer *buffer = streamData->currentBuffer; |
|
383 |
int nBytesToOutput = streamData->bytesPerSample * streamData->nChannels * framesPerBuffer; |
|
5400 | 384 |
int nBytesLeftInBuffer; |
5416 | 385 |
int readOffset; |
386 |
int writeOffset = 0; |
|
5400 | 387 |
int nSent; |
388 |
int retVal = paContinue; |
|
389 |
||
5421 | 390 |
readOffset = streamData->readOffset; |
5413 | 391 |
again: |
5421 | 392 |
if (buffer != NULL) { |
5429 | 393 |
nBytesLeftInBuffer = buffer->bufferSize - readOffset; |
394 |
if (DEBUGGING) { |
|
395 |
fprintf(stderr, "pa: %d from %p[%d] to [%d]; next: %p last: %p)\n", |
|
396 |
nBytesLeftInBuffer, buffer, readOffset, writeOffset, |
|
397 |
buffer->nextBuffer, streamData->lastBuffer); |
|
398 |
} |
|
5400 | 399 |
} else { |
5429 | 400 |
nBytesLeftInBuffer = 0; |
5400 | 401 |
} |
402 |
if (nBytesLeftInBuffer >= nBytesToOutput) { |
|
5429 | 403 |
memcpy(outputBuffer+writeOffset, buffer->sampleData+readOffset, nBytesToOutput); |
404 |
nSent = nBytesToOutput; |
|
405 |
if (DEBUGGING) { |
|
406 |
fprintf(stderr, "pa: %d from buffer\n", nSent); |
|
407 |
} |
|
408 |
nBytesToOutput = 0; |
|
409 |
readOffset += nSent; |
|
5400 | 410 |
} else { |
5429 | 411 |
nSent = nBytesLeftInBuffer; |
412 |
if (nSent > 0) { |
|
413 |
memcpy(outputBuffer+writeOffset, buffer->sampleData+readOffset, nBytesLeftInBuffer); |
|
414 |
if (DEBUGGING) { |
|
415 |
fprintf(stderr, "pa: %d from buffer\n", nBytesLeftInBuffer); |
|
416 |
} |
|
417 |
nBytesToOutput -= nSent; |
|
418 |
readOffset += nBytesLeftInBuffer; |
|
419 |
} |
|
5400 | 420 |
} |
5421 | 421 |
if (buffer != NULL) { |
5429 | 422 |
streamData->readOffset = readOffset; |
423 |
if (readOffset >= buffer->bufferSize) { |
|
424 |
LOCK(streamData->lock); |
|
425 |
// next buffer |
|
426 |
streamData->currentBuffer = buffer->nextBuffer; |
|
427 |
streamData->readOffset = readOffset = 0; |
|
428 |
// this buffer onto freeList |
|
429 |
buffer->nextBuffer = streamData->freeList; |
|
430 |
streamData->freeList = buffer; |
|
431 |
if (DEBUGGING) { |
|
432 |
fprintf(stderr, "pa: put on freelist: %p\n", buffer); |
|
433 |
} |
|
434 |
if (streamData->currentBuffer == NULL) { |
|
435 |
if (DEBUGGING) { |
|
436 |
fprintf(stderr, "pa: done with last buffer\n"); |
|
437 |
} |
|
438 |
streamData->lastBuffer = NULL; |
|
439 |
retVal = paComplete; |
|
440 |
} |
|
441 |
UNLOCK(streamData->lock); |
|
442 |
if (nBytesToOutput > 0) { |
|
443 |
writeOffset += nSent; |
|
444 |
if (streamData->currentBuffer == NULL) { |
|
445 |
memset(outputBuffer+writeOffset, 0, nBytesToOutput); |
|
446 |
} else { |
|
447 |
buffer = streamData->currentBuffer; |
|
448 |
readOffset = 0; |
|
449 |
if (DEBUGGING) { |
|
450 |
fprintf(stderr, "pa: %d more\n", nBytesToOutput); |
|
451 |
} |
|
452 |
goto again; |
|
453 |
} |
|
454 |
} |
|
455 |
} |
|
5400 | 456 |
} |
457 |
||
458 |
return paContinue; |
|
459 |
} |
|
460 |
||
461 |
/* |
|
462 |
* This routine is called by portaudio when playback is done. |
|
463 |
*/ |
|
464 |
static void |
|
465 |
paStreamFinished( void* userData ) |
|
466 |
{ |
|
5421 | 467 |
struct paStreamData *streamData = (struct paStreamData *)userData; |
468 |
||
469 |
streamData->hasFinished = 1; |
|
5400 | 470 |
if (DEBUGGING) { |
5429 | 471 |
fprintf(stderr, "pa: Stream Completed\n" ); |
5400 | 472 |
} |
473 |
} |
|
474 |
||
5405 | 475 |
#endif /* SUPPORT_PORTAUDIO */ |
721 | 476 |
|
5421 | 477 |
#ifdef SUPPORT_JACKAUDIO |
478 |
||
479 |
struct jackBuffer { |
|
480 |
void* sampleData; |
|
481 |
int bufferSize; |
|
482 |
struct jackBuffer* nextBuffer; |
|
483 |
}; |
|
484 |
||
485 |
struct jackStreamData { |
|
486 |
jack_port_t *jack_input_port; |
|
487 |
jack_port_t *jack_output_port; |
|
488 |
jack_client_t *jack_client; |
|
489 |
MUTEX lock; |
|
490 |
int readOffset; |
|
491 |
int bytesPerSample; // bytesPerSample (1, 2 or 4) |
|
492 |
int nChannels; // num channels (1 or 2) |
|
493 |
int hasFinished; |
|
494 |
struct jackBuffer* currentBuffer; |
|
495 |
struct jackBuffer* lastBuffer; |
|
496 |
struct jackBuffer* freeList; |
|
497 |
}; |
|
498 |
||
499 |
/* |
|
500 |
* This routine will be called by the Jack engine when audio is needed. |
|
501 |
* It may called at interrupt level on some machines, so don't do anything |
|
502 |
* that could mess up the system like calling malloc() or free(). |
|
503 |
*/ |
|
504 |
static int |
|
505 |
jack_callback(jack_nframes_t nframes, void *userData) |
|
506 |
{ |
|
507 |
struct jackStreamData *streamData = (struct jackStreamData*)userData; |
|
508 |
struct jackBuffer *buffer = streamData->currentBuffer; |
|
509 |
int nBytesToOutput = streamData->bytesPerSample * streamData->nChannels * nframes; |
|
510 |
// int nBytesToOutput = sizeof (jack_default_audio_sample_t) * nframes; |
|
511 |
int nBytesLeftInBuffer; |
|
512 |
int readOffset; |
|
513 |
int writeOffset = 0; |
|
514 |
int nSent; |
|
515 |
int retVal = paContinue; |
|
516 |
jack_default_audio_sample_t *in, *out; |
|
517 |
||
518 |
in = jack_port_get_buffer (streamData->jack_input_port, nframes); |
|
519 |
out = jack_port_get_buffer (streamData->jack_output_port, nframes); |
|
520 |
||
521 |
readOffset = streamData->readOffset; |
|
522 |
again: |
|
523 |
if (buffer != NULL) { |
|
5429 | 524 |
nBytesLeftInBuffer = buffer->bufferSize - readOffset; |
525 |
if (DEBUGGING) { |
|
526 |
fprintf(stderr, "jack: %d from %p[%d] to [%d]; next: %p last: %p)\n", |
|
527 |
nBytesLeftInBuffer, buffer, readOffset, writeOffset, |
|
528 |
buffer->nextBuffer, streamData->lastBuffer); |
|
529 |
} |
|
5421 | 530 |
} else { |
5429 | 531 |
nBytesLeftInBuffer = 0; |
5421 | 532 |
} |
533 |
if (nBytesLeftInBuffer >= nBytesToOutput) { |
|
5429 | 534 |
memcpy(out+writeOffset, buffer->sampleData+readOffset, nBytesToOutput); |
535 |
nSent = nBytesToOutput; |
|
536 |
if (DEBUGGING) { |
|
537 |
fprintf(stderr, "jack: %d from buffer\n", nSent); |
|
538 |
} |
|
539 |
nBytesToOutput = 0; |
|
540 |
readOffset += nSent; |
|
5421 | 541 |
} else { |
5429 | 542 |
nSent = nBytesLeftInBuffer; |
543 |
if (nSent > 0) { |
|
544 |
memcpy(out+writeOffset, buffer->sampleData+readOffset, nBytesLeftInBuffer); |
|
545 |
if (DEBUGGING) { |
|
546 |
fprintf(stderr, "jack: %d from buffer\n", nBytesLeftInBuffer); |
|
547 |
} |
|
548 |
nBytesToOutput -= nSent; |
|
549 |
readOffset += nBytesLeftInBuffer; |
|
550 |
} |
|
5421 | 551 |
} |
552 |
if (buffer != NULL) { |
|
5429 | 553 |
streamData->readOffset = readOffset; |
554 |
if (readOffset >= buffer->bufferSize) { |
|
555 |
LOCK(streamData->lock); |
|
556 |
// next buffer |
|
557 |
streamData->currentBuffer = buffer->nextBuffer; |
|
558 |
streamData->readOffset = readOffset = 0; |
|
559 |
// this buffer onto freeList |
|
560 |
buffer->nextBuffer = streamData->freeList; |
|
561 |
streamData->freeList = buffer; |
|
562 |
if (DEBUGGING) { |
|
563 |
fprintf(stderr, "jack: put on freelist: %p\n", buffer); |
|
564 |
} |
|
565 |
if (streamData->currentBuffer == NULL) { |
|
566 |
if (DEBUGGING) { |
|
567 |
fprintf(stderr, "jack: done with last buffer\n"); |
|
568 |
} |
|
569 |
streamData->lastBuffer = NULL; |
|
570 |
retVal = paComplete; |
|
571 |
} |
|
572 |
UNLOCK(streamData->lock); |
|
573 |
if (nBytesToOutput > 0) { |
|
574 |
writeOffset += nSent; |
|
575 |
if (streamData->currentBuffer == NULL) { |
|
576 |
memset(out+writeOffset, 0, nBytesToOutput); |
|
577 |
} else { |
|
578 |
buffer = streamData->currentBuffer; |
|
579 |
readOffset = 0; |
|
580 |
if (DEBUGGING) { |
|
581 |
fprintf(stderr, "jack: %d more\n", nBytesToOutput); |
|
582 |
} |
|
583 |
goto again; |
|
584 |
} |
|
585 |
} |
|
586 |
} |
|
5421 | 587 |
} |
588 |
return 0; |
|
589 |
} |
|
590 |
||
591 |
/** |
|
592 |
* JACK calls this shutdown_callback if the server ever shuts down or |
|
593 |
* decides to disconnect the client. |
|
594 |
*/ |
|
595 |
void |
|
596 |
jack_shutdown (void *userData) |
|
597 |
{ |
|
598 |
struct jackStreamData *streamData = (struct jackStreamData*)userData; |
|
599 |
} |
|
600 |
||
601 |
#endif /* SUPPORT_JACKAUDIO */ |
|
602 |
||
721 | 603 |
%} |
788 | 604 |
! ! |
605 |
||
28 | 606 |
!SoundStream class methodsFor:'documentation'! |
607 |
||
31 | 608 |
copyright |
609 |
" |
|
610 |
COPYRIGHT (c) 1993 by Claus Gittinger |
|
5429 | 611 |
All Rights Reserved |
31 | 612 |
|
613 |
This software is furnished under a license and may be used |
|
614 |
only in accordance with the terms of that license and with the |
|
615 |
inclusion of the above copyright notice. This software may not |
|
616 |
be provided or otherwise made available to, or used by, any |
|
617 |
other person. No title to or ownership of the software is |
|
618 |
hereby transferred. |
|
619 |
" |
|
620 |
! |
|
621 |
||
28 | 622 |
documentation |
623 |
" |
|
5400 | 624 |
Preliminary (unfinished) interface to an audio device. |
625 |
Currently works with |
|
5429 | 626 |
LINUXs |
627 |
SUNs (and other) /dev/audio driver |
|
628 |
IRIX (indy). |
|
629 |
PORTAUDIO (osx). |
|
593 | 630 |
On iris, the default setup is for 8 bit mono |
28 | 631 |
so I can play the standard sound files I have here. |
632 |
It needs much more work, for stereo, different sampling rates etc. |
|
633 |
||
5424 | 634 |
This is an experimental class - its interface & implementation may change in the future. |
592 | 635 |
|
259 | 636 |
[author:] |
5429 | 637 |
Claus Gittinger |
5447 | 638 |
|
639 |
[caveat:] |
|
640 |
this class was written in the early 90's to experiment with a cheap soundblaster board, |
|
641 |
to provide output for a modular synth at that time. |
|
642 |
It is not supported or to be taken serious... |
|
643 |
Actually, it seems to be broken. |
|
28 | 644 |
" |
152 | 645 |
! ! |
45 | 646 |
|
595 | 647 |
!SoundStream class methodsFor:'initialization'! |
648 |
||
5411 | 649 |
debug:aBoolean |
650 |
%{ |
|
651 |
DEBUGGING = (aBoolean == true); |
|
652 |
%} |
|
653 |
! |
|
654 |
||
595 | 655 |
initialize |
656 |
UnsupportedOperationSignal isNil ifTrue:[ |
|
5429 | 657 |
UnsupportedOperationSignal := StreamError newSignalMayProceed:true. |
658 |
UnsupportedOperationSignal nameClass:self message:#unsupportedOperationSignal. |
|
659 |
UnsupportedOperationSignal notifierString:'unsupported operation'. |
|
595 | 660 |
] |
661 |
! ! |
|
662 |
||
0 | 663 |
!SoundStream class methodsFor:'instance creation'! |
664 |
||
5402 | 665 |
determineConcreteClass |
666 |
self allSubclassesDo:[:each | |
|
5429 | 667 |
each isAbstract ifFalse:[ |
668 |
each isSupported ifTrue:[ |
|
669 |
^ each |
|
670 |
] |
|
671 |
] |
|
5402 | 672 |
]. |
673 |
^ nil |
|
5421 | 674 |
|
675 |
" |
|
676 |
self determineConcreteClass |
|
677 |
" |
|
5402 | 678 |
! |
679 |
||
680 |
new |
|
681 |
self == SoundStream ifTrue:[ |
|
5429 | 682 |
ConcreteClass isNil ifTrue:[ |
683 |
ConcreteClass := self determineConcreteClass. |
|
684 |
ConcreteClass isNil ifTrue:[ |
|
685 |
OpenError raiseErrorString:'missing sound support'. |
|
686 |
]. |
|
687 |
]. |
|
688 |
^ ConcreteClass new. |
|
5402 | 689 |
]. |
690 |
^ self basicNew initialize |
|
691 |
||
692 |
" |
|
693 |
SoundStream new |
|
694 |
" |
|
695 |
! |
|
696 |
||
932 | 697 |
readWrite |
698 |
"create and return a new soundStream for readWrite (i.e. filtering)" |
|
699 |
||
700 |
|newStream| |
|
5402 | 701 |
|
5403 | 702 |
newStream := self new. |
932 | 703 |
newStream openForReadWrite isNil ifTrue:[^nil]. |
704 |
^ newStream |
|
705 |
||
706 |
"SoundStream readWrite" |
|
707 |
! |
|
708 |
||
0 | 709 |
reading |
593 | 710 |
"create and return a new soundStream for reading (i.e. recording)" |
711 |
||
0 | 712 |
|newStream| |
5403 | 713 |
|
714 |
newStream := self new. |
|
0 | 715 |
newStream openForReading isNil ifTrue:[^nil]. |
716 |
^ newStream |
|
717 |
||
718 |
"SoundStream reading" |
|
593 | 719 |
|
720 |
"Modified: / 12.12.1997 / 16:51:56 / cg" |
|
0 | 721 |
! |
722 |
||
723 |
writing |
|
593 | 724 |
"create and return a new soundStream for writing (i.e. playback)" |
725 |
||
0 | 726 |
|newStream| |
727 |
||
5403 | 728 |
newStream := self new. |
0 | 729 |
newStream openForWriting isNil ifTrue:[^nil]. |
730 |
^ newStream |
|
731 |
||
121
606a3ccd3682
linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents:
112
diff
changeset
|
732 |
" |
606a3ccd3682
linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents:
112
diff
changeset
|
733 |
SoundStream writing |
606a3ccd3682
linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents:
112
diff
changeset
|
734 |
" |
606a3ccd3682
linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents:
112
diff
changeset
|
735 |
|
593 | 736 |
"Created: / 17.11.1995 / 17:25:42 / cg" |
737 |
"Modified: / 12.12.1997 / 16:51:38 / cg" |
|
0 | 738 |
! |
739 |
||
714 | 740 |
writing16Bit |
741 |
"just an example, has never been tried (I also |
|
742 |
have no samples for this ... leave it as an exercise)" |
|
743 |
||
744 |
|newStream| |
|
745 |
||
5403 | 746 |
newStream := self new. |
5422 | 747 |
(newStream supportedAudioFormats includesAny:#(S16 U16)) ifFalse:[ |
5429 | 748 |
OpenError raiseRequestErrorString:'sound system does not support 16bit audio' |
5422 | 749 |
]. |
714 | 750 |
newStream bitsPerSample:16. |
751 |
newStream openForWriting isNil ifTrue:[^nil]. |
|
752 |
^ newStream |
|
753 |
||
754 |
"SoundStream writing16Bit" |
|
755 |
||
756 |
"Modified: / 12.12.1997 / 16:51:49 / cg" |
|
757 |
"Created: / 21.12.1998 / 00:02:17 / cg" |
|
758 |
! |
|
759 |
||
712 | 760 |
writing16BitStereo |
0 | 761 |
"just an example, has never been tried (I also |
592 | 762 |
have no samples for this ... leave it as an exercise)" |
0 | 763 |
|
764 |
|newStream| |
|
765 |
||
5422 | 766 |
newStream := self new. |
767 |
(newStream supportedAudioFormats includesAny:#(S16 U16)) ifFalse:[ |
|
5429 | 768 |
OpenError raiseRequestErrorString:'sound system does not support 16bit audio' |
0 | 769 |
]. |
770 |
newStream bitsPerSample:16. |
|
771 |
newStream numberOfChannels:2. |
|
772 |
newStream openForWriting isNil ifTrue:[^nil]. |
|
773 |
^ newStream |
|
774 |
||
775 |
"SoundStream writing16BitStereo" |
|
593 | 776 |
|
777 |
"Modified: / 12.12.1997 / 16:51:49 / cg" |
|
5400 | 778 |
! |
779 |
||
780 |
writingFloat |
|
781 |
|newStream| |
|
782 |
||
5422 | 783 |
newStream := self new. |
784 |
(newStream supportedAudioFormats includes:#F32) ifFalse:[ |
|
5429 | 785 |
OpenError raiseRequestErrorString:'sound system does not support float audio' |
5400 | 786 |
]. |
787 |
newStream setAudioFormat:#F32. |
|
788 |
newStream numberOfChannels:1. |
|
789 |
newStream openForWriting isNil ifTrue:[^nil]. |
|
790 |
^ newStream |
|
791 |
||
792 |
"SoundStream writingFloat" |
|
793 |
! |
|
794 |
||
795 |
writingFloatStereo |
|
796 |
|newStream| |
|
797 |
||
5422 | 798 |
newStream := self new. |
799 |
(newStream supportedAudioFormats includes:#F32) ifFalse:[ |
|
5429 | 800 |
OpenError raiseRequestErrorString:'sound system does not support float audio' |
5400 | 801 |
]. |
802 |
newStream setAudioFormat:#F32. |
|
803 |
newStream numberOfChannels:2. |
|
804 |
newStream openForWriting isNil ifTrue:[^nil]. |
|
805 |
^ newStream |
|
806 |
||
807 |
"SoundStream writingFloatStereo" |
|
0 | 808 |
! ! |
809 |
||
596 | 810 |
!SoundStream class methodsFor:'Signal constants'! |
811 |
||
812 |
unsupportedOperationSignal |
|
813 |
^ UnsupportedOperationSignal |
|
814 |
! ! |
|
815 |
||
592 | 816 |
!SoundStream class methodsFor:'conversion helpers'! |
0 | 817 |
|
5401 | 818 |
aLawToLinear16:aLawValue |
819 |
"given an aLaw byte, return the decoded signed 16bit value" |
|
820 |
||
821 |
" |
|
822 |
Linearer Input Output |
|
823 |
s0000000wxyza... n000wxyz |
|
824 |
s0000001wxyza... n001wxyz |
|
825 |
s000001wxyzab... n010wxyz |
|
826 |
s00001wxyzabc... n011wxyz |
|
827 |
s0001wxyzabcd... n100wxyz |
|
828 |
s001wxyzabcde... n101wxyz |
|
829 |
s01wxyzabcdef... n110wxyz |
|
830 |
s1wxyzabcdefg... n111wxyz |
|
831 |
" |
|
832 |
||
833 |
|ix iexp mant| |
|
834 |
||
835 |
ix := aLawValue bitAnd:16r007F. "/ remove sign bit |
|
5405 | 836 |
iexp := ix rightShift: 4. "/ extract exponent |
5401 | 837 |
mant := ix bitAnd:16r000F. "/ now get mantissa |
838 |
(iexp > 0) ifTrue:[ |
|
5429 | 839 |
mant := mant + 16. "/ add leading '1', if exponent > 0 |
5401 | 840 |
]. |
5405 | 841 |
mant := (mant bitShift: 4) + 16r0008. "/ now mantissa left justified and |
5429 | 842 |
"/ 1/2 quantization step added |
5405 | 843 |
(iexp > 1) ifTrue:[ "/ now left shift according exponent |
5429 | 844 |
mant := mant bitShift: (iexp - 1). |
5401 | 845 |
]. |
846 |
"/ from 12 to 16bit |
|
847 |
mant := mant bitShift:4. |
|
5405 | 848 |
aLawValue > 127 ifTrue:[ "/ invert, if negative sample |
5429 | 849 |
^ mant |
5401 | 850 |
] ifFalse:[ |
5429 | 851 |
^ mant negated |
5401 | 852 |
]. |
853 |
||
854 |
" |
|
855 |
self aLawToLinear16:2r00000000 -8 |
|
856 |
self aLawToLinear16:2r00000001 -24 |
|
857 |
self aLawToLinear16:2r00010000 -264 |
|
858 |
self aLawToLinear16:2r00100000 -528 |
|
859 |
self aLawToLinear16:2r01000000 -2112 |
|
860 |
self aLawToLinear16:2r11000000 2112 |
|
861 |
" |
|
862 |
! |
|
863 |
||
596 | 864 |
linear16ToUlaw:a16bitSignedValue |
865 |
"given a 16it signed value, encode into uLaw byte" |
|
866 |
||
867 |
|absVal sign exp mantissa byte| |
|
868 |
||
869 |
%{ |
|
870 |
/* |
|
871 |
* so heavily used when playing sounds ... |
|
872 |
* made it a primitive. |
|
873 |
*/ |
|
874 |
if (__isSmallInteger(a16bitSignedValue)) { |
|
5429 | 875 |
int __sign = 0; |
876 |
int __absVal = __intVal(a16bitSignedValue); |
|
877 |
int __exp, __mantissa, __byte; |
|
878 |
static char __uLawExp[] = |
|
879 |
{ |
|
880 |
0,1,2,2,3,3,3,3,4,4,4,4,4,4,4,4, |
|
881 |
5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5, |
|
882 |
6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6, |
|
883 |
6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6, |
|
884 |
7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, |
|
885 |
7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, |
|
886 |
7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, |
|
887 |
7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7 |
|
888 |
}; |
|
889 |
||
890 |
if (__absVal < 0) { |
|
891 |
if (__absVal <= -32256) { |
|
892 |
RETURN (__MKSMALLINT(0)); |
|
893 |
} |
|
894 |
__absVal = -__absVal; |
|
895 |
__sign = 0x80; |
|
896 |
} else { |
|
897 |
if (__absVal >= 32256) { |
|
898 |
RETURN (__MKSMALLINT(128)); |
|
899 |
} |
|
900 |
} |
|
901 |
||
902 |
__exp = __uLawExp[__absVal >> 8]; |
|
903 |
__mantissa = (__absVal >> (__exp+3)) & 0xF; |
|
904 |
__byte = ~(__sign | (__exp<<4) | __mantissa) & 0xFF; |
|
905 |
RETURN (__MKSMALLINT(__byte)); |
|
596 | 906 |
} |
907 |
%}. |
|
908 |
"/ |
|
909 |
"/ fallback for non-integral argument |
|
910 |
"/ |
|
712 | 911 |
a16bitSignedValue isInteger ifFalse:[ |
5429 | 912 |
^ self uLawToLinear16:a16bitSignedValue asInteger |
596 | 913 |
]. |
712 | 914 |
^ 0 |
596 | 915 |
|
916 |
" |
|
1556
8a78c9a5a8f7
STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents:
1480
diff
changeset
|
917 |
SoundStream uLawToLinear16:(SoundStream linear16ToUlaw:0) |
8a78c9a5a8f7
STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents:
1480
diff
changeset
|
918 |
SoundStream uLawToLinear16:(SoundStream linear16ToUlaw:32256) |
8a78c9a5a8f7
STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents:
1480
diff
changeset
|
919 |
SoundStream uLawToLinear16:(SoundStream linear16ToUlaw:-32256) |
8a78c9a5a8f7
STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents:
1480
diff
changeset
|
920 |
SoundStream uLawToLinear16:(SoundStream linear16ToUlaw:32767) |
596 | 921 |
SoundStream uLawToLinear16:(SoundStream linear16ToUlaw:-32767) |
1556
8a78c9a5a8f7
STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents:
1480
diff
changeset
|
922 |
SoundStream uLawToLinear16:(SoundStream linear16ToUlaw:100) |
8a78c9a5a8f7
STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents:
1480
diff
changeset
|
923 |
SoundStream uLawToLinear16:(SoundStream linear16ToUlaw:-100) |
8a78c9a5a8f7
STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents:
1480
diff
changeset
|
924 |
SoundStream uLawToLinear16:(SoundStream linear16ToUlaw:104) |
8a78c9a5a8f7
STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents:
1480
diff
changeset
|
925 |
SoundStream uLawToLinear16:(SoundStream linear16ToUlaw:-104) |
596 | 926 |
" |
927 |
||
928 |
"Modified: / 9.12.1997 / 16:46:24 / cg" |
|
929 |
! |
|
930 |
||
592 | 931 |
uLawToLinear16:uLawValue |
932 |
"given a uLaw byte, return the decoded signed 16bit value. |
|
933 |
Currently unused - but will be" |
|
0 | 934 |
|
935 |
^ #( |
|
5429 | 936 |
"0 " -32256 |
937 |
"1 " -31228 |
|
938 |
"2 " -30200 |
|
939 |
"3 " -29172 |
|
940 |
"4 " -28143 |
|
941 |
"5 " -27115 |
|
942 |
"6 " -26087 |
|
943 |
"7 " -25059 |
|
944 |
"8 " -24031 |
|
945 |
"9 " -23002 |
|
946 |
"10 " -21974 |
|
947 |
"11 " -20946 |
|
948 |
"12 " -19918 |
|
949 |
"13 " -18889 |
|
950 |
"14 " -17861 |
|
951 |
"15 " -16833 |
|
952 |
"16 " -16062 |
|
953 |
"17 " -15548 |
|
954 |
"18 " -15033 |
|
955 |
"19 " -14519 |
|
956 |
"20 " -14005 |
|
957 |
"21 " -13491 |
|
958 |
"22 " -12977 |
|
959 |
"23 " -12463 |
|
960 |
"24 " -11949 |
|
961 |
"25 " -11435 |
|
962 |
"26 " -10920 |
|
963 |
"27 " -10406 |
|
964 |
"28 " -9892 |
|
965 |
"29 " -9378 |
|
966 |
"30 " -8864 |
|
967 |
"31 " -8350 |
|
968 |
"32 " -7964 |
|
969 |
"33 " -7707 |
|
970 |
"34 " -7450 |
|
971 |
"35 " -7193 |
|
972 |
"36 " -6936 |
|
973 |
"37 " -6679 |
|
974 |
"38 " -6422 |
|
975 |
"39 " -6165 |
|
976 |
"40 " -5908 |
|
977 |
"41 " -5651 |
|
978 |
"42 " -5394 |
|
979 |
"43 " -5137 |
|
980 |
"44 " -4880 |
|
981 |
"45 " -4623 |
|
982 |
"46 " -4365 |
|
983 |
"47 " -4108 |
|
984 |
"48 " -3916 |
|
985 |
"49 " -3787 |
|
986 |
"50 " -3659 |
|
987 |
"51 " -3530 |
|
988 |
"52 " -3402 |
|
989 |
"53 " -3273 |
|
990 |
"54 " -3144 |
|
991 |
"55 " -3016 |
|
992 |
"56 " -2887 |
|
993 |
"57 " -2759 |
|
994 |
"58 " -2630 |
|
995 |
"59 " -2502 |
|
996 |
"60 " -2373 |
|
997 |
"61 " -2245 |
|
998 |
"62 " -2116 |
|
999 |
"63 " -1988 |
|
1000 |
"64 " -1891 |
|
1001 |
"65 " -1827 |
|
1002 |
"66 " -1763 |
|
1003 |
"67 " -1698 |
|
1004 |
"68 " -1634 |
|
1005 |
"69 " -1570 |
|
1006 |
"70 " -1506 |
|
1007 |
"71 " -1441 |
|
1008 |
"72 " -1377 |
|
1009 |
"73 " -1313 |
|
1010 |
"74 " -1249 |
|
1011 |
"75 " -1184 |
|
1012 |
"76 " -1120 |
|
1013 |
"77 " -1056 |
|
1014 |
"78 " -992 |
|
1015 |
"79 " -927 |
|
1016 |
"80 " -879 |
|
1017 |
"81 " -847 |
|
1018 |
"82 " -815 |
|
1019 |
"83 " -783 |
|
1020 |
"84 " -751 |
|
1021 |
"85 " -718 |
|
1022 |
"86 " -686 |
|
1023 |
"87 " -654 |
|
1024 |
"88 " -622 |
|
1025 |
"89 " -590 |
|
1026 |
"90 " -558 |
|
1027 |
"91 " -526 |
|
1028 |
"92 " -494 |
|
1029 |
"93 " -461 |
|
1030 |
"94 " -429 |
|
1031 |
"95 " -397 |
|
1032 |
"96 " -373 |
|
1033 |
"97 " -357 |
|
1034 |
"98 " -341 |
|
1035 |
"99 " -325 |
|
1036 |
"100" -309 |
|
1037 |
"101" -293 |
|
1038 |
"102" -277 |
|
1039 |
"103" -261 |
|
1040 |
"104" -245 |
|
1041 |
"105" -228 |
|
1042 |
"106" -212 |
|
1043 |
"107" -196 |
|
1044 |
"108" -180 |
|
1045 |
"109" -164 |
|
1046 |
"110" -148 |
|
1047 |
"111" -132 |
|
1048 |
"112" -120 |
|
1049 |
"113" -112 |
|
1050 |
"114" -104 |
|
1051 |
"115" -96 |
|
1052 |
"116" -88 |
|
1053 |
"117" -80 |
|
1054 |
"118" -72 |
|
1055 |
"119" -64 |
|
1056 |
"120" -56 |
|
1057 |
"121" -48 |
|
1058 |
"122" -40 |
|
1059 |
"123" -32 |
|
1060 |
"124" -24 |
|
1061 |
"125" -16 |
|
1062 |
"126" -8 |
|
1063 |
"127" 0 |
|
1064 |
"128" 32256 |
|
1065 |
"129" 31228 |
|
1066 |
"130" 30200 |
|
1067 |
"131" 29172 |
|
1068 |
"132" 28143 |
|
1069 |
"133" 27115 |
|
1070 |
"134" 26087 |
|
1071 |
"135" 25059 |
|
1072 |
"136" 24031 |
|
1073 |
"137" 23002 |
|
1074 |
"138" 21974 |
|
1075 |
"139" 20946 |
|
1076 |
"140" 19918 |
|
1077 |
"141" 18889 |
|
1078 |
"142" 17861 |
|
1079 |
"143" 16833 |
|
1080 |
"144" 16062 |
|
1081 |
"145" 15548 |
|
1082 |
"146" 15033 |
|
1083 |
"147" 14519 |
|
1084 |
"148" 14005 |
|
1085 |
"149" 13491 |
|
1086 |
"150" 12977 |
|
1087 |
"151" 12463 |
|
1088 |
"152" 11949 |
|
1089 |
"153" 11435 |
|
1090 |
"154" 10920 |
|
1091 |
"155" 10406 |
|
1092 |
"156" 9892 |
|
1093 |
"157" 9378 |
|
1094 |
"158" 8864 |
|
1095 |
"159" 8350 |
|
1096 |
"160" 7964 |
|
1097 |
"161" 7707 |
|
1098 |
"162" 7450 |
|
1099 |
"163" 7193 |
|
1100 |
"164" 6936 |
|
1101 |
"165" 6679 |
|
1102 |
"166" 6422 |
|
1103 |
"167" 6165 |
|
1104 |
"168" 5908 |
|
1105 |
"169" 5651 |
|
1106 |
"170" 5394 |
|
1107 |
"171" 5137 |
|
1108 |
"172" 4880 |
|
1109 |
"173" 4623 |
|
1110 |
"174" 4365 |
|
1111 |
"175" 4108 |
|
1112 |
"176" 3916 |
|
1113 |
"177" 3787 |
|
1114 |
"178" 3659 |
|
1115 |
"179" 3530 |
|
1116 |
"180" 3402 |
|
1117 |
"181" 3273 |
|
1118 |
"182" 3144 |
|
1119 |
"183" 3016 |
|
1120 |
"184" 2887 |
|
1121 |
"185" 2759 |
|
1122 |
"186" 2630 |
|
1123 |
"187" 2502 |
|
1124 |
"188" 2373 |
|
1125 |
"189" 2245 |
|
1126 |
"190" 2116 |
|
1127 |
"191" 1988 |
|
1128 |
"192" 1891 |
|
1129 |
"193" 1827 |
|
1130 |
"194" 1763 |
|
1131 |
"195" 1698 |
|
1132 |
"196" 1634 |
|
1133 |
"197" 1570 |
|
1134 |
"198" 1506 |
|
1135 |
"199" 1441 |
|
1136 |
"200" 1377 |
|
1137 |
"201" 1313 |
|
1138 |
"202" 1249 |
|
1139 |
"203" 1184 |
|
1140 |
"204" 1120 |
|
1141 |
"205" 1056 |
|
1142 |
"206" 992 |
|
1143 |
"207" 927 |
|
1144 |
"208" 879 |
|
1145 |
"209" 847 |
|
1146 |
"210" 815 |
|
1147 |
"211" 783 |
|
1148 |
"212" 751 |
|
1149 |
"213" 718 |
|
1150 |
"214" 686 |
|
1151 |
"215" 654 |
|
1152 |
"216" 622 |
|
1153 |
"217" 590 |
|
1154 |
"218" 558 |
|
1155 |
"219" 526 |
|
1156 |
"220" 494 |
|
1157 |
"221" 461 |
|
1158 |
"222" 429 |
|
1159 |
"223" 397 |
|
1160 |
"224" 373 |
|
1161 |
"225" 357 |
|
1162 |
"226" 341 |
|
1163 |
"227" 325 |
|
1164 |
"228" 309 |
|
1165 |
"229" 293 |
|
1166 |
"230" 277 |
|
1167 |
"231" 261 |
|
1168 |
"232" 245 |
|
1169 |
"233" 228 |
|
1170 |
"234" 212 |
|
1171 |
"235" 196 |
|
1172 |
"236" 180 |
|
1173 |
"237" 164 |
|
1174 |
"238" 148 |
|
1175 |
"239" 132 |
|
1176 |
"240" 120 |
|
1177 |
"241" 112 |
|
1178 |
"242" 104 |
|
1179 |
"243" 96 |
|
1180 |
"244" 88 |
|
1181 |
"245" 80 |
|
1182 |
"246" 72 |
|
1183 |
"247" 64 |
|
1184 |
"248" 56 |
|
1185 |
"249" 48 |
|
1186 |
"250" 40 |
|
1187 |
"251" 32 |
|
1188 |
"252" 24 |
|
1189 |
"253" 16 |
|
1190 |
"254" 8 |
|
1191 |
"255" 0 |
|
0 | 1192 |
) at:(uLawValue + 1) |
592 | 1193 |
|
1194 |
"Modified: / 9.12.1997 / 16:34:17 / cg" |
|
0 | 1195 |
! ! |
1196 |
||
121
606a3ccd3682
linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents:
112
diff
changeset
|
1197 |
!SoundStream class methodsFor:'default values'! |
606a3ccd3682
linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents:
112
diff
changeset
|
1198 |
|
596 | 1199 |
defaultAudioFormat |
2822 | 1200 |
OperatingSystem isMSWINDOWSlike ifTrue:[ |
5429 | 1201 |
^ #S16 |
712 | 1202 |
]. |
5400 | 1203 |
OperatingSystem isOSXlike ifTrue:[ |
5429 | 1204 |
^ #S16 |
5400 | 1205 |
]. |
1556
8a78c9a5a8f7
STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents:
1480
diff
changeset
|
1206 |
^ #U8 |
596 | 1207 |
! |
1208 |
||
121
606a3ccd3682
linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents:
112
diff
changeset
|
1209 |
defaultBitsPerSample |
606a3ccd3682
linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents:
112
diff
changeset
|
1210 |
"minimum, supported by all audio systems" |
606a3ccd3682
linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents:
112
diff
changeset
|
1211 |
|
2822 | 1212 |
OperatingSystem isMSWINDOWSlike ifTrue:[ |
5429 | 1213 |
^ 16 |
712 | 1214 |
]. |
5400 | 1215 |
OperatingSystem isOSXlike ifTrue:[ |
5429 | 1216 |
^ 16 |
5400 | 1217 |
]. |
121
606a3ccd3682
linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents:
112
diff
changeset
|
1218 |
^ 8 |
606a3ccd3682
linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents:
112
diff
changeset
|
1219 |
! |
606a3ccd3682
linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents:
112
diff
changeset
|
1220 |
|
606a3ccd3682
linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents:
112
diff
changeset
|
1221 |
defaultNumberOfChannels |
606a3ccd3682
linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents:
112
diff
changeset
|
1222 |
"minimum, supported by all audio systems" |
606a3ccd3682
linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents:
112
diff
changeset
|
1223 |
|
606a3ccd3682
linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents:
112
diff
changeset
|
1224 |
^ 1 |
606a3ccd3682
linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents:
112
diff
changeset
|
1225 |
! |
606a3ccd3682
linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents:
112
diff
changeset
|
1226 |
|
606a3ccd3682
linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents:
112
diff
changeset
|
1227 |
defaultSampleRate |
606a3ccd3682
linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents:
112
diff
changeset
|
1228 |
"minimum, supported by all audio systems" |
606a3ccd3682
linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents:
112
diff
changeset
|
1229 |
|
606a3ccd3682
linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents:
112
diff
changeset
|
1230 |
^ 8000 |
606a3ccd3682
linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents:
112
diff
changeset
|
1231 |
! ! |
606a3ccd3682
linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents:
112
diff
changeset
|
1232 |
|
606a3ccd3682
linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents:
112
diff
changeset
|
1233 |
!SoundStream class methodsFor:'playing'! |
606a3ccd3682
linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents:
112
diff
changeset
|
1234 |
|
606a3ccd3682
linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents:
112
diff
changeset
|
1235 |
playSoundFile:aFilename |
593 | 1236 |
"play a soundFile" |
1237 |
||
5402 | 1238 |
|mime inStream soundStream count totalCount buffer startTime playTime delayedTime waitTime| |
1239 |
||
1240 |
mime := aFilename asFilename mimeTypeFromName. |
|
1241 |
mime isAudioType ifFalse:[ |
|
5429 | 1242 |
self error:'not an audio file: ',aFilename asFilename baseName |
5402 | 1243 |
]. |
1244 |
self halt. |
|
121
606a3ccd3682
linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents:
112
diff
changeset
|
1245 |
inStream := aFilename asFilename readStream. |
1154
6158d4545b71
Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents:
1151
diff
changeset
|
1246 |
inStream isNil ifTrue:[self error:'cannot open']. |
121
606a3ccd3682
linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents:
112
diff
changeset
|
1247 |
|
606a3ccd3682
linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents:
112
diff
changeset
|
1248 |
soundStream := self writing. |
1154
6158d4545b71
Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents:
1151
diff
changeset
|
1249 |
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
|
1250 |
|
1432
077bf1bfc8c4
Use Timestamp/#asTimestamp instead of AbsoluteTime/#asAbsoluteTime
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
1251 |
startTime := Timestamp now. |
121
606a3ccd3682
linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents:
112
diff
changeset
|
1252 |
totalCount := 0. |
606a3ccd3682
linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents:
112
diff
changeset
|
1253 |
|
606a3ccd3682
linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents:
112
diff
changeset
|
1254 |
buffer := ByteArray new:4096. |
606a3ccd3682
linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents:
112
diff
changeset
|
1255 |
[(count := inStream nextBytesInto:buffer) > 0] whileTrue:[ |
5429 | 1256 |
totalCount := totalCount + count. |
1257 |
soundStream nextPutBytes:count from:buffer. |
|
121
606a3ccd3682
linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents:
112
diff
changeset
|
1258 |
]. |
606a3ccd3682
linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents:
112
diff
changeset
|
1259 |
|
606a3ccd3682
linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents:
112
diff
changeset
|
1260 |
inStream close. |
4867 | 1261 |
soundStream flush. |
121
606a3ccd3682
linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents:
112
diff
changeset
|
1262 |
|
606a3ccd3682
linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents:
112
diff
changeset
|
1263 |
"/ |
5400 | 1264 |
"/ at least the linux audio driver behaves funny, if we close too early... |
121
606a3ccd3682
linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents:
112
diff
changeset
|
1265 |
"/ |
606a3ccd3682
linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents:
112
diff
changeset
|
1266 |
playTime := totalCount / soundStream sampleRate. |
3226 | 1267 |
delayedTime := Timestamp now secondDeltaFrom: startTime. |
121
606a3ccd3682
linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents:
112
diff
changeset
|
1268 |
waitTime := playTime - delayedTime + 0.1. |
606a3ccd3682
linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents:
112
diff
changeset
|
1269 |
|
606a3ccd3682
linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents:
112
diff
changeset
|
1270 |
(Delay forSeconds:waitTime) wait. |
606a3ccd3682
linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents:
112
diff
changeset
|
1271 |
|
606a3ccd3682
linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents:
112
diff
changeset
|
1272 |
soundStream close. |
606a3ccd3682
linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents:
112
diff
changeset
|
1273 |
|
606a3ccd3682
linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents:
112
diff
changeset
|
1274 |
" |
606a3ccd3682
linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents:
112
diff
changeset
|
1275 |
SoundStream playSoundFile:'/usr/local/lib/sounds/laugh.snd' |
606a3ccd3682
linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents:
112
diff
changeset
|
1276 |
SoundStream playSoundFile:'/usr/local/lib/sounds/spacemusic.snd' |
5402 | 1277 |
SoundStream playSoundFile:'../../goodies/not_ported/sound/sampleFiles/pluck-pcm16.aiff' |
121
606a3ccd3682
linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents:
112
diff
changeset
|
1278 |
" |
606a3ccd3682
linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents:
112
diff
changeset
|
1279 |
|
4867 | 1280 |
"Created: / 17-11-1995 / 17:25:30 / cg" |
1281 |
"Modified: / 17-03-2019 / 15:02:57 / Claus Gittinger" |
|
121
606a3ccd3682
linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents:
112
diff
changeset
|
1282 |
! ! |
606a3ccd3682
linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents:
112
diff
changeset
|
1283 |
|
5400 | 1284 |
!SoundStream class methodsFor:'queries'! |
1285 |
||
5421 | 1286 |
defaultClass |
1287 |
^ ConcreteClass |
|
1288 |
||
1289 |
" |
|
1290 |
SoundStream defaultClass:(SoundStream::JackAudio) |
|
1291 |
" |
|
1292 |
! |
|
1293 |
||
1294 |
defaultClass:aClass |
|
1295 |
self assert:(aClass isSupported). |
|
1296 |
ConcreteClass := aClass. |
|
1297 |
||
1298 |
" |
|
1299 |
SoundStream defaultClass:(SoundStream::JackAudio) |
|
5428 | 1300 |
SoundStream defaultClass:(SoundStream::PortAudio) |
5421 | 1301 |
" |
1302 |
! |
|
1303 |
||
5402 | 1304 |
isSupported |
1305 |
^ false. |
|
1306 |
! |
|
1307 |
||
5418 | 1308 |
noteToHertz:noteName |
1309 |
"notename is one of: |
|
5429 | 1310 |
a1, b2, f3, c#3 etc." |
5418 | 1311 |
|
1312 |
|octave lastDigit note f sharp| |
|
1313 |
||
1314 |
octave := 4. |
|
1315 |
(lastDigit := noteName last) isDigit ifTrue:[ |
|
5429 | 1316 |
octave := lastDigit digitValue |
5418 | 1317 |
]. |
1318 |
note := noteName first. |
|
1319 |
sharp := (noteName size > 1) and:[noteName second == $#]. |
|
1320 |
note = $a ifTrue:[ |
|
5429 | 1321 |
f := sharp ifTrue:[466.2] ifFalse:[440] |
5418 | 1322 |
] ifFalse:[ note = $b ifTrue:[ |
5429 | 1323 |
f := 493.8 |
5418 | 1324 |
] ifFalse:[ note = $c ifTrue:[ |
5429 | 1325 |
f := sharp ifTrue:[277.2] ifFalse:[261.6] |
5418 | 1326 |
] ifFalse:[ note = $d ifTrue:[ |
5429 | 1327 |
f := sharp ifTrue:[311.1] ifFalse:[293.6] |
5418 | 1328 |
] ifFalse:[ note = $e ifTrue:[ |
5429 | 1329 |
f := 329.6 |
5418 | 1330 |
] ifFalse:[ note = $f ifTrue:[ |
5429 | 1331 |
f := sharp ifTrue:[370] ifFalse:[349.2] |
5418 | 1332 |
] ifFalse:[ note = $g ifTrue:[ |
5429 | 1333 |
f := sharp ifTrue:[415.3] ifFalse:[392] |
5418 | 1334 |
]]]]]]]. |
1335 |
||
1336 |
f := f * (2 raisedTo:octave-4). |
|
1337 |
^ f. |
|
1338 |
||
1339 |
" |
|
1340 |
SoundStream noteToHertz:'a' |
|
5421 | 1341 |
SoundStream noteToHertz:'g4' |
1342 |
SoundStream noteToHertz:'e5' |
|
1343 |
SoundStream noteToHertz:'b3' |
|
1344 |
SoundStream noteToHertz:'c#3' |
|
5418 | 1345 |
" |
1346 |
||
1347 |
"Modified: / 31.1.1999 / 12:06:27 / cg" |
|
1348 |
! |
|
1349 |
||
5400 | 1350 |
usedAudio |
1351 |
"returns a symbol describing which audio system is used; |
|
1352 |
one of PORTAUDIO, DEV_AUDIO, WIN32_WAVESOUND, IRIS_AUDIO" |
|
1353 |
||
5406 | 1354 |
ConcreteClass isNil ifTrue:[^ nil]. |
1355 |
^ ConcreteClass nameSymbol |
|
5400 | 1356 |
! ! |
1357 |
||
596 | 1358 |
!SoundStream methodsFor:'catching invalid methods'! |
1359 |
||
1360 |
pathName:filename |
|
1361 |
"catch pathname access - its fixed here" |
|
1362 |
||
1363 |
self shouldNotImplement |
|
1364 |
! |
|
1365 |
||
1366 |
pathName:filename in:aDirectory |
|
1367 |
"catch pathname access - its fixed here" |
|
1368 |
||
1369 |
self shouldNotImplement |
|
1370 |
! ! |
|
1371 |
||
5400 | 1372 |
!SoundStream methodsFor:'error handling'! |
1373 |
||
1374 |
lastErrorString |
|
1375 |
"return a message string describing the last error" |
|
1376 |
||
1377 |
lastErrorString notNil ifTrue:[ |
|
5429 | 1378 |
^ lastErrorString |
5400 | 1379 |
]. |
1380 |
^ super lastErrorString |
|
1381 |
! ! |
|
1382 |
||
596 | 1383 |
!SoundStream methodsFor:'mode setting'! |
1384 |
||
1385 |
bitsPerSample |
|
1386 |
"return the number of bits per sample - usually 8" |
|
1387 |
||
1388 |
^ bitsPerSample |
|
1389 |
! |
|
1390 |
||
1391 |
bitsPerSample:aNumber |
|
1392 |
"set the number of bits per sample" |
|
1393 |
||
5400 | 1394 |
|supported ok| |
1395 |
||
1396 |
ok := false. |
|
1397 |
supported := self supportedAudioFormats. |
|
1398 |
aNumber == 16 ifTrue:[ |
|
5429 | 1399 |
#(S16 S16_LE S16_BE U16 U16_LE U16_BE) doWithExit:[:fmt :exit | |
1400 |
(supported includes:fmt) ifTrue:[ |
|
1401 |
self setAudioFormat:fmt. |
|
1402 |
ok := true. |
|
1403 |
exit value:nil. |
|
1404 |
] |
|
1405 |
] |
|
5400 | 1406 |
]. |
1407 |
aNumber == 8 ifTrue:[ |
|
5429 | 1408 |
#(S8 U8) doWithExit:[:fmt :exit | |
1409 |
(supported includes:fmt) ifTrue:[ |
|
1410 |
self setAudioFormat:fmt. |
|
1411 |
ok := true. |
|
1412 |
exit value:nil. |
|
1413 |
] |
|
1414 |
] |
|
5400 | 1415 |
]. |
1416 |
aNumber == 24 ifTrue:[ |
|
5429 | 1417 |
#(S24 S24_LE S24_BE U24 U24_LE U24_BE) doWithExit:[:fmt :exit | |
1418 |
(supported includes:fmt) ifTrue:[ |
|
1419 |
self setAudioFormat:fmt. |
|
1420 |
ok := true. |
|
1421 |
exit value:nil. |
|
1422 |
] |
|
1423 |
] |
|
5400 | 1424 |
]. |
1425 |
aNumber == 32 ifTrue:[ |
|
5429 | 1426 |
#(S32 S32_LE S32_BE U32 U32_LE U32_BE) doWithExit:[:fmt :exit | |
1427 |
(supported includes:fmt) ifTrue:[ |
|
1428 |
self setAudioFormat:fmt. |
|
1429 |
ok := true. |
|
1430 |
exit value:nil. |
|
1431 |
] |
|
1432 |
] |
|
5400 | 1433 |
]. |
1434 |
ok ifFalse:[ |
|
5429 | 1435 |
UnsupportedOperationSignal raiseRequestErrorString:'unsupported format'. |
5400 | 1436 |
]. |
596 | 1437 |
bitsPerSample := aNumber |
1438 |
! |
|
1439 |
||
1440 |
numberOfChannels |
|
1441 |
"return the number of channels (1 or 2; usually 1)" |
|
1442 |
||
1443 |
^ numberOfChannels |
|
1444 |
! |
|
1445 |
||
1446 |
numberOfChannels:aNumber |
|
5400 | 1447 |
"set the number of channels |
1448 |
- on some devices, this is a nop" |
|
596 | 1449 |
|
1450 |
numberOfChannels := aNumber |
|
1451 |
! |
|
1452 |
||
1453 |
sampleRate |
|
1454 |
"return the sample rate" |
|
1455 |
||
1456 |
^ sampleRate |
|
1457 |
! |
|
1458 |
||
1459 |
sampleRate:aNumber |
|
5400 | 1460 |
"set the sample rate in hertz |
1461 |
- on some devices, this is a nop" |
|
596 | 1462 |
|
1463 |
self setSampleRate:aNumber. |
|
1464 |
! ! |
|
1465 |
||
592 | 1466 |
!SoundStream methodsFor:'private'! |
1467 |
||
593 | 1468 |
dumpSettings |
1469 |
"debugging interface - dump the current settings" |
|
1470 |
||
921 | 1471 |
audioFormat == #S16 ifTrue:[ |
5429 | 1472 |
UninterpretedBytes isBigEndian ifTrue:[ |
1473 |
audioFormat := #S16_BE |
|
1474 |
] ifFalse:[ |
|
1475 |
audioFormat := #S16_LE |
|
1476 |
] |
|
921 | 1477 |
]. |
1478 |
audioFormat == #U16 ifTrue:[ |
|
5429 | 1479 |
UninterpretedBytes isBigEndian ifTrue:[ |
1480 |
audioFormat := #U16_BE |
|
1481 |
] ifFalse:[ |
|
1482 |
audioFormat := #U16_LE |
|
1483 |
] |
|
921 | 1484 |
]. |
5402 | 1485 |
Transcript show:'sampleRate: '; showCR:sampleRate. |
1486 |
Transcript show:'format: '; showCR:audioFormat. |
|
1487 |
Transcript show:'fragmentSize: '; showCR:fragmentSize. |
|
1488 |
Transcript show:'channels: '; showCR:numberOfChannels. |
|
920 | 1489 |
Transcript show:'supported audioFormats: '; showCR:(self supportedAudioFormats). |
592 | 1490 |
|
1491 |
" |
|
593 | 1492 |
self writing dumpSettings; close |
1493 |
" |
|
1494 |
! |
|
1495 |
||
5400 | 1496 |
fileDescriptorOrNil |
1497 |
handle notNil ifTrue:[ |
|
5429 | 1498 |
^ self fileDescriptor. |
5400 | 1499 |
]. |
1500 |
^ nil |
|
1501 |
! |
|
1502 |
||
1556
8a78c9a5a8f7
STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents:
1480
diff
changeset
|
1503 |
initialize |
596 | 1504 |
"initialize for least common mode" |
593 | 1505 |
|
3156 | 1506 |
super initialize. |
3482 | 1507 |
"/ transparent |
1508 |
eolMode := nil. |
|
596 | 1509 |
buffered := false. |
1269
17546758fc7a
buffered:falsem to NonPositionableExternalStreams is already set.
Stefan Vogel <sv@exept.de>
parents:
1154
diff
changeset
|
1510 |
binary := true. |
712 | 1511 |
bitsPerSample := self class defaultBitsPerSample. |
1512 |
audioFormat := self class defaultAudioFormat. |
|
1513 |
numberOfChannels := self class defaultNumberOfChannels. |
|
1514 |
sampleRate := self class defaultSampleRate. |
|
1515 |
pathName := nil. |
|
592 | 1516 |
! |
1517 |
||
1518 |
resetSoundCard |
|
593 | 1519 |
"debugging interface - reset the soundCard" |
1520 |
||
595 | 1521 |
^ UnsupportedOperationSignal raise |
592 | 1522 |
|
1523 |
" |
|
593 | 1524 |
self writing resetSoundCard; dumpSettings; close |
592 | 1525 |
" |
1526 |
! |
|
1527 |
||
1528 |
setAudioFormat:aSymbol |
|
593 | 1529 |
"set the format of the audio data as specified by aSymbol. |
4617 | 1530 |
Returns true if sucessful - may fail with some formats on many sound devices." |
593 | 1531 |
|
5402 | 1532 |
audioFormat := aSymbol. |
5400 | 1533 |
((audioFormat == #U8) or:[audioFormat == #S8]) ifTrue:[ |
5429 | 1534 |
bitsPerSample := 8. |
1535 |
^ self |
|
5400 | 1536 |
]. |
1537 |
(#(U16 U16_LE U16_BE S16 S16_LE S16_BE) includes:audioFormat) ifTrue:[ |
|
5429 | 1538 |
bitsPerSample := 16. |
1539 |
^ self |
|
5400 | 1540 |
]. |
1541 |
(#(U24 U24_LE U24_BE S24 S24_LE S24_BE) includes:audioFormat) ifTrue:[ |
|
5429 | 1542 |
bitsPerSample := 24. |
1543 |
^ self |
|
5400 | 1544 |
]. |
1545 |
(#(U32 U32_LE U32_BE S32 S32_LE S32_BE) includes:audioFormat) ifTrue:[ |
|
5429 | 1546 |
bitsPerSample := 32. |
1547 |
^ self |
|
5400 | 1548 |
]. |
1549 |
(audioFormat == #F32) ifTrue:[ |
|
5429 | 1550 |
bitsPerSample := 32. |
1551 |
^ self |
|
5400 | 1552 |
]. |
1553 |
bitsPerSample := 8. |
|
592 | 1554 |
|
1555 |
" |
|
919 | 1556 |
self writing dumpSettings; close |
592 | 1557 |
self writing setAudioFormat:#'MU_LAW'; close |
597 | 1558 |
self writing setAudioFormat:#'U8'; dumpSettings; close |
1559 |
self writing setAudioFormat:#'MPEG'; dumpSettings; close |
|
592 | 1560 |
" |
593 | 1561 |
! |
1562 |
||
1563 |
setChannels:nChannels |
|
1564 |
"set the number of channels (1 -> mono; 2 -> stereo). |
|
4617 | 1565 |
Returns true if sucessful - may fail with many sound devices." |
593 | 1566 |
|
5405 | 1567 |
numberOfChannels := nChannels. |
593 | 1568 |
|
1569 |
" |
|
1570 |
self writing setChannels:2; dumpSettings; close |
|
1571 |
self writing setChannels:2; setSampleRate:10000; dumpSettings; close |
|
1572 |
self writing setChannels:2; setSampleRate:40000; dumpSettings; close |
|
1573 |
" |
|
1574 |
! |
|
1575 |
||
1576 |
setFragmentSize:blockSize |
|
5402 | 1577 |
"set the soundDriver's fragmentSize" |
1578 |
||
1579 |
fragmentSize := blockSize. |
|
593 | 1580 |
! |
1581 |
||
1582 |
setSampleRate:hz |
|
5402 | 1583 |
"set the sample rate" |
1584 |
||
1585 |
sampleRate := hz. |
|
593 | 1586 |
|
1587 |
" |
|
1588 |
self writing setSampleRate:10000; dumpSettings; close |
|
1589 |
self writing setSampleRate:1000; dumpSettings; close |
|
919 | 1590 |
self writing setSampleRate:8000; dumpSettings; close |
593 | 1591 |
" |
121
606a3ccd3682
linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents:
112
diff
changeset
|
1592 |
! |
606a3ccd3682
linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents:
112
diff
changeset
|
1593 |
|
596 | 1594 |
supportedAudioFormats |
1595 |
"return a collection of supported audio formats. |
|
5400 | 1596 |
possibly returned symbols are: |
5429 | 1597 |
U8 unsigned 8bit samples |
1598 |
S8 signed 8bit samples |
|
1599 |
U16 unsigned 16bit samples in native format |
|
1600 |
U16_LE unsigned 16bit big endian samples |
|
1601 |
U16_BE unsigned 16bit big endian samples |
|
1602 |
S16 signed 16bit little endian samples in native format |
|
1603 |
S16_LE signed 16bit little endian samples |
|
1604 |
S16_BE signed 16bit big endian samples |
|
1605 |
S24 signed 24bit little endian samples in native format |
|
1606 |
S24_LE signed 24bit little endian samples |
|
1607 |
S24_BE signed 24bit big endian samples |
|
1608 |
S32 signed 32bit little endian samples in native format |
|
1609 |
S32_LE signed 32bit little endian samples |
|
1610 |
S32_BE signed 32bit big endian samples |
|
1611 |
F32 float samples |
|
1612 |
MPEG audio mpeg encoded |
|
1613 |
MU_LAW u-law encoded 8bit samples |
|
1614 |
A_LAW a-law encoded 8bit samples |
|
1615 |
IMA_ADPCM adpcm encoded |
|
5400 | 1616 |
the set of returned symbols depends on the underlying sound hardware. |
596 | 1617 |
" |
121
606a3ccd3682
linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents:
112
diff
changeset
|
1618 |
|
5402 | 1619 |
^ #( U8) |
0 | 1620 |
|
596 | 1621 |
" |
1622 |
|s formats| |
|
0 | 1623 |
|
596 | 1624 |
s := self writing. |
1625 |
formats := s supportedAudioFormats. |
|
1626 |
s close. |
|
1556
8a78c9a5a8f7
STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents:
1480
diff
changeset
|
1627 |
formats |
596 | 1628 |
" |
0 | 1629 |
! ! |
1630 |
||
5400 | 1631 |
!SoundStream methodsFor:'redefined'! |
1632 |
||
1633 |
close |
|
1634 |
self flush. |
|
1635 |
super close. |
|
1636 |
! ! |
|
1637 |
||
1474 | 1638 |
!SoundStream protectedMethodsFor:'redefined'! |
0 | 1639 |
|
593 | 1640 |
closeFile |
1641 |
"a stream has been collected - close the file" |
|
1642 |
||
5402 | 1643 |
self subclassResponsibility |
1474 | 1644 |
! ! |
1645 |
||
1646 |
!SoundStream methodsFor:'redefined'! |
|
593 | 1647 |
|
274
f45bd0d6ea31
Rename synchronizeOutput --> flush.
Stefan Vogel <sv@exept.de>
parents:
259
diff
changeset
|
1648 |
flush |
f45bd0d6ea31
Rename synchronizeOutput --> flush.
Stefan Vogel <sv@exept.de>
parents:
259
diff
changeset
|
1649 |
"wait until all sound has been played" |
f45bd0d6ea31
Rename synchronizeOutput --> flush.
Stefan Vogel <sv@exept.de>
parents:
259
diff
changeset
|
1650 |
|
5402 | 1651 |
self subclassResponsibility |
1652 |
||
277
ab17540f022a
oops - your last checkin was garbage
Claus Gittinger <cg@exept.de>
parents:
274
diff
changeset
|
1653 |
! |
274
f45bd0d6ea31
Rename synchronizeOutput --> flush.
Stefan Vogel <sv@exept.de>
parents:
259
diff
changeset
|
1654 |
|
712 | 1655 |
isOpen |
4635 | 1656 |
self isExecutor ifTrue:[ |
5429 | 1657 |
^ false. |
4635 | 1658 |
]. |
721 | 1659 |
handle1 notNil ifTrue:[^ true]. |
1583 | 1660 |
handle2 notNil ifTrue:[^ true]. |
2321
6f4cc7b644db
filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents:
1853
diff
changeset
|
1661 |
^ handle notNil |
4635 | 1662 |
|
1663 |
"Modified: / 23-04-2018 / 18:29:42 / stefan" |
|
712 | 1664 |
! |
1665 |
||
121
606a3ccd3682
linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents:
112
diff
changeset
|
1666 |
nextBytes:count into:anObject startingAt:start |
606a3ccd3682
linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents:
112
diff
changeset
|
1667 |
"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
|
1668 |
bytes read or nil on error. |
606a3ccd3682
linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents:
112
diff
changeset
|
1669 |
Use with ByteArrays only." |
606a3ccd3682
linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents:
112
diff
changeset
|
1670 |
|
5402 | 1671 |
self subclassResponsibility |
277
ab17540f022a
oops - your last checkin was garbage
Claus Gittinger <cg@exept.de>
parents:
274
diff
changeset
|
1672 |
! |
121
606a3ccd3682
linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents:
112
diff
changeset
|
1673 |
|
606a3ccd3682
linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents:
112
diff
changeset
|
1674 |
nextPutBytes:count from:anObject startingAt:start |
606a3ccd3682
linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents:
112
diff
changeset
|
1675 |
"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
|
1676 |
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
|
1677 |
Redefined, since IRIS audio library cannot be used with stdio. |
4193 | 1678 |
(at least I don't know). Use with ByteArrays only." |
121
606a3ccd3682
linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents:
112
diff
changeset
|
1679 |
|
5402 | 1680 |
self subclassResponsibility |
277
ab17540f022a
oops - your last checkin was garbage
Claus Gittinger <cg@exept.de>
parents:
274
diff
changeset
|
1681 |
! |
121
606a3ccd3682
linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents:
112
diff
changeset
|
1682 |
|
1480 | 1683 |
openWithMode:aMode attributes:attributeSpec |
5402 | 1684 |
self subclassResponsibility |
277
ab17540f022a
oops - your last checkin was garbage
Claus Gittinger <cg@exept.de>
parents:
274
diff
changeset
|
1685 |
! ! |
0 | 1686 |
|
1687 |
!SoundStream methodsFor:'sine wave generation'! |
|
1688 |
||
5418 | 1689 |
pause:nSeconds |
1690 |
"output noting for nSeconds" |
|
1691 |
||
1692 |
|buffer numSamples restSamples| |
|
1693 |
||
1694 |
"allocate memory for 1 sec playing time" |
|
1695 |
numSamples := self sampleRate. |
|
1696 |
audioFormat == #U16 ifTrue:[ |
|
5429 | 1697 |
buffer := WordArray new:numSamples withAll:16r8000. |
5418 | 1698 |
] ifFalse:[ audioFormat == #S16 ifTrue:[ |
5429 | 1699 |
buffer := SignedWordArray new:numSamples withAll:0. |
5418 | 1700 |
] ifFalse:[ audioFormat == #F32 ifTrue:[ |
5429 | 1701 |
buffer := FloatArray new:numSamples withAll:0.0. |
5421 | 1702 |
] ifFalse:[ |
5429 | 1703 |
self halt |
5418 | 1704 |
]]]. |
1705 |
||
1706 |
1 to:nSeconds truncated do:[:s | |
|
5429 | 1707 |
self nextPutBytes:(numSamples*2) from:buffer startingAt:1 |
5418 | 1708 |
]. |
1709 |
restSamples := ((nSeconds - nSeconds truncated) * numSamples) truncated. |
|
1710 |
restSamples > 0 ifTrue:[ |
|
5429 | 1711 |
self nextPutBytes:(restSamples*2) from:buffer startingAt:1 |
5418 | 1712 |
]. |
1713 |
! |
|
1714 |
||
5400 | 1715 |
playSine16:freq forSeconds:nSeconds |
722 | 1716 |
"output some tone for some time |
1717 |
in S16 audioFormat - a test method" |
|
1718 |
||
5400 | 1719 |
|buffer numSamples val scale isUnsigned restSamples| |
923 | 1720 |
|
1721 |
(audioFormat startsWith:#U16) ifFalse:[ |
|
5429 | 1722 |
(audioFormat startsWith:#S16) ifFalse:[ |
1723 |
self error:'must be in 16bit mode' mayProceed:true. |
|
1724 |
^ self |
|
1725 |
] |
|
923 | 1726 |
]. |
722 | 1727 |
|
5400 | 1728 |
numSamples := self sampleRate. |
722 | 1729 |
buffer := WordArray new:numSamples. |
1730 |
||
1731 |
"fill it with a sine wave" |
|
1732 |
||
923 | 1733 |
isUnsigned := audioFormat startsWith:#U16. |
1734 |
||
722 | 1735 |
scale := freq * 2 * (Float pi). |
1736 |
1 to:numSamples do:[:i | |
|
5429 | 1737 |
val := (scale * i / self sampleRate) sin. |
1738 |
val := (val * 16r7FFF) rounded. |
|
1739 |
isUnsigned ifTrue:[ |
|
1740 |
val := val + 32768 |
|
1741 |
]. |
|
1742 |
buffer at:i put:(val bitAnd:16rFFFF) |
|
714 | 1743 |
]. |
722 | 1744 |
|
5400 | 1745 |
1 to:nSeconds truncated do:[:s | |
5429 | 1746 |
self nextPutBytes:(numSamples*2) from:buffer startingAt:1 |
5400 | 1747 |
]. |
1748 |
restSamples := ((nSeconds - nSeconds truncated) * numSamples) truncated. |
|
1749 |
restSamples > 0 ifTrue:[ |
|
5429 | 1750 |
self nextPutBytes:(restSamples*2) from:buffer startingAt:1 |
5400 | 1751 |
]. |
722 | 1752 |
|
1753 |
" |
|
923 | 1754 |
SoundStream writing setAudioFormat:#S16; playSine16:440 forSeconds:2; close |
1755 |
SoundStream writing setAudioFormat:#S16; playSine16:880 forSeconds:2; close |
|
1756 |
SoundStream writing setAudioFormat:#S16; playSine16:1760 forSeconds:2; close |
|
1757 |
SoundStream writing setAudioFormat:#S16; playSine16:3520 forSeconds:2; close |
|
1758 |
SoundStream writing tuneTone:440; close |
|
1759 |
||
1760 |
SoundStream writing setAudioFormat:#U16; playSine16:880 forSeconds:2; close |
|
1761 |
SoundStream writing setAudioFormat:#U16_LE; playSine16:880 forSeconds:2; close |
|
722 | 1762 |
" |
1763 |
||
1764 |
"Modified: / 31.1.1999 / 12:12:41 / cg" |
|
1765 |
! |
|
1766 |
||
5400 | 1767 |
playSine:freq forSeconds:nSeconds |
1768 |
"output some tone for some time - a test method" |
|
1769 |
||
1770 |
audioFormat == #F32 ifTrue:[ |
|
5429 | 1771 |
self playSineF32:freq forSeconds:nSeconds. |
1772 |
^ self. |
|
5400 | 1773 |
]. |
1774 |
self playSine16:freq forSeconds:nSeconds. |
|
1775 |
||
1776 |
" |
|
1777 |
SoundStream writing setAudioFormat:#F32; playSine:440 forSeconds:2; close |
|
1778 |
SoundStream writing setAudioFormat:#F32; playSine:880 forSeconds:2; close |
|
1779 |
SoundStream writing setAudioFormat:#F32; playSine:1760 forSeconds:2; close |
|
1780 |
SoundStream writing setAudioFormat:#F32; playSine:3520 forSeconds:2; close |
|
1781 |
" |
|
1782 |
! |
|
1783 |
||
1784 |
playSineF32:freq forSeconds:nSeconds |
|
1785 |
"output some tone for some time |
|
1786 |
in F32 audioFormat - a test method" |
|
1787 |
||
5407 | 1788 |
|buffer numSamples val scale restSamples numChannels| |
5400 | 1789 |
|
1790 |
(audioFormat == #F32) ifFalse:[ |
|
5429 | 1791 |
self error:'must be in float mode' mayProceed:true. |
5400 | 1792 |
]. |
1793 |
||
1794 |
numSamples := self sampleRate. |
|
5407 | 1795 |
numChannels := self numberOfChannels. |
1796 |
buffer := FloatArray new:(numSamples * numChannels). |
|
5400 | 1797 |
|
1798 |
"fill it with a sine wave" |
|
1799 |
||
1800 |
scale := freq * 2 * (Float pi). |
|
5407 | 1801 |
numChannels == 2 ifTrue:[ |
5429 | 1802 |
1 to:numSamples do:[:i | |
1803 |
val := (scale * i / self sampleRate) sin. |
|
1804 |
buffer at:(i-1)*2 put:val. |
|
1805 |
buffer at:(i-1)*2+1 put:0. |
|
1806 |
]. |
|
5407 | 1807 |
] ifFalse:[ |
5429 | 1808 |
1 to:numSamples do:[:i | |
1809 |
val := (scale * i / self sampleRate) sin. |
|
1810 |
buffer at:i put:val |
|
1811 |
]. |
|
5400 | 1812 |
]. |
1813 |
||
1814 |
1 to:nSeconds truncated do:[:s | |
|
5429 | 1815 |
self nextPutBytes:(numSamples*4) from:buffer startingAt:1 |
5400 | 1816 |
]. |
1817 |
restSamples := ((nSeconds - nSeconds truncated) * numSamples) truncated. |
|
1818 |
restSamples > 0 ifTrue:[ |
|
5429 | 1819 |
self nextPutBytes:(restSamples*4) from:buffer startingAt:1 |
5400 | 1820 |
]. |
1821 |
||
1822 |
" |
|
1823 |
SoundStream writing setAudioFormat:#F32; playSineF32:440 forSeconds:2; close |
|
1824 |
SoundStream writing setAudioFormat:#F32; playSineF32:880 forSeconds:2; close |
|
1825 |
SoundStream writing setAudioFormat:#F32; playSineF32:1760 forSeconds:2; close |
|
1826 |
SoundStream writing setAudioFormat:#F32; playSineF32:3520 forSeconds:2; close |
|
1827 |
" |
|
1828 |
||
1829 |
"Modified: / 31.1.1999 / 12:12:41 / cg" |
|
1830 |
! |
|
1831 |
||
788 | 1832 |
testMelody |
5418 | 1833 |
#(g 0.5 |
1834 |
e 0.5 |
|
1835 |
e 0.5 |
|
1836 |
f 0.5 |
|
1837 |
d 0.5 |
|
1838 |
d 0.5 |
|
1839 |
c 0.5 |
|
1840 |
d 0.5 |
|
1841 |
e 0.5 |
|
1842 |
f 0.5 |
|
1843 |
g 0.5 |
|
1844 |
g 0.5 |
|
1845 |
g 0.5 |
|
1846 |
) pairWiseDo:[:note :duration | |
|
5429 | 1847 |
self playSine:(self class noteToHertz:note) forSeconds:duration. |
1848 |
self pause:0.05. |
|
5418 | 1849 |
]. |
1850 |
||
1851 |
" |
|
1852 |
self writing testMelody; close |
|
1853 |
" |
|
1854 |
||
1855 |
"Created: / 31.1.1999 / 12:07:45 / cg" |
|
1856 |
"Modified: / 31.1.1999 / 12:16:09 / cg" |
|
1857 |
! |
|
1858 |
||
1859 |
testOctaves |
|
788 | 1860 |
3 timesRepeat:[ |
5429 | 1861 |
self playSine:220 forSeconds:0.5. |
1862 |
self playSine:440 forSeconds:0.5. |
|
1863 |
self playSine:880 forSeconds:0.5. |
|
1864 |
self playSine:1760 forSeconds:0.5. |
|
1865 |
self playSine:3520 forSeconds:0.5. |
|
788 | 1866 |
] |
1867 |
||
1868 |
" |
|
5418 | 1869 |
self writing testOctaves; close |
788 | 1870 |
" |
1871 |
||
1872 |
"Created: / 31.1.1999 / 12:07:45 / cg" |
|
1873 |
"Modified: / 31.1.1999 / 12:16:09 / cg" |
|
1874 |
! |
|
1875 |
||
722 | 1876 |
tuneTone |
1877 |
^ self tuneTone:440 |
|
596 | 1878 |
|
1879 |
" |
|
5413 | 1880 |
SoundStream debug:true |
596 | 1881 |
SoundStream writing tuneTone; close |
1882 |
SoundStream writing setSampleRate:4000; tuneTone; close |
|
1883 |
SoundStream writing setSampleRate:8000; tuneTone; close |
|
1884 |
SoundStream writing setSampleRate:10000; tuneTone; close |
|
1885 |
SoundStream writing setSampleRate:20000; tuneTone; close |
|
1886 |
SoundStream writing setSampleRate:40000; tuneTone; close |
|
5413 | 1887 |
SoundStream writing setSampleRate:44000; tuneTone; close |
923 | 1888 |
|
1889 |
SoundStream writing setSampleRate:40000; dumpSettings; close |
|
596 | 1890 |
SoundStream writing setSampleRate:20000; dumpSettings; close |
1891 |
" |
|
1892 |
||
722 | 1893 |
"Modified: / 31.1.1999 / 12:06:27 / cg" |
1894 |
! |
|
1895 |
||
5400 | 1896 |
tuneTone16:freq seconds:nSeconds |
1897 |
"output some tone for nSeconds in S16 audioFormat - a test method" |
|
1898 |
||
1899 |
|buffer numSamples val scale restSamples| |
|
597 | 1900 |
|
923 | 1901 |
(audioFormat startsWith:#U16) ifFalse:[ |
5429 | 1902 |
(audioFormat startsWith:#S16) ifFalse:[ |
1903 |
self error:'must be in 16bit mode' mayProceed:true. |
|
1904 |
^ self |
|
1905 |
] |
|
923 | 1906 |
]. |
1907 |
||
5400 | 1908 |
"allocate memory for 1 sec playing time" |
597 | 1909 |
numSamples := self sampleRate. |
5415 | 1910 |
audioFormat == #U16 ifTrue:[ |
5429 | 1911 |
buffer := WordArray new:numSamples. |
5415 | 1912 |
] ifFalse:[ |
5429 | 1913 |
buffer := SignedWordArray new:numSamples. |
5415 | 1914 |
]. |
597 | 1915 |
|
1916 |
"fill it with a sine wave" |
|
5416 | 1917 |
"/ buffer is 1 second, |
5413 | 1918 |
"/ contains freq periods, |
1919 |
"/ each of which is 0 .. 2pi |
|
1920 |
scale := freq * 2 * (Float pi) / numSamples. |
|
597 | 1921 |
1 to:numSamples do:[:i | |
5429 | 1922 |
val := (scale * (i-1)) sin. |
1923 |
val := (val * 16r7FFF) rounded. |
|
1924 |
audioFormat == #U16 ifTrue:[ |
|
1925 |
val := val + 16r8000 |
|
1926 |
]. |
|
1927 |
buffer at:i put:val |
|
597 | 1928 |
]. |
5414 | 1929 |
|
5400 | 1930 |
1 to:nSeconds truncated do:[:s | |
5429 | 1931 |
self nextPutBytes:(numSamples*2) from:buffer startingAt:1 |
597 | 1932 |
]. |
5400 | 1933 |
restSamples := ((nSeconds - nSeconds truncated) * numSamples) truncated. |
1934 |
restSamples > 0 ifTrue:[ |
|
5429 | 1935 |
self nextPutBytes:(restSamples*2) from:buffer startingAt:1 |
5400 | 1936 |
]. |
597 | 1937 |
|
1938 |
"of course, the frequency should be below half the |
|
1939 |
sampleRate - hear below ... |
|
1940 |
||
5415 | 1941 |
SoundStream writing setSampleRate:4000; tuneTone16:440 seconds:3; close |
5417 | 1942 |
SoundStream writing setSampleRate:8000; tuneTone16:440 seconds:3; close |
5407 | 1943 |
SoundStream writing setSampleRate:10000; tuneTone16:440 seconds:1; close |
1944 |
SoundStream writing setSampleRate:20000; tuneTone16:440 seconds:1; close |
|
5417 | 1945 |
SoundStream writing setSampleRate:40000; tuneTone16:440 seconds:3; close |
5407 | 1946 |
SoundStream writing tuneTone16:440 seconds:1; close |
597 | 1947 |
" |
1948 |
||
714 | 1949 |
"Modified: / 21.12.1998 / 09:11:30 / cg" |
597 | 1950 |
! |
1951 |
||
5400 | 1952 |
tuneTone8:freq seconds:nSeconds |
1953 |
"output some tone for nSeconds in U8 audioFormat - a test method" |
|
1954 |
||
1955 |
|buffer numSamples val scale restSamples| |
|
0 | 1956 |
|
923 | 1957 |
(audioFormat == #U8) ifFalse:[ |
5429 | 1958 |
(audioFormat == #S8) ifFalse:[ |
1959 |
self error:'must be in 8bit mode' mayProceed:true. |
|
1960 |
^ self |
|
1961 |
] |
|
923 | 1962 |
]. |
1963 |
||
5400 | 1964 |
"allocate memory for 1 sec playing time" |
0 | 1965 |
numSamples := self sampleRate. |
1966 |
buffer := ByteArray new:numSamples. |
|
1967 |
||
1968 |
"fill it with a sine wave" |
|
1969 |
||
5413 | 1970 |
scale := freq * 2 * (Float pi) / numSamples. |
0 | 1971 |
1 to:numSamples do:[:i | |
5429 | 1972 |
val := (scale * i) sin. |
1973 |
val := (val * 127) rounded. |
|
1974 |
audioFormat == #U8 ifTrue:[ |
|
1975 |
val := val + 16r80. |
|
1976 |
]. |
|
1977 |
buffer at:i put:(val bitAnd:16rFF) |
|
0 | 1978 |
]. |
1979 |
||
5400 | 1980 |
1 to:nSeconds truncated do:[:s | |
5429 | 1981 |
self nextPutBytes:numSamples from:buffer startingAt:1 |
593 | 1982 |
]. |
5400 | 1983 |
restSamples := ((nSeconds - nSeconds truncated) * numSamples) truncated. |
1984 |
restSamples > 0 ifTrue:[ |
|
5429 | 1985 |
self nextPutBytes:restSamples from:buffer startingAt:1 |
5400 | 1986 |
]. |
593 | 1987 |
|
1988 |
"of course, the frequency should be below half the |
|
1989 |
sampleRate - hear below ... |
|
0 | 1990 |
|
593 | 1991 |
SoundStream writing tuneTone; close |
5413 | 1992 |
SoundStream writing setSampleRate:4000; tuneTone:440 seconds:1; close |
1993 |
SoundStream writing setSampleRate:4000; tuneTone:2000 seconds:1; close |
|
1994 |
SoundStream writing setSampleRate:8000; tuneTone:440 seconds:1; close |
|
1995 |
SoundStream writing setSampleRate:8000; tuneTone:2000 seconds:1; close |
|
1996 |
SoundStream writing setSampleRate:8000; tuneTone:4000 seconds:1; close |
|
1997 |
SoundStream writing setSampleRate:10000; tuneTone:440 seconds:1; close |
|
1998 |
SoundStream writing setSampleRate:10000; tuneTone:2000 seconds:1; close |
|
1999 |
SoundStream writing setSampleRate:10000; tuneTone:4000 seconds:1; close |
|
2000 |
SoundStream writing setSampleRate:20000; tuneTone:440 seconds:1; close |
|
2001 |
SoundStream writing setSampleRate:20000; tuneTone:2000 seconds:1; close |
|
2002 |
SoundStream writing setSampleRate:20000; tuneTone:4000 seconds:1; close |
|
2003 |
SoundStream writing setSampleRate:20000; tuneTone:8000 seconds:1; close |
|
2004 |
SoundStream writing setSampleRate:40000; tuneTone:440 seconds:1; close |
|
2005 |
SoundStream writing setSampleRate:40000; tuneTone:2000 seconds:1; close |
|
2006 |
SoundStream writing setSampleRate:40000; tuneTone:4000 seconds:1; close |
|
2007 |
SoundStream writing setSampleRate:40000; tuneTone:8000 seconds:1; close |
|
2008 |
SoundStream writing setSampleRate:40000; tuneTone:10000 seconds:1; close |
|
593 | 2009 |
" |
2010 |
||
597 | 2011 |
"Modified: / 15.12.1997 / 13:43:05 / cg" |
722 | 2012 |
"Created: / 31.1.1999 / 12:05:17 / cg" |
597 | 2013 |
! |
2014 |
||
788 | 2015 |
tuneTone:freq |
5402 | 2016 |
self tuneTone:freq seconds:3 |
2017 |
||
2018 |
" |
|
2019 |
SoundStream writing tuneTone:880; close |
|
5413 | 2020 |
SoundStream writing setSampleRate:4000; tuneTone:440 seconds:1; close |
2021 |
SoundStream writing setSampleRate:4000; tuneTone:880 seconds:1; close |
|
2022 |
SoundStream writing setSampleRate:8000; tuneTone:440 seconds:1; close |
|
2023 |
SoundStream writing setSampleRate:8000; tuneTone:880 seconds:1; close |
|
2024 |
SoundStream writing setSampleRate:10000; tuneTone:440 seconds:1; close |
|
2025 |
SoundStream writing setSampleRate:10000; tuneTone:880 seconds:1; close |
|
2026 |
||
2027 |
SoundStream writing setSampleRate:20000; tuneTone:440 seconds:1; close |
|
2028 |
SoundStream writing setSampleRate:20000; tuneTone:880 seconds:1; close |
|
2029 |
||
2030 |
SoundStream writing setSampleRate:40000; tuneTone:440 seconds:1; close |
|
2031 |
SoundStream writing setSampleRate:40000; tuneTone:880 seconds:1; close |
|
2032 |
SoundStream writing setSampleRate:40000; tuneTone:1760 seconds:1; close |
|
2033 |
SoundStream writing setSampleRate:40000; tuneTone:3520 seconds:1; close |
|
2034 |
SoundStream writing setSampleRate:40000; tuneTone:7020 seconds:1; close |
|
2035 |
SoundStream writing setSampleRate:40000; tuneTone:14040 seconds:1; close |
|
2036 |
||
2037 |
SoundStream writing setSampleRate:44100; tuneTone:440 seconds:1; close |
|
2038 |
SoundStream writing setSampleRate:44100; tuneTone:880 seconds:1; close |
|
2039 |
SoundStream writing setSampleRate:44100; tuneTone:1760 seconds:1; close |
|
2040 |
SoundStream writing setSampleRate:44100; tuneTone:3520 seconds:1; close |
|
2041 |
SoundStream writing setSampleRate:44100; tuneTone:7020 seconds:1; close |
|
2042 |
SoundStream writing setSampleRate:44100; tuneTone:14040 seconds:1; close |
|
5402 | 2043 |
|
2044 |
SoundStream writing setSampleRate:20000; dumpSettings; close |
|
2045 |
" |
|
2046 |
||
2047 |
"Modified: / 31.1.1999 / 12:07:14 / cg" |
|
2048 |
! |
|
2049 |
||
5405 | 2050 |
tuneTone:freq seconds:nSeconds |
5413 | 2051 |
((audioFormat startsWith:#S16) or:[audioFormat startsWith:#U16]) ifTrue:[ |
5428 | 2052 |
^ self tuneTone16:freq seconds:nSeconds |
5402 | 2053 |
]. |
2054 |
audioFormat == #F32 ifTrue:[ |
|
5428 | 2055 |
^ self tuneToneF32:freq seconds:nSeconds |
788 | 2056 |
]. |
2057 |
audioFormat == #MU_LAW ifTrue:[ |
|
5428 | 2058 |
^ self tuneToneMU:freq seconds:nSeconds |
788 | 2059 |
]. |
5402 | 2060 |
self tuneTone8:freq seconds:nSeconds |
788 | 2061 |
|
2062 |
" |
|
2063 |
SoundStream writing tuneTone:880; close |
|
5428 | 2064 |
SoundStream writing setSampleRate:4000; tuneTone:440 seconds:1; close |
5413 | 2065 |
SoundStream writing setSampleRate:4000; tuneTone:880 seconds:1; close |
2066 |
SoundStream writing setSampleRate:8000; tuneTone:440 seconds:1; close |
|
2067 |
SoundStream writing setSampleRate:8000; tuneTone:880 seconds:1; close |
|
2068 |
SoundStream writing setSampleRate:10000; tuneTone:440 seconds:1; close |
|
2069 |
SoundStream writing setSampleRate:10000; tuneTone:880 seconds:1; close |
|
2070 |
||
2071 |
SoundStream writing setSampleRate:20000; tuneTone:440 seconds:1; close |
|
2072 |
SoundStream writing setSampleRate:20000; tuneTone:880 seconds:1; close |
|
2073 |
||
2074 |
SoundStream writing setSampleRate:40000; tuneTone:440 seconds:1; close |
|
2075 |
SoundStream writing setSampleRate:40000; tuneTone:880 seconds:1; close |
|
2076 |
SoundStream writing setSampleRate:40000; tuneTone:1760 seconds:1; close |
|
2077 |
SoundStream writing setSampleRate:40000; tuneTone:3520 seconds:1; close |
|
2078 |
SoundStream writing setSampleRate:40000; tuneTone:7020 seconds:1; close |
|
2079 |
SoundStream writing setSampleRate:40000; tuneTone:14040 seconds:1; close |
|
2080 |
||
2081 |
SoundStream writing setSampleRate:44100; tuneTone:440 seconds:1; close |
|
2082 |
SoundStream writing setSampleRate:44100; tuneTone:880 seconds:1; close |
|
2083 |
SoundStream writing setSampleRate:44100; tuneTone:1760 seconds:1; close |
|
2084 |
SoundStream writing setSampleRate:44100; tuneTone:3520 seconds:1; close |
|
2085 |
SoundStream writing setSampleRate:44100; tuneTone:7020 seconds:1; close |
|
2086 |
SoundStream writing setSampleRate:44100; tuneTone:14040 seconds:1; close |
|
923 | 2087 |
|
788 | 2088 |
SoundStream writing setSampleRate:20000; dumpSettings; close |
2089 |
" |
|
2090 |
||
2091 |
"Modified: / 31.1.1999 / 12:07:14 / cg" |
|
2092 |
! |
|
2093 |
||
5400 | 2094 |
tuneToneF32:freq seconds:nSeconds |
2095 |
"output some tone for nSeconds in F32 audioFormat - a test method" |
|
2096 |
||
2097 |
|buffer numSamples val scale restSamples| |
|
2098 |
||
2099 |
(audioFormat == #F32) ifFalse:[ |
|
5428 | 2100 |
self error:'must be in f32 mode' mayProceed:true. |
2101 |
^ self |
|
5400 | 2102 |
]. |
2103 |
||
2104 |
"allocate memory for 1sec playing time" |
|
2105 |
numSamples := self sampleRate. |
|
2106 |
buffer := FloatArray new:numSamples. |
|
2107 |
||
2108 |
"fill it with a sine wave" |
|
2109 |
||
5413 | 2110 |
scale := freq * 2 * (Float pi) / numSamples. |
5400 | 2111 |
1 to:numSamples do:[:i | |
5428 | 2112 |
val := (scale * i) sin. |
2113 |
buffer at:i put:val |
|
5400 | 2114 |
]. |
2115 |
||
2116 |
1 to:nSeconds truncated do:[:s | |
|
5428 | 2117 |
self nextPutBytes:(numSamples*4) from:buffer startingAt:1 |
5400 | 2118 |
]. |
2119 |
restSamples := ((nSeconds - nSeconds truncated) * numSamples) truncated. |
|
2120 |
restSamples > 0 ifTrue:[ |
|
5428 | 2121 |
self nextPutBytes:(restSamples*4) from:buffer startingAt:1 |
5400 | 2122 |
]. |
2123 |
||
2124 |
"of course, the frequency should be below half the |
|
2125 |
sampleRate - hear below ... |
|
2126 |
||
5412 | 2127 |
SoundStream debug:true |
2128 |
SoundStream debug:false |
|
2129 |
||
5400 | 2130 |
SoundStream writing tuneTone; close |
5417 | 2131 |
SoundStream writing setAudioFormat:#F32; tuneTone; close |
5428 | 2132 |
SoundStream writing setSampleRate:4000; tuneTone:440 seconds:1; close |
2133 |
SoundStream writing setSampleRate:4000; tuneTone:2000 seconds:1; close |
|
2134 |
SoundStream writing setSampleRate:8000; tuneTone:440 seconds:1; close |
|
2135 |
SoundStream writing setSampleRate:8000; tuneTone:2000 seconds:1; close |
|
2136 |
SoundStream writing setSampleRate:8000; tuneTone:4000 seconds:1; close |
|
2137 |
SoundStream writing setSampleRate:10000; tuneTone:440 seconds:1; close |
|
2138 |
SoundStream writing setSampleRate:10000; tuneTone:2000 seconds:1; close |
|
2139 |
SoundStream writing setSampleRate:10000; tuneTone:4000 seconds:1; close |
|
2140 |
SoundStream writing setSampleRate:20000; tuneTone:440 seconds:1; close |
|
2141 |
SoundStream writing setSampleRate:20000; tuneTone:2000 seconds:1; close |
|
2142 |
SoundStream writing setSampleRate:20000; tuneTone:4000 seconds:1; close |
|
2143 |
SoundStream writing setSampleRate:20000; tuneTone:8000 seconds:1; close |
|
2144 |
SoundStream writing setSampleRate:40000; tuneTone:440 seconds:1; close |
|
2145 |
SoundStream writing setSampleRate:40000; tuneTone:2000 seconds:1; close |
|
2146 |
SoundStream writing setSampleRate:40000; tuneTone:4000 seconds:1; close |
|
2147 |
SoundStream writing setSampleRate:40000; tuneTone:8000 seconds:1; close |
|
2148 |
SoundStream writing setSampleRate:40000; tuneTone:10000 seconds:1; close |
|
5400 | 2149 |
" |
2150 |
||
2151 |
"Modified: / 15.12.1997 / 13:43:05 / cg" |
|
2152 |
"Created: / 31.1.1999 / 12:05:17 / cg" |
|
2153 |
! |
|
2154 |
||
5402 | 2155 |
tuneToneMU:freq seconds:nSeconds |
2156 |
"output some tone for nSeconds in MU_LAW audioFormat - a test method" |
|
2157 |
||
2158 |
|buffer numSamples val scale restSamples| |
|
597 | 2159 |
|
2160 |
"allocate memory for 1sec playing time" |
|
2161 |
numSamples := self sampleRate. |
|
2162 |
buffer := ByteArray new:numSamples. |
|
2163 |
||
2164 |
"fill it with a sine wave" |
|
2165 |
||
5413 | 2166 |
scale := freq * 2 * (Float pi) / numSamples. |
597 | 2167 |
1 to:numSamples do:[:i | |
5429 | 2168 |
val := (scale * i) sin. |
2169 |
val := (val * 16r7FFF) rounded. |
|
2170 |
buffer at:i put:(self class linear16ToUlaw:val) |
|
597 | 2171 |
]. |
2172 |
||
5402 | 2173 |
1 to:nSeconds truncated do:[:s | |
5429 | 2174 |
self nextPutBytes:numSamples from:buffer startingAt:1 |
597 | 2175 |
]. |
5402 | 2176 |
restSamples := ((nSeconds - nSeconds truncated) * numSamples) truncated. |
2177 |
restSamples > 0 ifTrue:[ |
|
5429 | 2178 |
self nextPutBytes:restSamples from:buffer startingAt:1 |
5402 | 2179 |
]. |
597 | 2180 |
|
2181 |
"of course, the frequency should be below half the |
|
2182 |
sampleRate - hear below ... |
|
2183 |
||
5413 | 2184 |
SoundStream writing setSampleRate:8000; tuneToneMU:440 seconds:1; close |
2185 |
SoundStream writing setSampleRate:10000; tuneToneMU:440 seconds:1; close |
|
2186 |
SoundStream writing setSampleRate:20000; tuneToneMU:440 seconds:1; close |
|
2187 |
SoundStream writing setSampleRate:40000; tuneToneMU:440 seconds:1; close |
|
597 | 2188 |
" |
2189 |
||
2190 |
"Modified: / 15.12.1997 / 13:46:19 / cg" |
|
0 | 2191 |
! ! |
121
606a3ccd3682
linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents:
112
diff
changeset
|
2192 |
|
5402 | 2193 |
!SoundStream::DevAudio class methodsFor:'default values'! |
2194 |
||
2195 |
defaultSampleRate |
|
2196 |
"minimum, supported by all audio systems" |
|
2197 |
||
2198 |
%{ |
|
2199 |
#ifdef SUPPORT_DEV_AUDIO |
|
2200 |
RETURN (__MKSMALLINT(DEV_AUDIO_DEFAULT_FREQ)); |
|
2201 |
#endif |
|
2202 |
%}. |
|
2203 |
||
2204 |
^ 8000 |
|
2205 |
! ! |
|
2206 |
||
2207 |
!SoundStream::DevAudio class methodsFor:'documentation'! |
|
2208 |
||
2209 |
documentation |
|
2210 |
" |
|
5424 | 2211 |
interface to /dev/audio (sun, hpux, linux, ...) |
5402 | 2212 |
" |
2213 |
! ! |
|
2214 |
||
2215 |
!SoundStream::DevAudio class methodsFor:'queries'! |
|
2216 |
||
2217 |
isSupported |
|
2218 |
%{ |
|
2219 |
#ifdef SUPPORT_DEV_AUDIO |
|
2220 |
RETURN(true); |
|
2221 |
#endif |
|
2222 |
%}. |
|
2223 |
^ false. |
|
2224 |
! ! |
|
2225 |
||
2226 |
!SoundStream::DevAudio methodsFor:'misc'! |
|
2227 |
||
2228 |
dumpSettings |
|
2229 |
"debugging interface - dump the current settings" |
|
2230 |
||
2231 |
|fd blockSize speed channels stereo format| |
|
2232 |
||
2233 |
fd := self fileDescriptorOrNil. |
|
2234 |
||
2235 |
audioFormat == #S16 ifTrue:[ |
|
5429 | 2236 |
UninterpretedBytes isBigEndian ifTrue:[ |
2237 |
audioFormat := #S16_BE |
|
2238 |
] ifFalse:[ |
|
2239 |
audioFormat := #S16_LE |
|
2240 |
] |
|
5402 | 2241 |
]. |
2242 |
audioFormat == #U16 ifTrue:[ |
|
5429 | 2243 |
UninterpretedBytes isBigEndian ifTrue:[ |
2244 |
audioFormat := #U16_BE |
|
2245 |
] ifFalse:[ |
|
2246 |
audioFormat := #U16_LE |
|
2247 |
] |
|
5402 | 2248 |
]. |
2249 |
||
2250 |
%{ |
|
2251 |
#ifdef SUPPORT_DEV_AUDIO |
|
2252 |
if (fd != nil) { |
|
5429 | 2253 |
int f = __intVal(fd); |
2254 |
int __blockSize = -1; |
|
2255 |
int __speed = -1; |
|
2256 |
int __channels = __intVal(__INST(numberOfChannels)); |
|
2257 |
int __stereo = __channels > 1; |
|
2258 |
int __format = -1; |
|
2259 |
||
2260 |
channels = nil; |
|
2261 |
blockSize = nil; |
|
2262 |
stereo = nil; |
|
2263 |
speed = nil; |
|
5402 | 2264 |
|
2265 |
# if defined(SNDCTL_DSP_GETBLKSIZE) |
|
5429 | 2266 |
if (ioctl(f, SNDCTL_DSP_GETBLKSIZE, &__blockSize) >= 0) { |
2267 |
blockSize = __MKSMALLINT(__blockSize); |
|
2268 |
} |
|
5402 | 2269 |
# endif |
2270 |
||
2271 |
# if defined(SNDCTL_DSP_CHANNELS) |
|
5429 | 2272 |
if (ioctl(f, SNDCTL_DSP_CHANNELS, &__channels) >= 0) { |
2273 |
channels = __MKSMALLINT(__channels); |
|
2274 |
stereo = __MKSMALLINT(__channels > 1); |
|
2275 |
} |
|
5402 | 2276 |
# else |
2277 |
# if defined(SNDCTL_DSP_STEREO) |
|
5429 | 2278 |
if (ioctl(f, SNDCTL_DSP_STEREO, &__stereo) >= 0) { |
2279 |
stereo = __MKSMALLINT(__stereo); |
|
2280 |
} |
|
5402 | 2281 |
# endif |
2282 |
# endif |
|
2283 |
||
2284 |
# if defined(SNDCTL_DSP_SPEED) |
|
5429 | 2285 |
if (ioctl(f, SNDCTL_DSP_SPEED, &__speed) >= 0) { |
2286 |
speed = __MKSMALLINT(__speed); |
|
2287 |
} |
|
5402 | 2288 |
# endif |
2289 |
||
2290 |
# if defined(SNDCTL_DSP_GETFMT) |
|
5429 | 2291 |
if (ioctl(f, SNDCTL_DSP_GETFMT, &__format) >= 0) { |
2292 |
format = __MKSMALLINT(__format); |
|
2293 |
} |
|
5402 | 2294 |
# else |
2295 |
# if defined(SNDCTL_DSP_SETFMT) && defined(AFMT_QUERY) |
|
5429 | 2296 |
__format = AFMT_QUERY; |
2297 |
if (ioctl(f, SNDCTL_DSP_SETFMT, &__format) >= 0) { |
|
2298 |
switch (__format) { |
|
5402 | 2299 |
# ifdef AFMT_MU_LAW |
5429 | 2300 |
case AFMT_MU_LAW: |
2301 |
format = @symbol(MU_LAW); |
|
2302 |
break; |
|
5402 | 2303 |
# endif |
2304 |
# ifdef AFMT_A_LAW |
|
5429 | 2305 |
case AFMT_A_LAW: |
2306 |
format = @symbol(A_LAW); |
|
2307 |
break; |
|
5402 | 2308 |
# endif |
2309 |
# ifdef AFMT_U8 |
|
5429 | 2310 |
case AFMT_U8: |
2311 |
format = @symbol(U8); |
|
2312 |
break; |
|
5402 | 2313 |
# endif |
2314 |
# ifdef AFMT_S8 |
|
5429 | 2315 |
case AFMT_S8: |
2316 |
format = @symbol(S8); |
|
2317 |
break; |
|
5402 | 2318 |
# endif |
2319 |
# ifdef AFMT_S16_LE |
|
5429 | 2320 |
case AFMT_S16_LE: |
2321 |
format = @symbol(S16_LE); |
|
2322 |
break; |
|
5402 | 2323 |
# endif |
2324 |
# ifdef AFMT_S16_BE |
|
5429 | 2325 |
case AFMT_S16_BE: |
2326 |
format = @symbol(S16_BE); |
|
2327 |
break; |
|
5402 | 2328 |
# endif |
2329 |
# ifdef AFMT_U16_LE |
|
5429 | 2330 |
case AFMT_U16_LE: |
2331 |
format = @symbol(U16_LE); |
|
2332 |
break; |
|
5402 | 2333 |
# endif |
2334 |
# ifdef AFMT_U16_BE |
|
5429 | 2335 |
case AFMT_U16_BE: |
2336 |
format = @symbol(U16_BE); |
|
2337 |
break; |
|
5402 | 2338 |
# endif |
2339 |
# ifdef AFMT_MPEG |
|
5429 | 2340 |
case AFMT_MPEG: |
2341 |
format = @symbol(MPEG); |
|
2342 |
break; |
|
5402 | 2343 |
# endif |
5429 | 2344 |
default: |
2345 |
format = nil; |
|
2346 |
} |
|
2347 |
} |
|
5402 | 2348 |
} |
2349 |
# endif |
|
2350 |
# endif |
|
2351 |
#endif /* SUPPORT_DEV_AUDIO */ |
|
2352 |
||
2353 |
%}. |
|
2354 |
format notNil ifTrue:[ |
|
5429 | 2355 |
Transcript show:'format: '; showCR:format |
5402 | 2356 |
]. |
2357 |
blockSize notNil ifTrue:[ |
|
5429 | 2358 |
Transcript show:'blockSize: '; showCR:blockSize |
5402 | 2359 |
]. |
2360 |
speed notNil ifTrue:[ |
|
5429 | 2361 |
Transcript show:'speed: '; showCR:speed |
5402 | 2362 |
]. |
2363 |
channels notNil ifTrue:[ |
|
5429 | 2364 |
Transcript show:'channels: '; showCR:channels |
5402 | 2365 |
]. |
2366 |
stereo notNil ifTrue:[ |
|
5429 | 2367 |
Transcript show:'stereo: '; showCR:stereo |
5402 | 2368 |
]. |
2369 |
||
2370 |
Transcript show:'supported audioFormats: '; showCR:(self supportedAudioFormats). |
|
2371 |
||
2372 |
" |
|
2373 |
self writing dumpSettings; close |
|
2374 |
" |
|
2375 |
! |
|
2376 |
||
2377 |
flush |
|
2378 |
"wait until all sound has been played" |
|
2379 |
||
2380 |
self fileDescriptorOrNil isNil ifTrue:[^ self]. |
|
2381 |
super flush. |
|
2382 |
! ! |
|
2383 |
||
2384 |
!SoundStream::DevAudio methodsFor:'open & close'! |
|
2385 |
||
2386 |
closeFile |
|
2387 |
"a stream has been collected - close the file" |
|
2388 |
||
2389 |
%{ |
|
2390 |
#ifdef SUPPORT_DEV_AUDIO |
|
2391 |
OBJ fp; |
|
2392 |
int fd; |
|
2393 |
FILE *f; |
|
2394 |
||
2395 |
if ((fp = __INST(handle)) != nil) { |
|
5429 | 2396 |
f = __FILEVal(fp); |
2397 |
__INST(handle) = nil; |
|
5402 | 2398 |
# ifdef LINUX |
5429 | 2399 |
sigsetmask(~0); |
5402 | 2400 |
# endif |
5429 | 2401 |
if (__INST(buffered) == true) { |
2402 |
fflush(f); |
|
2403 |
fclose(f); |
|
2404 |
} else { |
|
2405 |
fd = fileno(f); |
|
2406 |
close(fd); |
|
2407 |
fclose(f); |
|
2408 |
} |
|
5402 | 2409 |
# ifdef LINUX |
5429 | 2410 |
sigsetmask(0); |
5402 | 2411 |
# endif |
2412 |
} |
|
2413 |
RETURN (self); |
|
2414 |
#endif /* SUPPORT_DEV_AUDIO */ |
|
2415 |
%}. |
|
2416 |
! |
|
2417 |
||
2418 |
openWithMode:aMode attributes:attributeSpec |
|
2419 |
|ok error errorStringOrNil| |
|
2420 |
||
2421 |
%{ |
|
2422 |
#ifdef SUPPORT_DEV_AUDIO |
|
2423 |
int __fd; |
|
2424 |
int __mode; |
|
2425 |
FILE *f; |
|
2426 |
||
2427 |
ok = false; |
|
2428 |
if (strcmp(__stringVal(aMode), "w") == 0) { |
|
5429 | 2429 |
__mode = O_WRONLY; |
5402 | 2430 |
} else if (strcmp(__stringVal(aMode), "r") == 0) { |
5429 | 2431 |
__mode = O_RDONLY; |
5402 | 2432 |
} else { |
5429 | 2433 |
__mode = O_RDWR; |
5402 | 2434 |
} |
2435 |
do { |
|
5429 | 2436 |
__BEGIN_INTERRUPTABLE__ |
2437 |
__fd = open((char *) __stringVal(__INST(pathName)), __mode /* |O_NDELAY */); |
|
2438 |
__END_INTERRUPTABLE__ |
|
5402 | 2439 |
} while ((__fd < 0) && (errno == EINTR)); |
2440 |
||
2441 |
if (__fd >= 0) { |
|
5429 | 2442 |
/* |
2443 |
* make it a FILE * |
|
2444 |
*/ |
|
2445 |
f = fdopen(__fd, __stringVal(aMode)); |
|
2446 |
if (! f) { |
|
2447 |
error = __mkSmallInteger(errno); |
|
2448 |
__BEGIN_INTERRUPTABLE__ |
|
2449 |
close(__fd); |
|
2450 |
__END_INTERRUPTABLE__ |
|
2451 |
goto out; |
|
2452 |
} |
|
2453 |
setbuf(f, NULL); |
|
2454 |
__INST(buffered) = false; |
|
2455 |
__INST(handle) = __MKEXTERNALADDRESS(f); |
|
2456 |
__STORESELF(handle); |
|
5402 | 2457 |
|
2458 |
#if defined(PCM_ENABLE_OUTPUT) && defined(PCM_ENABLE_INPUT) |
|
2459 |
# if defined(SNDCTL_DSP_SETTRIGGER) |
|
5429 | 2460 |
if (__mode == O_RDWR) { |
2461 |
int enable_bits = ~(PCM_ENABLE_OUTPUT|PCM_ENABLE_INPUT); |
|
2462 |
||
2463 |
if (ioctl(__fd, SNDCTL_DSP_SETTRIGGER, &enable_bits) == -1) |
|
2464 |
{ |
|
2465 |
console_fprintf(stderr, "can't request synchronous start of fullduplex operation"); |
|
2466 |
} |
|
2467 |
} |
|
5402 | 2468 |
# endif |
2469 |
#endif |
|
5429 | 2470 |
ok = true; |
5402 | 2471 |
} else { |
5429 | 2472 |
error = __mkSmallInteger(errno); |
5402 | 2473 |
} |
2474 |
out:; |
|
2475 |
#endif /* SUPPORT_DEV_AUDIO */ |
|
2476 |
%}. |
|
2477 |
ok == false ifTrue:[ |
|
5429 | 2478 |
lastErrorString := errorStringOrNil. |
2479 |
lastErrorNumber := error ? -1. |
|
2480 |
self openError:error. |
|
2481 |
"normally not reached" |
|
2482 |
^ nil. |
|
5402 | 2483 |
]. |
2484 |
self registerForFinalization. |
|
2485 |
! ! |
|
2486 |
||
2487 |
!SoundStream::DevAudio methodsFor:'private'! |
|
2488 |
||
2489 |
initialize |
|
2490 |
"initialize for least common mode" |
|
2491 |
||
2492 |
super initialize. |
|
2493 |
||
2494 |
OperatingSystem isUNIXlike ifTrue:[ |
|
5429 | 2495 |
'/dev/audio' asFilename exists ifTrue:[ |
2496 |
"/ |
|
2497 |
"/ sunos or linux |
|
2498 |
"/ |
|
2499 |
pathName := '/dev/audio'. |
|
2500 |
]. |
|
5402 | 2501 |
]. |
2502 |
! |
|
2503 |
||
2504 |
resetSoundCard |
|
2505 |
"debugging interface - reset the soundCard" |
|
2506 |
||
2507 |
|fd| |
|
2508 |
||
2509 |
fd := self fileDescriptorOrNil. |
|
2510 |
fd isNil ifTrue:[ |
|
5429 | 2511 |
self errorNotOpen. |
2512 |
^ nil |
|
5402 | 2513 |
]. |
2514 |
%{ |
|
2515 |
#ifdef SUPPORT_DEV_AUDIO |
|
2516 |
int f = __intVal(fd); |
|
2517 |
||
2518 |
if (__isSmallInteger(fd)) { |
|
5429 | 2519 |
int __dummy; |
5402 | 2520 |
# if defined(SNDCTL_DSP_RESET) |
5429 | 2521 |
if (ioctl(f, SNDCTL_DSP_RESET, &__dummy) >= 0) { |
2522 |
RETURN (self); |
|
2523 |
} |
|
5402 | 2524 |
# endif |
2525 |
} |
|
2526 |
#endif /* SUPPORT_DEV_AUDIO */ |
|
2527 |
%}. |
|
2528 |
^ UnsupportedOperationSignal raise |
|
2529 |
||
2530 |
" |
|
2531 |
self writing resetSoundCard; dumpSettings; close |
|
2532 |
" |
|
2533 |
! |
|
2534 |
||
2535 |
setAudioFormat:aSymbol |
|
2536 |
"set the format of the audio data as specified by aSymbol. |
|
2537 |
Returns true if sucessful - may fail with some formats on many sound devices." |
|
2538 |
||
2539 |
|fd ok| |
|
2540 |
||
2541 |
audioFormat == aSymbol ifTrue:[^ self]. |
|
2542 |
super setAudioFormat:aSymbol. |
|
2543 |
||
2544 |
fd := self fileDescriptor. |
|
2545 |
fd isNil ifTrue:[ |
|
5429 | 2546 |
^ self |
5402 | 2547 |
]. |
2548 |
%{ |
|
2549 |
#ifdef SUPPORT_DEV_AUDIO |
|
2550 |
OBJ sym = aSymbol; |
|
2551 |
||
2552 |
if (__isSmallInteger(fd)) { |
|
5429 | 2553 |
int f = __intVal(fd); |
2554 |
int __fmt = 0, __fmtWant; |
|
2555 |
union { |
|
2556 |
unsigned short us; |
|
2557 |
unsigned char ub[2]; |
|
2558 |
} u; |
|
2559 |
||
2560 |
if (__isSymbol(sym)) { |
|
2561 |
if (sym == @symbol(U16)) { |
|
2562 |
u.us = 0x1234; |
|
2563 |
if (u.ub[0] == 0x34) { |
|
2564 |
/* printf("U16_LE\n"); */ |
|
2565 |
sym = @symbol(U16_LE); |
|
2566 |
} else { |
|
2567 |
/* printf("U16_BE\n"); */ |
|
2568 |
sym = @symbol(U16_BE); |
|
2569 |
} |
|
2570 |
} else if (sym == @symbol(S16)) { |
|
2571 |
u.us = 0x1234; |
|
2572 |
if (u.ub[0] == 0x34) { |
|
2573 |
/* printf("S16_LE\n"); */ |
|
2574 |
sym = @symbol(S16_LE); |
|
2575 |
} else { |
|
2576 |
/* printf("S16_BE\n"); */ |
|
2577 |
sym = @symbol(S16_BE); |
|
2578 |
} |
|
2579 |
} |
|
2580 |
||
2581 |
if (0) { |
|
5402 | 2582 |
# ifdef AFMT_MU_LAW |
5429 | 2583 |
} else if (sym == @symbol(MU_LAW)) { |
2584 |
__fmt = AFMT_MU_LAW; |
|
5402 | 2585 |
# endif |
2586 |
# ifdef AFMT_A_LAW |
|
5429 | 2587 |
} else if (sym == @symbol(A_LAW)) { |
2588 |
__fmt = AFMT_A_LAW; |
|
5402 | 2589 |
# endif |
2590 |
# ifdef AFMT_IMA_ADPCM |
|
5429 | 2591 |
} else if (sym == @symbol(IMA_ADPCM)) { |
2592 |
__fmt = AFMT_IMA_ADPCM; |
|
5402 | 2593 |
# endif |
2594 |
# ifdef AFMT_U8 |
|
5429 | 2595 |
} else if (sym == @symbol(U8)) { |
2596 |
__fmt = AFMT_U8; |
|
5402 | 2597 |
# endif |
2598 |
# ifdef AFMT_S8 |
|
5429 | 2599 |
} else if (sym == @symbol(S8)) { |
2600 |
__fmt = AFMT_S8; |
|
5402 | 2601 |
# endif |
2602 |
# ifdef AFMT_U16_LE |
|
5429 | 2603 |
} else if (sym == @symbol(U16_LE)) { |
2604 |
__fmt = AFMT_U16_LE; |
|
5402 | 2605 |
# endif |
2606 |
# ifdef AFMT_U16_BE |
|
5429 | 2607 |
} else if (sym == @symbol(U16_BE)) { |
2608 |
__fmt = AFMT_U16_BE; |
|
5402 | 2609 |
# endif |
2610 |
# ifdef AFMT_S16_LE |
|
5429 | 2611 |
} else if (sym == @symbol(S16_LE)) { |
2612 |
__fmt = AFMT_S16_LE; |
|
5402 | 2613 |
# endif |
2614 |
# ifdef AFMT_S16_BE |
|
5429 | 2615 |
} else if (sym == @symbol(S16_BE)) { |
2616 |
__fmt = AFMT_S16_BE; |
|
5402 | 2617 |
# endif |
2618 |
# ifdef AFMT_MPEG |
|
5429 | 2619 |
} else if (sym == @symbol(MPEG)) { |
2620 |
__fmt = AFMT_MPEG; |
|
5402 | 2621 |
# endif |
2622 |
||
2623 |
# ifdef AUDIO_FORMAT_LINEAR16BIT |
|
5429 | 2624 |
} else if (sym == @symbol(S16)) { |
2625 |
__fmt = AUDIO_FORMAT_LINEAR16BIT; |
|
5402 | 2626 |
# endif |
2627 |
# ifdef AUDIO_FORMAT_ULAW |
|
5429 | 2628 |
} else if (sym == @symbol(MU_LAW)) { |
2629 |
__fmt = AUDIO_FORMAT_ULAW; |
|
5402 | 2630 |
# endif |
2631 |
# ifdef AUDIO_FORMAT_ALAW |
|
5429 | 2632 |
} else if (sym == @symbol(A_LAW)) { |
2633 |
__fmt = AUDIO_FORMAT_ALAW; |
|
5402 | 2634 |
# endif |
5429 | 2635 |
} else { |
2636 |
console_fprintf(stderr, "bad format: %s\n", __stringVal(sym)); |
|
2637 |
ok = false; |
|
2638 |
goto bad; |
|
2639 |
} |
|
2640 |
} |
|
5402 | 2641 |
|
2642 |
# ifdef SNDCTL_DSP_SETFMT |
|
5429 | 2643 |
__fmtWant = __fmt; |
2644 |
||
2645 |
if (ioctl(f, SNDCTL_DSP_SETFMT, &__fmt) >= 0) { |
|
2646 |
if (__fmt == __fmtWant) { |
|
2647 |
__INST(audioFormat) = sym; |
|
2648 |
} else { |
|
2649 |
/* console_fprintf(stderr, "want: %x; got: %x\n", __fmtWant, __fmt); */ |
|
2650 |
} |
|
2651 |
} else { |
|
2652 |
/* console_fprintf(stderr, "got err-ret from setFmp %x\n", __fmt); */ |
|
2653 |
ok = false; |
|
2654 |
} |
|
5402 | 2655 |
# else |
2656 |
# ifdef AUDIO_SET_DATA_FORMAT /* hpux */ |
|
5429 | 2657 |
if (ioctl (f, AUDIO_SET_DATA_FORMAT, __fmt)) { |
2658 |
/* console_fprintf(stderr, "got err-ret from AUDIO_SET_DATA_FORMAT\n"); */ |
|
2659 |
} |
|
5402 | 2660 |
# endif |
2661 |
# endif /* SNDCTL_DSP_SETFMT */ |
|
2662 |
||
2663 |
bad: ; |
|
2664 |
} |
|
2665 |
#endif /* SUPPORT_DEV_AUDIO */ |
|
2666 |
%}. |
|
2667 |
||
2668 |
" |
|
2669 |
self writing dumpSettings; close |
|
2670 |
self writing setAudioFormat:#'MU_LAW'; close |
|
2671 |
self writing setAudioFormat:#'U8'; dumpSettings; close |
|
2672 |
self writing setAudioFormat:#'MPEG'; dumpSettings; close |
|
2673 |
" |
|
2674 |
! |
|
2675 |
||
2676 |
setChannels:nChannels |
|
2677 |
"set the number of channels (1 -> mono; 2 -> stereo). |
|
2678 |
Returns true if sucessful - may fail with many sound devices." |
|
2679 |
||
2680 |
|fd| |
|
2681 |
||
2682 |
numberOfChannels := nChannels. |
|
2683 |
||
2684 |
fd := self fileDescriptorOrNil. |
|
2685 |
fd isNil ifTrue:[ |
|
5429 | 2686 |
^ self |
5402 | 2687 |
]. |
2688 |
%{ |
|
2689 |
||
2690 |
#ifdef SUPPORT_DEV_AUDIO |
|
2691 |
if (__isSmallInteger(fd) && __isSmallInteger(nChannels)) { |
|
5429 | 2692 |
int f = __intVal(fd); |
2693 |
int __nCh = __intVal(nChannels); |
|
5402 | 2694 |
|
2695 |
# ifdef SNDCTL_DSP_STEREO |
|
5429 | 2696 |
if ((__nCh == 1) || (__nCh == 2)) { |
2697 |
int __stereo = (__nCh == 2) ? 1 : 0; |
|
2698 |
||
2699 |
if (ioctl(f, SNDCTL_DSP_STEREO, &__stereo) >= 0) { |
|
2700 |
if (__stereo == 0) { |
|
2701 |
__INST(numberOfChannels) = __MKSMALLINT(1); |
|
2702 |
} else { |
|
2703 |
__INST(numberOfChannels) = __MKSMALLINT(2); |
|
2704 |
} |
|
2705 |
RETURN (self); |
|
2706 |
} |
|
2707 |
} |
|
5402 | 2708 |
# else |
2709 |
# ifdef SOUND_PCM_WRITE_CHANNELS |
|
5429 | 2710 |
if (ioctl(f, SOUND_PCM_WRITE_CHANNELS, &__nCh) >= 0) { |
2711 |
RETURN (self); |
|
2712 |
} |
|
5402 | 2713 |
# else |
2714 |
# ifdef AUDIO_SET_CHANNELS /* hpux */ |
|
5429 | 2715 |
if (ioctl (f, AUDIO_SET_CHANNELS, __nCh)) { |
2716 |
/* console_fprintf(stderr, "got err-ret from AUDIO_SET_CHANNELS\n"); */ |
|
2717 |
RETURN (self); |
|
2718 |
} |
|
5402 | 2719 |
# endif |
2720 |
# endif |
|
2721 |
# endif |
|
2722 |
} |
|
2723 |
#endif /* SUPPORT_DEV_AUDIO */ |
|
2724 |
%}. |
|
2725 |
||
2726 |
" |
|
2727 |
self writing setChannels:2; dumpSettings; close |
|
2728 |
self writing setChannels:2; setSampleRate:10000; dumpSettings; close |
|
2729 |
self writing setChannels:2; setSampleRate:40000; dumpSettings; close |
|
2730 |
" |
|
2731 |
! |
|
2732 |
||
2733 |
setFragmentSize:blockSize |
|
2734 |
"set the soundDriver's fragmentSize" |
|
2735 |
||
2736 |
|fd| |
|
2737 |
||
2738 |
fragmentSize := blockSize. |
|
2739 |
||
2740 |
fd := self fileDescriptorOrNil. |
|
2741 |
fd isNil ifTrue:[ |
|
5429 | 2742 |
^ self |
5402 | 2743 |
]. |
2744 |
||
2745 |
%{ |
|
2746 |
#ifdef SUPPORT_DEV_AUDIO |
|
2747 |
int f = __intVal(fd); |
|
2748 |
int __blockSize = __intVal(blockSize); |
|
2749 |
||
2750 |
if (__isSmallInteger(fd) && __isSmallInteger(blockSize)) { |
|
5429 | 2751 |
__blockSize = __intVal(blockSize); |
5402 | 2752 |
# if defined(SNDCTL_DSP_SETFRAGMENT) |
5429 | 2753 |
if (ioctl(f, SNDCTL_DSP_SETFRAGMENT, &__blockSize) >= 0) { |
2754 |
RETURN (self); |
|
2755 |
} |
|
5402 | 2756 |
# endif |
2757 |
# ifdef AUDIO_SET_CHANNELS /* hpux */ |
|
5429 | 2758 |
if (ioctl (f, AUDIO_SET_TXBUFSIZE, __blockSize)) { |
2759 |
/* console_fprintf(stderr, "got err-ret from AUDIO_SET_TXBUFSIZE\n"); */ |
|
2760 |
RETURN (self); |
|
2761 |
} |
|
5402 | 2762 |
# endif |
2763 |
} |
|
2764 |
#endif // SUPPORT_DEV_AUDIO |
|
2765 |
%}. |
|
2766 |
! |
|
2767 |
||
2768 |
setSampleRate:hz |
|
2769 |
"set the sample rate" |
|
2770 |
||
2771 |
|fd| |
|
2772 |
||
2773 |
sampleRate := hz. |
|
2774 |
||
2775 |
fd := self fileDescriptorOrNil. |
|
2776 |
fd isNil ifTrue:[ |
|
5429 | 2777 |
^ self |
5402 | 2778 |
]. |
2779 |
%{ |
|
2780 |
#ifdef SUPPORT_DEV_AUDIO |
|
2781 |
int f = __intVal(fd); |
|
2782 |
int __rate = __intVal(hz); |
|
2783 |
||
2784 |
if (__isSmallInteger(fd) && __isSmallInteger(hz)) { |
|
5429 | 2785 |
int __rateWant = __rate; |
5402 | 2786 |
|
2787 |
# if defined(SNDCTL_DSP_SPEED) |
|
5429 | 2788 |
if (ioctl(f, SNDCTL_DSP_SPEED, &__rate) >= 0) { |
2789 |
if (__rate != __rateWant) { |
|
2790 |
console_fprintf(stderr, "SoundStream [warning]: actual rate is %d\n", __rate); |
|
2791 |
hz = __MKSMALLINT(__rate); |
|
2792 |
} |
|
2793 |
__INST(sampleRate) = hz; |
|
2794 |
RETURN (self); |
|
2795 |
} |
|
5402 | 2796 |
# else |
2797 |
# if defined(SOUND_PCM_WRITE_RATE) |
|
5429 | 2798 |
if (ioctl(f, SOUND_PCM_WRITE_RATE, &__rate) >= 0) { |
2799 |
if (__rate != __rateWant) { |
|
2800 |
console_fprintf(stderr, "SoundStream [warning]: actual rate is %d\n", __rate); |
|
2801 |
hz = __MKSMALLINT(__rate); |
|
2802 |
} |
|
2803 |
__INST(sampleRate) = hz; |
|
2804 |
RETURN (self); |
|
2805 |
} |
|
5402 | 2806 |
# else |
2807 |
# ifdef AUDIO_SET_SAMPLE_RATE /* hpux */ |
|
5429 | 2808 |
if (ioctl (f, AUDIO_SET_SAMPLE_RATE, __rate)) { |
2809 |
/* console_fprintf(stderr, "got err-ret from AUDIO_SET_SAMPLE_RATE\n"); */ |
|
2810 |
__INST(sampleRate) = hz; |
|
2811 |
RETURN (self); |
|
2812 |
} |
|
5402 | 2813 |
# endif |
2814 |
# endif |
|
2815 |
# endif |
|
2816 |
} |
|
2817 |
#endif // SUPPORT_DEV_AUDIO |
|
2818 |
%}. |
|
2819 |
||
2820 |
" |
|
2821 |
self writing setSampleRate:10000; dumpSettings; close |
|
2822 |
self writing setSampleRate:1000; dumpSettings; close |
|
2823 |
self writing setSampleRate:8000; dumpSettings; close |
|
2824 |
" |
|
2825 |
! ! |
|
2826 |
||
2827 |
!SoundStream::DevAudio methodsFor:'queries'! |
|
2828 |
||
2829 |
supportedAudioFormats |
|
2830 |
"return a collection of supported audio formats. |
|
2831 |
possibly returned symbols are: |
|
5429 | 2832 |
U8 unsigned 8bit samples |
2833 |
S8 signed 8bit samples |
|
2834 |
U16 unsigned 16bit samples in native format |
|
2835 |
U16_LE unsigned 16bit big endian samples |
|
2836 |
U16_BE unsigned 16bit big endian samples |
|
2837 |
S16 signed 16bit little endian samples in native format |
|
2838 |
S16_LE signed 16bit little endian samples |
|
2839 |
S16_BE signed 16bit big endian samples |
|
2840 |
S24 signed 24bit little endian samples in native format |
|
2841 |
S24_LE signed 24bit little endian samples |
|
2842 |
S24_BE signed 24bit big endian samples |
|
2843 |
S32 signed 32bit little endian samples in native format |
|
2844 |
S32_LE signed 32bit little endian samples |
|
2845 |
S32_BE signed 32bit big endian samples |
|
2846 |
F32 float samples |
|
2847 |
MPEG audio mpeg encoded |
|
2848 |
MU_LAW u-law encoded 8bit samples |
|
2849 |
A_LAW a-law encoded 8bit samples |
|
2850 |
IMA_ADPCM adpcm encoded |
|
5402 | 2851 |
the set of returned symbols depends on the underlying sound hardware. |
2852 |
" |
|
2853 |
||
2854 |
|fd audioFormatMask |
|
2855 |
supportedFormats |
|
2856 |
supports_MU_LAW supports_A_LAW supports_MPEG |
|
2857 |
supports_IMA_ADPCM |
|
2858 |
supports_S8 supports_U8 |
|
2859 |
supports_S16_LE supports_S16_BE |
|
2860 |
supports_U16_LE supports_U16_BE |
|
2861 |
supports_U32_LE supports_U32_BE |
|
2862 |
supports_S24_LE supports_S24_BE |
|
2863 |
supports_S32_LE supports_S32_BE |
|
2864 |
supports_F32 |
|
2865 |
| |
|
2866 |
||
2867 |
fd := self fileDescriptorOrNil. |
|
2868 |
||
2869 |
%{ |
|
2870 |
#ifdef SUPPORT_DEV_AUDIO |
|
2871 |
supports_MU_LAW = true; |
|
2872 |
||
2873 |
if (fd != nil) { |
|
5429 | 2874 |
int f = __intVal(fd); |
2875 |
int __audioFormatMask = 0; |
|
5402 | 2876 |
|
2877 |
# if defined(SNDCTL_DSP_GETFMTS) |
|
5429 | 2878 |
if (ioctl(f, SNDCTL_DSP_GETFMTS, &__audioFormatMask) >= 0) { |
2879 |
audioFormatMask = __MKSMALLINT(__audioFormatMask); |
|
5402 | 2880 |
|
2881 |
# ifdef AFMT_MU_LAW |
|
5429 | 2882 |
supports_MU_LAW = (__audioFormatMask & AFMT_MU_LAW) ? true : false; |
5402 | 2883 |
# endif |
2884 |
# ifdef AFMT_A_LAW |
|
5429 | 2885 |
supports_A_LAW = (__audioFormatMask & AFMT_A_LAW) ? true : false; |
5402 | 2886 |
# endif |
2887 |
# ifdef AFMT_IMA_ADPCM |
|
5429 | 2888 |
supports_IMA_ADPCM = (__audioFormatMask & AFMT_IMA_ADPCM) ? true : false; |
5402 | 2889 |
# endif |
2890 |
# ifdef AFMT_U8 |
|
5429 | 2891 |
supports_U8 = (__audioFormatMask & AFMT_U8) ? true : false; |
5402 | 2892 |
# endif |
2893 |
# ifdef AFMT_S16_LE |
|
5429 | 2894 |
supports_S16_LE = (__audioFormatMask & AFMT_S16_LE) ? true : false; |
5402 | 2895 |
# endif |
2896 |
# ifdef AFMT_S16_BE |
|
5429 | 2897 |
supports_S16_BE = (__audioFormatMask & AFMT_S16_BE) ? true : false; |
5402 | 2898 |
# endif |
2899 |
# ifdef AFMT_S8 |
|
5429 | 2900 |
supports_S8 = (__audioFormatMask & AFMT_S8) ? true : false; |
5402 | 2901 |
# endif |
2902 |
# ifdef AFMT_U16_LE |
|
5429 | 2903 |
supports_U16_LE = (__audioFormatMask & AFMT_U16_LE) ? true : false; |
5402 | 2904 |
# endif |
2905 |
# ifdef AFMT_U16_BE |
|
5429 | 2906 |
supports_U16_BE = (__audioFormatMask & AFMT_U16_BE) ? true : false; |
5402 | 2907 |
# endif |
2908 |
# ifdef AFMT_MPEG |
|
5429 | 2909 |
supports_MPEG = (__audioFormatMask & AFMT_MPEG) ? true : false; |
5402 | 2910 |
# endif |
5429 | 2911 |
} |
5402 | 2912 |
} |
2913 |
# endif // SNDCTL_DSP_GETFMTS |
|
2914 |
||
2915 |
# ifdef hpux |
|
2916 |
supports_A_LAW = true; |
|
2917 |
supports_S16_BE = true; |
|
2918 |
# endif |
|
2919 |
#endif /* SUPPORT_DEV_AUDIO */ |
|
2920 |
%}. |
|
2921 |
supportedFormats := IdentitySet new. |
|
2922 |
(supports_MU_LAW ? false) ifTrue:[ |
|
5429 | 2923 |
supportedFormats add:#'MU_LAW' |
5402 | 2924 |
]. |
2925 |
(supports_A_LAW ? false) ifTrue:[ |
|
5429 | 2926 |
supportedFormats add:#'A_LAW' |
5402 | 2927 |
]. |
2928 |
(supports_IMA_ADPCM ? false) ifTrue:[ |
|
5429 | 2929 |
supportedFormats add:#'IMA_ADPCM' |
5402 | 2930 |
]. |
2931 |
(supports_MPEG ? false) ifTrue:[ |
|
5429 | 2932 |
supportedFormats add:#'MPEG' |
5402 | 2933 |
]. |
2934 |
(supports_S8 ? false) ifTrue:[ |
|
5429 | 2935 |
supportedFormats add:#'S8' |
5402 | 2936 |
]. |
2937 |
(supports_U8 ? false) ifTrue:[ |
|
5429 | 2938 |
supportedFormats add:#'U8' |
5402 | 2939 |
]. |
2940 |
(supports_S16_LE ? false) ifTrue:[ |
|
5429 | 2941 |
supportedFormats add:#'S16_LE'. |
2942 |
UninterpretedBytes isBigEndian ifFalse:[ |
|
2943 |
supportedFormats add:#'S16'. |
|
2944 |
] |
|
5402 | 2945 |
]. |
2946 |
(supports_S16_BE ? false) ifTrue:[ |
|
5429 | 2947 |
supportedFormats add:#'S16_BE'. |
2948 |
UninterpretedBytes isBigEndian ifTrue:[ |
|
2949 |
supportedFormats add:#'S16'. |
|
2950 |
] |
|
5402 | 2951 |
]. |
2952 |
(supports_S24_LE ? false) ifTrue:[ |
|
5429 | 2953 |
supportedFormats add:#'S24_LE'. |
2954 |
UninterpretedBytes isBigEndian ifFalse:[ |
|
2955 |
supportedFormats add:#'S24'. |
|
2956 |
] |
|
5402 | 2957 |
]. |
2958 |
(supports_S24_BE ? false) ifTrue:[ |
|
5429 | 2959 |
supportedFormats add:#'S24_BE'. |
2960 |
UninterpretedBytes isBigEndian ifTrue:[ |
|
2961 |
supportedFormats add:#'S24'. |
|
2962 |
] |
|
5402 | 2963 |
]. |
2964 |
(supports_S32_LE ? false) ifTrue:[ |
|
5429 | 2965 |
supportedFormats add:#'S32_LE'. |
2966 |
UninterpretedBytes isBigEndian ifFalse:[ |
|
2967 |
supportedFormats add:#'S32'. |
|
2968 |
] |
|
5402 | 2969 |
]. |
2970 |
(supports_S32_BE ? false) ifTrue:[ |
|
5429 | 2971 |
supportedFormats add:#'S32_BE'. |
2972 |
UninterpretedBytes isBigEndian ifTrue:[ |
|
2973 |
supportedFormats add:#'S32'. |
|
2974 |
] |
|
5402 | 2975 |
]. |
2976 |
(supports_U16_LE ? false) ifTrue:[ |
|
5429 | 2977 |
supportedFormats add:#'U16_LE'. |
2978 |
UninterpretedBytes isBigEndian ifFalse:[ |
|
2979 |
supportedFormats add:#'U16'. |
|
2980 |
] |
|
5402 | 2981 |
]. |
2982 |
(supports_U16_BE ? false) ifTrue:[ |
|
5429 | 2983 |
supportedFormats add:#'U16_BE'. |
2984 |
UninterpretedBytes isBigEndian ifTrue:[ |
|
2985 |
supportedFormats add:#'U16'. |
|
2986 |
] |
|
5402 | 2987 |
]. |
2988 |
(supports_F32 ? false) ifTrue:[ |
|
5429 | 2989 |
supportedFormats add:#'F32' |
5402 | 2990 |
]. |
2991 |
^ supportedFormats. |
|
2992 |
||
2993 |
" |
|
2994 |
|s formats| |
|
2995 |
||
2996 |
s := self writing. |
|
2997 |
formats := s supportedAudioFormats. |
|
2998 |
s close. |
|
2999 |
formats |
|
3000 |
" |
|
3001 |
! ! |
|
3002 |
||
3003 |
!SoundStream::DevAudio methodsFor:'reading'! |
|
3004 |
||
3005 |
nextBytes:count into:anObject startingAt:start |
|
3006 |
"read the next count bytes into an object and return the number of |
|
3007 |
bytes read or nil on error. |
|
3008 |
Use with ByteArrays only." |
|
3009 |
||
3010 |
%{ |
|
3011 |
#ifdef SUPPORT_DEV_AUDIO |
|
3012 |
/* |
|
3013 |
* redefined to work around a bug in the linux sound driver; |
|
3014 |
* if a read is interrupted (EINTR), it is not defined, how many |
|
3015 |
* bytes have been read from the device. |
|
3016 |
* |
|
3017 |
* As a workaround, disable signals here to prevent being interrupted. |
|
3018 |
*/ |
|
3019 |
int cnt, offs, objSize, n; |
|
3020 |
char *cp; |
|
3021 |
OBJ fp; |
|
3022 |
FILE *f; |
|
3023 |
int fd; |
|
3024 |
||
3025 |
if ((fp = __INST(handle)) != nil) { |
|
5429 | 3026 |
f = __FILEVal(fp); |
3027 |
if (__INST(mode) != @symbol(writeonly)) { |
|
3028 |
if (__bothSmallInteger(count, start)) { |
|
3029 |
cnt = __intVal(count); |
|
3030 |
offs = __intVal(start) - 1; |
|
3031 |
||
3032 |
objSize = _Size(anObject) - OHDR_SIZE; |
|
3033 |
if ( (offs >= 0) && (cnt >= 0) && (objSize >= (cnt + offs)) ) { |
|
3034 |
do { |
|
3035 |
cp = (char *)__InstPtr(anObject) + OHDR_SIZE + offs; |
|
3036 |
||
3037 |
n = cnt; |
|
5402 | 3038 |
# ifdef LINUX |
5429 | 3039 |
sigsetmask(~0); |
5402 | 3040 |
# endif |
5429 | 3041 |
if (__INST(buffered) == true) { |
3042 |
n = fread(cp, 1, n, f); |
|
3043 |
} else { |
|
3044 |
fd = fileno(f); |
|
3045 |
n = read(fd, cp, n); |
|
3046 |
} |
|
5402 | 3047 |
# ifdef LINUX |
5429 | 3048 |
sigsetmask(0); |
5402 | 3049 |
# endif |
5429 | 3050 |
__BEGIN_INTERRUPTABLE__ |
3051 |
__END_INTERRUPTABLE__ |
|
3052 |
// console_fprintf(stderr, "SoundStream: read %d bytes\n", n); |
|
3053 |
if (n > 0) { |
|
3054 |
offs += n; |
|
3055 |
cnt -= n; |
|
3056 |
} else { |
|
3057 |
if (n < 0) { |
|
3058 |
console_fprintf(stderr, "read error: %d\n", __threadErrno); |
|
3059 |
RETURN (count); |
|
3060 |
} |
|
3061 |
} |
|
3062 |
} while (cnt); |
|
3063 |
} |
|
3064 |
RETURN (count); |
|
3065 |
} |
|
3066 |
} |
|
5402 | 3067 |
} |
3068 |
#endif /* SUPPORT_DEV_AUDIO */ |
|
3069 |
||
3070 |
%}. |
|
3071 |
self errorUnsupportedOperation |
|
3072 |
! ! |
|
3073 |
||
3074 |
!SoundStream::DevAudio methodsFor:'writing'! |
|
3075 |
||
3076 |
nextPutBytes:count from:anObject startingAt:start |
|
3077 |
"write count bytes from an object starting at index start. |
|
3078 |
return the number of bytes written or nil on error. |
|
3079 |
Redefined, since IRIS audio library cannot be used with stdio. |
|
3080 |
(at least I don't know). Use with ByteArrays only." |
|
3081 |
||
3082 |
%{ |
|
3083 |
#ifdef SUPPORT_DEV_AUDIO |
|
3084 |
/* |
|
3085 |
* redefine to work around a bug in the linux sound driver; |
|
3086 |
* if a write is interrupted (EINTR), it is not defined, how many |
|
3087 |
* bytes have been written to the device. |
|
3088 |
* I.e. a retry of the write may lead to ever-playing without ever |
|
3089 |
* finishing. |
|
3090 |
* |
|
3091 |
* As a workaround, disable signals here to prevent the write from |
|
3092 |
* being interrupted. |
|
3093 |
*/ |
|
3094 |
int cnt, offs, objSize, n; |
|
3095 |
char *cp; |
|
3096 |
OBJ fp; |
|
3097 |
FILE *f; |
|
3098 |
int fd; |
|
3099 |
||
3100 |
if ((fp = __INST(handle)) != nil) { |
|
5429 | 3101 |
f = __FILEVal(fp); |
3102 |
if (__INST(mode) != @symbol(readonly)) { |
|
3103 |
if (__bothSmallInteger(count, start)) { |
|
3104 |
cnt = __intVal(count); |
|
3105 |
offs = __intVal(start) - 1; |
|
3106 |
||
3107 |
objSize = _Size(anObject) - OHDR_SIZE; |
|
3108 |
if ( (offs >= 0) && (cnt >= 0) && (objSize >= (cnt + offs)) ) { |
|
3109 |
do { |
|
3110 |
cp = (char *)__InstPtr(anObject) + OHDR_SIZE + offs; |
|
3111 |
||
3112 |
n = cnt; |
|
5402 | 3113 |
# ifdef LINUX |
5429 | 3114 |
sigsetmask(~0); |
5402 | 3115 |
# endif |
5429 | 3116 |
if (__INST(buffered) == true) { |
3117 |
n = fwrite(cp, 1, n, f); |
|
3118 |
} else { |
|
3119 |
fd = fileno(f); |
|
3120 |
n = write(fd, cp, n); |
|
3121 |
} |
|
5402 | 3122 |
# ifdef LINUX |
5429 | 3123 |
sigsetmask(0); |
5402 | 3124 |
# endif |
5429 | 3125 |
__BEGIN_INTERRUPTABLE__ |
3126 |
__END_INTERRUPTABLE__ |
|
3127 |
if (n > 0) { |
|
3128 |
offs += n; |
|
3129 |
cnt -= n; |
|
3130 |
} else { |
|
3131 |
if (n < 0) { |
|
3132 |
console_fprintf(stderr, "write error: %d\n", __threadErrno); |
|
3133 |
RETURN (count); |
|
3134 |
} |
|
3135 |
} |
|
3136 |
} while (cnt); |
|
3137 |
} |
|
3138 |
RETURN (count); |
|
3139 |
} |
|
3140 |
} |
|
5402 | 3141 |
} |
3142 |
#endif /* SUPPORT_DEV_AUDIO */ |
|
3143 |
||
3144 |
%}. |
|
3145 |
^ self errorUnsupportedOperation |
|
3146 |
! ! |
|
3147 |
||
3148 |
!SoundStream::IRISAudio class methodsFor:'documentation'! |
|
3149 |
||
3150 |
documentation |
|
3151 |
" |
|
5424 | 3152 |
interface to the silicon graphics IRIX audio system |
5402 | 3153 |
" |
3154 |
! ! |
|
3155 |
||
3156 |
!SoundStream::IRISAudio class methodsFor:'queries'! |
|
3157 |
||
3158 |
isSupported |
|
3159 |
%{ |
|
3160 |
#ifdef SUPPORT_IRIS_AUDIO |
|
3161 |
RETURN(true); |
|
3162 |
#endif |
|
3163 |
%}. |
|
3164 |
^ false. |
|
3165 |
! ! |
|
3166 |
||
3167 |
!SoundStream::IRISAudio methodsFor:'misc'! |
|
3168 |
||
3169 |
flush |
|
3170 |
"wait until all sound has been played" |
|
3171 |
||
3172 |
%{ |
|
3173 |
#ifdef SUPPORT_IRIS_AUDIO |
|
3174 |
OPJ port; |
|
3175 |
ALport p; |
|
3176 |
||
3177 |
if ((port = __INST(alPort)) != nil) { |
|
5429 | 3178 |
p = __ALportVal(port); |
3179 |
while (ALgetfilled(p) > 0) { |
|
3180 |
sginap(1); |
|
3181 |
} |
|
5402 | 3182 |
} |
3183 |
RETURN(self); |
|
3184 |
#endif /* SUPPORT_IRIS_AUDIO */ |
|
3185 |
%}. |
|
3186 |
||
3187 |
! ! |
|
3188 |
||
3189 |
!SoundStream::IRISAudio methodsFor:'open & close'! |
|
3190 |
||
3191 |
closeFile |
|
3192 |
"a stream has been collected - close the file" |
|
3193 |
||
3194 |
%{ |
|
3195 |
#ifdef SUPPORT_IRIS_AUDIO |
|
3196 |
OBJ port; |
|
3197 |
||
3198 |
if ((port = __INST(alPort)) != nil) { |
|
5429 | 3199 |
__INST(alPort) = nil; |
3200 |
ALcloseport(__ALportVal(port)); |
|
5402 | 3201 |
} |
3202 |
RETURN (self); |
|
3203 |
#endif /* SUPPORT_IRIS_AUDIO */ |
|
3204 |
%}. |
|
3205 |
||
3206 |
! |
|
3207 |
||
3208 |
openWithMode:aMode attributes:attributeSpec |
|
3209 |
|ok error errorStringOrNil| |
|
3210 |
||
3211 |
%{ |
|
3212 |
#ifdef SUPPORT_IRIS_AUDIO |
|
3213 |
ALconfig config; |
|
3214 |
ALport p; |
|
3215 |
long params[] = { |
|
5429 | 3216 |
AL_INPUT_SOURCE, AL_INPUT_MIC, |
3217 |
AL_INPUT_RATE, 8000, |
|
3218 |
AL_OUTPUT_RATE, 8000, |
|
5402 | 3219 |
}; |
3220 |
||
3221 |
ok = false. |
|
3222 |
config = ALnewconfig(); |
|
3223 |
if (__INST(numberOfChannels) == __MKSMALLINT(2)) |
|
5429 | 3224 |
ALsetchannels(config, AL_STEREO); |
5402 | 3225 |
else |
5429 | 3226 |
ALsetchannels(config, AL_MONO); |
5402 | 3227 |
if (__INST(bitsPerSample) == __MKSMALLINT(16)) |
5429 | 3228 |
ALsetwidth(config, AL_SAMPLE_16); |
5402 | 3229 |
else |
5429 | 3230 |
ALsetwidth(config, AL_SAMPLE_8); |
5402 | 3231 |
|
3232 |
if (__isSmallInteger(__INST(sampleRate))) |
|
5429 | 3233 |
params[3] = params[5] = __intVal(__INST(sampleRate)); |
5402 | 3234 |
|
3235 |
ALsetparams(AL_DEFAULT_DEVICE, params, 6); |
|
3236 |
p = ALopenport("smallchat", (char *)_stringVal(aMode), config); |
|
3237 |
if (p) { |
|
5429 | 3238 |
OBJ t; |
3239 |
||
3240 |
t = __MKEXTERNALADDRESS(p); __INST(alPort) = t; __STORE(self, t); |
|
5402 | 3241 |
} else { |
5429 | 3242 |
__INST(alPort) = nil; |
3243 |
goto out; |
|
5402 | 3244 |
} |
3245 |
__INST(binary) = true; |
|
3246 |
||
3247 |
ALfreeconfig(config); |
|
3248 |
/* |
|
3249 |
* get the parameters actually installed |
|
3250 |
*/ |
|
3251 |
config = ALgetconfig(p); |
|
3252 |
switch (ALgetchannels(config)) { |
|
5429 | 3253 |
default: |
3254 |
/* cannot happen */ |
|
3255 |
case AL_MONO: |
|
3256 |
__INST(numberOfChannels) = __MKSMALLINT(1); |
|
3257 |
break; |
|
3258 |
case AL_STEREO: |
|
3259 |
__INST(numberOfChannels) = __MKSMALLINT(2); |
|
3260 |
break; |
|
5402 | 3261 |
} |
3262 |
switch (ALgetwidth(config)) { |
|
5429 | 3263 |
default: |
3264 |
/* cannot happen */ |
|
3265 |
case AL_SAMPLE_8: |
|
3266 |
__INST(bitsPerSample) = __MKSMALLINT(8); |
|
3267 |
break; |
|
3268 |
case AL_SAMPLE_16: |
|
3269 |
__INST(bitsPerSample) = __MKSMALLINT(16); |
|
3270 |
break; |
|
3271 |
case AL_SAMPLE_24: |
|
3272 |
__INST(bitsPerSample) = __MKSMALLINT(24); |
|
3273 |
break; |
|
5402 | 3274 |
} |
3275 |
ALgetparams(AL_DEFAULT_DEVICE, params, 6); |
|
3276 |
__INST(sampleRate) = __MKSMALLINT(params[3]); |
|
3277 |
||
3278 |
ALfreeconfig(config); |
|
3279 |
ok = true; |
|
3280 |
out:; |
|
3281 |
#endif /* SUPPORT_IRIS_AUDIO */ |
|
3282 |
||
3283 |
%}. |
|
3284 |
ok == false ifTrue:[ |
|
5429 | 3285 |
lastErrorString := errorStringOrNil. |
3286 |
lastErrorNumber := error ? -1. |
|
3287 |
self openError:error. |
|
3288 |
"normally not reached" |
|
3289 |
^ nil. |
|
5402 | 3290 |
]. |
3291 |
self registerForFinalization. |
|
3292 |
! ! |
|
3293 |
||
3294 |
!SoundStream::IRISAudio methodsFor:'queries'! |
|
3295 |
||
3296 |
supportedAudioFormats |
|
3297 |
"return a collection of supported audio formats. |
|
3298 |
possibly returned symbols are: |
|
5429 | 3299 |
U8 unsigned 8bit samples |
3300 |
S8 signed 8bit samples |
|
3301 |
U16 unsigned 16bit samples in native format |
|
3302 |
U16_LE unsigned 16bit big endian samples |
|
3303 |
U16_BE unsigned 16bit big endian samples |
|
3304 |
S16 signed 16bit little endian samples in native format |
|
3305 |
S16_LE signed 16bit little endian samples |
|
3306 |
S16_BE signed 16bit big endian samples |
|
3307 |
S24 signed 24bit little endian samples in native format |
|
3308 |
S24_LE signed 24bit little endian samples |
|
3309 |
S24_BE signed 24bit big endian samples |
|
3310 |
S32 signed 32bit little endian samples in native format |
|
3311 |
S32_LE signed 32bit little endian samples |
|
3312 |
S32_BE signed 32bit big endian samples |
|
3313 |
F32 float samples |
|
3314 |
MPEG audio mpeg encoded |
|
3315 |
MU_LAW u-law encoded 8bit samples |
|
3316 |
A_LAW a-law encoded 8bit samples |
|
3317 |
IMA_ADPCM adpcm encoded |
|
5402 | 3318 |
the set of returned symbols depends on the underlying sound hardware. |
3319 |
" |
|
3320 |
||
3321 |
^ #( U8 U16_BE U16 ) |
|
3322 |
||
3323 |
" |
|
3324 |
|s formats| |
|
3325 |
||
3326 |
s := self writing. |
|
3327 |
formats := s supportedAudioFormats. |
|
3328 |
s close. |
|
3329 |
formats |
|
3330 |
" |
|
3331 |
! ! |
|
3332 |
||
3333 |
!SoundStream::IRISAudio methodsFor:'reading'! |
|
3334 |
||
3335 |
nextBytes:count into:anObject startingAt:start |
|
3336 |
"read the next count bytes into an object and return the number of |
|
3337 |
bytes read or nil on error. |
|
3338 |
Use with ByteArrays only." |
|
3339 |
||
3340 |
%{ |
|
3341 |
#ifdef SUPPORT_IRIS_AUDIO |
|
3342 |
{ |
|
3343 |
OBJ port; |
|
3344 |
ALport p; |
|
3345 |
int cnt, offs, nSamp; |
|
3346 |
int objSize; |
|
3347 |
char *cp; |
|
3348 |
||
3349 |
if ((port = __INST(alPort)) != nil) { |
|
5429 | 3350 |
if (__INST(mode) != _writeonly) { |
3351 |
if (__bothSmallInteger(count, start)) { |
|
3352 |
cnt = __intVal(count); |
|
3353 |
offs = __intVal(start) - 1; |
|
3354 |
p = __ALportVal(port); |
|
3355 |
objSize = _Size(anObject) - OHDR_SIZE; |
|
3356 |
if ((offs >= 0) && (cnt >= 0) && (objSize >= (cnt + offs))) { |
|
3357 |
cp = (char *)__InstPtr(anObject) + OHDR_SIZE + offs; |
|
3358 |
if (__INST(bitsPerSample) == __MKSMALLINT(16)) |
|
3359 |
nSamp = cnt / 2; |
|
3360 |
else |
|
3361 |
nSamp = cnt; |
|
3362 |
ALreadsamps(p, cp, nSamp); |
|
3363 |
RETURN ( __MKSMALLINT(cnt) ); |
|
3364 |
} |
|
3365 |
} |
|
3366 |
} |
|
5402 | 3367 |
} |
3368 |
} |
|
3369 |
#endif /* SUPPORT_IRIS_AUDIO */ |
|
3370 |
||
3371 |
%}. |
|
3372 |
self errorUnsupportedOperation |
|
3373 |
! ! |
|
3374 |
||
3375 |
!SoundStream::IRISAudio methodsFor:'writing'! |
|
3376 |
||
3377 |
nextPutBytes:count from:anObject startingAt:start |
|
3378 |
"write count bytes from an object starting at index start. |
|
3379 |
return the number of bytes written or nil on error. |
|
3380 |
Redefined, since IRIS audio library cannot be used with stdio. |
|
3381 |
(at least I don't know). Use with ByteArrays only." |
|
3382 |
||
3383 |
%{ |
|
3384 |
#ifdef SUPPORT_IRIS_AUDIO |
|
3385 |
{ |
|
3386 |
OBJ port; |
|
3387 |
ALport p; |
|
3388 |
int cnt, offs, nSamp; |
|
3389 |
int objSize; |
|
3390 |
char *cp; |
|
3391 |
||
3392 |
if ((port = __INST(alPort)) != nil) { |
|
5429 | 3393 |
if (__INST(mode) != @symbol(readonly)) { |
3394 |
if (__bothSmallInteger(count, start)) { |
|
3395 |
cnt = __intVal(count); |
|
3396 |
offs = __intVal(start) - 1; |
|
3397 |
p = __ALportVal(port); |
|
3398 |
||
3399 |
/* |
|
3400 |
* compute number of samples |
|
3401 |
*/ |
|
3402 |
objSize = _Size(anObject) - OHDR_SIZE; |
|
3403 |
if ( (offs >= 0) && (cnt >= 0) && (objSize >= (cnt + offs)) ) { |
|
3404 |
cp = (char *)__InstPtr(anObject) + OHDR_SIZE + offs; |
|
3405 |
if (__INST(bitsPerSample) == __MKSMALLINT(16)) |
|
3406 |
nSamp = cnt / 2; |
|
3407 |
else |
|
3408 |
nSamp = cnt; |
|
3409 |
ALwritesamps(p, cp, cnt); |
|
3410 |
RETURN ( count ); |
|
3411 |
} |
|
3412 |
} |
|
3413 |
} |
|
5402 | 3414 |
} |
3415 |
} |
|
3416 |
#endif /* SUPPORT_IRIS_AUDIO */ |
|
3417 |
%}. |
|
5405 | 3418 |
self errorUnsupportedOperation |
5402 | 3419 |
! ! |
3420 |
||
5424 | 3421 |
!SoundStream::JackAudio class methodsFor:'documentation'! |
3422 |
||
3423 |
documentation |
|
3424 |
" |
|
3425 |
interface to the jack audio system |
|
3426 |
" |
|
3427 |
! ! |
|
3428 |
||
5421 | 3429 |
!SoundStream::JackAudio class methodsFor:'queries'! |
3430 |
||
5423 | 3431 |
defaultAudioFormat |
3432 |
^ #F32 |
|
3433 |
! |
|
3434 |
||
5421 | 3435 |
isSupported |
3436 |
%{ |
|
3437 |
#ifdef SUPPORT_JACKAUDIO |
|
3438 |
RETURN(true); |
|
3439 |
#endif |
|
3440 |
%}. |
|
3441 |
^ false. |
|
3442 |
! ! |
|
3443 |
||
3444 |
!SoundStream::JackAudio methodsFor:'open & close'! |
|
3445 |
||
3446 |
closeFile |
|
3447 |
"a stream has been collected - close the file" |
|
3448 |
||
3449 |
%{ |
|
3450 |
#ifdef SUPPORT_JACKAUDIO |
|
3451 |
OBJ str; |
|
3452 |
if ((str = __INST(handle1)) != nil) { |
|
5429 | 3453 |
struct jackStreamData* streamData = (struct jackStreamData*)__externalAddressVal(str); |
3454 |
struct jackBuffer* buffer; |
|
3455 |
||
3456 |
if (DEBUGGING) { |
|
3457 |
fprintf(stderr, "jack close\n"); |
|
3458 |
} |
|
3459 |
__externalAddressVal(str) = NULL; |
|
3460 |
__INST(handle1) = nil; |
|
3461 |
jack_client_close( streamData->jack_client ); |
|
3462 |
||
3463 |
LOCK(streamData->lock); |
|
3464 |
||
3465 |
buffer = streamData->currentBuffer; |
|
3466 |
streamData->currentBuffer = NULL; |
|
3467 |
streamData->lastBuffer = NULL; |
|
3468 |
while (buffer != NULL) { |
|
3469 |
struct jackBuffer* nextBuffer = buffer->nextBuffer; |
|
3470 |
free(buffer->sampleData); |
|
3471 |
free(buffer); |
|
3472 |
buffer = nextBuffer; |
|
3473 |
} |
|
3474 |
buffer = streamData->freeList; |
|
3475 |
streamData->freeList = NULL; |
|
3476 |
while (buffer != NULL) { |
|
3477 |
struct jackBuffer* nextBuffer = buffer->nextBuffer; |
|
3478 |
free(buffer->sampleData); |
|
3479 |
free(buffer); |
|
3480 |
buffer = nextBuffer; |
|
3481 |
} |
|
3482 |
||
3483 |
UNLOCK(streamData->lock); |
|
3484 |
RELEASELOCK(streamData->lock); |
|
3485 |
free(streamData); |
|
5421 | 3486 |
} |
3487 |
RETURN (self); |
|
3488 |
#endif // SUPPORT_JACKAUDIO |
|
3489 |
%}. |
|
3490 |
! |
|
3491 |
||
3492 |
openWithMode:aMode attributes:attributeSpec |
|
3493 |
|ok error errorStringOrNil| |
|
3494 |
||
3495 |
openMode := aMode. |
|
3496 |
openAttributes := attributeSpec. |
|
3497 |
%{ |
|
3498 |
#ifdef SUPPORT_JACKAUDIO |
|
3499 |
jack_options_t options = JackNullOption; |
|
3500 |
jack_client_t *client; |
|
5425 | 3501 |
jack_port_t *output_port; |
5421 | 3502 |
struct jackStreamData* streamData; |
3503 |
int nChannels, sampleRate, bytesPerSample; |
|
3504 |
# define FRAMES_PER_BUFFER 128 |
|
3505 |
||
3506 |
ok = false; |
|
3507 |
||
3508 |
if (__isSmallInteger(__INST(numberOfChannels))) { |
|
5429 | 3509 |
nChannels = __intVal(__INST(numberOfChannels)); |
5421 | 3510 |
} else { |
5429 | 3511 |
nChannels = 1; |
5421 | 3512 |
} |
3513 |
||
3514 |
if (__INST(audioFormat) == @symbol(F32)) { |
|
5429 | 3515 |
bytesPerSample = 4; |
5421 | 3516 |
} else { |
5429 | 3517 |
fprintf(stderr, "SoundStream [warning]: only f32 supported with jack\n"); |
3518 |
errorStringOrNil = __MKSTRING("audioFormat must be f32 with jack"); |
|
3519 |
goto out; |
|
5421 | 3520 |
} |
3521 |
||
3522 |
streamData = (struct jackStreamData*)malloc(sizeof(struct jackStreamData)); |
|
3523 |
if (streamData == NULL) { |
|
5429 | 3524 |
fprintf(stderr, "SoundStream [warning]: failed to allocate jackStream\n"); |
3525 |
errorStringOrNil = __MKSTRING("failed to allocate jackStream"); |
|
3526 |
goto out; |
|
5421 | 3527 |
} |
3528 |
||
3529 |
if ((client = jack_client_open ("stx", JackNullOption, NULL)) == 0) { |
|
5429 | 3530 |
fprintf(stderr, "SoundStream [warning]: JACK server not running?\n"); |
3531 |
free(streamData); |
|
3532 |
errorStringOrNil = __MKSTRING("JACK server not running"); |
|
3533 |
goto out; |
|
5421 | 3534 |
} |
5424 | 3535 |
jack_set_process_callback (client, jack_callback, 0); |
5421 | 3536 |
|
5425 | 3537 |
output_port = jack_port_register (client, "stx_out", JACK_DEFAULT_AUDIO_TYPE, JackPortIsOutput, 0); |
3538 |
sampleRate = jack_get_sample_rate (client); |
|
3539 |
__INST(sampleRate) = __MKSMALLINT(sampleRate); |
|
3540 |
// if (__isSmallInteger(__INST(sampleRate))) { |
|
3541 |
// sampleRate = __intVal(__INST(sampleRate)); |
|
3542 |
// } else { |
|
3543 |
// fprintf(stderr, "SoundStream [warning]: using default sampleRate 8000\n"); |
|
3544 |
// sampleRate = 8000; |
|
3545 |
// } |
|
3546 |
||
5421 | 3547 |
streamData->jack_client = client; |
5425 | 3548 |
streamData->jack_output_port = output_port; |
5421 | 3549 |
INITLOCK(streamData->lock); |
3550 |
streamData->readOffset = 0; |
|
3551 |
streamData->bytesPerSample = bytesPerSample; |
|
3552 |
streamData->nChannels = nChannels; |
|
3553 |
||
3554 |
streamData->currentBuffer = NULL; |
|
3555 |
streamData->lastBuffer = NULL; |
|
3556 |
streamData->freeList = NULL; |
|
3557 |
streamData->hasFinished = 0; |
|
3558 |
||
3559 |
{ |
|
5429 | 3560 |
OBJ t; |
3561 |
t = __MKEXTERNALADDRESS(streamData); __INST(handle1) = t; __STORE(self, t); |
|
5421 | 3562 |
} |
3563 |
__INST(binary) = true; |
|
3564 |
||
3565 |
// paErr = Pa_SetStreamFinishedCallback( stream, &paStreamFinished ); |
|
3566 |
// if( paErr != paNoError ) { |
|
3567 |
// fprintf(stderr, "SoundStream [warning]: setFinishedCallback: %s\n", Pa_GetErrorText( paErr )); |
|
3568 |
// free(paStreamData); |
|
3569 |
// errorStringOrNil = __MKSTRING(Pa_GetErrorText( paErr )); |
|
3570 |
// goto out; |
|
3571 |
// }; |
|
3572 |
||
3573 |
ok = true; |
|
3574 |
out:; |
|
3575 |
#endif /* SUPPORT_JACKAUDIO */ |
|
3576 |
||
3577 |
%}. |
|
3578 |
ok == false ifTrue:[ |
|
5429 | 3579 |
lastErrorString := errorStringOrNil. |
3580 |
lastErrorNumber := error ? -1. |
|
3581 |
self openError:error. |
|
3582 |
"normally not reached" |
|
3583 |
^ nil. |
|
5421 | 3584 |
]. |
3585 |
self registerForFinalization. |
|
3586 |
! |
|
3587 |
||
3588 |
reopenStream |
|
3589 |
handle1 isNil ifTrue:[^ self]. |
|
3590 |
self closeFile. |
|
3591 |
self openWithMode:openMode attributes:openAttributes |
|
3592 |
! ! |
|
3593 |
||
5423 | 3594 |
!SoundStream::JackAudio methodsFor:'queries'! |
3595 |
||
3596 |
supportedAudioFormats |
|
3597 |
"return a collection of supported audio formats. |
|
3598 |
possibly returned symbols are: |
|
5429 | 3599 |
U8 unsigned 8bit samples |
3600 |
S8 signed 8bit samples |
|
3601 |
U16 unsigned 16bit samples in native format |
|
3602 |
U16_LE unsigned 16bit big endian samples |
|
3603 |
U16_BE unsigned 16bit big endian samples |
|
3604 |
S16 signed 16bit little endian samples in native format |
|
3605 |
S16_LE signed 16bit little endian samples |
|
3606 |
S16_BE signed 16bit big endian samples |
|
3607 |
S24 signed 24bit little endian samples in native format |
|
3608 |
S24_LE signed 24bit little endian samples |
|
3609 |
S24_BE signed 24bit big endian samples |
|
3610 |
S32 signed 32bit little endian samples in native format |
|
3611 |
S32_LE signed 32bit little endian samples |
|
3612 |
S32_BE signed 32bit big endian samples |
|
3613 |
F32 float samples |
|
3614 |
MPEG audio mpeg encoded |
|
3615 |
MU_LAW u-law encoded 8bit samples |
|
3616 |
A_LAW a-law encoded 8bit samples |
|
3617 |
IMA_ADPCM adpcm encoded |
|
5423 | 3618 |
the set of returned symbols depends on the underlying sound hardware. |
3619 |
" |
|
3620 |
||
3621 |
^ #(F32) |
|
3622 |
||
3623 |
" |
|
3624 |
|s formats| |
|
3625 |
||
3626 |
s := self writing. |
|
3627 |
formats := s supportedAudioFormats. |
|
3628 |
s close. |
|
3629 |
formats |
|
3630 |
" |
|
3631 |
! ! |
|
3632 |
||
5402 | 3633 |
!SoundStream::PortAudio class methodsFor:'default values'! |
3634 |
||
3635 |
defaultSampleRate |
|
3636 |
"minimum, supported by all audio systems" |
|
3637 |
||
3638 |
%{ |
|
3639 |
#ifdef SUPPORT_PORTAUDIO |
|
3640 |
RETURN (__MKSMALLINT(PORTAUDIO_DEFAULT_FREQ)); |
|
3641 |
#endif |
|
3642 |
%}. |
|
3643 |
||
3644 |
^ 8000 |
|
3645 |
! ! |
|
3646 |
||
3647 |
!SoundStream::PortAudio class methodsFor:'documentation'! |
|
3648 |
||
3649 |
documentation |
|
3650 |
" |
|
5424 | 3651 |
interface to the portaudio library |
5402 | 3652 |
" |
3653 |
! ! |
|
3654 |
||
3655 |
!SoundStream::PortAudio class methodsFor:'initialization'! |
|
3656 |
||
3657 |
primitiveInitializeDevice |
|
3658 |
|errorMessageOrNil| |
|
3659 |
||
3660 |
%{ |
|
3661 |
#ifdef SUPPORT_PORTAUDIO |
|
3662 |
PaError paErr = 0; |
|
3663 |
||
3664 |
if (DEBUGGING) { |
|
5429 | 3665 |
fprintf(stderr, "calling Pa_Initialize...\n"); |
5402 | 3666 |
} |
3667 |
if ((paErr = Pa_Initialize()) != paNoError ) { |
|
5429 | 3668 |
errorMessageOrNil = __MKSTRING(Pa_GetErrorText( paErr ) ); |
3669 |
fprintf(stderr, "SoundStream [error]: Pa_Initialize failed\n"); |
|
5402 | 3670 |
}; |
3671 |
#endif |
|
3672 |
%}. |
|
3673 |
errorMessageOrNil notNil ifTrue:[ |
|
5429 | 3674 |
self error:'failed to initialize audio device: ',errorMessageOrNil |
5402 | 3675 |
]. |
3676 |
||
3677 |
! ! |
|
3678 |
||
3679 |
!SoundStream::PortAudio class methodsFor:'queries'! |
|
3680 |
||
5423 | 3681 |
defaultAudioFormat |
3682 |
^ #S16 |
|
3683 |
! |
|
3684 |
||
5402 | 3685 |
isSupported |
3686 |
%{ |
|
3687 |
#ifdef SUPPORT_PORTAUDIO |
|
3688 |
RETURN(true); |
|
3689 |
#endif |
|
3690 |
%}. |
|
3691 |
^ false. |
|
3692 |
! ! |
|
3693 |
||
3694 |
!SoundStream::PortAudio methodsFor:'misc'! |
|
3695 |
||
3696 |
flush |
|
3697 |
"wait until all sound has been played" |
|
3698 |
||
5419 | 3699 |
[self hasOutputPending] whileTrue:[ |
5429 | 3700 |
Delay waitForMilliseconds:20. |
3701 |
"/ Processor yield |
|
5419 | 3702 |
] |
3703 |
! |
|
3704 |
||
3705 |
hasOutputPending |
|
5402 | 3706 |
%{ |
3707 |
#ifdef SUPPORT_PORTAUDIO |
|
3708 |
OBJ str; |
|
3709 |
if ((str = __INST(handle1)) != nil) { |
|
5429 | 3710 |
struct paStreamData* streamData = (struct paStreamData*)__externalAddressVal(str); |
3711 |
||
3712 |
RETURN ((streamData->currentBuffer != NULL) ? true : false); |
|
5402 | 3713 |
} |
3714 |
#endif /* SUPPORT_PORTAUDIO */ |
|
3715 |
%}. |
|
5419 | 3716 |
^ false |
5429 | 3717 |
! |
3718 |
||
3719 |
outputBytesPending |
|
3720 |
%{ |
|
3721 |
#ifdef SUPPORT_PORTAUDIO |
|
3722 |
OBJ str; |
|
3723 |
int n = 0; |
|
3724 |
||
3725 |
if ((str = __INST(handle1)) != nil) { |
|
3726 |
struct paStreamData* streamData = (struct paStreamData*)__externalAddressVal(str); |
|
3727 |
int offs; |
|
3728 |
struct paBuffer *buffer; |
|
3729 |
||
3730 |
if (streamData != NULL) { |
|
3731 |
offs = streamData->readOffset; |
|
3732 |
||
3733 |
buffer = streamData->currentBuffer; |
|
3734 |
if (buffer != NULL) { |
|
3735 |
n = buffer->bufferSize - offs; |
|
3736 |
while ((buffer = buffer->nextBuffer) != NULL) { |
|
3737 |
n += buffer->bufferSize; |
|
3738 |
} |
|
3739 |
} |
|
3740 |
} |
|
3741 |
} |
|
3742 |
RETURN (__MKSMALLINT(n)); |
|
3743 |
#endif /* SUPPORT_PORTAUDIO */ |
|
3744 |
%}. |
|
3745 |
^ 0 |
|
5402 | 3746 |
! ! |
3747 |
||
3748 |
!SoundStream::PortAudio methodsFor:'open & close'! |
|
3749 |
||
3750 |
closeFile |
|
3751 |
"a stream has been collected - close the file" |
|
3752 |
||
3753 |
%{ |
|
3754 |
#ifdef SUPPORT_PORTAUDIO |
|
3755 |
OBJ str; |
|
3756 |
if ((str = __INST(handle1)) != nil) { |
|
5429 | 3757 |
struct paStreamData* streamData = (struct paStreamData*)__externalAddressVal(str); |
3758 |
struct paBuffer* buffer; |
|
3759 |
||
3760 |
if (DEBUGGING) { |
|
3761 |
fprintf(stderr, "pa close\n"); |
|
3762 |
} |
|
3763 |
__externalAddressVal(str) = NULL; |
|
3764 |
__INST(handle1) = nil; |
|
3765 |
// Pa_StopStream( streamData->stream ); |
|
3766 |
Pa_CloseStream( streamData->stream ); |
|
3767 |
||
3768 |
LOCK(streamData->lock); |
|
3769 |
||
3770 |
buffer = streamData->currentBuffer; |
|
3771 |
streamData->currentBuffer = NULL; |
|
3772 |
streamData->lastBuffer = NULL; |
|
3773 |
while (buffer != NULL) { |
|
3774 |
struct paBuffer* nextBuffer = buffer->nextBuffer; |
|
3775 |
free(buffer->sampleData); |
|
3776 |
free(buffer); |
|
3777 |
buffer = nextBuffer; |
|
3778 |
} |
|
3779 |
buffer = streamData->freeList; |
|
3780 |
streamData->freeList = NULL; |
|
3781 |
while (buffer != NULL) { |
|
3782 |
struct paBuffer* nextBuffer = buffer->nextBuffer; |
|
3783 |
free(buffer->sampleData); |
|
3784 |
free(buffer); |
|
3785 |
buffer = nextBuffer; |
|
3786 |
} |
|
3787 |
||
3788 |
UNLOCK(streamData->lock); |
|
3789 |
RELEASELOCK(streamData->lock); |
|
3790 |
free(streamData); |
|
5402 | 3791 |
} |
3792 |
RETURN (self); |
|
3793 |
#endif // SUPPORT_PORTAUDIO |
|
3794 |
%}. |
|
3795 |
! |
|
3796 |
||
3797 |
openWithMode:aMode attributes:attributeSpec |
|
3798 |
|ok error errorStringOrNil| |
|
3799 |
||
5409 | 3800 |
openMode := aMode. |
3801 |
openAttributes := attributeSpec. |
|
5402 | 3802 |
%{ |
3803 |
#ifdef SUPPORT_PORTAUDIO |
|
3804 |
static PaStreamParameters outputParameters; |
|
3805 |
PaStream *stream; |
|
3806 |
PaError paErr; |
|
5421 | 3807 |
struct paStreamData* streamData; |
5402 | 3808 |
int nChannels, sampleRate, bytesPerSample; |
3809 |
# define FRAMES_PER_BUFFER 128 |
|
3810 |
||
3811 |
ok = false; |
|
3812 |
||
3813 |
/* default output device */ |
|
3814 |
outputParameters.device = Pa_GetDefaultOutputDevice(); |
|
3815 |
if (outputParameters.device == paNoDevice) { |
|
5429 | 3816 |
fprintf(stderr, "SoundStream [warning]: No default output device.\n"); |
3817 |
errorStringOrNil = __MKSTRING("No default output device"); |
|
3818 |
goto out; |
|
5402 | 3819 |
} |
3820 |
||
3821 |
if (__isSmallInteger(__INST(numberOfChannels))) { |
|
5429 | 3822 |
nChannels = __intVal(__INST(numberOfChannels)); |
5402 | 3823 |
} else { |
5429 | 3824 |
nChannels = 1; |
5402 | 3825 |
} |
3826 |
outputParameters.channelCount = nChannels; |
|
3827 |
outputParameters.suggestedLatency = Pa_GetDeviceInfo( outputParameters.device )->defaultLowOutputLatency; |
|
3828 |
outputParameters.hostApiSpecificStreamInfo = NULL; |
|
3829 |
||
3830 |
// The standard formats paFloat32, paInt16, paInt32, paInt24, paInt8 |
|
3831 |
// and aUInt8 are usually implemented by all implementations. |
|
3832 |
// The floating point representation (paFloat32) uses +1.0 and -1.0 as the |
|
3833 |
// maximum and minimum respectively. |
|
3834 |
// paUInt8 is an unsigned 8 bit format where 128 is considered "ground" |
|
3835 |
||
3836 |
if (__INST(audioFormat) == @symbol(S16)) { |
|
5429 | 3837 |
outputParameters.sampleFormat = paInt16; |
3838 |
bytesPerSample = 2; |
|
5402 | 3839 |
} else if (__INST(audioFormat) == @symbol(S32)) { |
5429 | 3840 |
outputParameters.sampleFormat = paInt32; |
3841 |
bytesPerSample = 4; |
|
5402 | 3842 |
} else if (__INST(audioFormat) == @symbol(S24)) { |
5429 | 3843 |
outputParameters.sampleFormat = paInt24; |
3844 |
bytesPerSample = 3; |
|
5402 | 3845 |
} else if (__INST(audioFormat) == @symbol(S8)) { |
5429 | 3846 |
outputParameters.sampleFormat = paInt8; |
3847 |
bytesPerSample = 1; |
|
5402 | 3848 |
} else if (__INST(audioFormat) == @symbol(F32)) { |
5429 | 3849 |
outputParameters.sampleFormat = paFloat32; |
3850 |
bytesPerSample = 4; |
|
5402 | 3851 |
} else if (__INST(audioFormat) == @symbol(U8)) { |
5429 | 3852 |
outputParameters.sampleFormat = paUInt8; |
3853 |
bytesPerSample = 1; |
|
5402 | 3854 |
} else { |
5429 | 3855 |
fprintf(stderr, "SoundStream [warning]: unknown format - using U8\n"); |
3856 |
outputParameters.sampleFormat = paUInt8; |
|
3857 |
bytesPerSample = 1; |
|
5402 | 3858 |
} |
3859 |
||
3860 |
if (__isSmallInteger(__INST(sampleRate))) { |
|
5429 | 3861 |
sampleRate = __intVal(__INST(sampleRate)); |
5402 | 3862 |
} else { |
5429 | 3863 |
fprintf(stderr, "SoundStream [warning]: using default sampleRate 8000\n"); |
3864 |
sampleRate = 8000; |
|
5402 | 3865 |
} |
3866 |
||
5421 | 3867 |
streamData = (struct paStreamData*)malloc(sizeof(struct paStreamData)); |
3868 |
if (streamData == NULL) { |
|
5429 | 3869 |
fprintf(stderr, "SoundStream [warning]: failed to allocate paStream\n"); |
3870 |
errorStringOrNil = __MKSTRING("failed to allocate paStream"); |
|
3871 |
goto out; |
|
5402 | 3872 |
} |
3873 |
||
3874 |
paErr = Pa_OpenStream( |
|
5429 | 3875 |
&stream, |
3876 |
NULL, /* no input */ |
|
3877 |
&outputParameters, |
|
3878 |
sampleRate, |
|
3879 |
FRAMES_PER_BUFFER, |
|
3880 |
paClipOff, /* we won't output out of range samples so don't bother clipping them */ |
|
3881 |
paCallback, |
|
3882 |
streamData ); |
|
5402 | 3883 |
|
3884 |
if (paErr != paNoError) { |
|
5429 | 3885 |
fprintf(stderr, "SoundStream [warning]: openStream: %s\n", Pa_GetErrorText( paErr )); |
3886 |
free(streamData); |
|
3887 |
errorStringOrNil = __MKSTRING(Pa_GetErrorText( paErr )); |
|
3888 |
goto out; |
|
5402 | 3889 |
} |
5421 | 3890 |
streamData->stream = stream; |
3891 |
INITLOCK(streamData->lock); |
|
3892 |
streamData->readOffset = 0; |
|
3893 |
streamData->bytesPerSample = bytesPerSample; |
|
3894 |
streamData->nChannels = nChannels; |
|
3895 |
||
3896 |
streamData->currentBuffer = NULL; |
|
3897 |
streamData->lastBuffer = NULL; |
|
3898 |
streamData->freeList = NULL; |
|
3899 |
streamData->hasFinished = 0; |
|
5402 | 3900 |
|
3901 |
{ |
|
5429 | 3902 |
OBJ t; |
3903 |
t = __MKEXTERNALADDRESS(streamData); __INST(handle1) = t; __STORE(self, t); |
|
5402 | 3904 |
} |
3905 |
__INST(binary) = true; |
|
3906 |
||
3907 |
paErr = Pa_SetStreamFinishedCallback( stream, &paStreamFinished ); |
|
3908 |
if( paErr != paNoError ) { |
|
5429 | 3909 |
fprintf(stderr, "SoundStream [warning]: setFinishedCallback: %s\n", Pa_GetErrorText( paErr )); |
3910 |
free(streamData); |
|
3911 |
errorStringOrNil = __MKSTRING(Pa_GetErrorText( paErr )); |
|
3912 |
goto out; |
|
5402 | 3913 |
}; |
3914 |
||
3915 |
ok = true; |
|
3916 |
out:; |
|
3917 |
#endif /* SUPPORT_PORTAUDIO */ |
|
3918 |
||
3919 |
%}. |
|
3920 |
ok == false ifTrue:[ |
|
5429 | 3921 |
lastErrorString := errorStringOrNil. |
3922 |
lastErrorNumber := error ? -1. |
|
3923 |
self openError:error. |
|
3924 |
"normally not reached" |
|
3925 |
^ nil. |
|
5402 | 3926 |
]. |
3927 |
self registerForFinalization. |
|
3928 |
||
5407 | 3929 |
! |
3930 |
||
3931 |
reopenStream |
|
5408 | 3932 |
handle1 isNil ifTrue:[^ self]. |
5409 | 3933 |
self closeFile. |
3934 |
self openWithMode:openMode attributes:openAttributes |
|
5402 | 3935 |
! ! |
3936 |
||
3937 |
!SoundStream::PortAudio methodsFor:'private'! |
|
3938 |
||
3939 |
initialize |
|
3940 |
"initialize for least common mode" |
|
3941 |
||
3942 |
super initialize. |
|
3943 |
||
3944 |
(IsInitialized ? false) ifFalse:[ |
|
5429 | 3945 |
self class primitiveInitializeDevice |
5402 | 3946 |
]. |
3947 |
||
3948 |
"Created: 17.11.1995 / 17:28:14 / cg" |
|
5407 | 3949 |
! |
3950 |
||
3951 |
setAudioFormat:aSymbol |
|
3952 |
super setAudioFormat:aSymbol. |
|
3953 |
self reopenStream |
|
3954 |
! |
|
3955 |
||
3956 |
setChannels:numChannels |
|
3957 |
super setChannels:numChannels. |
|
3958 |
self reopenStream |
|
3959 |
! |
|
3960 |
||
3961 |
setFragmentSize:blockSize |
|
3962 |
super setFragmentSize:blockSize. |
|
3963 |
self reopenStream |
|
3964 |
! |
|
3965 |
||
3966 |
setSampleRate:hz |
|
3967 |
super setSampleRate:hz. |
|
3968 |
self reopenStream |
|
5402 | 3969 |
! ! |
3970 |
||
3971 |
!SoundStream::PortAudio methodsFor:'queries'! |
|
3972 |
||
3973 |
supportedAudioFormats |
|
3974 |
"return a collection of supported audio formats. |
|
3975 |
possibly returned symbols are: |
|
5429 | 3976 |
U8 unsigned 8bit samples |
3977 |
S8 signed 8bit samples |
|
3978 |
U16 unsigned 16bit samples in native format |
|
3979 |
U16_LE unsigned 16bit big endian samples |
|
3980 |
U16_BE unsigned 16bit big endian samples |
|
3981 |
S16 signed 16bit little endian samples in native format |
|
3982 |
S16_LE signed 16bit little endian samples |
|
3983 |
S16_BE signed 16bit big endian samples |
|
3984 |
S24 signed 24bit little endian samples in native format |
|
3985 |
S24_LE signed 24bit little endian samples |
|
3986 |
S24_BE signed 24bit big endian samples |
|
3987 |
S32 signed 32bit little endian samples in native format |
|
3988 |
S32_LE signed 32bit little endian samples |
|
3989 |
S32_BE signed 32bit big endian samples |
|
3990 |
F32 float samples |
|
3991 |
MPEG audio mpeg encoded |
|
3992 |
MU_LAW u-law encoded 8bit samples |
|
3993 |
A_LAW a-law encoded 8bit samples |
|
3994 |
IMA_ADPCM adpcm encoded |
|
5402 | 3995 |
the set of returned symbols depends on the underlying sound hardware. |
3996 |
" |
|
3997 |
||
5408 | 3998 |
^ #(U8 S8 S16_LE S16 S24_LE S24 S32_LE S32 F32) |
5402 | 3999 |
|
4000 |
" |
|
4001 |
|s formats| |
|
4002 |
||
4003 |
s := self writing. |
|
4004 |
formats := s supportedAudioFormats. |
|
4005 |
s close. |
|
4006 |
formats |
|
4007 |
" |
|
4008 |
! ! |
|
4009 |
||
4010 |
!SoundStream::PortAudio methodsFor:'reading'! |
|
4011 |
||
4012 |
nextBytes:count into:anObject startingAt:start |
|
4013 |
"read the next count bytes into an object and return the number of |
|
4014 |
bytes read or nil on error. |
|
4015 |
Use with ByteArrays only." |
|
4016 |
||
4017 |
self errorUnsupportedOperation |
|
4018 |
! ! |
|
4019 |
||
4020 |
!SoundStream::PortAudio methodsFor:'writing'! |
|
4021 |
||
4022 |
nextPutBytes:count from:anObject startingAt:start |
|
4023 |
"write count bytes from an object starting at index start. |
|
4024 |
return the number of bytes written or nil on error. |
|
4025 |
Redefined, since IRIS audio library cannot be used with stdio. |
|
4026 |
(at least I don't know). Use with ByteArrays only." |
|
4027 |
||
4028 |
%{ |
|
4029 |
#ifdef SUPPORT_PORTAUDIO |
|
4030 |
OBJ str; |
|
4031 |
||
4032 |
if ((str = __INST(handle1)) != nil) { |
|
5429 | 4033 |
if (__INST(mode) != @symbol(readonly)) { |
4034 |
if (__bothSmallInteger(count, start)) { |
|
4035 |
// allocate a buffer |
|
4036 |
struct paStreamData* streamData = (struct paStreamData*)__externalAddressVal(str); |
|
4037 |
int cnt = __intVal(count); |
|
4038 |
int offs = __intVal(start) - 1; |
|
4039 |
int objSize; |
|
4040 |
||
4041 |
objSize = _Size(anObject) - OHDR_SIZE; |
|
4042 |
if ( (offs >= 0) && (cnt >= 0) && (objSize >= (cnt + offs)) ) { |
|
4043 |
struct paBuffer* newBuffer; |
|
4044 |
struct paBuffer* toFree; |
|
4045 |
int mustStart = 0; |
|
4046 |
unsigned char* newSampleData; |
|
4047 |
||
4048 |
// try freeList |
|
4049 |
LOCK(streamData->lock); |
|
4050 |
if ((streamData->freeList != NULL) |
|
4051 |
&& (streamData->freeList->bufferSize == cnt)) { |
|
4052 |
// reuse |
|
4053 |
newBuffer = streamData->freeList; |
|
4054 |
streamData->freeList = newBuffer->nextBuffer; |
|
4055 |
newSampleData = newBuffer->sampleData; |
|
4056 |
toFree = NULL; |
|
4057 |
if (DEBUGGING) { |
|
4058 |
fprintf(stderr, "from free: %p (->%p)\n", newBuffer, newBuffer->sampleData); |
|
4059 |
} |
|
4060 |
} else { |
|
4061 |
// free them all |
|
4062 |
toFree = streamData->freeList; |
|
4063 |
streamData->freeList = NULL; |
|
4064 |
newBuffer = malloc(sizeof(struct paBuffer)); |
|
4065 |
newSampleData = malloc(cnt); |
|
4066 |
newBuffer->sampleData = newSampleData; |
|
4067 |
newBuffer->bufferSize = cnt; |
|
4068 |
if (DEBUGGING) { |
|
4069 |
fprintf(stderr, "alloc: %p (->%p)\n", newBuffer, newBuffer->sampleData); |
|
4070 |
} |
|
4071 |
} |
|
4072 |
||
4073 |
memcpy(newSampleData, (__ByteArrayInstPtr(anObject)->ba_element)+offs, cnt); |
|
4074 |
newBuffer->nextBuffer = NULL; |
|
4075 |
||
4076 |
if (streamData->lastBuffer == NULL) { |
|
4077 |
// start stream's buffer list |
|
4078 |
streamData->currentBuffer = newBuffer; |
|
4079 |
mustStart = 1; |
|
4080 |
} else { |
|
4081 |
// append to stream's buffer list |
|
4082 |
streamData->lastBuffer->nextBuffer = newBuffer; |
|
4083 |
} |
|
4084 |
streamData->lastBuffer = newBuffer; |
|
4085 |
streamData->hasFinished = 0; |
|
4086 |
UNLOCK(streamData->lock); |
|
4087 |
||
4088 |
if (mustStart) { |
|
4089 |
PaError paErr = Pa_StartStream( streamData->stream ); |
|
4090 |
if ( paErr != paNoError ) { |
|
4091 |
if (DEBUGGING) { |
|
4092 |
fprintf(stderr, "start error\n"); |
|
4093 |
} |
|
4094 |
RETURN (0); |
|
4095 |
}; |
|
4096 |
} |
|
4097 |
RETURN (count); |
|
4098 |
} |
|
4099 |
} |
|
4100 |
} |
|
5402 | 4101 |
} |
4102 |
#endif /* SUPPORT_PORTAUDIO */ |
|
4103 |
||
4104 |
%}. |
|
5405 | 4105 |
self errorUnsupportedOperation |
5402 | 4106 |
! ! |
4107 |
||
4108 |
!SoundStream::Win32DirectSound class methodsFor:'documentation'! |
|
4109 |
||
4110 |
documentation |
|
4111 |
" |
|
5424 | 4112 |
interface to the windows direct sound API |
5402 | 4113 |
" |
4114 |
! ! |
|
4115 |
||
4116 |
!SoundStream::Win32DirectSound class methodsFor:'queries'! |
|
4117 |
||
4118 |
isSupported |
|
4119 |
%{ |
|
4120 |
#ifdef SUPPORT_WIN32_DIRECTSOUND |
|
4121 |
RETURN(true); |
|
4122 |
#endif |
|
4123 |
%}. |
|
4124 |
^ false. |
|
4125 |
! ! |
|
4126 |
||
4127 |
!SoundStream::Win32DirectSound methodsFor:'misc'! |
|
4128 |
||
4129 |
flush |
|
4130 |
"wait until all sound has been played" |
|
4131 |
||
4132 |
"/ as yet unimplemented |
|
4133 |
^ self |
|
4134 |
! ! |
|
4135 |
||
4136 |
!SoundStream::Win32DirectSound methodsFor:'open & close'! |
|
4137 |
||
4138 |
closeFile |
|
4139 |
"a stream has been collected - close the file" |
|
4140 |
||
4141 |
%{ |
|
4142 |
#ifdef SUPPORT_WIN32_DIRECTSOUND |
|
4143 |
OBJ oDirectSound, oDSBuffer; |
|
4144 |
LPDIRECTSOUND t_pDirectSound; |
|
4145 |
LPDIRECTSOUNDBUFFER t_pDSBuffer; |
|
4146 |
||
4147 |
if ((oDSBuffer = __INST(pDSBuffer)) != nil) { |
|
5429 | 4148 |
__INST(pDSBuffer) = nil; |
4149 |
t_pDSBuffer = __DSBufferVal(oDSBuffer); |
|
4150 |
if (t_pDSBuffer) { |
|
4151 |
IDirectSoundBuffer_Stop(t_pDSBuffer); |
|
4152 |
IDirectSoundBuffer_Release(t_pDSBuffer); |
|
4153 |
} |
|
5402 | 4154 |
} |
4155 |
if ((oDirectSound = __INST(pDirectSound)) != nil) { |
|
5429 | 4156 |
__INST(pDirectSound) = nil; |
4157 |
t_pDirectSound = __DirectSoundVal(oDirectSound); |
|
4158 |
if (t_pDirectSound) { |
|
4159 |
IDirectSound_Release(t_pDirectSound); |
|
4160 |
} |
|
5402 | 4161 |
} |
4162 |
RETURN (self); |
|
4163 |
#endif /* SUPPORT_WIN32_DIRECTSOUND */ |
|
4164 |
%}. |
|
4165 |
||
4166 |
! |
|
4167 |
||
4168 |
openWithMode:aMode attributes:attributeSpec |
|
4169 |
|ok error errorStringOrNil| |
|
4170 |
||
4171 |
%{ |
|
4172 |
#ifdef SUPPORT_WIN32_DIRECTSOUND |
|
4173 |
HRESULT result; |
|
4174 |
LPDIRECTSOUND t_pDirectSound; |
|
4175 |
LPDIRECTSOUNDBUFFER t_pDSBuffer, t_pDSPrimeBuffer; |
|
4176 |
WAVEFORMATEX wfFormat; |
|
4177 |
DSBUFFERDESC dsbdDesc, primarydsbDesc; |
|
4178 |
BYTE *pDSBuffData; |
|
4179 |
int t_cbBufSize; |
|
4180 |
int dwDataLen; |
|
4181 |
||
4182 |
ok = false; |
|
4183 |
||
4184 |
/* Create the DS object */ |
|
4185 |
if ((result = DirectSoundCreate(NULL, &t_pDirectSound, NULL)) != DS_OK) { |
|
5429 | 4186 |
console_fprintf(stderr,"SoundStream: Cannot open default sound device!!\n"); |
4187 |
goto out; |
|
5402 | 4188 |
} |
4189 |
||
4190 |
/* Define the wave format structure */ |
|
4191 |
wfFormat.wFormatTag = WAVE_FORMAT_PCM; |
|
4192 |
wfFormat.nChannels = __intVal(__INST(numberOfChannels)); |
|
4193 |
wfFormat.nSamplesPerSec = __intVal(__INST(sampleRate)); |
|
4194 |
wfFormat.wBitsPerSample = __intVal(__INST(bitsPerSample)); |
|
4195 |
wfFormat.nBlockAlign = wfFormat.nChannels * wfFormat.wBitsPerSample / 8; |
|
4196 |
wfFormat.nAvgBytesPerSec = wfFormat.nSamplesPerSec * wfFormat.nBlockAlign; |
|
4197 |
wfFormat.cbSize = 0; |
|
4198 |
||
4199 |
# if 0 |
|
4200 |
/* Setup the primary DS buffer description */ |
|
4201 |
ZeroMemory(&primarydsbDesc, sizeof(DSBUFFERDESC)); |
|
4202 |
primarydsbDesc.dwSize = sizeof(DSBUFFERDESC); |
|
4203 |
primarydsbDesc.dwFlags = DSBCAPS_PRIMARYBUFFER; |
|
4204 |
primarydsbDesc.dwBufferBytes = 0; |
|
4205 |
primarydsbDesc.lpwfxFormat = NULL; |
|
4206 |
||
4207 |
/* Create the primary DS buffer */ |
|
4208 |
if ((result = IDirectSound_CreateSoundBuffer(t_pDirectSound, &primarydsbDesc, |
|
5429 | 4209 |
&t_pDSPrimeBuffer, NULL)) != DS_OK) { |
4210 |
console_fprintf(stderr,"SoundStream: Cannot get the primary DS buffer address!\n"); |
|
4211 |
IDirectSound_Release(t_pDirectSound); |
|
4212 |
goto out; |
|
5402 | 4213 |
} |
4214 |
||
4215 |
/* Set the primary DS buffer sound format. We have to do this because |
|
4216 |
the default primary buffer is 8-bit, 22kHz! */ |
|
4217 |
if ((result = IDirectSoundBuffer_SetFormat(t_pDSPrimeBuffer, &wfFormat)) != DS_OK) { |
|
5429 | 4218 |
console_fprintf(stderr,"SoundStream: Cannot set the primary DS buffer to proper sound format (%x) (%d)!\n", result, result); |
4219 |
IDirectSoundBuffer_Stop(t_pDSPrimeBuffer); |
|
4220 |
IDirectSoundBuffer_Release(t_pDSPrimeBuffer); |
|
4221 |
IDirectSound_Release(t_pDirectSound); |
|
4222 |
goto out; |
|
5402 | 4223 |
} |
4224 |
# endif /* 0 */ |
|
4225 |
||
4226 |
/* Setup the secondary DS buffer description */ |
|
4227 |
t_cbBufSize = RT_BUFFER_SIZE * sizeof(short) * NBUFS; |
|
4228 |
__INST(bufferSize) = __MKSMALLINT(t_cbBufSize); |
|
4229 |
||
4230 |
ZeroMemory(&dsbdDesc, sizeof(DSBUFFERDESC)); |
|
4231 |
dsbdDesc.dwSize = sizeof(DSBUFFERDESC); |
|
4232 |
dsbdDesc.dwFlags = DSBCAPS_GLOBALFOCUS; |
|
4233 |
dsbdDesc.dwBufferBytes = t_cbBufSize; |
|
4234 |
dsbdDesc.lpwfxFormat = &wfFormat; |
|
4235 |
||
4236 |
/* Create the secondary DS buffer */ |
|
4237 |
if ((result = IDirectSound_CreateSoundBuffer(t_pDirectSound, &dsbdDesc, &t_pDSBuffer, NULL)) != DS_OK) { |
|
5429 | 4238 |
console_fprintf(stderr,"SoundStream: couldn't create sound buffer!\n"); |
4239 |
IDirectSoundBuffer_Stop(t_pDSPrimeBuffer); |
|
4240 |
IDirectSoundBuffer_Release(t_pDSPrimeBuffer); |
|
4241 |
IDirectSound_Release(t_pDirectSound); |
|
4242 |
goto out; |
|
5402 | 4243 |
} |
4244 |
||
4245 |
/* Lock the DS buffer */ |
|
4246 |
if ((result = IDirectSoundBuffer_Lock(t_pDSBuffer, 0, t_cbBufSize, (LPLPVOID)&pDSBuffData, |
|
5429 | 4247 |
&dwDataLen, NULL, NULL, 0)) != DS_OK) { |
4248 |
console_fprintf(stderr,"SoundStream: couldn't lock sound buffer!\n"); |
|
4249 |
goto errorAndOut; |
|
5402 | 4250 |
} |
4251 |
||
4252 |
/* Zero the DS buffer */ |
|
4253 |
ZeroMemory(pDSBuffData, dwDataLen); |
|
4254 |
||
4255 |
/* Unlock the DS buffer */ |
|
4256 |
if ((result = IDirectSoundBuffer_Unlock(t_pDSBuffer, pDSBuffData, dwDataLen, NULL, 0)) != DS_OK) { |
|
5429 | 4257 |
console_fprintf(stderr,"SoundStream: couldn't unlock sound buffer!\n"); |
4258 |
goto errorAndOut; |
|
5402 | 4259 |
} |
4260 |
||
4261 |
__INST(bufferOffset) = __MKSMALLINT(0); // reset last write position to start of buffer |
|
4262 |
||
4263 |
/* Start the buffer playback */ |
|
4264 |
if ((result = IDirectSoundBuffer_Play(t_pDSBuffer, 0, 0, DSBPLAY_LOOPING) != DS_OK)) { |
|
5429 | 4265 |
console_fprintf(stderr,"SoundStream: couldn't play sound buffer!\n"); |
5402 | 4266 |
|
4267 |
errorAndOut: |
|
5429 | 4268 |
IDirectSoundBuffer_Stop(t_pDSBuffer); |
4269 |
IDirectSoundBuffer_Stop(t_pDSPrimeBuffer); |
|
4270 |
IDirectSoundBuffer_Release(t_pDSPrimeBuffer); |
|
4271 |
IDirectSound_Release(t_pDirectSound); |
|
4272 |
goto out; |
|
5402 | 4273 |
} |
4274 |
||
4275 |
{ |
|
5429 | 4276 |
OBJ t; |
4277 |
||
4278 |
t = __MKEXTERNALADDRESS(t_pDSBuffer); __INST(pDSBuffer) = t; __STORE(self, t); |
|
4279 |
t = __MKEXTERNALADDRESS(t_pDirectSound); __INST(pDirectSound) = t; __STORE(self, t); |
|
5402 | 4280 |
} |
4281 |
ok = true; |
|
4282 |
out:; |
|
4283 |
#endif /* SUPPORT_WIN32_DIRECTSOUND */ |
|
4284 |
||
4285 |
%}. |
|
4286 |
ok == false ifTrue:[ |
|
5429 | 4287 |
lastErrorString := errorStringOrNil. |
4288 |
lastErrorNumber := error ? -1. |
|
4289 |
self openError:error. |
|
4290 |
"normally not reached" |
|
4291 |
^ nil. |
|
5402 | 4292 |
]. |
4293 |
self registerForFinalization. |
|
4294 |
! ! |
|
4295 |
||
4296 |
!SoundStream::Win32DirectSound methodsFor:'queries'! |
|
4297 |
||
4298 |
supportedAudioFormats |
|
4299 |
"return a collection of supported audio formats. |
|
4300 |
possibly returned symbols are: |
|
5429 | 4301 |
U8 unsigned 8bit samples |
4302 |
S8 signed 8bit samples |
|
4303 |
U16 unsigned 16bit samples in native format |
|
4304 |
U16_LE unsigned 16bit big endian samples |
|
4305 |
U16_BE unsigned 16bit big endian samples |
|
4306 |
S16 signed 16bit little endian samples in native format |
|
4307 |
S16_LE signed 16bit little endian samples |
|
4308 |
S16_BE signed 16bit big endian samples |
|
4309 |
S24 signed 24bit little endian samples in native format |
|
4310 |
S24_LE signed 24bit little endian samples |
|
4311 |
S24_BE signed 24bit big endian samples |
|
4312 |
S32 signed 32bit little endian samples in native format |
|
4313 |
S32_LE signed 32bit little endian samples |
|
4314 |
S32_BE signed 32bit big endian samples |
|
4315 |
F32 float samples |
|
4316 |
MPEG audio mpeg encoded |
|
4317 |
MU_LAW u-law encoded 8bit samples |
|
4318 |
A_LAW a-law encoded 8bit samples |
|
4319 |
IMA_ADPCM adpcm encoded |
|
5402 | 4320 |
the set of returned symbols depends on the underlying sound hardware. |
4321 |
" |
|
4322 |
||
4323 |
^ #(S16_LE S16) |
|
4324 |
||
4325 |
" |
|
4326 |
|s formats| |
|
4327 |
||
4328 |
s := self writing. |
|
4329 |
formats := s supportedAudioFormats. |
|
4330 |
s close. |
|
4331 |
formats |
|
4332 |
" |
|
4333 |
! ! |
|
4334 |
||
4335 |
!SoundStream::Win32DirectSound methodsFor:'reading'! |
|
4336 |
||
4337 |
nextBytes:count into:anObject startingAt:start |
|
4338 |
"read the next count bytes into an object and return the number of |
|
4339 |
bytes read or nil on error. |
|
4340 |
Use with ByteArrays only." |
|
4341 |
||
4342 |
self errorUnsupportedOperation |
|
4343 |
! ! |
|
4344 |
||
4345 |
!SoundStream::Win32DirectSound methodsFor:'writing'! |
|
4346 |
||
4347 |
nextPutBytes:count from:anObject startingAt:start |
|
4348 |
"write count bytes from an object starting at index start. |
|
4349 |
return the number of bytes written or nil on error. |
|
4350 |
Redefined, since IRIS audio library cannot be used with stdio. |
|
4351 |
(at least I don't know). Use with ByteArrays only." |
|
4352 |
||
4353 |
%{ |
|
4354 |
#ifdef SUPPORT_WIN32_DIRECTSOUND |
|
4355 |
{ |
|
4356 |
HRESULT hr; |
|
4357 |
DWORD status; |
|
4358 |
LPVOID lpbuf1 = NULL; |
|
4359 |
LPVOID lpbuf2 = NULL; |
|
4360 |
DWORD dwsize1 = 0; |
|
4361 |
DWORD dwsize2 = 0; |
|
4362 |
DWORD playPos, safePos, endWrite; |
|
4363 |
DWORD millis; |
|
4364 |
OBJ oDirectSound, oDSBuffer; |
|
4365 |
LPDIRECTSOUND t_pDirectSound = (LPDIRECTSOUND)0; |
|
4366 |
LPDIRECTSOUNDBUFFER t_pDSBuffer = (LPDIRECTSOUNDBUFFER)0; |
|
4367 |
int t_cbBufOffset, t_cbBufSize; |
|
4368 |
short *buf; |
|
4369 |
int cnt, offs; |
|
4370 |
||
4371 |
if ((oDSBuffer = __INST(pDSBuffer)) != nil) { |
|
5429 | 4372 |
t_pDSBuffer = __DSBufferVal(oDSBuffer); |
5402 | 4373 |
} |
4374 |
if ((oDirectSound = __INST(pDirectSound)) != nil) { |
|
5429 | 4375 |
t_pDirectSound = __DirectSoundVal(oDirectSound); |
5402 | 4376 |
} |
4377 |
||
4378 |
if (!t_pDSBuffer || !t_pDirectSound) { |
|
5429 | 4379 |
console_fprintf(stderr, "SoundStream not open!\n"); |
4380 |
RETURN (0); |
|
5402 | 4381 |
} |
4382 |
t_cbBufOffset = __intVal(__INST(bufferOffset)); |
|
4383 |
t_cbBufSize = __intVal(__INST(bufferSize)); |
|
4384 |
||
4385 |
cnt = __intVal(count); |
|
4386 |
offs = __intVal(start) - 1; |
|
4387 |
buf = (short *)__InstPtr(anObject) + OHDR_SIZE + offs; |
|
4388 |
||
4389 |
// Should be playing, right? |
|
4390 |
hr = IDirectSoundBuffer_GetStatus(t_pDSBuffer, &status ); |
|
4391 |
if (!(status && DSBSTATUS_PLAYING)) { |
|
5429 | 4392 |
console_fprintf(stderr, "Buffer not playing!\n"); |
4393 |
RETURN (0); |
|
5402 | 4394 |
} |
4395 |
||
4396 |
// Sleep until we have enough room in buffer. |
|
4397 |
hr = IDirectSoundBuffer_GetCurrentPosition(t_pDSBuffer, &playPos, &safePos ); |
|
4398 |
if( hr != DS_OK ) { |
|
5429 | 4399 |
console_fprintf(stderr, "Cannot get position!\n"); |
4400 |
RETURN (0); |
|
5402 | 4401 |
} |
4402 |
if( playPos < t_cbBufOffset ) playPos += t_cbBufSize; |
|
4403 |
||
4404 |
endWrite = t_cbBufOffset + (cnt * sizeof(short)); |
|
4405 |
while ( playPos < endWrite ) { |
|
5429 | 4406 |
// Calculate number of milliseconds until we will have room, as |
4407 |
// time = distance * (milliseconds/second) / ((bytes/sample) * (samples/second)), |
|
4408 |
// rounded up. |
|
4409 |
millis = (DWORD) (1.0 + ((endWrite - playPos) * 1000.0) / ( sizeof(short) * __intVal(__INST(sampleRate)))); |
|
4410 |
||
4411 |
// Sleep for that long |
|
4412 |
Sleep( millis ); |
|
4413 |
||
4414 |
// Wake up, find out where we are now |
|
4415 |
hr = IDirectSoundBuffer_GetCurrentPosition(t_pDSBuffer, &playPos, &safePos ); |
|
4416 |
if( hr != DS_OK ) { |
|
4417 |
console_fprintf(stderr, "Cannot get position!\n"); |
|
4418 |
RETURN (0); |
|
4419 |
} |
|
4420 |
if( playPos < t_cbBufOffset ) playPos += t_cbBufSize; // unwrap offset |
|
5402 | 4421 |
} |
4422 |
||
4423 |
// Lock free space in the DS |
|
4424 |
hr = IDirectSoundBuffer_Lock(t_pDSBuffer, t_cbBufOffset, cnt * sizeof(short), &lpbuf1, &dwsize1, &lpbuf2, &dwsize2, 0); |
|
4425 |
if (hr == DS_OK) { |
|
5429 | 4426 |
// Copy the buffer into the DS |
4427 |
CopyMemory(lpbuf1, buf, dwsize1); |
|
4428 |
if(NULL != lpbuf2) CopyMemory(lpbuf2, buf+dwsize1, dwsize2); |
|
4429 |
||
4430 |
// Update our buffer offset and unlock sound buffer |
|
4431 |
t_cbBufOffset = (t_cbBufOffset + dwsize1 + dwsize2) % t_cbBufSize; |
|
4432 |
IDirectSoundBuffer_Unlock(t_pDSBuffer, lpbuf1, dwsize1, lpbuf2, dwsize2); |
|
5402 | 4433 |
} |
4434 |
__INST(buffferOffset) = __MKSMALLINT(t_cbBufOffset); |
|
4435 |
||
4436 |
RETURN (count); |
|
4437 |
} |
|
4438 |
#endif /* SUPPORT_WIN32_DIRECTSOUND */ |
|
4439 |
||
4440 |
%}. |
|
5405 | 4441 |
self errorUnsupportedOperation |
5402 | 4442 |
! ! |
4443 |
||
4444 |
!SoundStream::Win32WaveSound class methodsFor:'documentation'! |
|
4445 |
||
4446 |
documentation |
|
4447 |
" |
|
5424 | 4448 |
interface to the windows wave sound API |
5402 | 4449 |
" |
4450 |
! ! |
|
4451 |
||
4452 |
!SoundStream::Win32WaveSound class methodsFor:'queries'! |
|
4453 |
||
4454 |
isSupported |
|
4455 |
%{ |
|
4456 |
#ifdef SUPPORT_WIN32_WAVESOUND |
|
4457 |
RETURN(true); |
|
4458 |
#endif |
|
4459 |
%}. |
|
4460 |
^ false. |
|
4461 |
! ! |
|
4462 |
||
4463 |
!SoundStream::Win32WaveSound methodsFor:'misc'! |
|
4464 |
||
4465 |
flush |
|
4466 |
"wait until all sound has been played" |
|
4467 |
||
4468 |
"/ as yet unimplemented |
|
4469 |
^ self |
|
4470 |
! ! |
|
4471 |
||
4472 |
!SoundStream::Win32WaveSound methodsFor:'open & close'! |
|
4473 |
||
4474 |
closeFile |
|
4475 |
"a stream has been collected - close the file" |
|
4476 |
||
4477 |
%{ |
|
4478 |
#ifdef SUPPORT_WIN32_WAVESOUND |
|
4479 |
struct buf *bp, *next; |
|
4480 |
int r; |
|
4481 |
HWAVEOUT t_waveHandle; |
|
4482 |
OBJ oWaveHandle; |
|
4483 |
||
4484 |
if ((oWaveHandle = __INST(waveHandle)) != nil) { |
|
5429 | 4485 |
t_waveHandle = __WaveHandleVal(oWaveHandle); |
5402 | 4486 |
|
4487 |
# ifdef NO_WAIT_IN_CLOSE |
|
5429 | 4488 |
/* Force cancellation of any pending buffers */ |
4489 |
(void)waveOutReset(t_waveHandle); |
|
5402 | 4490 |
# endif |
4491 |
||
5429 | 4492 |
/* Wait until all pending buffers have been freed */ |
4493 |
while (free_buffers < total_buffers) { |
|
4494 |
WaitForSingleObject(free_buffer_event, INFINITE); |
|
4495 |
} |
|
5402 | 4496 |
|
4497 |
# ifndef NO_WAIT_IN_CLOSE |
|
5429 | 4498 |
/* Force cancellation of any pending buffers */ |
4499 |
(void)waveOutReset(t_waveHandle); |
|
5402 | 4500 |
# endif |
4501 |
||
5429 | 4502 |
/* Close the device */ |
4503 |
if ((r = waveOutClose(t_waveHandle)) != 0) { |
|
4504 |
console_printf("waveOutClose\n"); |
|
4505 |
RETURN(self); |
|
4506 |
} |
|
4507 |
||
4508 |
EnterCriticalSection(&free_list_lock); |
|
4509 |
||
4510 |
/* Free allocated buffers */ |
|
4511 |
for (bp = free_list; bp != NULL; bp = next) { |
|
4512 |
next = bp->next; |
|
4513 |
(void)free(bp); |
|
4514 |
} |
|
4515 |
free_list = NULL; |
|
4516 |
||
4517 |
LeaveCriticalSection(&free_list_lock); |
|
4518 |
||
4519 |
__INST(waveHandle) = nil; |
|
5402 | 4520 |
} |
4521 |
RETURN (self); |
|
4522 |
#endif /* SUPPORT_WIN32_WAVESOUND */ |
|
4523 |
%}. |
|
4524 |
||
4525 |
! |
|
4526 |
||
4527 |
openWithMode:aMode attributes:attributeSpec |
|
4528 |
|ok error errorStringOrNil| |
|
4529 |
||
4530 |
%{ |
|
4531 |
#ifdef SUPPORT_WIN32_WAVESOUND |
|
4532 |
PCMWAVEFORMAT waveFormat; |
|
4533 |
int r; |
|
4534 |
HWAVEOUT t_waveHandle; |
|
4535 |
OBJ oWaveHandle; |
|
4536 |
||
4537 |
ok = false; |
|
4538 |
||
4539 |
if ((oWaveHandle = __INST(waveHandle)) != nil) { |
|
5429 | 4540 |
goto out; |
5402 | 4541 |
} |
4542 |
||
4543 |
waveFormat.wf.wFormatTag = WAVE_FORMAT_PCM; |
|
4544 |
waveFormat.wf.nChannels = __intVal(__INST(numberOfChannels)); |
|
4545 |
waveFormat.wf.nSamplesPerSec = __intVal(__INST(sampleRate)); |
|
4546 |
waveFormat.wBitsPerSample = __intVal(__INST(bitsPerSample)); |
|
4547 |
waveFormat.wf.nBlockAlign = waveFormat.wf.nChannels * waveFormat.wBitsPerSample / 8; |
|
4548 |
waveFormat.wf.nAvgBytesPerSec = waveFormat.wf.nSamplesPerSec * waveFormat.wf.nBlockAlign; |
|
4549 |
||
4550 |
r = waveOutOpen(&t_waveHandle, |
|
5429 | 4551 |
WAVE_MAPPER, |
4552 |
(WAVEFORMAT *)&waveFormat, |
|
4553 |
(DWORD_PTR)waveCallBack, |
|
4554 |
(DWORD_PTR)0, |
|
4555 |
CALLBACK_FUNCTION); |
|
5402 | 4556 |
if (r != 0) { |
5429 | 4557 |
console_printf("waveOutOpen\n"); |
4558 |
goto out; |
|
5402 | 4559 |
} |
4560 |
||
4561 |
(void)waveOutReset(t_waveHandle); |
|
4562 |
||
4563 |
free_list = NULL; |
|
4564 |
InitializeCriticalSection(&free_list_lock); |
|
4565 |
free_buffers = 0; |
|
4566 |
free_buffer_event = CreateEvent(NULL, FALSE, FALSE, NULL); |
|
4567 |
total_buffers = 0; |
|
4568 |
||
4569 |
{ |
|
5429 | 4570 |
OBJ t; |
4571 |
||
4572 |
t = __MKEXTERNALADDRESS(t_waveHandle); __INST(waveHandle) = t; __STORE(self, t); |
|
5402 | 4573 |
} |
4574 |
||
4575 |
# if 0 |
|
4576 |
/* |
|
4577 |
* HACK: If we immediately start writing valid audio data to the device |
|
4578 |
* then the sound is choppy in the beginning. Writing a null packet to |
|
4579 |
* to the device first seems to fix this problem although I have no idea |
|
4580 |
* why - DAC |
|
4581 |
*/ |
|
4582 |
{ |
|
5429 | 4583 |
char null[DATALEN]; |
4584 |
int i; |
|
4585 |
for (i = 0; i < DATALEN; i++) { |
|
4586 |
null[i] = 127; |
|
4587 |
} |
|
4588 |
audioWrite(null, DATALEN); |
|
5402 | 4589 |
} |
4590 |
# endif /* 0 */ |
|
4591 |
ok = true; |
|
4592 |
||
4593 |
out:; |
|
4594 |
||
4595 |
#endif /* !SUPPORT_WIN32_DIRECTSOUND */ |
|
4596 |
%}. |
|
4597 |
ok == false ifTrue:[ |
|
5429 | 4598 |
lastErrorString := errorStringOrNil. |
4599 |
lastErrorNumber := error ? -1. |
|
4600 |
self openError:error. |
|
4601 |
"normally not reached" |
|
4602 |
^ nil. |
|
5402 | 4603 |
]. |
4604 |
self registerForFinalization. |
|
4605 |
! ! |
|
4606 |
||
4607 |
!SoundStream::Win32WaveSound methodsFor:'queries'! |
|
4608 |
||
4609 |
supportedAudioFormats |
|
4610 |
"return a collection of supported audio formats. |
|
4611 |
possibly returned symbols are: |
|
5429 | 4612 |
U8 unsigned 8bit samples |
4613 |
S8 signed 8bit samples |
|
4614 |
U16 unsigned 16bit samples in native format |
|
4615 |
U16_LE unsigned 16bit big endian samples |
|
4616 |
U16_BE unsigned 16bit big endian samples |
|
4617 |
S16 signed 16bit little endian samples in native format |
|
4618 |
S16_LE signed 16bit little endian samples |
|
4619 |
S16_BE signed 16bit big endian samples |
|
4620 |
S24 signed 24bit little endian samples in native format |
|
4621 |
S24_LE signed 24bit little endian samples |
|
4622 |
S24_BE signed 24bit big endian samples |
|
4623 |
S32 signed 32bit little endian samples in native format |
|
4624 |
S32_LE signed 32bit little endian samples |
|
4625 |
S32_BE signed 32bit big endian samples |
|
4626 |
F32 float samples |
|
4627 |
MPEG audio mpeg encoded |
|
4628 |
MU_LAW u-law encoded 8bit samples |
|
4629 |
A_LAW a-law encoded 8bit samples |
|
4630 |
IMA_ADPCM adpcm encoded |
|
5402 | 4631 |
the set of returned symbols depends on the underlying sound hardware. |
4632 |
" |
|
4633 |
||
4634 |
^ #(S16_LE S16) |
|
4635 |
||
4636 |
" |
|
4637 |
|s formats| |
|
4638 |
||
4639 |
s := self writing. |
|
4640 |
formats := s supportedAudioFormats. |
|
4641 |
s close. |
|
4642 |
formats |
|
4643 |
" |
|
4644 |
! ! |
|
4645 |
||
4646 |
!SoundStream::Win32WaveSound methodsFor:'reading'! |
|
4647 |
||
4648 |
nextBytes:count into:anObject startingAt:start |
|
4649 |
"read the next count bytes into an object and return the number of |
|
4650 |
bytes read or nil on error. |
|
4651 |
Use with ByteArrays only." |
|
4652 |
||
4653 |
self errorUnsupportedOperation |
|
4654 |
! ! |
|
4655 |
||
4656 |
!SoundStream::Win32WaveSound methodsFor:'writing'! |
|
4657 |
||
4658 |
nextPutBytes:count from:anObject startingAt:start |
|
4659 |
"write count bytes from an object starting at index start. |
|
4660 |
return the number of bytes written or nil on error. |
|
4661 |
Redefined, since IRIS audio library cannot be used with stdio. |
|
4662 |
(at least I don't know). Use with ByteArrays only." |
|
4663 |
||
4664 |
%{ |
|
4665 |
#ifdef SUPPORT_WIN32_WAVESOUND |
|
4666 |
{ |
|
4667 |
struct buf *bp; |
|
4668 |
int len, i, r; |
|
4669 |
int dataLen, offs; |
|
4670 |
short *buf; |
|
4671 |
||
4672 |
HWAVEOUT t_waveHandle; |
|
4673 |
OBJ oWaveHandle; |
|
4674 |
||
4675 |
if ((oWaveHandle = __INST(waveHandle)) == nil) { |
|
5429 | 4676 |
RETURN(0); |
5402 | 4677 |
} |
4678 |
t_waveHandle = __WaveHandleVal(oWaveHandle); |
|
4679 |
||
4680 |
dataLen = __intVal(count); |
|
4681 |
offs = __intVal(start) - 1; |
|
4682 |
buf = (short *)__InstPtr(anObject) + OHDR_SIZE + offs; |
|
4683 |
||
4684 |
while (dataLen > 0) { |
|
5429 | 4685 |
if (free_list == NULL && total_buffers < MAXBUF) { |
4686 |
/* Expand available buffer space */ |
|
4687 |
bp = (struct buf *)malloc(sizeof(struct buf)); |
|
4688 |
total_buffers++; |
|
4689 |
} else { |
|
4690 |
if (free_list == NULL) { |
|
4691 |
/* We must wait for a free buffer */ |
|
4692 |
while (free_list == NULL) { |
|
4693 |
WaitForSingleObject(free_buffer_event, INFINITE); |
|
4694 |
} |
|
4695 |
} |
|
4696 |
EnterCriticalSection(&free_list_lock); |
|
4697 |
bp = free_list; |
|
4698 |
free_list = free_list->next; |
|
4699 |
--free_buffers; |
|
4700 |
LeaveCriticalSection(&free_list_lock); |
|
4701 |
r = waveOutUnprepareHeader(t_waveHandle, &bp->hdr, sizeof(WAVEHDR)); |
|
4702 |
if (r != 0) { |
|
4703 |
console_printf("waveOutUnprepareHeader\n"); |
|
4704 |
RETURN(self); |
|
4705 |
} |
|
4706 |
} |
|
4707 |
len = min(dataLen, DATALEN); |
|
4708 |
bp->hdr.lpData = (char *)bp->data; |
|
4709 |
bp->hdr.dwBufferLength = len; |
|
4710 |
bp->hdr.dwBytesRecorded = len; |
|
4711 |
bp->hdr.dwUser = (INT)(bp); |
|
4712 |
bp->hdr.dwFlags = 0; |
|
4713 |
bp->hdr.dwLoops = 0; |
|
4714 |
r = waveOutPrepareHeader(t_waveHandle, &bp->hdr, sizeof(WAVEHDR)); |
|
4715 |
if (r != 0) { |
|
4716 |
console_printf("waveOutPrepareHeader\n"); |
|
4717 |
RETURN(self); |
|
4718 |
} |
|
4719 |
for (i = 0; i < len; i++) { |
|
4720 |
bp->data[i] = buf[i]; |
|
4721 |
} |
|
4722 |
r = waveOutWrite(t_waveHandle, &bp->hdr, sizeof(WAVEHDR)); |
|
4723 |
if (r != 0) { |
|
4724 |
console_printf("waveOutWrite\n"); |
|
4725 |
RETURN(self); |
|
4726 |
} |
|
4727 |
buf += len; |
|
4728 |
dataLen -= len; |
|
5402 | 4729 |
} |
4730 |
RETURN (count); |
|
4731 |
} |
|
4732 |
#endif /* SUPPORT_WIN32_WAVESOUND */ |
|
4733 |
%}. |
|
5405 | 4734 |
self errorUnsupportedOperation |
5402 | 4735 |
! ! |
4736 |
||
152 | 4737 |
!SoundStream class methodsFor:'documentation'! |
4738 |
||
4739 |
version |
|
3622 | 4740 |
^ '$Header$' |
2418
4ea40741b2b5
Use __MKEXTERNALADDRESS() instead of __MKOBJ()
Stefan Vogel <sv@exept.de>
parents:
2321
diff
changeset
|
4741 |
! |
4ea40741b2b5
Use __MKEXTERNALADDRESS() instead of __MKOBJ()
Stefan Vogel <sv@exept.de>
parents:
2321
diff
changeset
|
4742 |
|
4ea40741b2b5
Use __MKEXTERNALADDRESS() instead of __MKOBJ()
Stefan Vogel <sv@exept.de>
parents:
2321
diff
changeset
|
4743 |
version_CVS |
3622 | 4744 |
^ '$Header$' |
918 | 4745 |
! ! |
1151
5963256af171
do not depend on TimeStamp - TimeStamp to return seconds-integer
Claus Gittinger <cg@exept.de>
parents:
934
diff
changeset
|
4746 |
|
3154
23ac6f3e69b6
Initialize in instance initialize method insted in #new
Stefan Vogel <sv@exept.de>
parents:
3000
diff
changeset
|
4747 |
|
596 | 4748 |
SoundStream initialize! |