--- a/SoundStream.st Fri Jan 03 21:26:46 2020 +0100
+++ b/SoundStream.st Fri Jan 03 21:36:41 2020 +0100
@@ -65,27 +65,21 @@
#ifdef __win32__
# ifndef NO_SOUND
-# define xxxUSE_WIN32_DIRECTSOUND
-# define USE_WIN32_WAVESOUND
-# define USED_AUDIO WIN32_WAVESOUND
-# define USED_AUDIO_STR "WIN32_WAVESOUND"
+# define xxxSUPPORT_WIN32_DIRECTSOUND
+# define SUPPORT_WIN32_WAVESOUND
# endif
#endif
#ifdef __iris__
# ifndef IRIX5
-# define USE_IRIS_AUDIO
-# define USED_AUDIO IRIS_AUDIO
-# define USED_AUDIO_STR "IRIS_AUDIO"
+# define SUPPORT_IRIS_AUDIO
# endif
#endif
-#ifndef USE_IRIS_AUDIO
-# ifndef USE_ALSA_AUDIO
+#ifndef SUPPORT_IRIS_AUDIO
+# ifndef SUPPORT_ALSA_AUDIO
# ifdef LINUX
-# define USE_DEV_AUDIO
-# define USED_AUDIO DEV_AUDIO
-# define USED_AUDIO_STR "DEV_AUDIO"
+# define SUPPORT_DEV_AUDIO
# endif
# endif
#endif
@@ -93,23 +87,19 @@
#ifndef NO_SOUND
# ifndef USED_AUDIO
# ifdef __osx__
-# define USE_PORTAUDIO
-# define USED_AUDIO PORTAUDIO
-# define USED_AUDIO_STR "PORTAUDIO"
+# define SUPPORT_PORTAUDIO
# endif
# endif
#endif
-#ifdef USE_IRIS_AUDIO
-// # define IRIS_AUDIO
+#ifdef SUPPORT_IRIS_AUDIO
# include <audio.h>
# define __ALportVal(o) (ALport)(__externalAddressVal(o))
# define alPort handle1
#endif
-#ifdef USE_ALSA_AUDIO
+#ifdef SUPPORT_ALSA_AUDIO
# ifdef LINUX
-// # define ALSA_AUDIO
# include <alsa/asoundlib.h>
# define MAX_NR_OF_CHANNELS 8
# define DEBUG_SOUND
@@ -118,13 +108,12 @@
# endif
#endif
-#ifdef USE_DEV_AUDIO
+#ifdef SUPPORT_DEV_AUDIO
# ifdef LINUX
# include <stdio.h>
# include <sys/soundcard.h>
# define DEV_AUDIO_DEFAULT_FREQ (8000)
# define DEV_AUDIO_DEFAULT_BUFFERSIZE (16384)
-// # define DEV_AUDIO
# endif
# ifdef FREEBSD
@@ -134,7 +123,6 @@
# include <machine/pcaudioio.h>
# define DEV_AUDIO_DEFAULT_FREQ (8000)
# define DEV_AUDIO_DEFAULT_BUFFERSIZE (16384)
-// # define DEV_AUDIO
# endif
# if defined(sunos) || defined(solaris)
@@ -146,7 +134,6 @@
# endif
# define DEV_AUDIO_DEFAULT_FREQ (8000)
# define DEV_AUDIO_DEFAULT_BUFFERSIZE (16384)
-// # define DEV_AUDIO
# endif
# if defined(hpux)
@@ -158,11 +145,10 @@
# include <unistd.h>
# define DEV_AUDIO_DEFAULT_FREQ (22050)
# define DEV_AUDIO_DEFAULT_BUFFERSIZE (16384)
-// # define DEV_AUDIO
# endif
-#endif /* USE_DEV_AUDIO */
-
-#ifdef USE_PORTAUDIO
+#endif /* SUPPORT_DEV_AUDIO */
+
+#ifdef SUPPORT_PORTAUDIO
// # include "pthread.h"
# include "portaudio.h"
# define PORTAUDIO_DEFAULT_FREQ (44100)
@@ -180,7 +166,7 @@
# define UNLOCK(lk) { (lk) = 0; }
# define MUTEX int
-#endif // USE_PORTAUDIO
+#endif // SUPPORT_PORTAUDIO
#ifdef __win32__
# define _WIN32
@@ -208,8 +194,7 @@
# include <stdio.h> /* */
# include <windows.h>
-# ifdef USE_WIN32_DIRECTSOUND
-// # define WIN32_DIRECTSOUND
+# ifdef SUPPORT_WIN32_DIRECTSOUND
# define CINTERFACE
# include "dsound.h"
# define __DirectSoundVal(o) (LPDIRECTSOUND)(__externalAddressVal(o))
@@ -222,8 +207,7 @@
# define pDSBuffer handle2
# else /* USE WAVE... */
-# ifdef USE_WIN32_WAVESOUND
-// # define WIN32_WAVE
+# ifdef SUPPORT_WIN32_WAVESOUND
# define __WaveHandleVal(o) (HWAVEOUT)(__externalAddressVal(o))
# define MAXBUF 10 /* Maximum number of buffers */
# define DATALEN 2048 /* Size of wave data buffer */
@@ -242,8 +226,8 @@
# define waveHandle handle1
-# endif /* USE_WIN32_WAVESOUND */
-# endif /* USE_WIN32_DIRECTSOUND */
+# endif /* SUPPORT_WIN32_WAVESOUND */
+# endif /* SUPPORT_WIN32_DIRECTSOUND */
# ifdef __DEF_Array
# define Array __DEF_Array
@@ -311,7 +295,7 @@
!SoundStream primitiveFunctions!
%{
-#ifdef USE_WIN32_WAVESOUND
+#ifdef SUPPORT_WIN32_WAVESOUND
/*
* This routine will be called by windows when audio is needed.
@@ -333,9 +317,9 @@
}
}
-#endif /* USE_WIN32_WAVESOUND */
-
-#ifdef USE_PORTAUDIO
+#endif /* SUPPORT_WIN32_WAVESOUND */
+
+#ifdef SUPPORT_PORTAUDIO
static int DEBUGGING = 0;
@@ -437,7 +421,7 @@
}
}
-#endif /* USE_PORTAUDIO */
+#endif /* SUPPORT_PORTAUDIO */
%}
! !
@@ -491,24 +475,24 @@
determineConcreteClass
self allSubclassesDo:[:each |
- each isAbstract ifFalse:[
- each isSupported ifTrue:[
- ^ each
- ]
- ]
+ each isAbstract ifFalse:[
+ each isSupported ifTrue:[
+ ^ each
+ ]
+ ]
].
^ nil
!
new
self == SoundStream ifTrue:[
- ConcreteClass isNil ifTrue:[
- ConcreteClass := self determineConcreteClass.
- ConcreteClass isNil ifTrue:[
- self openErrorSignal raiseErrorString:'missing sound support'.
- ].
- ].
- ^ ConcreteClass new.
+ ConcreteClass isNil ifTrue:[
+ ConcreteClass := self determineConcreteClass.
+ ConcreteClass isNil ifTrue:[
+ self openErrorSignal raiseErrorString:'missing sound support'.
+ ].
+ ].
+ ^ ConcreteClass new.
].
^ self basicNew initialize
@@ -584,7 +568,7 @@
|newStream|
OperatingSystem getOSType ~= 'irix' ifTrue:[
- self error:'unsupported audio mode'.
+ self error:'unsupported audio mode'.
].
newStream := self new.
newStream bitsPerSample:16.
@@ -601,7 +585,7 @@
|newStream|
OperatingSystem getOSType ~= 'osx' ifTrue:[
- self error:'unsupported audio mode'.
+ self error:'unsupported audio mode'.
].
newStream := self new.
newStream setAudioFormat:#F32.
@@ -616,7 +600,7 @@
|newStream|
OperatingSystem getOSType ~= 'osx' ifTrue:[
- self error:'unsupported audio mode'.
+ self error:'unsupported audio mode'.
].
newStream := self new.
newStream setAudioFormat:#F32.
@@ -653,22 +637,22 @@
|ix iexp mant|
ix := aLawValue bitAnd:16r007F. "/ remove sign bit
- iexp := ix rightShift: 4. "/ extract exponent
+ iexp := ix rightShift: 4. "/ extract exponent
mant := ix bitAnd:16r000F. "/ now get mantissa
(iexp > 0) ifTrue:[
- mant := mant + 16. "/ add leading '1', if exponent > 0
+ mant := mant + 16. "/ add leading '1', if exponent > 0
].
- mant := (mant bitShift: 4) + 16r0008. "/ now mantissa left justified and
- "/ 1/2 quantization step added
- (iexp > 1) ifTrue:[ "/ now left shift according exponent
- mant := mant bitShift: (iexp - 1).
+ mant := (mant bitShift: 4) + 16r0008. "/ now mantissa left justified and
+ "/ 1/2 quantization step added
+ (iexp > 1) ifTrue:[ "/ now left shift according exponent
+ mant := mant bitShift: (iexp - 1).
].
"/ from 12 to 16bit
mant := mant bitShift:4.
- aLawValue > 127 ifTrue:[ "/ invert, if negative sample
- ^ mant
+ aLawValue > 127 ifTrue:[ "/ invert, if negative sample
+ ^ mant
] ifFalse:[
- ^ mant negated
+ ^ mant negated
].
"
@@ -1059,7 +1043,7 @@
mime := aFilename asFilename mimeTypeFromName.
mime isAudioType ifFalse:[
- self error:'not an audio file: ',aFilename asFilename baseName
+ self error:'not an audio file: ',aFilename asFilename baseName
].
self halt.
inStream := aFilename asFilename readStream.
@@ -1073,8 +1057,8 @@
buffer := ByteArray new:4096.
[(count := inStream nextBytesInto:buffer) > 0] whileTrue:[
- totalCount := totalCount + count.
- soundStream nextPutBytes:count from:buffer.
+ totalCount := totalCount + count.
+ soundStream nextPutBytes:count from:buffer.
].
inStream close.
@@ -1233,18 +1217,18 @@
"debugging interface - dump the current settings"
audioFormat == #S16 ifTrue:[
- UninterpretedBytes isBigEndian ifTrue:[
- audioFormat := #S16_BE
- ] ifFalse:[
- audioFormat := #S16_LE
- ]
+ UninterpretedBytes isBigEndian ifTrue:[
+ audioFormat := #S16_BE
+ ] ifFalse:[
+ audioFormat := #S16_LE
+ ]
].
audioFormat == #U16 ifTrue:[
- UninterpretedBytes isBigEndian ifTrue:[
- audioFormat := #U16_BE
- ] ifFalse:[
- audioFormat := #U16_LE
- ]
+ UninterpretedBytes isBigEndian ifTrue:[
+ audioFormat := #U16_BE
+ ] ifFalse:[
+ audioFormat := #U16_LE
+ ]
].
Transcript show:'sampleRate: '; showCR:sampleRate.
Transcript show:'format: '; showCR:audioFormat.
@@ -1295,24 +1279,24 @@
audioFormat := aSymbol.
((audioFormat == #U8) or:[audioFormat == #S8]) ifTrue:[
- bitsPerSample := 8.
- ^ self
+ bitsPerSample := 8.
+ ^ self
].
(#(U16 U16_LE U16_BE S16 S16_LE S16_BE) includes:audioFormat) ifTrue:[
- bitsPerSample := 16.
- ^ self
+ bitsPerSample := 16.
+ ^ self
].
(#(U24 U24_LE U24_BE S24 S24_LE S24_BE) includes:audioFormat) ifTrue:[
- bitsPerSample := 24.
- ^ self
+ bitsPerSample := 24.
+ ^ self
].
(#(U32 U32_LE U32_BE S32 S32_LE S32_BE) includes:audioFormat) ifTrue:[
- bitsPerSample := 32.
- ^ self
+ bitsPerSample := 32.
+ ^ self
].
(audioFormat == #F32) ifTrue:[
- bitsPerSample := 32.
- ^ self
+ bitsPerSample := 32.
+ ^ self
].
bitsPerSample := 8.
@@ -1328,7 +1312,7 @@
"set the number of channels (1 -> mono; 2 -> stereo).
Returns true if sucessful - may fail with many sound devices."
- numberOfChannels := nChannels.
+ numberOfChannels := nChannels.
"
self writing setChannels:2; dumpSettings; close
@@ -1358,25 +1342,25 @@
supportedAudioFormats
"return a collection of supported audio formats.
possibly returned symbols are:
- U8 unsigned 8bit samples
- S8 signed 8bit samples
- U16 unsigned 16bit samples in native format
- U16_LE unsigned 16bit big endian samples
- U16_BE unsigned 16bit big endian samples
- S16 signed 16bit little endian samples in native format
- S16_LE signed 16bit little endian samples
- S16_BE signed 16bit big endian samples
- S24 signed 24bit little endian samples in native format
- S24_LE signed 24bit little endian samples
- S24_BE signed 24bit big endian samples
- S32 signed 32bit little endian samples in native format
- S32_LE signed 32bit little endian samples
- S32_BE signed 32bit big endian samples
- F32 float samples
- MPEG audio mpeg encoded
- MU_LAW u-law encoded 8bit samples
- A_LAW a-law encoded 8bit samples
- IMA_ADPCM adpcm encoded
+ U8 unsigned 8bit samples
+ S8 signed 8bit samples
+ U16 unsigned 16bit samples in native format
+ U16_LE unsigned 16bit big endian samples
+ U16_BE unsigned 16bit big endian samples
+ S16 signed 16bit little endian samples in native format
+ S16_LE signed 16bit little endian samples
+ S16_BE signed 16bit big endian samples
+ S24 signed 24bit little endian samples in native format
+ S24_LE signed 24bit little endian samples
+ S24_BE signed 24bit big endian samples
+ S32 signed 32bit little endian samples in native format
+ S32_LE signed 32bit little endian samples
+ S32_BE signed 32bit big endian samples
+ F32 float samples
+ MPEG audio mpeg encoded
+ MU_LAW u-law encoded 8bit samples
+ A_LAW a-law encoded 8bit samples
+ IMA_ADPCM adpcm encoded
the set of returned symbols depends on the underlying sound hardware.
"
@@ -1740,16 +1724,16 @@
"Modified: / 31.1.1999 / 12:07:14 / cg"
!
-tuneTone:freq seconds:nSeconds
+tuneTone:freq seconds:nSeconds
((audioFormat startsWith:#S16)
or:[audioFormat startsWith:#U16]) ifTrue:[
- ^ self tuneTone16:freq seconds:nSeconds
+ ^ self tuneTone16:freq seconds:nSeconds
].
audioFormat == #F32 ifTrue:[
- ^ self tuneToneF32:freq seconds:nSeconds
+ ^ self tuneToneF32:freq seconds:nSeconds
].
audioFormat == #MU_LAW ifTrue:[
- ^ self tuneToneMU:freq seconds:nSeconds
+ ^ self tuneToneMU:freq seconds:nSeconds
].
self tuneTone8:freq seconds:nSeconds
@@ -1855,17 +1839,17 @@
scale := freq * 2 * (Float pi).
1 to:numSamples do:[:i |
- val := (scale * i / numSamples) sin.
- val := (val * 16r7FFF) rounded.
- buffer at:i put:(self class linear16ToUlaw:val)
+ val := (scale * i / numSamples) sin.
+ val := (val * 16r7FFF) rounded.
+ buffer at:i put:(self class linear16ToUlaw:val)
].
1 to:nSeconds truncated do:[:s |
- self nextPutBytes:numSamples from:buffer startingAt:1
+ self nextPutBytes:numSamples from:buffer startingAt:1
].
restSamples := ((nSeconds - nSeconds truncated) * numSamples) truncated.
restSamples > 0 ifTrue:[
- self nextPutBytes:restSamples from:buffer startingAt:1
+ self nextPutBytes:restSamples from:buffer startingAt:1
].
"of course, the frequency should be below half the
@@ -1901,25 +1885,25 @@
documentation to be added.
class:
- <a short class summary here, describing what instances represent>
-
- responsibilities:
- <describing what my main role is>
-
- collaborators:
- <describing with whom and how I talk to>
+ <a short class summary here, describing what instances represent>
+
+ responsibilities:
+ <describing what my main role is>
+
+ collaborators:
+ <describing with whom and how I talk to>
API:
- <public api and main messages>
-
+ <public api and main messages>
+
example:
- <a one-line examples on how to use - can also be in a separate example method>
+ <a one-line examples on how to use - can also be in a separate example method>
implementation:
- <implementation points>
+ <implementation points>
[author:]
- exept MBP
+ exept MBP
[instance variables:]
@@ -1951,118 +1935,118 @@
fd := self fileDescriptorOrNil.
audioFormat == #S16 ifTrue:[
- UninterpretedBytes isBigEndian ifTrue:[
- audioFormat := #S16_BE
- ] ifFalse:[
- audioFormat := #S16_LE
- ]
+ UninterpretedBytes isBigEndian ifTrue:[
+ audioFormat := #S16_BE
+ ] ifFalse:[
+ audioFormat := #S16_LE
+ ]
].
audioFormat == #U16 ifTrue:[
- UninterpretedBytes isBigEndian ifTrue:[
- audioFormat := #U16_BE
- ] ifFalse:[
- audioFormat := #U16_LE
- ]
+ UninterpretedBytes isBigEndian ifTrue:[
+ audioFormat := #U16_BE
+ ] ifFalse:[
+ audioFormat := #U16_LE
+ ]
].
%{
#ifdef SUPPORT_DEV_AUDIO
if (fd != nil) {
- int f = __intVal(fd);
- int __blockSize = -1;
- int __speed = -1;
- int __channels = __intVal(__INST(numberOfChannels));
- int __stereo = __channels > 1;
- int __format = -1;
-
- channels = nil;
- blockSize = nil;
- stereo = nil;
- speed = nil;
+ int f = __intVal(fd);
+ int __blockSize = -1;
+ int __speed = -1;
+ int __channels = __intVal(__INST(numberOfChannels));
+ int __stereo = __channels > 1;
+ int __format = -1;
+
+ channels = nil;
+ blockSize = nil;
+ stereo = nil;
+ speed = nil;
# if defined(SNDCTL_DSP_GETBLKSIZE)
- if (ioctl(f, SNDCTL_DSP_GETBLKSIZE, &__blockSize) >= 0) {
- blockSize = __MKSMALLINT(__blockSize);
- }
+ if (ioctl(f, SNDCTL_DSP_GETBLKSIZE, &__blockSize) >= 0) {
+ blockSize = __MKSMALLINT(__blockSize);
+ }
# endif
# if defined(SNDCTL_DSP_CHANNELS)
- if (ioctl(f, SNDCTL_DSP_CHANNELS, &__channels) >= 0) {
- channels = __MKSMALLINT(__channels);
- stereo = __MKSMALLINT(__channels > 1);
- }
+ if (ioctl(f, SNDCTL_DSP_CHANNELS, &__channels) >= 0) {
+ channels = __MKSMALLINT(__channels);
+ stereo = __MKSMALLINT(__channels > 1);
+ }
# else
# if defined(SNDCTL_DSP_STEREO)
- if (ioctl(f, SNDCTL_DSP_STEREO, &__stereo) >= 0) {
- stereo = __MKSMALLINT(__stereo);
- }
+ if (ioctl(f, SNDCTL_DSP_STEREO, &__stereo) >= 0) {
+ stereo = __MKSMALLINT(__stereo);
+ }
# endif
# endif
# if defined(SNDCTL_DSP_SPEED)
- if (ioctl(f, SNDCTL_DSP_SPEED, &__speed) >= 0) {
- speed = __MKSMALLINT(__speed);
- }
+ if (ioctl(f, SNDCTL_DSP_SPEED, &__speed) >= 0) {
+ speed = __MKSMALLINT(__speed);
+ }
# endif
# if defined(SNDCTL_DSP_GETFMT)
- if (ioctl(f, SNDCTL_DSP_GETFMT, &__format) >= 0) {
- format = __MKSMALLINT(__format);
- }
+ if (ioctl(f, SNDCTL_DSP_GETFMT, &__format) >= 0) {
+ format = __MKSMALLINT(__format);
+ }
# else
# if defined(SNDCTL_DSP_SETFMT) && defined(AFMT_QUERY)
- __format = AFMT_QUERY;
- if (ioctl(f, SNDCTL_DSP_SETFMT, &__format) >= 0) {
- switch (__format) {
+ __format = AFMT_QUERY;
+ if (ioctl(f, SNDCTL_DSP_SETFMT, &__format) >= 0) {
+ switch (__format) {
# ifdef AFMT_MU_LAW
- case AFMT_MU_LAW:
- format = @symbol(MU_LAW);
- break;
+ case AFMT_MU_LAW:
+ format = @symbol(MU_LAW);
+ break;
# endif
# ifdef AFMT_A_LAW
- case AFMT_A_LAW:
- format = @symbol(A_LAW);
- break;
+ case AFMT_A_LAW:
+ format = @symbol(A_LAW);
+ break;
# endif
# ifdef AFMT_U8
- case AFMT_U8:
- format = @symbol(U8);
- break;
+ case AFMT_U8:
+ format = @symbol(U8);
+ break;
# endif
# ifdef AFMT_S8
- case AFMT_S8:
- format = @symbol(S8);
- break;
+ case AFMT_S8:
+ format = @symbol(S8);
+ break;
# endif
# ifdef AFMT_S16_LE
- case AFMT_S16_LE:
- format = @symbol(S16_LE);
- break;
+ case AFMT_S16_LE:
+ format = @symbol(S16_LE);
+ break;
# endif
# ifdef AFMT_S16_BE
- case AFMT_S16_BE:
- format = @symbol(S16_BE);
- break;
+ case AFMT_S16_BE:
+ format = @symbol(S16_BE);
+ break;
# endif
# ifdef AFMT_U16_LE
- case AFMT_U16_LE:
- format = @symbol(U16_LE);
- break;
+ case AFMT_U16_LE:
+ format = @symbol(U16_LE);
+ break;
# endif
# ifdef AFMT_U16_BE
- case AFMT_U16_BE:
- format = @symbol(U16_BE);
- break;
+ case AFMT_U16_BE:
+ format = @symbol(U16_BE);
+ break;
# endif
# ifdef AFMT_MPEG
- case AFMT_MPEG:
- format = @symbol(MPEG);
- break;
+ case AFMT_MPEG:
+ format = @symbol(MPEG);
+ break;
# endif
- default:
- format = nil;
- }
- }
+ default:
+ format = nil;
+ }
+ }
}
# endif
# endif
@@ -2070,19 +2054,19 @@
%}.
format notNil ifTrue:[
- Transcript show:'format: '; showCR:format
+ Transcript show:'format: '; showCR:format
].
blockSize notNil ifTrue:[
- Transcript show:'blockSize: '; showCR:blockSize
+ Transcript show:'blockSize: '; showCR:blockSize
].
speed notNil ifTrue:[
- Transcript show:'speed: '; showCR:speed
+ Transcript show:'speed: '; showCR:speed
].
channels notNil ifTrue:[
- Transcript show:'channels: '; showCR:channels
+ Transcript show:'channels: '; showCR:channels
].
stereo notNil ifTrue:[
- Transcript show:'stereo: '; showCR:stereo
+ Transcript show:'stereo: '; showCR:stereo
].
Transcript show:'supported audioFormats: '; showCR:(self supportedAudioFormats).
@@ -2111,21 +2095,21 @@
FILE *f;
if ((fp = __INST(handle)) != nil) {
- f = __FILEVal(fp);
- __INST(handle) = nil;
+ f = __FILEVal(fp);
+ __INST(handle) = nil;
# ifdef LINUX
- sigsetmask(~0);
+ sigsetmask(~0);
# endif
- if (__INST(buffered) == true) {
- fflush(f);
- fclose(f);
- } else {
- fd = fileno(f);
- close(fd);
- fclose(f);
- }
+ if (__INST(buffered) == true) {
+ fflush(f);
+ fclose(f);
+ } else {
+ fd = fileno(f);
+ close(fd);
+ fclose(f);
+ }
# ifdef LINUX
- sigsetmask(0);
+ sigsetmask(0);
# endif
}
RETURN (self);
@@ -2144,60 +2128,60 @@
ok = false;
if (strcmp(__stringVal(aMode), "w") == 0) {
- __mode = O_WRONLY;
+ __mode = O_WRONLY;
} else if (strcmp(__stringVal(aMode), "r") == 0) {
- __mode = O_RDONLY;
+ __mode = O_RDONLY;
} else {
- __mode = O_RDWR;
+ __mode = O_RDWR;
}
do {
- __BEGIN_INTERRUPTABLE__
- __fd = open((char *) __stringVal(__INST(pathName)), __mode /* |O_NDELAY */);
- __END_INTERRUPTABLE__
+ __BEGIN_INTERRUPTABLE__
+ __fd = open((char *) __stringVal(__INST(pathName)), __mode /* |O_NDELAY */);
+ __END_INTERRUPTABLE__
} while ((__fd < 0) && (errno == EINTR));
if (__fd >= 0) {
- /*
- * make it a FILE *
- */
- f = fdopen(__fd, __stringVal(aMode));
- if (! f) {
- error = __mkSmallInteger(errno);
- __BEGIN_INTERRUPTABLE__
- close(__fd);
- __END_INTERRUPTABLE__
- goto out;
- }
- setbuf(f, NULL);
- __INST(buffered) = false;
- __INST(handle) = __MKEXTERNALADDRESS(f);
- __STORESELF(handle);
+ /*
+ * make it a FILE *
+ */
+ f = fdopen(__fd, __stringVal(aMode));
+ if (! f) {
+ error = __mkSmallInteger(errno);
+ __BEGIN_INTERRUPTABLE__
+ close(__fd);
+ __END_INTERRUPTABLE__
+ goto out;
+ }
+ setbuf(f, NULL);
+ __INST(buffered) = false;
+ __INST(handle) = __MKEXTERNALADDRESS(f);
+ __STORESELF(handle);
#if defined(PCM_ENABLE_OUTPUT) && defined(PCM_ENABLE_INPUT)
# if defined(SNDCTL_DSP_SETTRIGGER)
- if (__mode == O_RDWR) {
- int enable_bits = ~(PCM_ENABLE_OUTPUT|PCM_ENABLE_INPUT);
-
- if (ioctl(__fd, SNDCTL_DSP_SETTRIGGER, &enable_bits) == -1)
- {
- console_fprintf(stderr, "can't request synchronous start of fullduplex operation");
- }
- }
+ if (__mode == O_RDWR) {
+ int enable_bits = ~(PCM_ENABLE_OUTPUT|PCM_ENABLE_INPUT);
+
+ if (ioctl(__fd, SNDCTL_DSP_SETTRIGGER, &enable_bits) == -1)
+ {
+ console_fprintf(stderr, "can't request synchronous start of fullduplex operation");
+ }
+ }
# endif
#endif
- ok = true;
+ ok = true;
} else {
- error = __mkSmallInteger(errno);
+ error = __mkSmallInteger(errno);
}
out:;
#endif /* SUPPORT_DEV_AUDIO */
%}.
ok == false ifTrue:[
- lastErrorString := errorStringOrNil.
- lastErrorNumber := error ? -1.
- self openError:error.
- "normally not reached"
- ^ nil.
+ lastErrorString := errorStringOrNil.
+ lastErrorNumber := error ? -1.
+ self openError:error.
+ "normally not reached"
+ ^ nil.
].
self registerForFinalization.
! !
@@ -2210,12 +2194,12 @@
super initialize.
OperatingSystem isUNIXlike ifTrue:[
- '/dev/audio' asFilename exists ifTrue:[
- "/
- "/ sunos or linux
- "/
- pathName := '/dev/audio'.
- ].
+ '/dev/audio' asFilename exists ifTrue:[
+ "/
+ "/ sunos or linux
+ "/
+ pathName := '/dev/audio'.
+ ].
].
!
@@ -2226,19 +2210,19 @@
fd := self fileDescriptorOrNil.
fd isNil ifTrue:[
- self errorNotOpen.
- ^ nil
+ self errorNotOpen.
+ ^ nil
].
%{
#ifdef SUPPORT_DEV_AUDIO
int f = __intVal(fd);
if (__isSmallInteger(fd)) {
- int __dummy;
+ int __dummy;
# if defined(SNDCTL_DSP_RESET)
- if (ioctl(f, SNDCTL_DSP_RESET, &__dummy) >= 0) {
- RETURN (self);
- }
+ if (ioctl(f, SNDCTL_DSP_RESET, &__dummy) >= 0) {
+ RETURN (self);
+ }
# endif
}
#endif /* SUPPORT_DEV_AUDIO */
@@ -2261,120 +2245,120 @@
fd := self fileDescriptor.
fd isNil ifTrue:[
- ^ self
+ ^ self
].
%{
#ifdef SUPPORT_DEV_AUDIO
OBJ sym = aSymbol;
if (__isSmallInteger(fd)) {
- int f = __intVal(fd);
- int __fmt = 0, __fmtWant;
- union {
- unsigned short us;
- unsigned char ub[2];
- } u;
-
- if (__isSymbol(sym)) {
- if (sym == @symbol(U16)) {
- u.us = 0x1234;
- if (u.ub[0] == 0x34) {
- /* printf("U16_LE\n"); */
- sym = @symbol(U16_LE);
- } else {
- /* printf("U16_BE\n"); */
- sym = @symbol(U16_BE);
- }
- } else if (sym == @symbol(S16)) {
- u.us = 0x1234;
- if (u.ub[0] == 0x34) {
- /* printf("S16_LE\n"); */
- sym = @symbol(S16_LE);
- } else {
- /* printf("S16_BE\n"); */
- sym = @symbol(S16_BE);
- }
- }
-
- if (0) {
+ int f = __intVal(fd);
+ int __fmt = 0, __fmtWant;
+ union {
+ unsigned short us;
+ unsigned char ub[2];
+ } u;
+
+ if (__isSymbol(sym)) {
+ if (sym == @symbol(U16)) {
+ u.us = 0x1234;
+ if (u.ub[0] == 0x34) {
+ /* printf("U16_LE\n"); */
+ sym = @symbol(U16_LE);
+ } else {
+ /* printf("U16_BE\n"); */
+ sym = @symbol(U16_BE);
+ }
+ } else if (sym == @symbol(S16)) {
+ u.us = 0x1234;
+ if (u.ub[0] == 0x34) {
+ /* printf("S16_LE\n"); */
+ sym = @symbol(S16_LE);
+ } else {
+ /* printf("S16_BE\n"); */
+ sym = @symbol(S16_BE);
+ }
+ }
+
+ if (0) {
# ifdef AFMT_MU_LAW
- } else if (sym == @symbol(MU_LAW)) {
- __fmt = AFMT_MU_LAW;
+ } else if (sym == @symbol(MU_LAW)) {
+ __fmt = AFMT_MU_LAW;
# endif
# ifdef AFMT_A_LAW
- } else if (sym == @symbol(A_LAW)) {
- __fmt = AFMT_A_LAW;
+ } else if (sym == @symbol(A_LAW)) {
+ __fmt = AFMT_A_LAW;
# endif
# ifdef AFMT_IMA_ADPCM
- } else if (sym == @symbol(IMA_ADPCM)) {
- __fmt = AFMT_IMA_ADPCM;
+ } else if (sym == @symbol(IMA_ADPCM)) {
+ __fmt = AFMT_IMA_ADPCM;
# endif
# ifdef AFMT_U8
- } else if (sym == @symbol(U8)) {
- __fmt = AFMT_U8;
+ } else if (sym == @symbol(U8)) {
+ __fmt = AFMT_U8;
# endif
# ifdef AFMT_S8
- } else if (sym == @symbol(S8)) {
- __fmt = AFMT_S8;
+ } else if (sym == @symbol(S8)) {
+ __fmt = AFMT_S8;
# endif
# ifdef AFMT_U16_LE
- } else if (sym == @symbol(U16_LE)) {
- __fmt = AFMT_U16_LE;
+ } else if (sym == @symbol(U16_LE)) {
+ __fmt = AFMT_U16_LE;
# endif
# ifdef AFMT_U16_BE
- } else if (sym == @symbol(U16_BE)) {
- __fmt = AFMT_U16_BE;
+ } else if (sym == @symbol(U16_BE)) {
+ __fmt = AFMT_U16_BE;
# endif
# ifdef AFMT_S16_LE
- } else if (sym == @symbol(S16_LE)) {
- __fmt = AFMT_S16_LE;
+ } else if (sym == @symbol(S16_LE)) {
+ __fmt = AFMT_S16_LE;
# endif
# ifdef AFMT_S16_BE
- } else if (sym == @symbol(S16_BE)) {
- __fmt = AFMT_S16_BE;
+ } else if (sym == @symbol(S16_BE)) {
+ __fmt = AFMT_S16_BE;
# endif
# ifdef AFMT_MPEG
- } else if (sym == @symbol(MPEG)) {
- __fmt = AFMT_MPEG;
+ } else if (sym == @symbol(MPEG)) {
+ __fmt = AFMT_MPEG;
# endif
# ifdef AUDIO_FORMAT_LINEAR16BIT
- } else if (sym == @symbol(S16)) {
- __fmt = AUDIO_FORMAT_LINEAR16BIT;
+ } else if (sym == @symbol(S16)) {
+ __fmt = AUDIO_FORMAT_LINEAR16BIT;
# endif
# ifdef AUDIO_FORMAT_ULAW
- } else if (sym == @symbol(MU_LAW)) {
- __fmt = AUDIO_FORMAT_ULAW;
+ } else if (sym == @symbol(MU_LAW)) {
+ __fmt = AUDIO_FORMAT_ULAW;
# endif
# ifdef AUDIO_FORMAT_ALAW
- } else if (sym == @symbol(A_LAW)) {
- __fmt = AUDIO_FORMAT_ALAW;
+ } else if (sym == @symbol(A_LAW)) {
+ __fmt = AUDIO_FORMAT_ALAW;
# endif
- } else {
- console_fprintf(stderr, "bad format: %s\n", __stringVal(sym));
- ok = false;
- goto bad;
- }
- }
+ } else {
+ console_fprintf(stderr, "bad format: %s\n", __stringVal(sym));
+ ok = false;
+ goto bad;
+ }
+ }
# ifdef SNDCTL_DSP_SETFMT
- __fmtWant = __fmt;
-
- if (ioctl(f, SNDCTL_DSP_SETFMT, &__fmt) >= 0) {
- if (__fmt == __fmtWant) {
- __INST(audioFormat) = sym;
- } else {
- /* console_fprintf(stderr, "want: %x; got: %x\n", __fmtWant, __fmt); */
- }
- } else {
- /* console_fprintf(stderr, "got err-ret from setFmp %x\n", __fmt); */
- ok = false;
- }
+ __fmtWant = __fmt;
+
+ if (ioctl(f, SNDCTL_DSP_SETFMT, &__fmt) >= 0) {
+ if (__fmt == __fmtWant) {
+ __INST(audioFormat) = sym;
+ } else {
+ /* console_fprintf(stderr, "want: %x; got: %x\n", __fmtWant, __fmt); */
+ }
+ } else {
+ /* console_fprintf(stderr, "got err-ret from setFmp %x\n", __fmt); */
+ ok = false;
+ }
# else
# ifdef AUDIO_SET_DATA_FORMAT /* hpux */
- if (ioctl (f, AUDIO_SET_DATA_FORMAT, __fmt)) {
- /* console_fprintf(stderr, "got err-ret from AUDIO_SET_DATA_FORMAT\n"); */
- }
+ if (ioctl (f, AUDIO_SET_DATA_FORMAT, __fmt)) {
+ /* console_fprintf(stderr, "got err-ret from AUDIO_SET_DATA_FORMAT\n"); */
+ }
# endif
# endif /* SNDCTL_DSP_SETFMT */
@@ -2401,39 +2385,39 @@
fd := self fileDescriptorOrNil.
fd isNil ifTrue:[
- ^ self
+ ^ self
].
%{
#ifdef SUPPORT_DEV_AUDIO
if (__isSmallInteger(fd) && __isSmallInteger(nChannels)) {
- int f = __intVal(fd);
- int __nCh = __intVal(nChannels);
+ int f = __intVal(fd);
+ int __nCh = __intVal(nChannels);
# ifdef SNDCTL_DSP_STEREO
- if ((__nCh == 1) || (__nCh == 2)) {
- int __stereo = (__nCh == 2) ? 1 : 0;
-
- if (ioctl(f, SNDCTL_DSP_STEREO, &__stereo) >= 0) {
- if (__stereo == 0) {
- __INST(numberOfChannels) = __MKSMALLINT(1);
- } else {
- __INST(numberOfChannels) = __MKSMALLINT(2);
- }
- RETURN (self);
- }
- }
+ if ((__nCh == 1) || (__nCh == 2)) {
+ int __stereo = (__nCh == 2) ? 1 : 0;
+
+ if (ioctl(f, SNDCTL_DSP_STEREO, &__stereo) >= 0) {
+ if (__stereo == 0) {
+ __INST(numberOfChannels) = __MKSMALLINT(1);
+ } else {
+ __INST(numberOfChannels) = __MKSMALLINT(2);
+ }
+ RETURN (self);
+ }
+ }
# else
# ifdef SOUND_PCM_WRITE_CHANNELS
- if (ioctl(f, SOUND_PCM_WRITE_CHANNELS, &__nCh) >= 0) {
- RETURN (self);
- }
+ if (ioctl(f, SOUND_PCM_WRITE_CHANNELS, &__nCh) >= 0) {
+ RETURN (self);
+ }
# else
# ifdef AUDIO_SET_CHANNELS /* hpux */
- if (ioctl (f, AUDIO_SET_CHANNELS, __nCh)) {
- /* console_fprintf(stderr, "got err-ret from AUDIO_SET_CHANNELS\n"); */
- RETURN (self);
- }
+ if (ioctl (f, AUDIO_SET_CHANNELS, __nCh)) {
+ /* console_fprintf(stderr, "got err-ret from AUDIO_SET_CHANNELS\n"); */
+ RETURN (self);
+ }
# endif
# endif
# endif
@@ -2457,7 +2441,7 @@
fd := self fileDescriptorOrNil.
fd isNil ifTrue:[
- ^ self
+ ^ self
].
%{
@@ -2466,17 +2450,17 @@
int __blockSize = __intVal(blockSize);
if (__isSmallInteger(fd) && __isSmallInteger(blockSize)) {
- __blockSize = __intVal(blockSize);
+ __blockSize = __intVal(blockSize);
# if defined(SNDCTL_DSP_SETFRAGMENT)
- if (ioctl(f, SNDCTL_DSP_SETFRAGMENT, &__blockSize) >= 0) {
- RETURN (self);
- }
+ if (ioctl(f, SNDCTL_DSP_SETFRAGMENT, &__blockSize) >= 0) {
+ RETURN (self);
+ }
# endif
# ifdef AUDIO_SET_CHANNELS /* hpux */
- if (ioctl (f, AUDIO_SET_TXBUFSIZE, __blockSize)) {
- /* console_fprintf(stderr, "got err-ret from AUDIO_SET_TXBUFSIZE\n"); */
- RETURN (self);
- }
+ if (ioctl (f, AUDIO_SET_TXBUFSIZE, __blockSize)) {
+ /* console_fprintf(stderr, "got err-ret from AUDIO_SET_TXBUFSIZE\n"); */
+ RETURN (self);
+ }
# endif
}
#endif // SUPPORT_DEV_AUDIO
@@ -2492,7 +2476,7 @@
fd := self fileDescriptorOrNil.
fd isNil ifTrue:[
- ^ self
+ ^ self
].
%{
#ifdef SUPPORT_DEV_AUDIO
@@ -2500,34 +2484,34 @@
int __rate = __intVal(hz);
if (__isSmallInteger(fd) && __isSmallInteger(hz)) {
- int __rateWant = __rate;
+ int __rateWant = __rate;
# if defined(SNDCTL_DSP_SPEED)
- if (ioctl(f, SNDCTL_DSP_SPEED, &__rate) >= 0) {
- if (__rate != __rateWant) {
- console_fprintf(stderr, "SoundStream [warning]: actual rate is %d\n", __rate);
- hz = __MKSMALLINT(__rate);
- }
- __INST(sampleRate) = hz;
- RETURN (self);
- }
+ if (ioctl(f, SNDCTL_DSP_SPEED, &__rate) >= 0) {
+ if (__rate != __rateWant) {
+ console_fprintf(stderr, "SoundStream [warning]: actual rate is %d\n", __rate);
+ hz = __MKSMALLINT(__rate);
+ }
+ __INST(sampleRate) = hz;
+ RETURN (self);
+ }
# else
# if defined(SOUND_PCM_WRITE_RATE)
- if (ioctl(f, SOUND_PCM_WRITE_RATE, &__rate) >= 0) {
- if (__rate != __rateWant) {
- console_fprintf(stderr, "SoundStream [warning]: actual rate is %d\n", __rate);
- hz = __MKSMALLINT(__rate);
- }
- __INST(sampleRate) = hz;
- RETURN (self);
- }
+ if (ioctl(f, SOUND_PCM_WRITE_RATE, &__rate) >= 0) {
+ if (__rate != __rateWant) {
+ console_fprintf(stderr, "SoundStream [warning]: actual rate is %d\n", __rate);
+ hz = __MKSMALLINT(__rate);
+ }
+ __INST(sampleRate) = hz;
+ RETURN (self);
+ }
# else
# ifdef AUDIO_SET_SAMPLE_RATE /* hpux */
- if (ioctl (f, AUDIO_SET_SAMPLE_RATE, __rate)) {
- /* console_fprintf(stderr, "got err-ret from AUDIO_SET_SAMPLE_RATE\n"); */
- __INST(sampleRate) = hz;
- RETURN (self);
- }
+ if (ioctl (f, AUDIO_SET_SAMPLE_RATE, __rate)) {
+ /* console_fprintf(stderr, "got err-ret from AUDIO_SET_SAMPLE_RATE\n"); */
+ __INST(sampleRate) = hz;
+ RETURN (self);
+ }
# endif
# endif
# endif
@@ -2547,25 +2531,25 @@
supportedAudioFormats
"return a collection of supported audio formats.
possibly returned symbols are:
- U8 unsigned 8bit samples
- S8 signed 8bit samples
- U16 unsigned 16bit samples in native format
- U16_LE unsigned 16bit big endian samples
- U16_BE unsigned 16bit big endian samples
- S16 signed 16bit little endian samples in native format
- S16_LE signed 16bit little endian samples
- S16_BE signed 16bit big endian samples
- S24 signed 24bit little endian samples in native format
- S24_LE signed 24bit little endian samples
- S24_BE signed 24bit big endian samples
- S32 signed 32bit little endian samples in native format
- S32_LE signed 32bit little endian samples
- S32_BE signed 32bit big endian samples
- F32 float samples
- MPEG audio mpeg encoded
- MU_LAW u-law encoded 8bit samples
- A_LAW a-law encoded 8bit samples
- IMA_ADPCM adpcm encoded
+ U8 unsigned 8bit samples
+ S8 signed 8bit samples
+ U16 unsigned 16bit samples in native format
+ U16_LE unsigned 16bit big endian samples
+ U16_BE unsigned 16bit big endian samples
+ S16 signed 16bit little endian samples in native format
+ S16_LE signed 16bit little endian samples
+ S16_BE signed 16bit big endian samples
+ S24 signed 24bit little endian samples in native format
+ S24_LE signed 24bit little endian samples
+ S24_BE signed 24bit big endian samples
+ S32 signed 32bit little endian samples in native format
+ S32_LE signed 32bit little endian samples
+ S32_BE signed 32bit big endian samples
+ F32 float samples
+ MPEG audio mpeg encoded
+ MU_LAW u-law encoded 8bit samples
+ A_LAW a-law encoded 8bit samples
+ IMA_ADPCM adpcm encoded
the set of returned symbols depends on the underlying sound hardware.
"
@@ -2589,44 +2573,44 @@
supports_MU_LAW = true;
if (fd != nil) {
- int f = __intVal(fd);
- int __audioFormatMask = 0;
+ int f = __intVal(fd);
+ int __audioFormatMask = 0;
# if defined(SNDCTL_DSP_GETFMTS)
- if (ioctl(f, SNDCTL_DSP_GETFMTS, &__audioFormatMask) >= 0) {
- audioFormatMask = __MKSMALLINT(__audioFormatMask);
+ if (ioctl(f, SNDCTL_DSP_GETFMTS, &__audioFormatMask) >= 0) {
+ audioFormatMask = __MKSMALLINT(__audioFormatMask);
# ifdef AFMT_MU_LAW
- supports_MU_LAW = (__audioFormatMask & AFMT_MU_LAW) ? true : false;
+ supports_MU_LAW = (__audioFormatMask & AFMT_MU_LAW) ? true : false;
# endif
# ifdef AFMT_A_LAW
- supports_A_LAW = (__audioFormatMask & AFMT_A_LAW) ? true : false;
+ supports_A_LAW = (__audioFormatMask & AFMT_A_LAW) ? true : false;
# endif
# ifdef AFMT_IMA_ADPCM
- supports_IMA_ADPCM = (__audioFormatMask & AFMT_IMA_ADPCM) ? true : false;
+ supports_IMA_ADPCM = (__audioFormatMask & AFMT_IMA_ADPCM) ? true : false;
# endif
# ifdef AFMT_U8
- supports_U8 = (__audioFormatMask & AFMT_U8) ? true : false;
+ supports_U8 = (__audioFormatMask & AFMT_U8) ? true : false;
# endif
# ifdef AFMT_S16_LE
- supports_S16_LE = (__audioFormatMask & AFMT_S16_LE) ? true : false;
+ supports_S16_LE = (__audioFormatMask & AFMT_S16_LE) ? true : false;
# endif
# ifdef AFMT_S16_BE
- supports_S16_BE = (__audioFormatMask & AFMT_S16_BE) ? true : false;
+ supports_S16_BE = (__audioFormatMask & AFMT_S16_BE) ? true : false;
# endif
# ifdef AFMT_S8
- supports_S8 = (__audioFormatMask & AFMT_S8) ? true : false;
+ supports_S8 = (__audioFormatMask & AFMT_S8) ? true : false;
# endif
# ifdef AFMT_U16_LE
- supports_U16_LE = (__audioFormatMask & AFMT_U16_LE) ? true : false;
+ supports_U16_LE = (__audioFormatMask & AFMT_U16_LE) ? true : false;
# endif
# ifdef AFMT_U16_BE
- supports_U16_BE = (__audioFormatMask & AFMT_U16_BE) ? true : false;
+ supports_U16_BE = (__audioFormatMask & AFMT_U16_BE) ? true : false;
# endif
# ifdef AFMT_MPEG
- supports_MPEG = (__audioFormatMask & AFMT_MPEG) ? true : false;
+ supports_MPEG = (__audioFormatMask & AFMT_MPEG) ? true : false;
# endif
- }
+ }
}
# endif // SNDCTL_DSP_GETFMTS
@@ -2638,73 +2622,73 @@
%}.
supportedFormats := IdentitySet new.
(supports_MU_LAW ? false) ifTrue:[
- supportedFormats add:#'MU_LAW'
+ supportedFormats add:#'MU_LAW'
].
(supports_A_LAW ? false) ifTrue:[
- supportedFormats add:#'A_LAW'
+ supportedFormats add:#'A_LAW'
].
(supports_IMA_ADPCM ? false) ifTrue:[
- supportedFormats add:#'IMA_ADPCM'
+ supportedFormats add:#'IMA_ADPCM'
].
(supports_MPEG ? false) ifTrue:[
- supportedFormats add:#'MPEG'
+ supportedFormats add:#'MPEG'
].
(supports_S8 ? false) ifTrue:[
- supportedFormats add:#'S8'
+ supportedFormats add:#'S8'
].
(supports_U8 ? false) ifTrue:[
- supportedFormats add:#'U8'
+ supportedFormats add:#'U8'
].
(supports_S16_LE ? false) ifTrue:[
- supportedFormats add:#'S16_LE'.
- UninterpretedBytes isBigEndian ifFalse:[
- supportedFormats add:#'S16'.
- ]
+ supportedFormats add:#'S16_LE'.
+ UninterpretedBytes isBigEndian ifFalse:[
+ supportedFormats add:#'S16'.
+ ]
].
(supports_S16_BE ? false) ifTrue:[
- supportedFormats add:#'S16_BE'.
- UninterpretedBytes isBigEndian ifTrue:[
- supportedFormats add:#'S16'.
- ]
+ supportedFormats add:#'S16_BE'.
+ UninterpretedBytes isBigEndian ifTrue:[
+ supportedFormats add:#'S16'.
+ ]
].
(supports_S24_LE ? false) ifTrue:[
- supportedFormats add:#'S24_LE'.
- UninterpretedBytes isBigEndian ifFalse:[
- supportedFormats add:#'S24'.
- ]
+ supportedFormats add:#'S24_LE'.
+ UninterpretedBytes isBigEndian ifFalse:[
+ supportedFormats add:#'S24'.
+ ]
].
(supports_S24_BE ? false) ifTrue:[
- supportedFormats add:#'S24_BE'.
- UninterpretedBytes isBigEndian ifTrue:[
- supportedFormats add:#'S24'.
- ]
+ supportedFormats add:#'S24_BE'.
+ UninterpretedBytes isBigEndian ifTrue:[
+ supportedFormats add:#'S24'.
+ ]
].
(supports_S32_LE ? false) ifTrue:[
- supportedFormats add:#'S32_LE'.
- UninterpretedBytes isBigEndian ifFalse:[
- supportedFormats add:#'S32'.
- ]
+ supportedFormats add:#'S32_LE'.
+ UninterpretedBytes isBigEndian ifFalse:[
+ supportedFormats add:#'S32'.
+ ]
].
(supports_S32_BE ? false) ifTrue:[
- supportedFormats add:#'S32_BE'.
- UninterpretedBytes isBigEndian ifTrue:[
- supportedFormats add:#'S32'.
- ]
+ supportedFormats add:#'S32_BE'.
+ UninterpretedBytes isBigEndian ifTrue:[
+ supportedFormats add:#'S32'.
+ ]
].
(supports_U16_LE ? false) ifTrue:[
- supportedFormats add:#'U16_LE'.
- UninterpretedBytes isBigEndian ifFalse:[
- supportedFormats add:#'U16'.
- ]
+ supportedFormats add:#'U16_LE'.
+ UninterpretedBytes isBigEndian ifFalse:[
+ supportedFormats add:#'U16'.
+ ]
].
(supports_U16_BE ? false) ifTrue:[
- supportedFormats add:#'U16_BE'.
- UninterpretedBytes isBigEndian ifTrue:[
- supportedFormats add:#'U16'.
- ]
+ supportedFormats add:#'U16_BE'.
+ UninterpretedBytes isBigEndian ifTrue:[
+ supportedFormats add:#'U16'.
+ ]
].
(supports_F32 ? false) ifTrue:[
- supportedFormats add:#'F32'
+ supportedFormats add:#'F32'
].
^ supportedFormats.
@@ -2741,47 +2725,47 @@
int fd;
if ((fp = __INST(handle)) != nil) {
- f = __FILEVal(fp);
- if (__INST(mode) != @symbol(writeonly)) {
- if (__bothSmallInteger(count, start)) {
- cnt = __intVal(count);
- offs = __intVal(start) - 1;
-
- objSize = _Size(anObject) - OHDR_SIZE;
- if ( (offs >= 0) && (cnt >= 0) && (objSize >= (cnt + offs)) ) {
- do {
- cp = (char *)__InstPtr(anObject) + OHDR_SIZE + offs;
-
- n = cnt;
+ f = __FILEVal(fp);
+ if (__INST(mode) != @symbol(writeonly)) {
+ if (__bothSmallInteger(count, start)) {
+ cnt = __intVal(count);
+ offs = __intVal(start) - 1;
+
+ objSize = _Size(anObject) - OHDR_SIZE;
+ if ( (offs >= 0) && (cnt >= 0) && (objSize >= (cnt + offs)) ) {
+ do {
+ cp = (char *)__InstPtr(anObject) + OHDR_SIZE + offs;
+
+ n = cnt;
# ifdef LINUX
- sigsetmask(~0);
+ sigsetmask(~0);
# endif
- if (__INST(buffered) == true) {
- n = fread(cp, 1, n, f);
- } else {
- fd = fileno(f);
- n = read(fd, cp, n);
- }
+ if (__INST(buffered) == true) {
+ n = fread(cp, 1, n, f);
+ } else {
+ fd = fileno(f);
+ n = read(fd, cp, n);
+ }
# ifdef LINUX
- sigsetmask(0);
+ sigsetmask(0);
# endif
- __BEGIN_INTERRUPTABLE__
- __END_INTERRUPTABLE__
- // console_fprintf(stderr, "SoundStream: read %d bytes\n", n);
- if (n > 0) {
- offs += n;
- cnt -= n;
- } else {
- if (n < 0) {
- console_fprintf(stderr, "read error: %d\n", __threadErrno);
- RETURN (count);
- }
- }
- } while (cnt);
- }
- RETURN (count);
- }
- }
+ __BEGIN_INTERRUPTABLE__
+ __END_INTERRUPTABLE__
+ // console_fprintf(stderr, "SoundStream: read %d bytes\n", n);
+ if (n > 0) {
+ offs += n;
+ cnt -= n;
+ } else {
+ if (n < 0) {
+ console_fprintf(stderr, "read error: %d\n", __threadErrno);
+ RETURN (count);
+ }
+ }
+ } while (cnt);
+ }
+ RETURN (count);
+ }
+ }
}
#endif /* SUPPORT_DEV_AUDIO */
@@ -2816,46 +2800,46 @@
int fd;
if ((fp = __INST(handle)) != nil) {
- f = __FILEVal(fp);
- if (__INST(mode) != @symbol(readonly)) {
- if (__bothSmallInteger(count, start)) {
- cnt = __intVal(count);
- offs = __intVal(start) - 1;
-
- objSize = _Size(anObject) - OHDR_SIZE;
- if ( (offs >= 0) && (cnt >= 0) && (objSize >= (cnt + offs)) ) {
- do {
- cp = (char *)__InstPtr(anObject) + OHDR_SIZE + offs;
-
- n = cnt;
+ f = __FILEVal(fp);
+ if (__INST(mode) != @symbol(readonly)) {
+ if (__bothSmallInteger(count, start)) {
+ cnt = __intVal(count);
+ offs = __intVal(start) - 1;
+
+ objSize = _Size(anObject) - OHDR_SIZE;
+ if ( (offs >= 0) && (cnt >= 0) && (objSize >= (cnt + offs)) ) {
+ do {
+ cp = (char *)__InstPtr(anObject) + OHDR_SIZE + offs;
+
+ n = cnt;
# ifdef LINUX
- sigsetmask(~0);
+ sigsetmask(~0);
# endif
- if (__INST(buffered) == true) {
- n = fwrite(cp, 1, n, f);
- } else {
- fd = fileno(f);
- n = write(fd, cp, n);
- }
+ if (__INST(buffered) == true) {
+ n = fwrite(cp, 1, n, f);
+ } else {
+ fd = fileno(f);
+ n = write(fd, cp, n);
+ }
# ifdef LINUX
- sigsetmask(0);
+ sigsetmask(0);
# endif
- __BEGIN_INTERRUPTABLE__
- __END_INTERRUPTABLE__
- if (n > 0) {
- offs += n;
- cnt -= n;
- } else {
- if (n < 0) {
- console_fprintf(stderr, "write error: %d\n", __threadErrno);
- RETURN (count);
- }
- }
- } while (cnt);
- }
- RETURN (count);
- }
- }
+ __BEGIN_INTERRUPTABLE__
+ __END_INTERRUPTABLE__
+ if (n > 0) {
+ offs += n;
+ cnt -= n;
+ } else {
+ if (n < 0) {
+ console_fprintf(stderr, "write error: %d\n", __threadErrno);
+ RETURN (count);
+ }
+ }
+ } while (cnt);
+ }
+ RETURN (count);
+ }
+ }
}
#endif /* SUPPORT_DEV_AUDIO */
@@ -2870,25 +2854,25 @@
documentation to be added.
class:
- <a short class summary here, describing what instances represent>
-
- responsibilities:
- <describing what my main role is>
-
- collaborators:
- <describing with whom and how I talk to>
+ <a short class summary here, describing what instances represent>
+
+ responsibilities:
+ <describing what my main role is>
+
+ collaborators:
+ <describing with whom and how I talk to>
API:
- <public api and main messages>
-
+ <public api and main messages>
+
example:
- <a one-line examples on how to use - can also be in a separate example method>
+ <a one-line examples on how to use - can also be in a separate example method>
implementation:
- <implementation points>
+ <implementation points>
[author:]
- exept MBP
+ exept MBP
[instance variables:]
@@ -2921,10 +2905,10 @@
ALport p;
if ((port = __INST(alPort)) != nil) {
- p = __ALportVal(port);
- while (ALgetfilled(p) > 0) {
- sginap(1);
- }
+ p = __ALportVal(port);
+ while (ALgetfilled(p) > 0) {
+ sginap(1);
+ }
}
RETURN(self);
#endif /* SUPPORT_IRIS_AUDIO */
@@ -2942,8 +2926,8 @@
OBJ port;
if ((port = __INST(alPort)) != nil) {
- __INST(alPort) = nil;
- ALcloseport(__ALportVal(port));
+ __INST(alPort) = nil;
+ ALcloseport(__ALportVal(port));
}
RETURN (self);
#endif /* SUPPORT_IRIS_AUDIO */
@@ -2959,34 +2943,34 @@
ALconfig config;
ALport p;
long params[] = {
- AL_INPUT_SOURCE, AL_INPUT_MIC,
- AL_INPUT_RATE, 8000,
- AL_OUTPUT_RATE, 8000,
+ AL_INPUT_SOURCE, AL_INPUT_MIC,
+ AL_INPUT_RATE, 8000,
+ AL_OUTPUT_RATE, 8000,
};
ok = false.
config = ALnewconfig();
if (__INST(numberOfChannels) == __MKSMALLINT(2))
- ALsetchannels(config, AL_STEREO);
+ ALsetchannels(config, AL_STEREO);
else
- ALsetchannels(config, AL_MONO);
+ ALsetchannels(config, AL_MONO);
if (__INST(bitsPerSample) == __MKSMALLINT(16))
- ALsetwidth(config, AL_SAMPLE_16);
+ ALsetwidth(config, AL_SAMPLE_16);
else
- ALsetwidth(config, AL_SAMPLE_8);
+ ALsetwidth(config, AL_SAMPLE_8);
if (__isSmallInteger(__INST(sampleRate)))
- params[3] = params[5] = __intVal(__INST(sampleRate));
+ params[3] = params[5] = __intVal(__INST(sampleRate));
ALsetparams(AL_DEFAULT_DEVICE, params, 6);
p = ALopenport("smallchat", (char *)_stringVal(aMode), config);
if (p) {
- OBJ t;
-
- t = __MKEXTERNALADDRESS(p); __INST(alPort) = t; __STORE(self, t);
+ OBJ t;
+
+ t = __MKEXTERNALADDRESS(p); __INST(alPort) = t; __STORE(self, t);
} else {
- __INST(alPort) = nil;
- goto out;
+ __INST(alPort) = nil;
+ goto out;
}
__INST(binary) = true;
@@ -2996,27 +2980,27 @@
*/
config = ALgetconfig(p);
switch (ALgetchannels(config)) {
- default:
- /* cannot happen */
- case AL_MONO:
- __INST(numberOfChannels) = __MKSMALLINT(1);
- break;
- case AL_STEREO:
- __INST(numberOfChannels) = __MKSMALLINT(2);
- break;
+ default:
+ /* cannot happen */
+ case AL_MONO:
+ __INST(numberOfChannels) = __MKSMALLINT(1);
+ break;
+ case AL_STEREO:
+ __INST(numberOfChannels) = __MKSMALLINT(2);
+ break;
}
switch (ALgetwidth(config)) {
- default:
- /* cannot happen */
- case AL_SAMPLE_8:
- __INST(bitsPerSample) = __MKSMALLINT(8);
- break;
- case AL_SAMPLE_16:
- __INST(bitsPerSample) = __MKSMALLINT(16);
- break;
- case AL_SAMPLE_24:
- __INST(bitsPerSample) = __MKSMALLINT(24);
- break;
+ default:
+ /* cannot happen */
+ case AL_SAMPLE_8:
+ __INST(bitsPerSample) = __MKSMALLINT(8);
+ break;
+ case AL_SAMPLE_16:
+ __INST(bitsPerSample) = __MKSMALLINT(16);
+ break;
+ case AL_SAMPLE_24:
+ __INST(bitsPerSample) = __MKSMALLINT(24);
+ break;
}
ALgetparams(AL_DEFAULT_DEVICE, params, 6);
__INST(sampleRate) = __MKSMALLINT(params[3]);
@@ -3028,11 +3012,11 @@
%}.
ok == false ifTrue:[
- lastErrorString := errorStringOrNil.
- lastErrorNumber := error ? -1.
- self openError:error.
- "normally not reached"
- ^ nil.
+ lastErrorString := errorStringOrNil.
+ lastErrorNumber := error ? -1.
+ self openError:error.
+ "normally not reached"
+ ^ nil.
].
self registerForFinalization.
! !
@@ -3042,25 +3026,25 @@
supportedAudioFormats
"return a collection of supported audio formats.
possibly returned symbols are:
- U8 unsigned 8bit samples
- S8 signed 8bit samples
- U16 unsigned 16bit samples in native format
- U16_LE unsigned 16bit big endian samples
- U16_BE unsigned 16bit big endian samples
- S16 signed 16bit little endian samples in native format
- S16_LE signed 16bit little endian samples
- S16_BE signed 16bit big endian samples
- S24 signed 24bit little endian samples in native format
- S24_LE signed 24bit little endian samples
- S24_BE signed 24bit big endian samples
- S32 signed 32bit little endian samples in native format
- S32_LE signed 32bit little endian samples
- S32_BE signed 32bit big endian samples
- F32 float samples
- MPEG audio mpeg encoded
- MU_LAW u-law encoded 8bit samples
- A_LAW a-law encoded 8bit samples
- IMA_ADPCM adpcm encoded
+ U8 unsigned 8bit samples
+ S8 signed 8bit samples
+ U16 unsigned 16bit samples in native format
+ U16_LE unsigned 16bit big endian samples
+ U16_BE unsigned 16bit big endian samples
+ S16 signed 16bit little endian samples in native format
+ S16_LE signed 16bit little endian samples
+ S16_BE signed 16bit big endian samples
+ S24 signed 24bit little endian samples in native format
+ S24_LE signed 24bit little endian samples
+ S24_BE signed 24bit big endian samples
+ S32 signed 32bit little endian samples in native format
+ S32_LE signed 32bit little endian samples
+ S32_BE signed 32bit big endian samples
+ F32 float samples
+ MPEG audio mpeg encoded
+ MU_LAW u-law encoded 8bit samples
+ A_LAW a-law encoded 8bit samples
+ IMA_ADPCM adpcm encoded
the set of returned symbols depends on the underlying sound hardware.
"
@@ -3093,23 +3077,23 @@
char *cp;
if ((port = __INST(alPort)) != nil) {
- if (__INST(mode) != _writeonly) {
- if (__bothSmallInteger(count, start)) {
- cnt = __intVal(count);
- offs = __intVal(start) - 1;
- p = __ALportVal(port);
- objSize = _Size(anObject) - OHDR_SIZE;
- if ((offs >= 0) && (cnt >= 0) && (objSize >= (cnt + offs))) {
- cp = (char *)__InstPtr(anObject) + OHDR_SIZE + offs;
- if (__INST(bitsPerSample) == __MKSMALLINT(16))
- nSamp = cnt / 2;
- else
- nSamp = cnt;
- ALreadsamps(p, cp, nSamp);
- RETURN ( __MKSMALLINT(cnt) );
- }
- }
- }
+ if (__INST(mode) != _writeonly) {
+ if (__bothSmallInteger(count, start)) {
+ cnt = __intVal(count);
+ offs = __intVal(start) - 1;
+ p = __ALportVal(port);
+ objSize = _Size(anObject) - OHDR_SIZE;
+ if ((offs >= 0) && (cnt >= 0) && (objSize >= (cnt + offs))) {
+ cp = (char *)__InstPtr(anObject) + OHDR_SIZE + offs;
+ if (__INST(bitsPerSample) == __MKSMALLINT(16))
+ nSamp = cnt / 2;
+ else
+ nSamp = cnt;
+ ALreadsamps(p, cp, nSamp);
+ RETURN ( __MKSMALLINT(cnt) );
+ }
+ }
+ }
}
}
#endif /* SUPPORT_IRIS_AUDIO */
@@ -3136,32 +3120,32 @@
char *cp;
if ((port = __INST(alPort)) != nil) {
- if (__INST(mode) != @symbol(readonly)) {
- if (__bothSmallInteger(count, start)) {
- cnt = __intVal(count);
- offs = __intVal(start) - 1;
- p = __ALportVal(port);
-
- /*
- * compute number of samples
- */
- objSize = _Size(anObject) - OHDR_SIZE;
- if ( (offs >= 0) && (cnt >= 0) && (objSize >= (cnt + offs)) ) {
- cp = (char *)__InstPtr(anObject) + OHDR_SIZE + offs;
- if (__INST(bitsPerSample) == __MKSMALLINT(16))
- nSamp = cnt / 2;
- else
- nSamp = cnt;
- ALwritesamps(p, cp, cnt);
- RETURN ( count );
- }
- }
- }
+ if (__INST(mode) != @symbol(readonly)) {
+ if (__bothSmallInteger(count, start)) {
+ cnt = __intVal(count);
+ offs = __intVal(start) - 1;
+ p = __ALportVal(port);
+
+ /*
+ * compute number of samples
+ */
+ objSize = _Size(anObject) - OHDR_SIZE;
+ if ( (offs >= 0) && (cnt >= 0) && (objSize >= (cnt + offs)) ) {
+ cp = (char *)__InstPtr(anObject) + OHDR_SIZE + offs;
+ if (__INST(bitsPerSample) == __MKSMALLINT(16))
+ nSamp = cnt / 2;
+ else
+ nSamp = cnt;
+ ALwritesamps(p, cp, cnt);
+ RETURN ( count );
+ }
+ }
+ }
}
}
#endif /* SUPPORT_IRIS_AUDIO */
%}.
- self errorUnsupportedOperation
+ self errorUnsupportedOperation
! !
!SoundStream::PortAudio class methodsFor:'default values'!
@@ -3185,25 +3169,25 @@
documentation to be added.
class:
- <a short class summary here, describing what instances represent>
-
- responsibilities:
- <describing what my main role is>
-
- collaborators:
- <describing with whom and how I talk to>
+ <a short class summary here, describing what instances represent>
+
+ responsibilities:
+ <describing what my main role is>
+
+ collaborators:
+ <describing with whom and how I talk to>
API:
- <public api and main messages>
-
+ <public api and main messages>
+
example:
- <a one-line examples on how to use - can also be in a separate example method>
+ <a one-line examples on how to use - can also be in a separate example method>
implementation:
- <implementation points>
+ <implementation points>
[author:]
- exept MBP
+ exept MBP
[instance variables:]
@@ -3224,16 +3208,16 @@
PaError paErr = 0;
if (DEBUGGING) {
- fprintf(stderr, "calling Pa_Initialize...\n");
+ fprintf(stderr, "calling Pa_Initialize...\n");
}
if ((paErr = Pa_Initialize()) != paNoError ) {
- errorMessageOrNil = __MKSTRING(Pa_GetErrorText( paErr ) );
- fprintf(stderr, "SoundStream [error]: Pa_Initialize failed\n");
+ errorMessageOrNil = __MKSTRING(Pa_GetErrorText( paErr ) );
+ fprintf(stderr, "SoundStream [error]: Pa_Initialize failed\n");
};
#endif
%}.
errorMessageOrNil notNil ifTrue:[
- self error:'failed to initialize audio device: ',errorMessageOrNil
+ self error:'failed to initialize audio device: ',errorMessageOrNil
].
! !
@@ -3258,14 +3242,14 @@
#ifdef SUPPORT_PORTAUDIO
OBJ str;
if ((str = __INST(handle1)) != nil) {
- struct paStreamData* paStreamData = (struct paStreamData*)__externalAddressVal(str);
-
- while (paStreamData->currentBuffer != NULL) {
- struct timespec a;
- a.tv_sec = 0;
- a.tv_nsec = 1 * 1000000; // 1 milliseconds asNanoseconds -> 1000000
- nanosleep( &a, NULL );
- }
+ struct paStreamData* paStreamData = (struct paStreamData*)__externalAddressVal(str);
+
+ while (paStreamData->currentBuffer != NULL) {
+ struct timespec a;
+ a.tv_sec = 0;
+ a.tv_nsec = 1 * 1000000; // 1 milliseconds asNanoseconds -> 1000000
+ nanosleep( &a, NULL );
+ }
}
#endif /* SUPPORT_PORTAUDIO */
%}.
@@ -3281,40 +3265,40 @@
#ifdef SUPPORT_PORTAUDIO
OBJ str;
if ((str = __INST(handle1)) != nil) {
- struct paStreamData* paStreamData = (struct paStreamData*)__externalAddressVal(str);
- struct paBuffer* buffer;
-
- if (DEBUGGING) {
- fprintf(stderr, "pa close\n");
- }
- __externalAddressVal(str) = NULL;
- __INST(handle1) = nil;
- // Pa_StopStream( paStreamData->stream );
- Pa_CloseStream( paStreamData->stream );
-
- LOCK(paStreamData->lock);
-
- buffer = paStreamData->currentBuffer;
- paStreamData->currentBuffer = NULL;
- paStreamData->lastBuffer = NULL;
- while (buffer != NULL) {
- struct paBuffer* nextBuffer = buffer->nextBuffer;
- free(buffer->sampleData);
- free(buffer);
- buffer = nextBuffer;
- }
- buffer = paStreamData->freeList;
- paStreamData->freeList = NULL;
- while (buffer != NULL) {
- struct paBuffer* nextBuffer = buffer->nextBuffer;
- free(buffer->sampleData);
- free(buffer);
- buffer = nextBuffer;
- }
-
- UNLOCK(paStreamData->lock);
- RELEASELOCK(paStreamData->lock);
- free(paStreamData);
+ struct paStreamData* paStreamData = (struct paStreamData*)__externalAddressVal(str);
+ struct paBuffer* buffer;
+
+ if (DEBUGGING) {
+ fprintf(stderr, "pa close\n");
+ }
+ __externalAddressVal(str) = NULL;
+ __INST(handle1) = nil;
+ // Pa_StopStream( paStreamData->stream );
+ Pa_CloseStream( paStreamData->stream );
+
+ LOCK(paStreamData->lock);
+
+ buffer = paStreamData->currentBuffer;
+ paStreamData->currentBuffer = NULL;
+ paStreamData->lastBuffer = NULL;
+ while (buffer != NULL) {
+ struct paBuffer* nextBuffer = buffer->nextBuffer;
+ free(buffer->sampleData);
+ free(buffer);
+ buffer = nextBuffer;
+ }
+ buffer = paStreamData->freeList;
+ paStreamData->freeList = NULL;
+ while (buffer != NULL) {
+ struct paBuffer* nextBuffer = buffer->nextBuffer;
+ free(buffer->sampleData);
+ free(buffer);
+ buffer = nextBuffer;
+ }
+
+ UNLOCK(paStreamData->lock);
+ RELEASELOCK(paStreamData->lock);
+ free(paStreamData);
}
RETURN (self);
#endif // SUPPORT_PORTAUDIO
@@ -3338,15 +3322,15 @@
/* default output device */
outputParameters.device = Pa_GetDefaultOutputDevice();
if (outputParameters.device == paNoDevice) {
- fprintf(stderr, "SoundStream [warning]: No default output device.\n");
- errorStringOrNil = __MKSTRING("No default output device");
- goto out;
+ fprintf(stderr, "SoundStream [warning]: No default output device.\n");
+ errorStringOrNil = __MKSTRING("No default output device");
+ goto out;
}
if (__isSmallInteger(__INST(numberOfChannels))) {
- nChannels = __intVal(__INST(numberOfChannels));
+ nChannels = __intVal(__INST(numberOfChannels));
} else {
- nChannels = 1;
+ nChannels = 1;
}
outputParameters.channelCount = nChannels;
outputParameters.suggestedLatency = Pa_GetDeviceInfo( outputParameters.device )->defaultLowOutputLatency;
@@ -3359,58 +3343,58 @@
// paUInt8 is an unsigned 8 bit format where 128 is considered "ground"
if (__INST(audioFormat) == @symbol(S16)) {
- outputParameters.sampleFormat = paInt16;
- bytesPerSample = 2;
+ outputParameters.sampleFormat = paInt16;
+ bytesPerSample = 2;
} else if (__INST(audioFormat) == @symbol(S32)) {
- outputParameters.sampleFormat = paInt32;
- bytesPerSample = 4;
+ outputParameters.sampleFormat = paInt32;
+ bytesPerSample = 4;
} else if (__INST(audioFormat) == @symbol(S24)) {
- outputParameters.sampleFormat = paInt24;
- bytesPerSample = 3;
+ outputParameters.sampleFormat = paInt24;
+ bytesPerSample = 3;
} else if (__INST(audioFormat) == @symbol(S8)) {
- outputParameters.sampleFormat = paInt8;
- bytesPerSample = 1;
+ outputParameters.sampleFormat = paInt8;
+ bytesPerSample = 1;
} else if (__INST(audioFormat) == @symbol(F32)) {
- outputParameters.sampleFormat = paFloat32;
- bytesPerSample = 4;
+ outputParameters.sampleFormat = paFloat32;
+ bytesPerSample = 4;
} else if (__INST(audioFormat) == @symbol(U8)) {
- outputParameters.sampleFormat = paUInt8;
- bytesPerSample = 1;
+ outputParameters.sampleFormat = paUInt8;
+ bytesPerSample = 1;
} else {
- fprintf(stderr, "SoundStream [warning]: unknown format - using U8\n");
- outputParameters.sampleFormat = paUInt8;
- bytesPerSample = 1;
+ fprintf(stderr, "SoundStream [warning]: unknown format - using U8\n");
+ outputParameters.sampleFormat = paUInt8;
+ bytesPerSample = 1;
}
if (__isSmallInteger(__INST(sampleRate))) {
- sampleRate = __intVal(__INST(sampleRate));
+ sampleRate = __intVal(__INST(sampleRate));
} else {
- fprintf(stderr, "SoundStream [warning]: using default sampleRate 8000\n");
- sampleRate = 8000;
+ fprintf(stderr, "SoundStream [warning]: using default sampleRate 8000\n");
+ sampleRate = 8000;
}
paStreamData = (struct paStreamData*)malloc(sizeof(struct paStreamData));
if (paStreamData == NULL) {
- fprintf(stderr, "SoundStream [warning]: failed to allocate paStream\n");
- errorStringOrNil = __MKSTRING("failed to allocate paStream");
- goto out;
+ fprintf(stderr, "SoundStream [warning]: failed to allocate paStream\n");
+ errorStringOrNil = __MKSTRING("failed to allocate paStream");
+ goto out;
}
paErr = Pa_OpenStream(
- &stream,
- NULL, /* no input */
- &outputParameters,
- sampleRate,
- FRAMES_PER_BUFFER,
- paClipOff, /* we won't output out of range samples so don't bother clipping them */
- paCallback,
- paStreamData );
+ &stream,
+ NULL, /* no input */
+ &outputParameters,
+ sampleRate,
+ FRAMES_PER_BUFFER,
+ paClipOff, /* we won't output out of range samples so don't bother clipping them */
+ paCallback,
+ paStreamData );
if (paErr != paNoError) {
- fprintf(stderr, "SoundStream [warning]: openStream: %s\n", Pa_GetErrorText( paErr ));
- free(paStreamData);
- errorStringOrNil = __MKSTRING(Pa_GetErrorText( paErr ));
- goto out;
+ fprintf(stderr, "SoundStream [warning]: openStream: %s\n", Pa_GetErrorText( paErr ));
+ free(paStreamData);
+ errorStringOrNil = __MKSTRING(Pa_GetErrorText( paErr ));
+ goto out;
}
paStreamData->stream = stream;
INITLOCK(paStreamData->lock);
@@ -3424,17 +3408,17 @@
paStreamData->hasFinished = 0;
{
- OBJ t;
- t = __MKEXTERNALADDRESS(paStreamData); __INST(handle1) = t; __STORE(self, t);
+ OBJ t;
+ t = __MKEXTERNALADDRESS(paStreamData); __INST(handle1) = t; __STORE(self, t);
}
__INST(binary) = true;
paErr = Pa_SetStreamFinishedCallback( stream, &paStreamFinished );
if( paErr != paNoError ) {
- fprintf(stderr, "SoundStream [warning]: setFinishedCallback: %s\n", Pa_GetErrorText( paErr ));
- free(paStreamData);
- errorStringOrNil = __MKSTRING(Pa_GetErrorText( paErr ));
- goto out;
+ fprintf(stderr, "SoundStream [warning]: setFinishedCallback: %s\n", Pa_GetErrorText( paErr ));
+ free(paStreamData);
+ errorStringOrNil = __MKSTRING(Pa_GetErrorText( paErr ));
+ goto out;
};
ok = true;
@@ -3443,11 +3427,11 @@
%}.
ok == false ifTrue:[
- lastErrorString := errorStringOrNil.
- lastErrorNumber := error ? -1.
- self openError:error.
- "normally not reached"
- ^ nil.
+ lastErrorString := errorStringOrNil.
+ lastErrorNumber := error ? -1.
+ self openError:error.
+ "normally not reached"
+ ^ nil.
].
self registerForFinalization.
@@ -3461,7 +3445,7 @@
super initialize.
(IsInitialized ? false) ifFalse:[
- self class primitiveInitializeDevice
+ self class primitiveInitializeDevice
].
"Created: 17.11.1995 / 17:28:14 / cg"
@@ -3472,25 +3456,25 @@
supportedAudioFormats
"return a collection of supported audio formats.
possibly returned symbols are:
- U8 unsigned 8bit samples
- S8 signed 8bit samples
- U16 unsigned 16bit samples in native format
- U16_LE unsigned 16bit big endian samples
- U16_BE unsigned 16bit big endian samples
- S16 signed 16bit little endian samples in native format
- S16_LE signed 16bit little endian samples
- S16_BE signed 16bit big endian samples
- S24 signed 24bit little endian samples in native format
- S24_LE signed 24bit little endian samples
- S24_BE signed 24bit big endian samples
- S32 signed 32bit little endian samples in native format
- S32_LE signed 32bit little endian samples
- S32_BE signed 32bit big endian samples
- F32 float samples
- MPEG audio mpeg encoded
- MU_LAW u-law encoded 8bit samples
- A_LAW a-law encoded 8bit samples
- IMA_ADPCM adpcm encoded
+ U8 unsigned 8bit samples
+ S8 signed 8bit samples
+ U16 unsigned 16bit samples in native format
+ U16_LE unsigned 16bit big endian samples
+ U16_BE unsigned 16bit big endian samples
+ S16 signed 16bit little endian samples in native format
+ S16_LE signed 16bit little endian samples
+ S16_BE signed 16bit big endian samples
+ S24 signed 24bit little endian samples in native format
+ S24_LE signed 24bit little endian samples
+ S24_BE signed 24bit big endian samples
+ S32 signed 32bit little endian samples in native format
+ S32_LE signed 32bit little endian samples
+ S32_BE signed 32bit big endian samples
+ F32 float samples
+ MPEG audio mpeg encoded
+ MU_LAW u-law encoded 8bit samples
+ A_LAW a-law encoded 8bit samples
+ IMA_ADPCM adpcm encoded
the set of returned symbols depends on the underlying sound hardware.
"
@@ -3519,73 +3503,73 @@
%}.
supportedFormats := IdentitySet new.
(supports_MU_LAW ? false) ifTrue:[
- supportedFormats add:#'MU_LAW'
+ supportedFormats add:#'MU_LAW'
].
(supports_A_LAW ? false) ifTrue:[
- supportedFormats add:#'A_LAW'
+ supportedFormats add:#'A_LAW'
].
(supports_IMA_ADPCM ? false) ifTrue:[
- supportedFormats add:#'IMA_ADPCM'
+ supportedFormats add:#'IMA_ADPCM'
].
(supports_MPEG ? false) ifTrue:[
- supportedFormats add:#'MPEG'
+ supportedFormats add:#'MPEG'
].
(supports_S8 ? false) ifTrue:[
- supportedFormats add:#'S8'
+ supportedFormats add:#'S8'
].
(supports_U8 ? false) ifTrue:[
- supportedFormats add:#'U8'
+ supportedFormats add:#'U8'
].
(supports_S16_LE ? false) ifTrue:[
- supportedFormats add:#'S16_LE'.
- UninterpretedBytes isBigEndian ifFalse:[
- supportedFormats add:#'S16'.
- ]
+ supportedFormats add:#'S16_LE'.
+ UninterpretedBytes isBigEndian ifFalse:[
+ supportedFormats add:#'S16'.
+ ]
].
(supports_S16_BE ? false) ifTrue:[
- supportedFormats add:#'S16_BE'.
- UninterpretedBytes isBigEndian ifTrue:[
- supportedFormats add:#'S16'.
- ]
+ supportedFormats add:#'S16_BE'.
+ UninterpretedBytes isBigEndian ifTrue:[
+ supportedFormats add:#'S16'.
+ ]
].
(supports_S24_LE ? false) ifTrue:[
- supportedFormats add:#'S24_LE'.
- UninterpretedBytes isBigEndian ifFalse:[
- supportedFormats add:#'S24'.
- ]
+ supportedFormats add:#'S24_LE'.
+ UninterpretedBytes isBigEndian ifFalse:[
+ supportedFormats add:#'S24'.
+ ]
].
(supports_S24_BE ? false) ifTrue:[
- supportedFormats add:#'S24_BE'.
- UninterpretedBytes isBigEndian ifTrue:[
- supportedFormats add:#'S24'.
- ]
+ supportedFormats add:#'S24_BE'.
+ UninterpretedBytes isBigEndian ifTrue:[
+ supportedFormats add:#'S24'.
+ ]
].
(supports_S32_LE ? false) ifTrue:[
- supportedFormats add:#'S32_LE'.
- UninterpretedBytes isBigEndian ifFalse:[
- supportedFormats add:#'S32'.
- ]
+ supportedFormats add:#'S32_LE'.
+ UninterpretedBytes isBigEndian ifFalse:[
+ supportedFormats add:#'S32'.
+ ]
].
(supports_S32_BE ? false) ifTrue:[
- supportedFormats add:#'S32_BE'.
- UninterpretedBytes isBigEndian ifTrue:[
- supportedFormats add:#'S32'.
- ]
+ supportedFormats add:#'S32_BE'.
+ UninterpretedBytes isBigEndian ifTrue:[
+ supportedFormats add:#'S32'.
+ ]
].
(supports_U16_LE ? false) ifTrue:[
- supportedFormats add:#'U16_LE'.
- UninterpretedBytes isBigEndian ifFalse:[
- supportedFormats add:#'U16'.
- ]
+ supportedFormats add:#'U16_LE'.
+ UninterpretedBytes isBigEndian ifFalse:[
+ supportedFormats add:#'U16'.
+ ]
].
(supports_U16_BE ? false) ifTrue:[
- supportedFormats add:#'U16_BE'.
- UninterpretedBytes isBigEndian ifTrue:[
- supportedFormats add:#'U16'.
- ]
+ supportedFormats add:#'U16_BE'.
+ UninterpretedBytes isBigEndian ifTrue:[
+ supportedFormats add:#'U16'.
+ ]
].
(supports_F32 ? false) ifTrue:[
- supportedFormats add:#'F32'
+ supportedFormats add:#'F32'
].
^ supportedFormats.
@@ -3622,79 +3606,79 @@
OBJ str;
if ((str = __INST(handle1)) != nil) {
- if (__INST(mode) != @symbol(readonly)) {
- if (__bothSmallInteger(count, start)) {
- // allocate a buffer
- struct paStreamData* paStreamData = (struct paStreamData*)__externalAddressVal(str);
- int cnt = __intVal(count);
- int offs = __intVal(start) - 1;
- int objSize;
-
- objSize = _Size(anObject) - OHDR_SIZE;
- if ( (offs >= 0) && (cnt >= 0) && (objSize >= (cnt + offs)) ) {
- struct paBuffer* newBuffer;
- struct paBuffer* toFree;
- int mustStart = 0;
- unsigned char* newSampleData;
-
- // try freeList
- LOCK(paStreamData->lock);
- if ((paStreamData->freeList != NULL)
- && (paStreamData->freeList->bufferSize == cnt)) {
- // reuse
- newBuffer = paStreamData->freeList;
- paStreamData->freeList = newBuffer->nextBuffer;
- newSampleData = newBuffer->sampleData;
- toFree = NULL;
- if (DEBUGGING) {
- fprintf(stderr, "from free: %p (->%p)\n", newBuffer, newBuffer->sampleData);
- }
- } else {
- // free them all
- toFree = paStreamData->freeList;
- paStreamData->freeList = NULL;
- newBuffer = malloc(sizeof(struct paBuffer));
- newSampleData = malloc(cnt);
- newBuffer->sampleData = newSampleData;
- newBuffer->bufferSize = cnt;
- if (DEBUGGING) {
- fprintf(stderr, "alloc: %p (->%p)\n", newBuffer, newBuffer->sampleData);
- }
- }
-
- memcpy(newSampleData, (__ByteArrayInstPtr(anObject)->ba_element)+offs, cnt);
- newBuffer->nextBuffer = NULL;
-
- if (paStreamData->lastBuffer == NULL) {
- // start stream's buffer list
- paStreamData->currentBuffer = newBuffer;
- mustStart = 1;
- } else {
- // append to stream's buffer list
- paStreamData->lastBuffer->nextBuffer = newBuffer;
- }
- paStreamData->lastBuffer = newBuffer;
- paStreamData->hasFinished = 0;
- UNLOCK(paStreamData->lock);
-
- if (mustStart) {
- PaError paErr = Pa_StartStream( paStreamData->stream );
- if ( paErr != paNoError ) {
- if (DEBUGGING) {
- fprintf(stderr, "start error\n");
- }
- RETURN (0);
- };
- }
- RETURN (count);
- }
- }
- }
+ if (__INST(mode) != @symbol(readonly)) {
+ if (__bothSmallInteger(count, start)) {
+ // allocate a buffer
+ struct paStreamData* paStreamData = (struct paStreamData*)__externalAddressVal(str);
+ int cnt = __intVal(count);
+ int offs = __intVal(start) - 1;
+ int objSize;
+
+ objSize = _Size(anObject) - OHDR_SIZE;
+ if ( (offs >= 0) && (cnt >= 0) && (objSize >= (cnt + offs)) ) {
+ struct paBuffer* newBuffer;
+ struct paBuffer* toFree;
+ int mustStart = 0;
+ unsigned char* newSampleData;
+
+ // try freeList
+ LOCK(paStreamData->lock);
+ if ((paStreamData->freeList != NULL)
+ && (paStreamData->freeList->bufferSize == cnt)) {
+ // reuse
+ newBuffer = paStreamData->freeList;
+ paStreamData->freeList = newBuffer->nextBuffer;
+ newSampleData = newBuffer->sampleData;
+ toFree = NULL;
+ if (DEBUGGING) {
+ fprintf(stderr, "from free: %p (->%p)\n", newBuffer, newBuffer->sampleData);
+ }
+ } else {
+ // free them all
+ toFree = paStreamData->freeList;
+ paStreamData->freeList = NULL;
+ newBuffer = malloc(sizeof(struct paBuffer));
+ newSampleData = malloc(cnt);
+ newBuffer->sampleData = newSampleData;
+ newBuffer->bufferSize = cnt;
+ if (DEBUGGING) {
+ fprintf(stderr, "alloc: %p (->%p)\n", newBuffer, newBuffer->sampleData);
+ }
+ }
+
+ memcpy(newSampleData, (__ByteArrayInstPtr(anObject)->ba_element)+offs, cnt);
+ newBuffer->nextBuffer = NULL;
+
+ if (paStreamData->lastBuffer == NULL) {
+ // start stream's buffer list
+ paStreamData->currentBuffer = newBuffer;
+ mustStart = 1;
+ } else {
+ // append to stream's buffer list
+ paStreamData->lastBuffer->nextBuffer = newBuffer;
+ }
+ paStreamData->lastBuffer = newBuffer;
+ paStreamData->hasFinished = 0;
+ UNLOCK(paStreamData->lock);
+
+ if (mustStart) {
+ PaError paErr = Pa_StartStream( paStreamData->stream );
+ if ( paErr != paNoError ) {
+ if (DEBUGGING) {
+ fprintf(stderr, "start error\n");
+ }
+ RETURN (0);
+ };
+ }
+ RETURN (count);
+ }
+ }
+ }
}
#endif /* SUPPORT_PORTAUDIO */
%}.
- self errorUnsupportedOperation
+ self errorUnsupportedOperation
! !
!SoundStream::Win32DirectSound class methodsFor:'documentation'!
@@ -3704,25 +3688,25 @@
documentation to be added.
class:
- <a short class summary here, describing what instances represent>
-
- responsibilities:
- <describing what my main role is>
-
- collaborators:
- <describing with whom and how I talk to>
+ <a short class summary here, describing what instances represent>
+
+ responsibilities:
+ <describing what my main role is>
+
+ collaborators:
+ <describing with whom and how I talk to>
API:
- <public api and main messages>
-
+ <public api and main messages>
+
example:
- <a one-line examples on how to use - can also be in a separate example method>
+ <a one-line examples on how to use - can also be in a separate example method>
implementation:
- <implementation points>
+ <implementation points>
[author:]
- exept MBP
+ exept MBP
[instance variables:]
@@ -3765,19 +3749,19 @@
LPDIRECTSOUNDBUFFER t_pDSBuffer;
if ((oDSBuffer = __INST(pDSBuffer)) != nil) {
- __INST(pDSBuffer) = nil;
- t_pDSBuffer = __DSBufferVal(oDSBuffer);
- if (t_pDSBuffer) {
- IDirectSoundBuffer_Stop(t_pDSBuffer);
- IDirectSoundBuffer_Release(t_pDSBuffer);
- }
+ __INST(pDSBuffer) = nil;
+ t_pDSBuffer = __DSBufferVal(oDSBuffer);
+ if (t_pDSBuffer) {
+ IDirectSoundBuffer_Stop(t_pDSBuffer);
+ IDirectSoundBuffer_Release(t_pDSBuffer);
+ }
}
if ((oDirectSound = __INST(pDirectSound)) != nil) {
- __INST(pDirectSound) = nil;
- t_pDirectSound = __DirectSoundVal(oDirectSound);
- if (t_pDirectSound) {
- IDirectSound_Release(t_pDirectSound);
- }
+ __INST(pDirectSound) = nil;
+ t_pDirectSound = __DirectSoundVal(oDirectSound);
+ if (t_pDirectSound) {
+ IDirectSound_Release(t_pDirectSound);
+ }
}
RETURN (self);
#endif /* SUPPORT_WIN32_DIRECTSOUND */
@@ -3803,8 +3787,8 @@
/* Create the DS object */
if ((result = DirectSoundCreate(NULL, &t_pDirectSound, NULL)) != DS_OK) {
- console_fprintf(stderr,"SoundStream: Cannot open default sound device!!\n");
- goto out;
+ console_fprintf(stderr,"SoundStream: Cannot open default sound device!!\n");
+ goto out;
}
/* Define the wave format structure */
@@ -3826,20 +3810,20 @@
/* Create the primary DS buffer */
if ((result = IDirectSound_CreateSoundBuffer(t_pDirectSound, &primarydsbDesc,
- &t_pDSPrimeBuffer, NULL)) != DS_OK) {
- console_fprintf(stderr,"SoundStream: Cannot get the primary DS buffer address!\n");
- IDirectSound_Release(t_pDirectSound);
- goto out;
+ &t_pDSPrimeBuffer, NULL)) != DS_OK) {
+ console_fprintf(stderr,"SoundStream: Cannot get the primary DS buffer address!\n");
+ IDirectSound_Release(t_pDirectSound);
+ goto out;
}
/* Set the primary DS buffer sound format. We have to do this because
the default primary buffer is 8-bit, 22kHz! */
if ((result = IDirectSoundBuffer_SetFormat(t_pDSPrimeBuffer, &wfFormat)) != DS_OK) {
- console_fprintf(stderr,"SoundStream: Cannot set the primary DS buffer to proper sound format (%x) (%d)!\n", result, result);
- IDirectSoundBuffer_Stop(t_pDSPrimeBuffer);
- IDirectSoundBuffer_Release(t_pDSPrimeBuffer);
- IDirectSound_Release(t_pDirectSound);
- goto out;
+ console_fprintf(stderr,"SoundStream: Cannot set the primary DS buffer to proper sound format (%x) (%d)!\n", result, result);
+ IDirectSoundBuffer_Stop(t_pDSPrimeBuffer);
+ IDirectSoundBuffer_Release(t_pDSPrimeBuffer);
+ IDirectSound_Release(t_pDirectSound);
+ goto out;
}
# endif /* 0 */
@@ -3855,18 +3839,18 @@
/* Create the secondary DS buffer */
if ((result = IDirectSound_CreateSoundBuffer(t_pDirectSound, &dsbdDesc, &t_pDSBuffer, NULL)) != DS_OK) {
- console_fprintf(stderr,"SoundStream: couldn't create sound buffer!\n");
- IDirectSoundBuffer_Stop(t_pDSPrimeBuffer);
- IDirectSoundBuffer_Release(t_pDSPrimeBuffer);
- IDirectSound_Release(t_pDirectSound);
- goto out;
+ console_fprintf(stderr,"SoundStream: couldn't create sound buffer!\n");
+ IDirectSoundBuffer_Stop(t_pDSPrimeBuffer);
+ IDirectSoundBuffer_Release(t_pDSPrimeBuffer);
+ IDirectSound_Release(t_pDirectSound);
+ goto out;
}
/* Lock the DS buffer */
if ((result = IDirectSoundBuffer_Lock(t_pDSBuffer, 0, t_cbBufSize, (LPLPVOID)&pDSBuffData,
- &dwDataLen, NULL, NULL, 0)) != DS_OK) {
- console_fprintf(stderr,"SoundStream: couldn't lock sound buffer!\n");
- goto errorAndOut;
+ &dwDataLen, NULL, NULL, 0)) != DS_OK) {
+ console_fprintf(stderr,"SoundStream: couldn't lock sound buffer!\n");
+ goto errorAndOut;
}
/* Zero the DS buffer */
@@ -3874,29 +3858,29 @@
/* Unlock the DS buffer */
if ((result = IDirectSoundBuffer_Unlock(t_pDSBuffer, pDSBuffData, dwDataLen, NULL, 0)) != DS_OK) {
- console_fprintf(stderr,"SoundStream: couldn't unlock sound buffer!\n");
- goto errorAndOut;
+ console_fprintf(stderr,"SoundStream: couldn't unlock sound buffer!\n");
+ goto errorAndOut;
}
__INST(bufferOffset) = __MKSMALLINT(0); // reset last write position to start of buffer
/* Start the buffer playback */
if ((result = IDirectSoundBuffer_Play(t_pDSBuffer, 0, 0, DSBPLAY_LOOPING) != DS_OK)) {
- console_fprintf(stderr,"SoundStream: couldn't play sound buffer!\n");
+ console_fprintf(stderr,"SoundStream: couldn't play sound buffer!\n");
errorAndOut:
- IDirectSoundBuffer_Stop(t_pDSBuffer);
- IDirectSoundBuffer_Stop(t_pDSPrimeBuffer);
- IDirectSoundBuffer_Release(t_pDSPrimeBuffer);
- IDirectSound_Release(t_pDirectSound);
- goto out;
+ IDirectSoundBuffer_Stop(t_pDSBuffer);
+ IDirectSoundBuffer_Stop(t_pDSPrimeBuffer);
+ IDirectSoundBuffer_Release(t_pDSPrimeBuffer);
+ IDirectSound_Release(t_pDirectSound);
+ goto out;
}
{
- OBJ t;
-
- t = __MKEXTERNALADDRESS(t_pDSBuffer); __INST(pDSBuffer) = t; __STORE(self, t);
- t = __MKEXTERNALADDRESS(t_pDirectSound); __INST(pDirectSound) = t; __STORE(self, t);
+ OBJ t;
+
+ t = __MKEXTERNALADDRESS(t_pDSBuffer); __INST(pDSBuffer) = t; __STORE(self, t);
+ t = __MKEXTERNALADDRESS(t_pDirectSound); __INST(pDirectSound) = t; __STORE(self, t);
}
ok = true;
out:;
@@ -3904,11 +3888,11 @@
%}.
ok == false ifTrue:[
- lastErrorString := errorStringOrNil.
- lastErrorNumber := error ? -1.
- self openError:error.
- "normally not reached"
- ^ nil.
+ lastErrorString := errorStringOrNil.
+ lastErrorNumber := error ? -1.
+ self openError:error.
+ "normally not reached"
+ ^ nil.
].
self registerForFinalization.
! !
@@ -3918,25 +3902,25 @@
supportedAudioFormats
"return a collection of supported audio formats.
possibly returned symbols are:
- U8 unsigned 8bit samples
- S8 signed 8bit samples
- U16 unsigned 16bit samples in native format
- U16_LE unsigned 16bit big endian samples
- U16_BE unsigned 16bit big endian samples
- S16 signed 16bit little endian samples in native format
- S16_LE signed 16bit little endian samples
- S16_BE signed 16bit big endian samples
- S24 signed 24bit little endian samples in native format
- S24_LE signed 24bit little endian samples
- S24_BE signed 24bit big endian samples
- S32 signed 32bit little endian samples in native format
- S32_LE signed 32bit little endian samples
- S32_BE signed 32bit big endian samples
- F32 float samples
- MPEG audio mpeg encoded
- MU_LAW u-law encoded 8bit samples
- A_LAW a-law encoded 8bit samples
- IMA_ADPCM adpcm encoded
+ U8 unsigned 8bit samples
+ S8 signed 8bit samples
+ U16 unsigned 16bit samples in native format
+ U16_LE unsigned 16bit big endian samples
+ U16_BE unsigned 16bit big endian samples
+ S16 signed 16bit little endian samples in native format
+ S16_LE signed 16bit little endian samples
+ S16_BE signed 16bit big endian samples
+ S24 signed 24bit little endian samples in native format
+ S24_LE signed 24bit little endian samples
+ S24_BE signed 24bit big endian samples
+ S32 signed 32bit little endian samples in native format
+ S32_LE signed 32bit little endian samples
+ S32_BE signed 32bit big endian samples
+ F32 float samples
+ MPEG audio mpeg encoded
+ MU_LAW u-law encoded 8bit samples
+ A_LAW a-law encoded 8bit samples
+ IMA_ADPCM adpcm encoded
the set of returned symbols depends on the underlying sound hardware.
"
@@ -3989,15 +3973,15 @@
int cnt, offs;
if ((oDSBuffer = __INST(pDSBuffer)) != nil) {
- t_pDSBuffer = __DSBufferVal(oDSBuffer);
+ t_pDSBuffer = __DSBufferVal(oDSBuffer);
}
if ((oDirectSound = __INST(pDirectSound)) != nil) {
- t_pDirectSound = __DirectSoundVal(oDirectSound);
+ t_pDirectSound = __DirectSoundVal(oDirectSound);
}
if (!t_pDSBuffer || !t_pDirectSound) {
- console_fprintf(stderr, "SoundStream not open!\n");
- RETURN (0);
+ console_fprintf(stderr, "SoundStream not open!\n");
+ RETURN (0);
}
t_cbBufOffset = __intVal(__INST(bufferOffset));
t_cbBufSize = __intVal(__INST(bufferSize));
@@ -4009,47 +3993,47 @@
// Should be playing, right?
hr = IDirectSoundBuffer_GetStatus(t_pDSBuffer, &status );
if (!(status && DSBSTATUS_PLAYING)) {
- console_fprintf(stderr, "Buffer not playing!\n");
- RETURN (0);
+ console_fprintf(stderr, "Buffer not playing!\n");
+ RETURN (0);
}
// Sleep until we have enough room in buffer.
hr = IDirectSoundBuffer_GetCurrentPosition(t_pDSBuffer, &playPos, &safePos );
if( hr != DS_OK ) {
- console_fprintf(stderr, "Cannot get position!\n");
- RETURN (0);
+ console_fprintf(stderr, "Cannot get position!\n");
+ RETURN (0);
}
if( playPos < t_cbBufOffset ) playPos += t_cbBufSize;
endWrite = t_cbBufOffset + (cnt * sizeof(short));
while ( playPos < endWrite ) {
- // Calculate number of milliseconds until we will have room, as
- // time = distance * (milliseconds/second) / ((bytes/sample) * (samples/second)),
- // rounded up.
- millis = (DWORD) (1.0 + ((endWrite - playPos) * 1000.0) / ( sizeof(short) * __intVal(__INST(sampleRate))));
-
- // Sleep for that long
- Sleep( millis );
-
- // Wake up, find out where we are now
- hr = IDirectSoundBuffer_GetCurrentPosition(t_pDSBuffer, &playPos, &safePos );
- if( hr != DS_OK ) {
- console_fprintf(stderr, "Cannot get position!\n");
- RETURN (0);
- }
- if( playPos < t_cbBufOffset ) playPos += t_cbBufSize; // unwrap offset
+ // Calculate number of milliseconds until we will have room, as
+ // time = distance * (milliseconds/second) / ((bytes/sample) * (samples/second)),
+ // rounded up.
+ millis = (DWORD) (1.0 + ((endWrite - playPos) * 1000.0) / ( sizeof(short) * __intVal(__INST(sampleRate))));
+
+ // Sleep for that long
+ Sleep( millis );
+
+ // Wake up, find out where we are now
+ hr = IDirectSoundBuffer_GetCurrentPosition(t_pDSBuffer, &playPos, &safePos );
+ if( hr != DS_OK ) {
+ console_fprintf(stderr, "Cannot get position!\n");
+ RETURN (0);
+ }
+ if( playPos < t_cbBufOffset ) playPos += t_cbBufSize; // unwrap offset
}
// Lock free space in the DS
hr = IDirectSoundBuffer_Lock(t_pDSBuffer, t_cbBufOffset, cnt * sizeof(short), &lpbuf1, &dwsize1, &lpbuf2, &dwsize2, 0);
if (hr == DS_OK) {
- // Copy the buffer into the DS
- CopyMemory(lpbuf1, buf, dwsize1);
- if(NULL != lpbuf2) CopyMemory(lpbuf2, buf+dwsize1, dwsize2);
-
- // Update our buffer offset and unlock sound buffer
- t_cbBufOffset = (t_cbBufOffset + dwsize1 + dwsize2) % t_cbBufSize;
- IDirectSoundBuffer_Unlock(t_pDSBuffer, lpbuf1, dwsize1, lpbuf2, dwsize2);
+ // Copy the buffer into the DS
+ CopyMemory(lpbuf1, buf, dwsize1);
+ if(NULL != lpbuf2) CopyMemory(lpbuf2, buf+dwsize1, dwsize2);
+
+ // Update our buffer offset and unlock sound buffer
+ t_cbBufOffset = (t_cbBufOffset + dwsize1 + dwsize2) % t_cbBufSize;
+ IDirectSoundBuffer_Unlock(t_pDSBuffer, lpbuf1, dwsize1, lpbuf2, dwsize2);
}
__INST(buffferOffset) = __MKSMALLINT(t_cbBufOffset);
@@ -4058,7 +4042,7 @@
#endif /* SUPPORT_WIN32_DIRECTSOUND */
%}.
- self errorUnsupportedOperation
+ self errorUnsupportedOperation
! !
!SoundStream::Win32WaveSound class methodsFor:'documentation'!
@@ -4068,25 +4052,25 @@
documentation to be added.
class:
- <a short class summary here, describing what instances represent>
-
- responsibilities:
- <describing what my main role is>
-
- collaborators:
- <describing with whom and how I talk to>
+ <a short class summary here, describing what instances represent>
+
+ responsibilities:
+ <describing what my main role is>
+
+ collaborators:
+ <describing with whom and how I talk to>
API:
- <public api and main messages>
-
+ <public api and main messages>
+
example:
- <a one-line examples on how to use - can also be in a separate example method>
+ <a one-line examples on how to use - can also be in a separate example method>
implementation:
- <implementation points>
+ <implementation points>
[author:]
- exept MBP
+ exept MBP
[instance variables:]
@@ -4130,41 +4114,41 @@
OBJ oWaveHandle;
if ((oWaveHandle = __INST(waveHandle)) != nil) {
- t_waveHandle = __WaveHandleVal(oWaveHandle);
+ t_waveHandle = __WaveHandleVal(oWaveHandle);
# ifdef NO_WAIT_IN_CLOSE
- /* Force cancellation of any pending buffers */
- (void)waveOutReset(t_waveHandle);
+ /* Force cancellation of any pending buffers */
+ (void)waveOutReset(t_waveHandle);
# endif
- /* Wait until all pending buffers have been freed */
- while (free_buffers < total_buffers) {
- WaitForSingleObject(free_buffer_event, INFINITE);
- }
+ /* Wait until all pending buffers have been freed */
+ while (free_buffers < total_buffers) {
+ WaitForSingleObject(free_buffer_event, INFINITE);
+ }
# ifndef NO_WAIT_IN_CLOSE
- /* Force cancellation of any pending buffers */
- (void)waveOutReset(t_waveHandle);
+ /* Force cancellation of any pending buffers */
+ (void)waveOutReset(t_waveHandle);
# endif
- /* Close the device */
- if ((r = waveOutClose(t_waveHandle)) != 0) {
- console_printf("waveOutClose\n");
- RETURN(self);
- }
-
- EnterCriticalSection(&free_list_lock);
-
- /* Free allocated buffers */
- for (bp = free_list; bp != NULL; bp = next) {
- next = bp->next;
- (void)free(bp);
- }
- free_list = NULL;
-
- LeaveCriticalSection(&free_list_lock);
-
- __INST(waveHandle) = nil;
+ /* Close the device */
+ if ((r = waveOutClose(t_waveHandle)) != 0) {
+ console_printf("waveOutClose\n");
+ RETURN(self);
+ }
+
+ EnterCriticalSection(&free_list_lock);
+
+ /* Free allocated buffers */
+ for (bp = free_list; bp != NULL; bp = next) {
+ next = bp->next;
+ (void)free(bp);
+ }
+ free_list = NULL;
+
+ LeaveCriticalSection(&free_list_lock);
+
+ __INST(waveHandle) = nil;
}
RETURN (self);
#endif /* SUPPORT_WIN32_WAVESOUND */
@@ -4185,7 +4169,7 @@
ok = false;
if ((oWaveHandle = __INST(waveHandle)) != nil) {
- goto out;
+ goto out;
}
waveFormat.wf.wFormatTag = WAVE_FORMAT_PCM;
@@ -4196,14 +4180,14 @@
waveFormat.wf.nAvgBytesPerSec = waveFormat.wf.nSamplesPerSec * waveFormat.wf.nBlockAlign;
r = waveOutOpen(&t_waveHandle,
- WAVE_MAPPER,
- (WAVEFORMAT *)&waveFormat,
- (DWORD_PTR)waveCallBack,
- (DWORD_PTR)0,
- CALLBACK_FUNCTION);
+ WAVE_MAPPER,
+ (WAVEFORMAT *)&waveFormat,
+ (DWORD_PTR)waveCallBack,
+ (DWORD_PTR)0,
+ CALLBACK_FUNCTION);
if (r != 0) {
- console_printf("waveOutOpen\n");
- goto out;
+ console_printf("waveOutOpen\n");
+ goto out;
}
(void)waveOutReset(t_waveHandle);
@@ -4215,9 +4199,9 @@
total_buffers = 0;
{
- OBJ t;
-
- t = __MKEXTERNALADDRESS(t_waveHandle); __INST(waveHandle) = t; __STORE(self, t);
+ OBJ t;
+
+ t = __MKEXTERNALADDRESS(t_waveHandle); __INST(waveHandle) = t; __STORE(self, t);
}
# if 0
@@ -4228,12 +4212,12 @@
* why - DAC
*/
{
- char null[DATALEN];
- int i;
- for (i = 0; i < DATALEN; i++) {
- null[i] = 127;
- }
- audioWrite(null, DATALEN);
+ char null[DATALEN];
+ int i;
+ for (i = 0; i < DATALEN; i++) {
+ null[i] = 127;
+ }
+ audioWrite(null, DATALEN);
}
# endif /* 0 */
ok = true;
@@ -4243,11 +4227,11 @@
#endif /* !SUPPORT_WIN32_DIRECTSOUND */
%}.
ok == false ifTrue:[
- lastErrorString := errorStringOrNil.
- lastErrorNumber := error ? -1.
- self openError:error.
- "normally not reached"
- ^ nil.
+ lastErrorString := errorStringOrNil.
+ lastErrorNumber := error ? -1.
+ self openError:error.
+ "normally not reached"
+ ^ nil.
].
self registerForFinalization.
! !
@@ -4257,25 +4241,25 @@
supportedAudioFormats
"return a collection of supported audio formats.
possibly returned symbols are:
- U8 unsigned 8bit samples
- S8 signed 8bit samples
- U16 unsigned 16bit samples in native format
- U16_LE unsigned 16bit big endian samples
- U16_BE unsigned 16bit big endian samples
- S16 signed 16bit little endian samples in native format
- S16_LE signed 16bit little endian samples
- S16_BE signed 16bit big endian samples
- S24 signed 24bit little endian samples in native format
- S24_LE signed 24bit little endian samples
- S24_BE signed 24bit big endian samples
- S32 signed 32bit little endian samples in native format
- S32_LE signed 32bit little endian samples
- S32_BE signed 32bit big endian samples
- F32 float samples
- MPEG audio mpeg encoded
- MU_LAW u-law encoded 8bit samples
- A_LAW a-law encoded 8bit samples
- IMA_ADPCM adpcm encoded
+ U8 unsigned 8bit samples
+ S8 signed 8bit samples
+ U16 unsigned 16bit samples in native format
+ U16_LE unsigned 16bit big endian samples
+ U16_BE unsigned 16bit big endian samples
+ S16 signed 16bit little endian samples in native format
+ S16_LE signed 16bit little endian samples
+ S16_BE signed 16bit big endian samples
+ S24 signed 24bit little endian samples in native format
+ S24_LE signed 24bit little endian samples
+ S24_BE signed 24bit big endian samples
+ S32 signed 32bit little endian samples in native format
+ S32_LE signed 32bit little endian samples
+ S32_BE signed 32bit big endian samples
+ F32 float samples
+ MPEG audio mpeg encoded
+ MU_LAW u-law encoded 8bit samples
+ A_LAW a-law encoded 8bit samples
+ IMA_ADPCM adpcm encoded
the set of returned symbols depends on the underlying sound hardware.
"
@@ -4321,7 +4305,7 @@
OBJ oWaveHandle;
if ((oWaveHandle = __INST(waveHandle)) == nil) {
- RETURN(0);
+ RETURN(0);
}
t_waveHandle = __WaveHandleVal(oWaveHandle);
@@ -4330,56 +4314,56 @@
buf = (short *)__InstPtr(anObject) + OHDR_SIZE + offs;
while (dataLen > 0) {
- if (free_list == NULL && total_buffers < MAXBUF) {
- /* Expand available buffer space */
- bp = (struct buf *)malloc(sizeof(struct buf));
- total_buffers++;
- } else {
- if (free_list == NULL) {
- /* We must wait for a free buffer */
- while (free_list == NULL) {
- WaitForSingleObject(free_buffer_event, INFINITE);
- }
- }
- EnterCriticalSection(&free_list_lock);
- bp = free_list;
- free_list = free_list->next;
- --free_buffers;
- LeaveCriticalSection(&free_list_lock);
- r = waveOutUnprepareHeader(t_waveHandle, &bp->hdr, sizeof(WAVEHDR));
- if (r != 0) {
- console_printf("waveOutUnprepareHeader\n");
- RETURN(self);
- }
- }
- len = min(dataLen, DATALEN);
- bp->hdr.lpData = (char *)bp->data;
- bp->hdr.dwBufferLength = len;
- bp->hdr.dwBytesRecorded = len;
- bp->hdr.dwUser = (INT)(bp);
- bp->hdr.dwFlags = 0;
- bp->hdr.dwLoops = 0;
- r = waveOutPrepareHeader(t_waveHandle, &bp->hdr, sizeof(WAVEHDR));
- if (r != 0) {
- console_printf("waveOutPrepareHeader\n");
- RETURN(self);
- }
- for (i = 0; i < len; i++) {
- bp->data[i] = buf[i];
- }
- r = waveOutWrite(t_waveHandle, &bp->hdr, sizeof(WAVEHDR));
- if (r != 0) {
- console_printf("waveOutWrite\n");
- RETURN(self);
- }
- buf += len;
- dataLen -= len;
+ if (free_list == NULL && total_buffers < MAXBUF) {
+ /* Expand available buffer space */
+ bp = (struct buf *)malloc(sizeof(struct buf));
+ total_buffers++;
+ } else {
+ if (free_list == NULL) {
+ /* We must wait for a free buffer */
+ while (free_list == NULL) {
+ WaitForSingleObject(free_buffer_event, INFINITE);
+ }
+ }
+ EnterCriticalSection(&free_list_lock);
+ bp = free_list;
+ free_list = free_list->next;
+ --free_buffers;
+ LeaveCriticalSection(&free_list_lock);
+ r = waveOutUnprepareHeader(t_waveHandle, &bp->hdr, sizeof(WAVEHDR));
+ if (r != 0) {
+ console_printf("waveOutUnprepareHeader\n");
+ RETURN(self);
+ }
+ }
+ len = min(dataLen, DATALEN);
+ bp->hdr.lpData = (char *)bp->data;
+ bp->hdr.dwBufferLength = len;
+ bp->hdr.dwBytesRecorded = len;
+ bp->hdr.dwUser = (INT)(bp);
+ bp->hdr.dwFlags = 0;
+ bp->hdr.dwLoops = 0;
+ r = waveOutPrepareHeader(t_waveHandle, &bp->hdr, sizeof(WAVEHDR));
+ if (r != 0) {
+ console_printf("waveOutPrepareHeader\n");
+ RETURN(self);
+ }
+ for (i = 0; i < len; i++) {
+ bp->data[i] = buf[i];
+ }
+ r = waveOutWrite(t_waveHandle, &bp->hdr, sizeof(WAVEHDR));
+ if (r != 0) {
+ console_printf("waveOutWrite\n");
+ RETURN(self);
+ }
+ buf += len;
+ dataLen -= len;
}
RETURN (count);
}
#endif /* SUPPORT_WIN32_WAVESOUND */
%}.
- self errorUnsupportedOperation
+ self errorUnsupportedOperation
! !
!SoundStream class methodsFor:'documentation'!