--- a/SoundStream.st Wed May 29 13:50:29 2013 +0200
+++ b/SoundStream.st Mon Jun 03 18:30:22 2013 +0200
@@ -226,7 +226,8 @@
# define Delay __DEF_Delay
#endif
-# define INT int
+# define INT STX_INT
+# define UINT STX_UINT
#endif /* WIN32 */
@@ -244,10 +245,11 @@
#ifdef WIN32_WAVE
static void CALLBACK
-waveCallBack(HWAVE waveHandle, UINT msg, DWORD inst, DWORD p1, DWORD p2)
+waveCallBack(HWAVE waveHandle, UINT msg, DWORD_PTR inst, DWORD_PTR p1, DWORD_PTR p2)
{
if (msg == MM_WOM_DONE) {
struct buf *bp = (struct buf *)p1;
+
EnterCriticalSection(&free_list_lock);
bp->next = free_list;
free_list = bp;
@@ -730,7 +732,7 @@
defaultAudioFormat
OperatingSystem isMSWINDOWSlike ifTrue:[
- ^ #S16
+ ^ #S16
].
^ #U8
!
@@ -739,7 +741,7 @@
"minimum, supported by all audio systems"
OperatingSystem isMSWINDOWSlike ifTrue:[
- ^ 16
+ ^ 16
].
^ 8
!
@@ -1073,12 +1075,12 @@
pathName := nil.
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'.
+ ].
].
"Created: 17.11.1995 / 17:28:14 / cg"
@@ -1964,7 +1966,7 @@
struct buf *bp;
int len, i, r;
int dataLen, offs;
- char *buf;
+ short *buf;
HWAVEOUT t_waveHandle;
OBJ oWaveHandle;
@@ -2005,7 +2007,7 @@
bp->hdr.lpData = (char *)bp->data;
bp->hdr.dwBufferLength = len;
bp->hdr.dwBytesRecorded = len;
- bp->hdr.dwUser = (DWORD)bp;
+ bp->hdr.dwUser = (INT)(bp);
bp->hdr.dwFlags = 0;
bp->hdr.dwLoops = 0;
r = waveOutPrepareHeader(t_waveHandle, &bp->hdr, sizeof(WAVEHDR));
@@ -2103,33 +2105,33 @@
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,
};
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;
+ OBJ t;
- t = __MKEXTERNALADDRESS(p); __INST(alPort) = t; __STORE(self, t);
+ t = __MKEXTERNALADDRESS(p); __INST(alPort) = t; __STORE(self, t);
} else {
- __INST(alPort) = nil;
- goto out;
+ __INST(alPort) = nil;
+ goto out;
}
__INST(binary) = true;
@@ -2139,27 +2141,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]);
@@ -2183,8 +2185,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 */
@@ -2205,20 +2207,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 */
@@ -2234,22 +2236,22 @@
/* 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");
- IDirectSoundBuffer_Stop(t_pDSBuffer);
- IDirectSoundBuffer_Stop(t_pDSPrimeBuffer);
- IDirectSoundBuffer_Release(t_pDSPrimeBuffer);
- IDirectSound_Release(t_pDirectSound);
- goto out;
+ &dwDataLen, NULL, NULL, 0)) != DS_OK) {
+ console_fprintf(stderr,"SoundStream: couldn't lock sound buffer!\n");
+ IDirectSoundBuffer_Stop(t_pDSBuffer);
+ IDirectSoundBuffer_Stop(t_pDSPrimeBuffer);
+ IDirectSoundBuffer_Release(t_pDSPrimeBuffer);
+ IDirectSound_Release(t_pDirectSound);
+ goto out;
}
/* Zero the DS buffer */
@@ -2257,32 +2259,32 @@
/* 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");
- IDirectSoundBuffer_Stop(t_pDSBuffer);
- IDirectSoundBuffer_Stop(t_pDSPrimeBuffer);
- IDirectSoundBuffer_Release(t_pDSPrimeBuffer);
- IDirectSound_Release(t_pDirectSound);
- goto out;
+ console_fprintf(stderr,"SoundStream: couldn't unlock sound buffer!\n");
+ IDirectSoundBuffer_Stop(t_pDSBuffer);
+ IDirectSoundBuffer_Stop(t_pDSPrimeBuffer);
+ IDirectSoundBuffer_Release(t_pDSPrimeBuffer);
+ IDirectSound_Release(t_pDirectSound);
+ goto out;
}
__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");
- IDirectSoundBuffer_Stop(t_pDSBuffer);
- IDirectSoundBuffer_Stop(t_pDSPrimeBuffer);
- IDirectSoundBuffer_Release(t_pDSPrimeBuffer);
- IDirectSound_Release(t_pDirectSound);
- ok = false;
- goto out;
+ console_fprintf(stderr,"SoundStream: couldn't play sound buffer!\n");
+ IDirectSoundBuffer_Stop(t_pDSBuffer);
+ IDirectSoundBuffer_Stop(t_pDSPrimeBuffer);
+ IDirectSoundBuffer_Release(t_pDSPrimeBuffer);
+ IDirectSound_Release(t_pDirectSound);
+ ok = false;
+ goto out;
}
{
- OBJ t;
+ OBJ t;
- t = __MKEXTERNALADDRESS(t_pDSBuffer); __INST(pDSBuffer) = t; __STORE(self, t);
- t = __MKEXTERNALADDRESS(t_pDirectSound); __INST(pDirectSound) = t; __STORE(self, t);
+ t = __MKEXTERNALADDRESS(t_pDSBuffer); __INST(pDSBuffer) = t; __STORE(self, t);
+ t = __MKEXTERNALADDRESS(t_pDirectSound); __INST(pDirectSound) = t; __STORE(self, t);
}
ok = true;
goto out;
@@ -2297,8 +2299,8 @@
OBJ oWaveHandle;
if ((oWaveHandle = __INST(waveHandle)) != nil) {
- ok = false;
- goto out;
+ ok = false;
+ goto out;
}
waveFormat.wf.wFormatTag = WAVE_FORMAT_PCM;
@@ -2309,15 +2311,15 @@
waveFormat.wf.nAvgBytesPerSec = waveFormat.wf.nSamplesPerSec * waveFormat.wf.nBlockAlign;
r = waveOutOpen(&t_waveHandle,
- WAVE_MAPPER,
- (WAVEFORMAT *)&waveFormat,
- (DWORD)waveCallBack,
- 0,
- CALLBACK_FUNCTION);
+ WAVE_MAPPER,
+ (WAVEFORMAT *)&waveFormat,
+ (DWORD_PTR)waveCallBack,
+ (DWORD_PTR)0,
+ CALLBACK_FUNCTION);
if (r != 0) {
- console_printf("waveOutOpen\n");
- ok = false;
- goto out;
+ console_printf("waveOutOpen\n");
+ ok = false;
+ goto out;
}
(void)waveOutReset(t_waveHandle);
@@ -2329,9 +2331,9 @@
total_buffers = 0;
{
- OBJ t;
+ OBJ t;
- t = __MKEXTERNALADDRESS(t_waveHandle); __INST(waveHandle) = t; __STORE(self, t);
+ t = __MKEXTERNALADDRESS(t_waveHandle); __INST(waveHandle) = t; __STORE(self, t);
}
# if 0
@@ -2342,12 +2344,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;
@@ -2362,49 +2364,49 @@
FILE *f;
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) && (__threadErrno == EINTR));
if (__fd >= 0) {
- /*
- * make it a FILE *
- */
- f = fdopen(__fd, __stringVal(aMode));
- if (! f) {
- __BEGIN_INTERRUPTABLE__
- close(__fd);
- __END_INTERRUPTABLE__
- ok = false;
- 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) {
+ __BEGIN_INTERRUPTABLE__
+ close(__fd);
+ __END_INTERRUPTABLE__
+ ok = false;
+ 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 (__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 (ioctl(__fd, SNDCTL_DSP_SETTRIGGER, &enable_bits) == -1)
+ {
+ console_fprintf(stderr, "can't request synchronous start of fullduplex operation");
+ }
+ }
# endif
#endif
- ok = true;
- goto out;
+ ok = true;
+ goto out;
}
}
#endif /* DEV_AUDIO */
@@ -2412,14 +2414,14 @@
out:;
%}.
ok == false ifTrue:[
- self openError:lastErrorNumber.
- "normally not reached"
- ^ nil.
+ self openError:lastErrorNumber.
+ "normally not reached"
+ ^ nil.
].
ok isNil ifTrue:[
- "its a regular file open (i.e. /dev/audio) "
- ^ super openWithMode:aMode attributes:attributeSpec.
+ "its a regular file open (i.e. /dev/audio) "
+ ^ super openWithMode:aMode attributes:attributeSpec.
].
Lobby register:self.
@@ -2698,11 +2700,11 @@
!SoundStream class methodsFor:'documentation'!
version
- ^ '$Header: /cvs/stx/stx/libbasic2/SoundStream.st,v 1.75 2012-10-26 09:52:32 stefan Exp $'
+ ^ '$Header: /cvs/stx/stx/libbasic2/SoundStream.st,v 1.76 2013-06-03 16:30:22 cg Exp $'
!
version_CVS
- ^ '$Header: /cvs/stx/stx/libbasic2/SoundStream.st,v 1.75 2012-10-26 09:52:32 stefan Exp $'
+ ^ '$Header: /cvs/stx/stx/libbasic2/SoundStream.st,v 1.76 2013-06-03 16:30:22 cg Exp $'
! !
SoundStream initialize!