SoundStream.st
changeset 724 2b22b88165ec
parent 722 0c3c1f866eb4
child 725 c18d8d084a17
equal deleted inserted replaced
723:04567da3394f 724:2b22b88165ec
    30 # include <audio.h>
    30 # include <audio.h>
    31 # define __ALportVal(o)  (ALport)(__externalAddressVal(o))
    31 # define __ALportVal(o)  (ALport)(__externalAddressVal(o))
    32 #endif
    32 #endif
    33 
    33 
    34 #ifdef LINUX
    34 #ifdef LINUX
       
    35 # include <stdio.h>
       
    36 # include <sys/soundcard.h>
       
    37 # define DEV_AUDIO_DEFAULT_FREQ (8000)
       
    38 # define DEV_AUDIO_DEFAULT_BUFFERSIZE (16384)
    35 # define DEV_AUDIO
    39 # define DEV_AUDIO
    36 # include <sys/soundcard.h>
       
    37 #endif
    40 #endif
    38 
    41 
       
    42 #ifdef FREEBSD
       
    43 # include <stdio.h>
       
    44 # include <sys/time.h>
       
    45 # include <sys/ioctl.h>
       
    46 # include <machine/pcaudioio.h>
       
    47 # define DEV_AUDIO_DEFAULT_FREQ (8000)
       
    48 # define DEV_AUDIO_DEFAULT_BUFFERSIZE (16384)
       
    49 # define DEV_AUDIO
       
    50 #endif
       
    51 
    39 #if defined(sunos) || defined(solaris)
    52 #if defined(sunos) || defined(solaris)
       
    53 # include <stdio.h>
       
    54 # ifdef solaris
       
    55 #  include <sys/audioio.h>
       
    56 # else
       
    57 #  include <sun/audioio.h>
       
    58 # endif
       
    59 # define DEV_AUDIO_DEFAULT_FREQ (8000)
       
    60 # define DEV_AUDIO_DEFAULT_BUFFERSIZE (16384)
       
    61 # define DEV_AUDIO
       
    62 #endif
       
    63 
       
    64 #if defined(hpux)
       
    65 # include <stdio.h>
       
    66 # include <sys/ioctl.h>
       
    67 # include <sys/inode.h>
       
    68 # include <sys/audio.h>
       
    69 # include <sys/time.h>
       
    70 # include <unistd.h>
       
    71 # define DEV_AUDIO_DEFAULT_FREQ (22050)
       
    72 # define DEV_AUDIO_DEFAULT_BUFFERSIZE (16384)
    40 # define DEV_AUDIO
    73 # define DEV_AUDIO
    41 #endif
    74 #endif
    42 
    75 
    43 #if defined(__openVMS__) || defined(LINUX)
    76 #if defined(__openVMS__) || defined(LINUX)
    44   /*
    77   /*
    47    */
    80    */
    48 # undef __new
    81 # undef __new
    49 # define __NEED_REDEF_new__                                   
    82 # define __NEED_REDEF_new__                                   
    50 #endif                                                        
    83 #endif                                                        
    51 
    84 
    52 #ifdef DEV_AUDIO
       
    53 # include <stdio.h>
       
    54 #endif
       
    55 
    85 
    56 #ifdef __NEED_REDEF_new__
    86 #ifdef __NEED_REDEF_new__
    57 # define __new  __STX___new
    87 # define __new  __STX___new
    58 #endif
    88 #endif
    59 
    89 
   656 !
   686 !
   657 
   687 
   658 defaultSampleRate
   688 defaultSampleRate
   659     "minimum, supported by all audio systems"
   689     "minimum, supported by all audio systems"
   660 
   690 
       
   691 %{
       
   692 #ifdef DEV_AUDIO
       
   693     RETURN (__MKSMALLINT(DEV_AUDIO_DEFAULT_FREQ));
       
   694 #endif
       
   695 %}.
       
   696 
   661     ^ 8000
   697     ^ 8000
   662 ! !
   698 ! !
   663 
   699 
   664 !SoundStream class methodsFor:'playing'!
   700 !SoundStream class methodsFor:'playing'!
   665 
   701 
   779     int __stereo = 0;
   815     int __stereo = 0;
   780     int __channels = 0;
   816     int __channels = 0;
   781 
   817 
   782 #if defined(DEV_AUDIO) 
   818 #if defined(DEV_AUDIO) 
   783     channels = __MKSMALLINT(1);
   819     channels = __MKSMALLINT(1);
       
   820     blockSize = __MKSMALLINT(DEV_AUDIO_DEFAULT_BUFFERSIZE);
   784     stereo = __MKSMALLINT(0);
   821     stereo = __MKSMALLINT(0);
   785     speed = __MKSMALLINT(8000);
   822     speed = __MKSMALLINT(DEV_AUDIO_DEFAULT_FREQ);
   786 
   823 
   787 # if defined(SNDCTL_DSP_GETBLKSIZE)
   824 # if defined(SNDCTL_DSP_GETBLKSIZE)
   788     if (ioctl(f, SNDCTL_DSP_GETBLKSIZE, &__blockSize) >= 0) {
   825     if (ioctl(f, SNDCTL_DSP_GETBLKSIZE, &__blockSize) >= 0) {
   789 	blockSize = __MKSMALLINT(__blockSize);
   826 	blockSize = __MKSMALLINT(__blockSize);
   790     }
   827     }
   900     union {
   937     union {
   901 	unsigned short us;
   938 	unsigned short us;
   902 	unsigned char ub[2];
   939 	unsigned char ub[2];
   903     } u;
   940     } u;
   904     OBJ sym = aSymbol;
   941     OBJ sym = aSymbol;
       
   942 
       
   943     if (__INST(audioFormat) == sym) {
       
   944 	RETURN (self);
       
   945     }
   905 
   946 
   906 #if defined(DEV_AUDIO)
   947 #if defined(DEV_AUDIO)
   907     if (__isSmallInteger(fd)) {
   948     if (__isSmallInteger(fd)) {
   908 	if (__isSymbol(sym)) {
   949 	if (__isSymbol(sym)) {
   909 	    if (sym == @symbol(U16)) {
   950 	    if (sym == @symbol(U16)) {
   965 # endif
  1006 # endif
   966 # ifdef AFMT_MPEG
  1007 # ifdef AFMT_MPEG
   967 	    } else if (sym == @symbol(MPEG)) {
  1008 	    } else if (sym == @symbol(MPEG)) {
   968 		__fmt = AFMT_MPEG;
  1009 		__fmt = AFMT_MPEG;
   969 # endif
  1010 # endif
       
  1011 
       
  1012 # ifdef AUDIO_FORMAT_LINEAR16BIT
       
  1013 	    } else if (sym == @symbol(S16)) {
       
  1014 		__fmt = AUDIO_FORMAT_LINEAR16BIT;
       
  1015 # endif
       
  1016 # ifdef AUDIO_FORMAT_ULAW
       
  1017 	    } else if (sym == @symbol(MU_LAW)) {
       
  1018 		__fmt = AUDIO_FORMAT_ULAW;
       
  1019 # endif
       
  1020 # ifdef AUDIO_FORMAT_ALAW
       
  1021 	    } else if (sym == @symbol(A_LAW)) {
       
  1022 		__fmt = AUDIO_FORMAT_ALAW;
       
  1023 # endif
   970 	    } else {
  1024 	    } else {
   971 		fprintf(stderr, "bad format: %s\n", __stringVal(sym));
  1025 		fprintf(stderr, "bad format: %s\n", __stringVal(sym));
   972 		goto bad;
  1026 		goto bad;
   973 	    }
  1027 	    }
   974 	}
  1028 	}
   975 
  1029 
       
  1030 # ifdef SNDCTL_DSP_SETFMT
   976 	__fmtWant = __fmt;
  1031 	__fmtWant = __fmt;
   977 
  1032 
   978 # ifdef SNDCTL_DSP_SETFMT
       
   979 	if (ioctl(f, SNDCTL_DSP_SETFMT, &__fmt) >= 0) {
  1033 	if (ioctl(f, SNDCTL_DSP_SETFMT, &__fmt) >= 0) {
   980 	    if (__fmt == __fmtWant) {
  1034 	    if (__fmt == __fmtWant) {
   981 		__INST(audioFormat) = sym;
  1035 		__INST(audioFormat) = sym;
   982 		RETURN (self);
  1036 		RETURN (self);
   983 	    } else {
  1037 	    } else {
   986 	} else {
  1040 	} else {
   987 		/* fprintf(stderr, "got err-return from setFmp %x\n", __fmt); */
  1041 		/* fprintf(stderr, "got err-return from setFmp %x\n", __fmt); */
   988 	}
  1042 	}
   989 # endif /* SNDCTL_DSP_SETFMT */
  1043 # endif /* SNDCTL_DSP_SETFMT */
   990 
  1044 
       
  1045 # ifdef AUDIO_SET_DATA_FORMAT /* hpux */
       
  1046 	if (ioctl (f, AUDIO_SET_DATA_FORMAT, __fmt)) {
       
  1047 	    /* fprintf(stderr, "got err-return from AUDIO_SET_DATA_FORMAT\n"); */
       
  1048 	}
       
  1049 # endif
       
  1050 
       
  1051 
   991 bad: ;
  1052 bad: ;
   992     }
  1053     }
   993 #endif /* DEV_AUDIO */
  1054 #endif /* DEV_AUDIO */
   994 
       
   995 #ifdef WIN32
       
   996     if (__INST(audioFormat) == sym) {
       
   997 	RETURN (self);
       
   998     }
       
   999 #endif
       
  1000 
  1055 
  1001 %}.
  1056 %}.
  1002     ^ UnsupportedOperationSignal raise
  1057     ^ UnsupportedOperationSignal raise
  1003 
  1058 
  1004     "
  1059     "
  1023     ].
  1078     ].
  1024 %{
  1079 %{
  1025     int f = __intVal(fd);
  1080     int f = __intVal(fd);
  1026     int __nCh = 0;
  1081     int __nCh = 0;
  1027 
  1082 
  1028 #if defined(DEV_AUDIO) && defined(SOUND_PCM_WRITE_CHANNELS)
  1083 #if defined(DEV_AUDIO)
  1029     if (__isSmallInteger(fd) && __isSmallInteger(nChannels)) {
  1084     if (__isSmallInteger(fd) && __isSmallInteger(nChannels)) {
  1030 	__nCh = __intVal(nChannels);
  1085 	__nCh = __intVal(nChannels);
       
  1086 # if defined(SOUND_PCM_WRITE_CHANNELS)
  1031 	if (ioctl(f, SOUND_PCM_WRITE_CHANNELS, &__nCh) >= 0) {
  1087 	if (ioctl(f, SOUND_PCM_WRITE_CHANNELS, &__nCh) >= 0) {
  1032 	    __INST(numberOfChannels) = nChannels;
  1088 	    __INST(numberOfChannels) = nChannels;
  1033 	    RETURN (self);
  1089 	    RETURN (self);
  1034 	}
  1090 	}
       
  1091 # endif
       
  1092 # ifdef AUDIO_SET_CHANNELS /* hpux */
       
  1093 	if (ioctl (f, AUDIO_SET_CHANNELS, __nCh)) {
       
  1094 	    /* fprintf(stderr, "got err-return from AUDIO_SET_CHANNELS\n"); */
       
  1095 	    __INST(numberOfChannels) = nChannels;
       
  1096 	    RETURN (self);
       
  1097 	}
       
  1098 # endif
  1035     }
  1099     }
  1036 #endif
  1100 #endif
  1037 %}.
  1101 %}.
  1038     ^ UnsupportedOperationSignal raise
  1102     ^ UnsupportedOperationSignal raise
  1039 
  1103 
  1059     ].
  1123     ].
  1060 %{
  1124 %{
  1061     int f = __intVal(fd);
  1125     int f = __intVal(fd);
  1062     int __blockSize = 0;
  1126     int __blockSize = 0;
  1063 
  1127 
  1064 #if defined(DEV_AUDIO) && defined(SNDCTL_DSP_SETFRAGMENT)
  1128 #if defined(DEV_AUDIO) 
  1065     if (__isSmallInteger(fd) && __isSmallInteger(blockSize)) {
  1129     if (__isSmallInteger(fd) && __isSmallInteger(blockSize)) {
  1066 	__blockSize = __intVal(blockSize);
  1130 	__blockSize = __intVal(blockSize);
       
  1131 # if defined(SNDCTL_DSP_SETFRAGMENT)
  1067 	if (ioctl(f, SNDCTL_DSP_SETFRAGMENT, &__blockSize) >= 0) {
  1132 	if (ioctl(f, SNDCTL_DSP_SETFRAGMENT, &__blockSize) >= 0) {
  1068 	    /* __INST(blockSize) = blockSize; */
  1133 	    /* __INST(blockSize) = blockSize; */
  1069 	    RETURN (self);
  1134 	    RETURN (self);
  1070 	}
  1135 	}
       
  1136 # endif
       
  1137 # ifdef AUDIO_SET_CHANNELS /* hpux */
       
  1138 	if (ioctl (f, AUDIO_SET_TXBUFSIZE, __blockSize)) {
       
  1139 	    /* fprintf(stderr, "got err-return from AUDIO_SET_TXBUFSIZE\n"); */
       
  1140 	    /* __INST(blockSize) = blockSize; */
       
  1141 	    RETURN (self);
       
  1142 	}
       
  1143 # endif
  1071     }
  1144     }
  1072 #endif
  1145 #endif
  1073 %}.
  1146 %}.
  1074     ^ UnsupportedOperationSignal raise
  1147     ^ UnsupportedOperationSignal raise
  1075 !
  1148 !
  1090 %{
  1163 %{
  1091     int f = __intVal(fd);
  1164     int f = __intVal(fd);
  1092     int __rate = 0;
  1165     int __rate = 0;
  1093     int __rateWant;
  1166     int __rateWant;
  1094 
  1167 
  1095 #if defined(DEV_AUDIO) && defined(SOUND_PCM_WRITE_RATE)
  1168 #if defined(DEV_AUDIO) 
  1096     if (__isSmallInteger(fd) && __isSmallInteger(hz)) {
  1169     if (__isSmallInteger(fd) && __isSmallInteger(hz)) {
  1097 	__rate = __rateWant = __intVal(hz);
  1170 	__rate = __intVal(hz);
       
  1171 # if defined(SOUND_PCM_WRITE_RATE)
       
  1172 	__rateWant = __rate;
  1098 	if (ioctl(f, SOUND_PCM_WRITE_RATE, &__rate) >= 0) {
  1173 	if (ioctl(f, SOUND_PCM_WRITE_RATE, &__rate) >= 0) {
  1099 	    if (__rate != __rateWant) {
  1174 	    if (__rate != __rateWant) {
  1100 		fprintf(stderr, "SoundStream [warning]: actual rate is %d\n", __rate);
  1175 		fprintf(stderr, "SoundStream [warning]: actual rate is %d\n", __rate);
  1101 		hz = __MKSMALLINT(__rate);
  1176 		hz = __MKSMALLINT(__rate);
  1102 	    }
  1177 	    }
  1103 	    __INST(sampleRate) = hz;
  1178 	    __INST(sampleRate) = hz;
  1104 	    RETURN (self);
  1179 	    RETURN (self);
  1105 	}
  1180 	}
       
  1181 # endif
       
  1182 # ifdef AUDIO_SET_SAMPLE_RATE /* hpux */
       
  1183 	if (ioctl (f, AUDIO_SET_SAMPLE_RATE, __rate)) {
       
  1184 	    /* fprintf(stderr, "got err-return from AUDIO_SET_SAMPLE_RATE\n"); */
       
  1185 	    __INST(sampleRate) = hz;
       
  1186 	    RETURN (self);
       
  1187 	}
       
  1188 # endif
  1106     }
  1189     }
  1107 #endif
  1190 #endif
  1108 %}.
  1191 %}.
  1109     ^ UnsupportedOperationSignal raise
  1192     ^ UnsupportedOperationSignal raise
  1110 
  1193 
  1186 	supports_MPEG = (__audioFormatMask & AFMT_MPEG) ? true : false;
  1269 	supports_MPEG = (__audioFormatMask & AFMT_MPEG) ? true : false;
  1187 #  endif
  1270 #  endif
  1188     }
  1271     }
  1189 # endif
  1272 # endif
  1190 
  1273 
       
  1274 # ifdef hpux
       
  1275     supports_MU_LAW = true;
       
  1276     supports_A_LAW = true;
       
  1277     supports_S16_BE = true;
       
  1278 # endif
  1191 #endif /* DEV_AUDIO */
  1279 #endif /* DEV_AUDIO */
  1192 
  1280 
  1193 #ifdef IRIS_AUDIO
  1281 #ifdef IRIS_AUDIO
  1194     supports_U8 = true;
  1282     supports_U8 = true;
  1195     supports_U16_BE = true;
  1283     supports_U16_BE = true;
  2222 ! !
  2310 ! !
  2223 
  2311 
  2224 !SoundStream class methodsFor:'documentation'!
  2312 !SoundStream class methodsFor:'documentation'!
  2225 
  2313 
  2226 version
  2314 version
  2227 ^ '$Header: /cvs/stx/stx/libbasic2/SoundStream.st,v 1.40 1999-02-04 08:36:28 cg Exp $'! !
  2315 ^ '$Header: /cvs/stx/stx/libbasic2/SoundStream.st,v 1.41 1999-02-04 18:32:51 cg Exp $'! !
  2228 SoundStream initialize!
  2316 SoundStream initialize!