SoundStream.st
changeset 724 2b22b88165ec
parent 722 0c3c1f866eb4
child 725 c18d8d084a17
--- a/SoundStream.st	Thu Feb 04 15:42:07 1999 +0100
+++ b/SoundStream.st	Thu Feb 04 19:32:51 1999 +0100
@@ -32,11 +32,44 @@
 #endif
 
 #ifdef LINUX
+# include <stdio.h>
+# include <sys/soundcard.h>
+# define DEV_AUDIO_DEFAULT_FREQ (8000)
+# define DEV_AUDIO_DEFAULT_BUFFERSIZE (16384)
 # define DEV_AUDIO
-# include <sys/soundcard.h>
+#endif
+
+#ifdef FREEBSD
+# include <stdio.h>
+# include <sys/time.h>
+# include <sys/ioctl.h>
+# 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)
+# include <stdio.h>
+# ifdef solaris
+#  include <sys/audioio.h>
+# else
+#  include <sun/audioio.h>
+# endif
+# define DEV_AUDIO_DEFAULT_FREQ (8000)
+# define DEV_AUDIO_DEFAULT_BUFFERSIZE (16384)
+# define DEV_AUDIO
+#endif
+
+#if defined(hpux)
+# include <stdio.h>
+# include <sys/ioctl.h>
+# include <sys/inode.h>
+# include <sys/audio.h>
+# include <sys/time.h>
+# include <unistd.h>
+# define DEV_AUDIO_DEFAULT_FREQ (22050)
+# define DEV_AUDIO_DEFAULT_BUFFERSIZE (16384)
 # define DEV_AUDIO
 #endif
 
@@ -49,9 +82,6 @@
 # define __NEED_REDEF_new__                                   
 #endif                                                        
 
-#ifdef DEV_AUDIO
-# include <stdio.h>
-#endif
 
 #ifdef __NEED_REDEF_new__
 # define __new  __STX___new
@@ -658,6 +688,12 @@
 defaultSampleRate
     "minimum, supported by all audio systems"
 
+%{
+#ifdef DEV_AUDIO
+    RETURN (__MKSMALLINT(DEV_AUDIO_DEFAULT_FREQ));
+#endif
+%}.
+
     ^ 8000
 ! !
 
@@ -781,8 +817,9 @@
 
 #if defined(DEV_AUDIO) 
     channels = __MKSMALLINT(1);
+    blockSize = __MKSMALLINT(DEV_AUDIO_DEFAULT_BUFFERSIZE);
     stereo = __MKSMALLINT(0);
-    speed = __MKSMALLINT(8000);
+    speed = __MKSMALLINT(DEV_AUDIO_DEFAULT_FREQ);
 
 # if defined(SNDCTL_DSP_GETBLKSIZE)
     if (ioctl(f, SNDCTL_DSP_GETBLKSIZE, &__blockSize) >= 0) {
@@ -903,6 +940,10 @@
     } u;
     OBJ sym = aSymbol;
 
+    if (__INST(audioFormat) == sym) {
+	RETURN (self);
+    }
+
 #if defined(DEV_AUDIO)
     if (__isSmallInteger(fd)) {
 	if (__isSymbol(sym)) {
@@ -967,15 +1008,28 @@
 	    } else if (sym == @symbol(MPEG)) {
 		__fmt = AFMT_MPEG;
 # endif
+
+# ifdef 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;
+# endif
+# ifdef AUDIO_FORMAT_ALAW
+	    } else if (sym == @symbol(A_LAW)) {
+		__fmt = AUDIO_FORMAT_ALAW;
+# endif
 	    } else {
 		fprintf(stderr, "bad format: %s\n", __stringVal(sym));
 		goto bad;
 	    }
 	}
 
+# ifdef SNDCTL_DSP_SETFMT
 	__fmtWant = __fmt;
 
-# ifdef SNDCTL_DSP_SETFMT
 	if (ioctl(f, SNDCTL_DSP_SETFMT, &__fmt) >= 0) {
 	    if (__fmt == __fmtWant) {
 		__INST(audioFormat) = sym;
@@ -988,16 +1042,17 @@
 	}
 # endif /* SNDCTL_DSP_SETFMT */
 
+# ifdef AUDIO_SET_DATA_FORMAT /* hpux */
+	if (ioctl (f, AUDIO_SET_DATA_FORMAT, __fmt)) {
+	    /* fprintf(stderr, "got err-return from AUDIO_SET_DATA_FORMAT\n"); */
+	}
+# endif
+
+
 bad: ;
     }
 #endif /* DEV_AUDIO */
 
-#ifdef WIN32
-    if (__INST(audioFormat) == sym) {
-	RETURN (self);
-    }
-#endif
-
 %}.
     ^ UnsupportedOperationSignal raise
 
@@ -1025,13 +1080,22 @@
     int f = __intVal(fd);
     int __nCh = 0;
 
-#if defined(DEV_AUDIO) && defined(SOUND_PCM_WRITE_CHANNELS)
+#if defined(DEV_AUDIO)
     if (__isSmallInteger(fd) && __isSmallInteger(nChannels)) {
 	__nCh = __intVal(nChannels);
+# if defined(SOUND_PCM_WRITE_CHANNELS)
 	if (ioctl(f, SOUND_PCM_WRITE_CHANNELS, &__nCh) >= 0) {
 	    __INST(numberOfChannels) = nChannels;
 	    RETURN (self);
 	}
+# endif
+# ifdef AUDIO_SET_CHANNELS /* hpux */
+	if (ioctl (f, AUDIO_SET_CHANNELS, __nCh)) {
+	    /* fprintf(stderr, "got err-return from AUDIO_SET_CHANNELS\n"); */
+	    __INST(numberOfChannels) = nChannels;
+	    RETURN (self);
+	}
+# endif
     }
 #endif
 %}.
@@ -1061,13 +1125,22 @@
     int f = __intVal(fd);
     int __blockSize = 0;
 
-#if defined(DEV_AUDIO) && defined(SNDCTL_DSP_SETFRAGMENT)
+#if defined(DEV_AUDIO) 
     if (__isSmallInteger(fd) && __isSmallInteger(blockSize)) {
 	__blockSize = __intVal(blockSize);
+# if defined(SNDCTL_DSP_SETFRAGMENT)
 	if (ioctl(f, SNDCTL_DSP_SETFRAGMENT, &__blockSize) >= 0) {
 	    /* __INST(blockSize) = blockSize; */
 	    RETURN (self);
 	}
+# endif
+# ifdef AUDIO_SET_CHANNELS /* hpux */
+	if (ioctl (f, AUDIO_SET_TXBUFSIZE, __blockSize)) {
+	    /* fprintf(stderr, "got err-return from AUDIO_SET_TXBUFSIZE\n"); */
+	    /* __INST(blockSize) = blockSize; */
+	    RETURN (self);
+	}
+# endif
     }
 #endif
 %}.
@@ -1092,9 +1165,11 @@
     int __rate = 0;
     int __rateWant;
 
-#if defined(DEV_AUDIO) && defined(SOUND_PCM_WRITE_RATE)
+#if defined(DEV_AUDIO) 
     if (__isSmallInteger(fd) && __isSmallInteger(hz)) {
-	__rate = __rateWant = __intVal(hz);
+	__rate = __intVal(hz);
+# if defined(SOUND_PCM_WRITE_RATE)
+	__rateWant = __rate;
 	if (ioctl(f, SOUND_PCM_WRITE_RATE, &__rate) >= 0) {
 	    if (__rate != __rateWant) {
 		fprintf(stderr, "SoundStream [warning]: actual rate is %d\n", __rate);
@@ -1103,6 +1178,14 @@
 	    __INST(sampleRate) = hz;
 	    RETURN (self);
 	}
+# endif
+# ifdef AUDIO_SET_SAMPLE_RATE /* hpux */
+	if (ioctl (f, AUDIO_SET_SAMPLE_RATE, __rate)) {
+	    /* fprintf(stderr, "got err-return from AUDIO_SET_SAMPLE_RATE\n"); */
+	    __INST(sampleRate) = hz;
+	    RETURN (self);
+	}
+# endif
     }
 #endif
 %}.
@@ -1188,6 +1271,11 @@
     }
 # endif
 
+# ifdef hpux
+    supports_MU_LAW = true;
+    supports_A_LAW = true;
+    supports_S16_BE = true;
+# endif
 #endif /* DEV_AUDIO */
 
 #ifdef IRIS_AUDIO
@@ -2224,5 +2312,5 @@
 !SoundStream class methodsFor:'documentation'!
 
 version
-^ '$Header: /cvs/stx/stx/libbasic2/SoundStream.st,v 1.40 1999-02-04 08:36:28 cg Exp $'! !
+^ '$Header: /cvs/stx/stx/libbasic2/SoundStream.st,v 1.41 1999-02-04 18:32:51 cg Exp $'! !
 SoundStream initialize!