openbsd-ports/mbone/speak_freely/patches/patch-aj
1999-09-21 15:22:53 +00:00

98 lines
2.0 KiB
Plaintext

--- soundbyte.c.orig Tue Sep 14 08:55:17 1999
+++ soundbyte.c Tue Sep 21 10:02:41 1999
@@ -30,6 +30,8 @@
#else /* FreeBSD / Linux */
#ifdef LINUX
#include <linux/soundcard.h>
+#elif __OpenBSD__
+#include <soundcard.h>
#else
#include <machine/soundcard.h>
#endif
@@ -63,6 +65,14 @@
#define MAX_GAIN 100
+void soundplayvol();
+
+#ifndef sun
+#ifdef HALF_DUPLEX
+static int oldvol = -1;
+#endif
+#endif
+
struct sound_buf {
struct sound_buf *snext; /* Next sound buffer */
int sblen; /* Length of this sound buffer */
@@ -290,6 +300,21 @@
#endif
ioctl(Audio_fd, AUDIO_SETINFO, &Audio_info);
#endif
+#ifndef sun
+#ifdef HALF_DUPLEX
+ if (iomode == O_RDONLY) {
+ if (oldvol == -1)
+ oldvol = soundgetvol();
+ soundplayvol(0);
+ } else if ( iomode == O_WRONLY
+ && oldvol != -1
+ ) {
+ if (soundgetvol() == 0)
+ soundplayvol(oldvol);
+ oldvol = -1;
+ }
+#endif
+#endif
return TRUE;
}
if (errno != EINTR) {
@@ -305,6 +330,15 @@
void soundterm()
{
if ((!neverRelease) && (audiof >= 0)) {
+#ifndef sun
+#ifdef HALF_DUPLEX
+ if (oldvol != -1) {
+ if (soundgetvol() == 0)
+ soundplayvol(oldvol);
+ oldvol = -1;
+ }
+#endif
+#endif
if (close(audiof) < 0) {
perror("closing audio device");
}
@@ -382,10 +416,30 @@
arg = (value << 8) | value;
- if (ioctl(Audio_fd, MIXER_WRITE(SOUND_MIXER_PCM), &arg) < 0)
- perror("SOUND_MIXER_PCM");
+ if (ioctl(Audio_fd, MIXER_WRITE(SOUND_MIXER_WRITE_PCM), &arg) < 0)
+ perror("SOUND_MIXER_WRITE_PCM");
#endif
}
+
+#ifndef sun
+#ifdef HALF_DUPLEX
+
+/* SOUNDGETVOL -- Get current playback volume. */
+
+int soundgetvol()
+{
+ int arg, v1, v2;
+
+ if (ioctl(Audio_fd, SOUND_MIXER_READ_PCM, &arg) < 0) {
+ perror("SOUND_MIXER_READ_PCM");
+ return -1;
+ }
+ v1 = arg & 0xFF;
+ v2 = (arg >> 8) & 0xFF;
+ return (v1 > v2) ? v1 : v2;
+}
+#endif
+#endif
/* SOUNDRECGAIN -- Set recording gain from 0 (minimum) to 100 (maximum). */