head 1.5; access; symbols pkgsrc-2026Q1:1.5.0.192 pkgsrc-2026Q1-base:1.5 pkgsrc-2025Q4:1.5.0.190 pkgsrc-2025Q4-base:1.5 pkgsrc-2025Q3:1.5.0.188 pkgsrc-2025Q3-base:1.5 pkgsrc-2025Q2:1.5.0.186 pkgsrc-2025Q2-base:1.5 pkgsrc-2025Q1:1.5.0.184 pkgsrc-2025Q1-base:1.5 pkgsrc-2024Q4:1.5.0.182 pkgsrc-2024Q4-base:1.5 pkgsrc-2024Q3:1.5.0.180 pkgsrc-2024Q3-base:1.5 pkgsrc-2024Q2:1.5.0.178 pkgsrc-2024Q2-base:1.5 pkgsrc-2024Q1:1.5.0.176 pkgsrc-2024Q1-base:1.5 pkgsrc-2023Q4:1.5.0.174 pkgsrc-2023Q4-base:1.5 pkgsrc-2023Q3:1.5.0.172 pkgsrc-2023Q3-base:1.5 pkgsrc-2023Q2:1.5.0.170 pkgsrc-2023Q2-base:1.5 pkgsrc-2023Q1:1.5.0.168 pkgsrc-2023Q1-base:1.5 pkgsrc-2022Q4:1.5.0.166 pkgsrc-2022Q4-base:1.5 pkgsrc-2022Q3:1.5.0.164 pkgsrc-2022Q3-base:1.5 pkgsrc-2022Q2:1.5.0.162 pkgsrc-2022Q2-base:1.5 pkgsrc-2022Q1:1.5.0.160 pkgsrc-2022Q1-base:1.5 pkgsrc-2021Q4:1.5.0.158 pkgsrc-2021Q4-base:1.5 pkgsrc-2021Q3:1.5.0.156 pkgsrc-2021Q3-base:1.5 pkgsrc-2021Q2:1.5.0.154 pkgsrc-2021Q2-base:1.5 pkgsrc-2021Q1:1.5.0.152 pkgsrc-2021Q1-base:1.5 pkgsrc-2020Q4:1.5.0.150 pkgsrc-2020Q4-base:1.5 pkgsrc-2020Q3:1.5.0.148 pkgsrc-2020Q3-base:1.5 pkgsrc-2020Q2:1.5.0.144 pkgsrc-2020Q2-base:1.5 pkgsrc-2020Q1:1.5.0.124 pkgsrc-2020Q1-base:1.5 pkgsrc-2019Q4:1.5.0.146 pkgsrc-2019Q4-base:1.5 pkgsrc-2019Q3:1.5.0.142 pkgsrc-2019Q3-base:1.5 pkgsrc-2019Q2:1.5.0.140 pkgsrc-2019Q2-base:1.5 pkgsrc-2019Q1:1.5.0.138 pkgsrc-2019Q1-base:1.5 pkgsrc-2018Q4:1.5.0.136 pkgsrc-2018Q4-base:1.5 pkgsrc-2018Q3:1.5.0.134 pkgsrc-2018Q3-base:1.5 pkgsrc-2018Q2:1.5.0.132 pkgsrc-2018Q2-base:1.5 pkgsrc-2018Q1:1.5.0.130 pkgsrc-2018Q1-base:1.5 pkgsrc-2017Q4:1.5.0.128 pkgsrc-2017Q4-base:1.5 pkgsrc-2017Q3:1.5.0.126 pkgsrc-2017Q3-base:1.5 pkgsrc-2017Q2:1.5.0.122 pkgsrc-2017Q2-base:1.5 pkgsrc-2017Q1:1.5.0.120 pkgsrc-2017Q1-base:1.5 pkgsrc-2016Q4:1.5.0.118 pkgsrc-2016Q4-base:1.5 pkgsrc-2016Q3:1.5.0.116 pkgsrc-2016Q3-base:1.5 pkgsrc-2016Q2:1.5.0.114 pkgsrc-2016Q2-base:1.5 pkgsrc-2016Q1:1.5.0.112 pkgsrc-2016Q1-base:1.5 pkgsrc-2015Q4:1.5.0.110 pkgsrc-2015Q4-base:1.5 pkgsrc-2015Q3:1.5.0.108 pkgsrc-2015Q3-base:1.5 pkgsrc-2015Q2:1.5.0.106 pkgsrc-2015Q2-base:1.5 pkgsrc-2015Q1:1.5.0.104 pkgsrc-2015Q1-base:1.5 pkgsrc-2014Q4:1.5.0.102 pkgsrc-2014Q4-base:1.5 pkgsrc-2014Q3:1.5.0.100 pkgsrc-2014Q3-base:1.5 pkgsrc-2014Q2:1.5.0.98 pkgsrc-2014Q2-base:1.5 pkgsrc-2014Q1:1.5.0.96 pkgsrc-2014Q1-base:1.5 pkgsrc-2013Q4:1.5.0.94 pkgsrc-2013Q4-base:1.5 pkgsrc-2013Q3:1.5.0.92 pkgsrc-2013Q3-base:1.5 pkgsrc-2013Q2:1.5.0.90 pkgsrc-2013Q2-base:1.5 pkgsrc-2013Q1:1.5.0.88 pkgsrc-2013Q1-base:1.5 pkgsrc-2012Q4:1.5.0.86 pkgsrc-2012Q4-base:1.5 pkgsrc-2012Q3:1.5.0.84 pkgsrc-2012Q3-base:1.5 pkgsrc-2012Q2:1.5.0.82 pkgsrc-2012Q2-base:1.5 pkgsrc-2012Q1:1.5.0.80 pkgsrc-2012Q1-base:1.5 pkgsrc-2011Q4:1.5.0.78 pkgsrc-2011Q4-base:1.5 pkgsrc-2011Q3:1.5.0.76 pkgsrc-2011Q3-base:1.5 pkgsrc-2011Q2:1.5.0.74 pkgsrc-2011Q2-base:1.5 pkgsrc-2011Q1:1.5.0.72 pkgsrc-2011Q1-base:1.5 pkgsrc-2010Q4:1.5.0.70 pkgsrc-2010Q4-base:1.5 pkgsrc-2010Q3:1.5.0.68 pkgsrc-2010Q3-base:1.5 pkgsrc-2010Q2:1.5.0.66 pkgsrc-2010Q2-base:1.5 pkgsrc-2010Q1:1.5.0.64 pkgsrc-2010Q1-base:1.5 pkgsrc-2009Q4:1.5.0.62 pkgsrc-2009Q4-base:1.5 pkgsrc-2009Q3:1.5.0.60 pkgsrc-2009Q3-base:1.5 pkgsrc-2009Q2:1.5.0.58 pkgsrc-2009Q2-base:1.5 pkgsrc-2009Q1:1.5.0.56 pkgsrc-2009Q1-base:1.5 pkgsrc-2008Q4:1.5.0.54 pkgsrc-2008Q4-base:1.5 pkgsrc-2008Q3:1.5.0.52 pkgsrc-2008Q3-base:1.5 cube-native-xorg:1.5.0.50 cube-native-xorg-base:1.5 pkgsrc-2008Q2:1.5.0.48 pkgsrc-2008Q2-base:1.5 cwrapper:1.5.0.46 pkgsrc-2008Q1:1.5.0.44 pkgsrc-2008Q1-base:1.5 pkgsrc-2007Q4:1.5.0.42 pkgsrc-2007Q4-base:1.5 pkgsrc-2007Q3:1.5.0.40 pkgsrc-2007Q3-base:1.5 pkgsrc-2007Q2:1.5.0.38 pkgsrc-2007Q2-base:1.5 pkgsrc-2007Q1:1.5.0.36 pkgsrc-2007Q1-base:1.5 pkgsrc-2006Q4:1.5.0.34 pkgsrc-2006Q4-base:1.5 pkgsrc-2006Q3:1.5.0.32 pkgsrc-2006Q3-base:1.5 pkgsrc-2006Q2:1.5.0.30 pkgsrc-2006Q2-base:1.5 pkgsrc-2006Q1:1.5.0.28 pkgsrc-2006Q1-base:1.5 pkgsrc-2005Q4:1.5.0.26 pkgsrc-2005Q4-base:1.5 pkgsrc-2005Q3:1.5.0.24 pkgsrc-2005Q3-base:1.5 pkgsrc-2005Q2:1.5.0.22 pkgsrc-2005Q2-base:1.5 pkgsrc-2005Q1:1.5.0.20 pkgsrc-2005Q1-base:1.5 pkgsrc-2004Q4:1.5.0.18 pkgsrc-2004Q4-base:1.5 pkgsrc-2004Q3:1.5.0.16 pkgsrc-2004Q3-base:1.5 pkgsrc-2004Q2:1.5.0.14 pkgsrc-2004Q2-base:1.5 pkgsrc-2004Q1:1.5.0.12 pkgsrc-2004Q1-base:1.5 pkgsrc-2003Q4:1.5.0.10 pkgsrc-2003Q4-base:1.5 netbsd-1-6-1:1.5.0.6 netbsd-1-6-1-base:1.5 netbsd-1-6:1.5.0.8 netbsd-1-6-RELEASE-base:1.5 pkgviews:1.5.0.4 pkgviews-base:1.5 buildlink2:1.5.0.2 buildlink2-base:1.5 netbsd-1-5-PATCH003:1.5 netbsd-1-5-PATCH001:1.5 netbsd-1-5-RELEASE:1.5 netbsd-1-4-PATCH003:1.5 netbsd-1-4-PATCH002:1.5 comdex-fall-1999:1.5 netbsd-1-4-PATCH001:1.5 netbsd-1-4-RELEASE:1.5 netbsd-1-3-PATCH003:1.4 netbsd-1-3-PATCH002:1.2; locks; strict; comment @# @; 1.5 date 98.11.05.02.46.09; author mycroft; state Exp; branches; next 1.4; 1.4 date 98.09.13.17.06.09; author garbled; state Exp; branches; next 1.3; 1.3 date 98.08.07.11.09.57; author agc; state Exp; branches; next 1.2; 1.2 date 98.05.04.23.42.39; author hubertf; state Exp; branches; next 1.1; 1.1 date 98.03.05.22.26.25; author mycroft; state Exp; branches; next ; desc @@ 1.5 log @3.0.28 @ text @$NetBSD$ --- /dev/null Wed Nov 4 21:26:51 1998 +++ src/auddev_netbsd.c Wed Nov 4 21:27:03 1998 @@@@ -0,0 +1,423 @@@@ +/* + * FILE: netbsd.c + * PROGRAM: RAT + * AUTHOR: Isidor Kouvelas + * MODIFIED: Colin Perkins + * + * $Revision: 1.4 $ + * $Date: 1998/09/13 17:06:09 $ + * + * Copyright (c) 1995,1996 University College London + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, is permitted, for non-commercial use only, provided + * that the following conditions are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the Computer Science + * Department at University College London + * 4. Neither the name of the University nor of the Department may be used + * to endorse or promote products derived from this software without + * specific prior written permission. + * Use of this software for commercial purposes is explicitly forbidden + * unless prior written permission is obtained from the authors. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + + + +#include "assert.h" +#include "bat_include.h" +#ifdef __NetBSD__ + +static audio_info_t dev_info; +static int mulaw_device = FALSE; /* TRUE if the hardware can only do 8bit mulaw sampling */ + +#define bat_to_device(x) ((x) * AUDIO_MAX_GAIN / MAX_AMP) +#define device_to_bat(x) ((x) * MAX_AMP / AUDIO_MAX_GAIN) + +/* Try to open the audio device. */ +/* Returns a valid file descriptor if ok, -1 otherwise. */ +int +audio_open(audio_format format) +{ + audio_info_t tmp_info; + + int audio_fd = open("/dev/audio", O_RDWR | O_NDELAY); + + if (audio_fd > 0) { + AUDIO_INITINFO(&dev_info); + dev_info.monitor_gain = 0; + dev_info.play.sample_rate = format.sample_rate; + dev_info.record.sample_rate = format.sample_rate; + dev_info.play.channels = format.num_channels; + dev_info.record.channels = format.num_channels; + dev_info.play.precision = format.bits_per_sample; + dev_info.record.precision = format.bits_per_sample; + dev_info.play.gain = (AUDIO_MAX_GAIN - AUDIO_MIN_GAIN) * 0.75; + dev_info.record.gain = (AUDIO_MAX_GAIN - AUDIO_MIN_GAIN) * 0.75; + dev_info.play.port = AUDIO_HEADPHONE; + dev_info.record.port = AUDIO_MICROPHONE; + dev_info.play.balance = AUDIO_MID_BALANCE; + dev_info.record.balance = AUDIO_MID_BALANCE; +#ifdef SunOS_5 + dev_info.play.buffer_size = DEVICE_BUF_UNIT; + dev_info.record.buffer_size = DEVICE_BUF_UNIT; +#endif + switch (format.encoding) { + case DEV_PCMU: + dev_info.record.encoding = AUDIO_ENCODING_ULAW; + dev_info.play.encoding = AUDIO_ENCODING_ULAW; + break; + case DEV_L8: + assert(format.bits_per_sample == 8); + dev_info.record.encoding = AUDIO_ENCODING_LINEAR; + dev_info.play.encoding = AUDIO_ENCODING_LINEAR; + break; + case DEV_L16: + assert(format.bits_per_sample == 16); + dev_info.record.encoding = AUDIO_ENCODING_LINEAR; + dev_info.play.encoding = AUDIO_ENCODING_LINEAR; + break; + default: + printf("ERROR: Unknown audio encoding in audio_open!\n"); + abort(); + } + + memcpy(&tmp_info, &dev_info, sizeof(audio_info_t)); + if (ioctl(audio_fd, AUDIO_SETINFO, (caddr_t)&tmp_info) < 0) { + if (format.encoding == DEV_L16) { +#ifdef DEBUG + printf("Old hardware detected: can't do 16 bit audio, trying 8 bit...\n"); +#endif + dev_info.play.precision = 8; + dev_info.record.precision = 8; + dev_info.record.encoding = AUDIO_ENCODING_ULAW; + dev_info.play.encoding = AUDIO_ENCODING_ULAW; + if (ioctl(audio_fd, AUDIO_SETINFO, (caddr_t)&dev_info) < 0) { + perror("Setting MULAW audio paramterts"); + return -1; + } + mulaw_device = TRUE; + } else { + perror("Setting audio paramterts"); + return -1; + } + } + return audio_fd; + } else { + /* Because we opened the device with O_NDELAY + * the waiting flag was not updated so update + * it manually using the audioctl device... + */ + audio_fd = open("/dev/audioctl", O_RDWR); + AUDIO_INITINFO(&dev_info); + dev_info.play.waiting = 1; + if (ioctl(audio_fd, AUDIO_SETINFO, (caddr_t)&dev_info) < 0) { +#ifdef DEBUG + perror("Setting requests"); +#endif + } + close(audio_fd); + return -1; + } +} + +/* Close the audio device */ +void +audio_close(int audio_fd) +{ + close(audio_fd); + audio_fd = -1; +} + +/* Flush input buffer */ +void +audio_drain(int audio_fd) +{ + ioctl(audio_fd, AUDIO_FLUSH, 0); +} + +/* Gain and volume values are in the range 0 - MAX_AMP */ + +void +audio_set_gain(int audio_fd, int gain) +{ + if (audio_fd <= 0) + return; + + AUDIO_INITINFO(&dev_info); + dev_info.record.gain = bat_to_device(gain); + if (ioctl(audio_fd, AUDIO_SETINFO, (caddr_t)&dev_info) < 0) + perror("Setting gain"); +} + +int +audio_get_gain(int audio_fd) +{ + if (audio_fd <= 0) + return (0); + + AUDIO_INITINFO(&dev_info); + if (ioctl(audio_fd, AUDIO_GETINFO, (caddr_t)&dev_info) < 0) + perror("Getting gain"); + return (device_to_bat(dev_info.record.gain)); +} + +void +audio_set_volume(int audio_fd, int vol) +{ + if (audio_fd <= 0) + return; + + AUDIO_INITINFO(&dev_info); + dev_info.play.gain = bat_to_device(vol); + if (ioctl(audio_fd, AUDIO_SETINFO, (caddr_t)&dev_info) < 0) + perror("Setting volume"); +} + +int +audio_get_volume(int audio_fd) +{ + if (audio_fd <= 0) + return (0); + + AUDIO_INITINFO(&dev_info); + if (ioctl(audio_fd, AUDIO_GETINFO, (caddr_t)&dev_info) < 0) + perror("Getting gain"); + return (device_to_bat(dev_info.play.gain)); +} + +int +audio_read(int audio_fd, sample *buf, int samples) +{ + int i, len; + static u_char mulaw_buf[DEVICE_REC_BUF]; + u_char *p; + + if (mulaw_device) { + if ((len = read(audio_fd, mulaw_buf, samples)) < 0) { + return 0; + } else { + p = mulaw_buf; + for (i = 0; i < len; i++) { + *buf++ = u2s((unsigned)*p); + p++; + } + return (len); + } + } else { + if ((len = read(audio_fd, (char *)buf, samples * BYTES_PER_SAMPLE)) < 0) { + return 0; + } else { + return (len / BYTES_PER_SAMPLE); + } + } +} + +int +audio_write(int audio_fd, sample *buf, int samples) +{ + int i, done, len, bps; + unsigned char *p, *q; + static u_char mulaw_buf[DEVICE_REC_BUF]; + + if (mulaw_device) { + p = mulaw_buf; + for (i = 0; i < samples; i++) + *p++ = lintomulaw[(unsigned short)*buf++]; + p = mulaw_buf; + len = samples; + bps = 1; + } else { + p = (char *)buf; + len = samples * BYTES_PER_SAMPLE; + bps = BYTES_PER_SAMPLE; + } + + q = p; + while (1) { + if ((done = write(audio_fd, p, len)) == len) + break; + if (errno != EINTR) + return (samples - ((len - done) / bps)); + len -= done; + p += done; + } + + return (samples); +} + +/* Set ops on audio device to be non-blocking */ +void +audio_non_block(int audio_fd) +{ + int on = 1; + + if (audio_fd <= 0) + return; + + if (ioctl(audio_fd, FIONBIO, (char *)&on) < 0) + fprintf(stderr, "Failed to set non blocking mode on audio device!\n"); +} + +/* Set ops on audio device to block */ +void +audio_block(int audio_fd) +{ + int on = 0; + + if (audio_fd <= 0) + return; + + if (ioctl(audio_fd, FIONBIO, (char *)&on) < 0) + fprintf(stderr, "Failed to set blocking mode on audio device!\n"); +} + +void +audio_set_oport(int audio_fd, int port) +{ + if (audio_fd <= 0) + return; + + AUDIO_INITINFO(&dev_info); + /* AUDIO_SPEAKER or AUDIO_HEADPHONE */ + dev_info.play.port = port; + if (ioctl(audio_fd, AUDIO_SETINFO, (caddr_t)&dev_info) < 0) + perror("Setting port"); +} + +int +audio_get_oport(int audio_fd) +{ + if (audio_fd <= 0) + return (AUDIO_SPEAKER); + + AUDIO_INITINFO(&dev_info); + if (ioctl(audio_fd, AUDIO_GETINFO, (caddr_t)&dev_info) < 0) + perror("Getting port"); + return (dev_info.play.port); +} + +int +audio_next_oport(int audio_fd) +{ + int port; + + if (audio_fd <= 0) + return (AUDIO_SPEAKER); + + AUDIO_INITINFO(&dev_info); + if (ioctl(audio_fd, AUDIO_GETINFO, (caddr_t)&dev_info) < 0) + perror("Getting port"); + + + port = dev_info.play.port; + port <<= 1; + + /* It is either wrong on some machines or i got something wrong! */ + if (dev_info.play.avail_ports < 3) + dev_info.play.avail_ports = 3; + + if ((port & dev_info.play.avail_ports) == 0) + port = 1; + + AUDIO_INITINFO(&dev_info); + dev_info.play.port = port; + if (ioctl(audio_fd, AUDIO_SETINFO, (caddr_t)&dev_info) < 0) + perror("Setting port"); + + return (port); +} + +void +audio_set_iport(int audio_fd, int port) +{ + if (audio_fd <= 0) + return; + + AUDIO_INITINFO(&dev_info); + dev_info.record.port = port; + if (ioctl(audio_fd, AUDIO_SETINFO, (caddr_t)&dev_info) < 0) + perror("Setting port"); +} + +int +audio_get_iport(int audio_fd) +{ + if (audio_fd <= 0) + return (AUDIO_SPEAKER); + + AUDIO_INITINFO(&dev_info); + if (ioctl(audio_fd, AUDIO_GETINFO, (caddr_t)&dev_info) < 0) + perror("Getting port"); + return (dev_info.record.port); +} + +int +audio_next_iport(int audio_fd) +{ + int port; + + if (audio_fd <= 0) + return (AUDIO_SPEAKER); + + AUDIO_INITINFO(&dev_info); + if (ioctl(audio_fd, AUDIO_GETINFO, (caddr_t)&dev_info) < 0) + perror("Getting port"); + + port = dev_info.record.port; + port <<= 1; + + if (dev_info.record.avail_ports > 3) + dev_info.record.avail_ports = 3; + + /* Hack to fix Sparc 5 SOLARIS bug */ + if ((port & dev_info.record.avail_ports) == 0) + port = 1; + + AUDIO_INITINFO(&dev_info); + dev_info.record.port = port; + if (ioctl(audio_fd, AUDIO_SETINFO, (caddr_t)&dev_info) < 0) + perror("Setting port"); + + return (port); +} + +void +audio_switch_out(int audio_fd, cushion_struct *ap) +{ + /* Full duplex device: do nothing! */ +} + +void +audio_switch_in(int audio_fd) +{ + /* Full duplex device: do nothing! */ +} + +int +audio_duplex(int audio_fd) +{ + return 1; +} + +#endif /* __NetBSD__ */ + @ 1.4 log @Makefile: removed tk80 as a category, added USE_X11, fixed up build target Patches: Added patch to fix alpha 64bit-ism, broke up patches into separate files, fix various Makefiles WRT PREFIX,X11BASE and LOCALBASE handling. All in all, this was a mess. It works now on elf/alpha, pending a fix to bsd.pkg.mk.. if that falls through, one line will fix it up in the Makefile. @ text @d2 427 a428 428 *** /dev/null Thu Mar 5 16:59:30 1998 --- src/auddev_netbsd.c Thu Mar 5 16:40:41 1998 *************** *** 0 **** --- 1,423 ---- + /* + * FILE: netbsd.c + * PROGRAM: RAT + * AUTHOR: Isidor Kouvelas + * MODIFIED: Colin Perkins + * + * $Revision: 1.3 $ + * $Date: 1998/08/07 11:09:57 $ + * + * Copyright (c) 1995,1996 University College London + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, is permitted, for non-commercial use only, provided + * that the following conditions are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the Computer Science + * Department at University College London + * 4. Neither the name of the University nor of the Department may be used + * to endorse or promote products derived from this software without + * specific prior written permission. + * Use of this software for commercial purposes is explicitly forbidden + * unless prior written permission is obtained from the authors. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + + + + #include "assert.h" + #include "bat_include.h" + #ifdef __NetBSD__ + + static audio_info_t dev_info; + static int mulaw_device = FALSE; /* TRUE if the hardware can only do 8bit mulaw sampling */ + + #define bat_to_device(x) ((x) * AUDIO_MAX_GAIN / MAX_AMP) + #define device_to_bat(x) ((x) * MAX_AMP / AUDIO_MAX_GAIN) + + /* Try to open the audio device. */ + /* Returns a valid file descriptor if ok, -1 otherwise. */ + int + audio_open(audio_format format) + { + audio_info_t tmp_info; + + int audio_fd = open("/dev/audio", O_RDWR | O_NDELAY); + + if (audio_fd > 0) { + AUDIO_INITINFO(&dev_info); + dev_info.monitor_gain = 0; + dev_info.play.sample_rate = format.sample_rate; + dev_info.record.sample_rate = format.sample_rate; + dev_info.play.channels = format.num_channels; + dev_info.record.channels = format.num_channels; + dev_info.play.precision = format.bits_per_sample; + dev_info.record.precision = format.bits_per_sample; + dev_info.play.gain = (AUDIO_MAX_GAIN - AUDIO_MIN_GAIN) * 0.75; + dev_info.record.gain = (AUDIO_MAX_GAIN - AUDIO_MIN_GAIN) * 0.75; + dev_info.play.port = AUDIO_HEADPHONE; + dev_info.record.port = AUDIO_MICROPHONE; + dev_info.play.balance = AUDIO_MID_BALANCE; + dev_info.record.balance = AUDIO_MID_BALANCE; + #ifdef SunOS_5 + dev_info.play.buffer_size = DEVICE_BUF_UNIT; + dev_info.record.buffer_size = DEVICE_BUF_UNIT; + #endif + switch (format.encoding) { + case DEV_PCMU: + dev_info.record.encoding = AUDIO_ENCODING_ULAW; + dev_info.play.encoding = AUDIO_ENCODING_ULAW; + break; + case DEV_L8: + assert(format.bits_per_sample == 8); + dev_info.record.encoding = AUDIO_ENCODING_LINEAR; + dev_info.play.encoding = AUDIO_ENCODING_LINEAR; + break; + case DEV_L16: + assert(format.bits_per_sample == 16); + dev_info.record.encoding = AUDIO_ENCODING_LINEAR; + dev_info.play.encoding = AUDIO_ENCODING_LINEAR; + break; + default: + printf("ERROR: Unknown audio encoding in audio_open!\n"); + abort(); + } + + memcpy(&tmp_info, &dev_info, sizeof(audio_info_t)); + if (ioctl(audio_fd, AUDIO_SETINFO, (caddr_t)&tmp_info) < 0) { + if (format.encoding == DEV_L16) { + #ifdef DEBUG + printf("Old hardware detected: can't do 16 bit audio, trying 8 bit...\n"); + #endif + dev_info.play.precision = 8; + dev_info.record.precision = 8; + dev_info.record.encoding = AUDIO_ENCODING_ULAW; + dev_info.play.encoding = AUDIO_ENCODING_ULAW; + if (ioctl(audio_fd, AUDIO_SETINFO, (caddr_t)&dev_info) < 0) { + perror("Setting MULAW audio paramterts"); + return -1; + } + mulaw_device = TRUE; + } else { + perror("Setting audio paramterts"); + return -1; + } + } + return audio_fd; + } else { + /* Because we opened the device with O_NDELAY + * the waiting flag was not updated so update + * it manually using the audioctl device... + */ + audio_fd = open("/dev/audioctl", O_RDWR); + AUDIO_INITINFO(&dev_info); + dev_info.play.waiting = 1; + if (ioctl(audio_fd, AUDIO_SETINFO, (caddr_t)&dev_info) < 0) { + #ifdef DEBUG + perror("Setting requests"); + #endif + } + close(audio_fd); + return -1; + } + } + + /* Close the audio device */ + void + audio_close(int audio_fd) + { + close(audio_fd); + audio_fd = -1; + } + + /* Flush input buffer */ + void + audio_drain(int audio_fd) + { + ioctl(audio_fd, AUDIO_FLUSH, 0); + } + + /* Gain and volume values are in the range 0 - MAX_AMP */ + + void + audio_set_gain(int audio_fd, int gain) + { + if (audio_fd <= 0) + return; + + AUDIO_INITINFO(&dev_info); + dev_info.record.gain = bat_to_device(gain); + if (ioctl(audio_fd, AUDIO_SETINFO, (caddr_t)&dev_info) < 0) + perror("Setting gain"); + } + + int + audio_get_gain(int audio_fd) + { + if (audio_fd <= 0) + return (0); + + AUDIO_INITINFO(&dev_info); + if (ioctl(audio_fd, AUDIO_GETINFO, (caddr_t)&dev_info) < 0) + perror("Getting gain"); + return (device_to_bat(dev_info.record.gain)); + } + + void + audio_set_volume(int audio_fd, int vol) + { + if (audio_fd <= 0) + return; + + AUDIO_INITINFO(&dev_info); + dev_info.play.gain = bat_to_device(vol); + if (ioctl(audio_fd, AUDIO_SETINFO, (caddr_t)&dev_info) < 0) + perror("Setting volume"); + } + + int + audio_get_volume(int audio_fd) + { + if (audio_fd <= 0) + return (0); + + AUDIO_INITINFO(&dev_info); + if (ioctl(audio_fd, AUDIO_GETINFO, (caddr_t)&dev_info) < 0) + perror("Getting gain"); + return (device_to_bat(dev_info.play.gain)); + } + + int + audio_read(int audio_fd, sample *buf, int samples) + { + int i, len; + static u_char mulaw_buf[DEVICE_REC_BUF]; + u_char *p; + + if (mulaw_device) { + if ((len = read(audio_fd, mulaw_buf, samples)) < 0) { + return 0; + } else { + p = mulaw_buf; + for (i = 0; i < len; i++) { + *buf++ = u2s((unsigned)*p); + p++; + } + return (len); + } + } else { + if ((len = read(audio_fd, (char *)buf, samples * BYTES_PER_SAMPLE)) < 0) { + return 0; + } else { + return (len / BYTES_PER_SAMPLE); + } + } + } + + int + audio_write(int audio_fd, sample *buf, int samples) + { + int i, done, len, bps; + unsigned char *p, *q; + static u_char mulaw_buf[DEVICE_REC_BUF]; + + if (mulaw_device) { + p = mulaw_buf; + for (i = 0; i < samples; i++) + *p++ = lintomulaw[(unsigned short)*buf++]; + p = mulaw_buf; + len = samples; + bps = 1; + } else { + p = (char *)buf; + len = samples * BYTES_PER_SAMPLE; + bps = BYTES_PER_SAMPLE; + } + + q = p; + while (1) { + if ((done = write(audio_fd, p, len)) == len) + break; + if (errno != EINTR) + return (samples - ((len - done) / bps)); + len -= done; + p += done; + } + + return (samples); + } + + /* Set ops on audio device to be non-blocking */ + void + audio_non_block(int audio_fd) + { + int on = 1; + + if (audio_fd <= 0) + return; + + if (ioctl(audio_fd, FIONBIO, (char *)&on) < 0) + fprintf(stderr, "Failed to set non blocking mode on audio device!\n"); + } + + /* Set ops on audio device to block */ + void + audio_block(int audio_fd) + { + int on = 0; + + if (audio_fd <= 0) + return; + + if (ioctl(audio_fd, FIONBIO, (char *)&on) < 0) + fprintf(stderr, "Failed to set blocking mode on audio device!\n"); + } + + void + audio_set_oport(int audio_fd, int port) + { + if (audio_fd <= 0) + return; + + AUDIO_INITINFO(&dev_info); + /* AUDIO_SPEAKER or AUDIO_HEADPHONE */ + dev_info.play.port = port; + if (ioctl(audio_fd, AUDIO_SETINFO, (caddr_t)&dev_info) < 0) + perror("Setting port"); + } + + int + audio_get_oport(int audio_fd) + { + if (audio_fd <= 0) + return (AUDIO_SPEAKER); + + AUDIO_INITINFO(&dev_info); + if (ioctl(audio_fd, AUDIO_GETINFO, (caddr_t)&dev_info) < 0) + perror("Getting port"); + return (dev_info.play.port); + } + + int + audio_next_oport(int audio_fd) + { + int port; + + if (audio_fd <= 0) + return (AUDIO_SPEAKER); + + AUDIO_INITINFO(&dev_info); + if (ioctl(audio_fd, AUDIO_GETINFO, (caddr_t)&dev_info) < 0) + perror("Getting port"); + + + port = dev_info.play.port; + port <<= 1; + + /* It is either wrong on some machines or i got something wrong! */ + if (dev_info.play.avail_ports < 3) + dev_info.play.avail_ports = 3; + + if ((port & dev_info.play.avail_ports) == 0) + port = 1; + + AUDIO_INITINFO(&dev_info); + dev_info.play.port = port; + if (ioctl(audio_fd, AUDIO_SETINFO, (caddr_t)&dev_info) < 0) + perror("Setting port"); + + return (port); + } + + void + audio_set_iport(int audio_fd, int port) + { + if (audio_fd <= 0) + return; + + AUDIO_INITINFO(&dev_info); + dev_info.record.port = port; + if (ioctl(audio_fd, AUDIO_SETINFO, (caddr_t)&dev_info) < 0) + perror("Setting port"); + } + + int + audio_get_iport(int audio_fd) + { + if (audio_fd <= 0) + return (AUDIO_SPEAKER); + + AUDIO_INITINFO(&dev_info); + if (ioctl(audio_fd, AUDIO_GETINFO, (caddr_t)&dev_info) < 0) + perror("Getting port"); + return (dev_info.record.port); + } + + int + audio_next_iport(int audio_fd) + { + int port; + + if (audio_fd <= 0) + return (AUDIO_SPEAKER); + + AUDIO_INITINFO(&dev_info); + if (ioctl(audio_fd, AUDIO_GETINFO, (caddr_t)&dev_info) < 0) + perror("Getting port"); + + port = dev_info.record.port; + port <<= 1; + + if (dev_info.record.avail_ports > 3) + dev_info.record.avail_ports = 3; + + /* Hack to fix Sparc 5 SOLARIS bug */ + if ((port & dev_info.record.avail_ports) == 0) + port = 1; + + AUDIO_INITINFO(&dev_info); + dev_info.record.port = port; + if (ioctl(audio_fd, AUDIO_SETINFO, (caddr_t)&dev_info) < 0) + perror("Setting port"); + + return (port); + } + + void + audio_switch_out(int audio_fd, cushion_struct *ap) + { + /* Full duplex device: do nothing! */ + } + + void + audio_switch_in(int audio_fd) + { + /* Full duplex device: do nothing! */ + } + + int + audio_duplex(int audio_fd) + { + return 1; + } + + #endif /* __NetBSD__ */ + @ 1.3 log @Add NetBSD RCS Ids. @ text @a1 116 *** Build~ Tue May 13 04:38:56 1997 --- Build Thu Mar 5 16:35:38 1998 *************** *** 55,59 **** Linux ) OSMVER=`echo $OSVERS | awk -F. '{printf("%d_%d", $1, $2)}'` ;; ! SunOS | IRIX | FreeBSD ) OSMVER=`echo $OSVERS | awk -F. '{print $1}'` ;; HP-UX ) OSTYPE=HPUX --- 55,59 ---- Linux ) OSMVER=`echo $OSVERS | awk -F. '{printf("%d_%d", $1, $2)}'` ;; ! SunOS | IRIX | FreeBSD | NetBSD ) OSMVER=`echo $OSVERS | awk -F. '{print $1}'` ;; HP-UX ) OSTYPE=HPUX *************** *** 69,74 **** echo "OSMVER=$OSMVER" # Create a directory for the .o files, if it doesn't exist... ! if [ ! -d objs/${USER:=`whoami`}/${OSTYPE}_${OSVERS} ]; then echo "Creating object directory objs/${USER}/${OSTYPE}_${OSVERS}..." mkdir bin/${USER} --- 69,76 ---- echo "OSMVER=$OSMVER" + USER=${USER:=`whoami`} + # Create a directory for the .o files, if it doesn't exist... ! if [ ! -d objs/${USER}/${OSTYPE}_${OSVERS} ]; then echo "Creating object directory objs/${USER}/${OSTYPE}_${OSVERS}..." mkdir bin/${USER} *************** *** 80,84 **** fi ! cmd="${MAKE:=make} OSTYPE=$OSTYPE OSMVER=$OSMVER OSVERS=$OSVERS USER=`whoami`" case $1 in rat ) echo "Running: $cmd bin/${USER}/rat-${OSTYPE}-${OSVERS}" --- 82,86 ---- fi ! cmd="${MAKE:=make} OSTYPE=$OSTYPE OSMVER=$OSMVER OSVERS=$OSVERS USER=$USER" case $1 in rat ) echo "Running: $cmd bin/${USER}/rat-${OSTYPE}-${OSVERS}" *** Makefile~ Tue May 27 06:29:15 1997 --- Makefile Thu Mar 5 16:37:53 1998 *************** *** 10,14 **** # -DDEBUG_RTP -DREPEAT ! DEFS += -D$(OSTYPE) -D$(OSTYPE)_$(OSMVER) -D$(USER) CC = gcc CFLAGS = -Wall -Werror $(INCS) $(DEFS) -g -O -fsigned-char --- 10,14 ---- # -DDEBUG_RTP -DREPEAT ! #DEFS += -D$(OSTYPE) -D$(OSTYPE)_$(OSMVER) -D$(USER) CC = gcc CFLAGS = -Wall -Werror $(INCS) $(DEFS) -g -O -fsigned-char *************** *** 53,56 **** --- 53,57 ---- $(OBJDIR)/auddev_linux.o \ $(OBJDIR)/auddev_freebsd.o \ + $(OBJDIR)/auddev_netbsd.o \ $(OBJDIR)/init_net.o \ $(OBJDIR)/init_session.o \ *** src/bat_include.h~ Tue May 27 06:27:48 1997 --- src/bat_include.h Thu Mar 5 16:22:59 1998 *************** *** 71,75 **** #include extern int h_errno; ! #if !defined(HPUX) && !defined(Linux) && !defined(__FreeBSD__) #include #include --- 71,75 ---- #include extern int h_errno; ! #if !defined(HPUX) && !defined(Linux) && !defined(__FreeBSD__) && !defined(__NetBSD__) #include #include *** src/config.h~ Fri May 23 08:44:14 1997 --- src/config.h Thu Mar 5 16:39:40 1998 *************** *** 57,60 **** --- 57,71 ---- #endif /* FreeBSD */ + #ifdef __NetBSD__ + #define OSNAME "NetBSD" + #define DEFINED_ERRLIST + #include + #include + #include + #include + #include + #include + #endif + #ifdef SunOS_5 #define OSNAME "Solaris" *** /dev/null Thu Mar 5 16:59:30 1998 --- Makefile_NetBSD_1 Thu Mar 5 16:41:44 1998 *************** *** 0 **** --- 1,7 ---- + INCS = -I/usr/X11R6/include \ + -I${PREFIX}/include/tcl8.0 \ + -I${PREFIX}/include/tk8.0 + LDLIBS = -L${PREFIX}/lib -ltk80 -ltcl80 \ + -L/usr/X11R6/lib -lXext -lX11 \ + -lm + d13 2 a14 2 + * $Revision: 1.2 $ + * $Date: 1998/05/04 23:42:39 $ @ 1.2 log @Update to 3.0.24 @ text @d1 2 d129 2 a130 2 + * $Revision: 1.1 $ + * $Date: 1998/03/05 22:26:25 $ @ 1.1 log @New packages for the Robust Audio Tool. Not thoroughly tested yet. @ text @a103 32 *** tcl/init.tcl~ Wed Mar 5 07:39:39 1997 --- tcl/init.tcl Thu Mar 5 16:44:45 1998 *************** *** 16,20 **** error "version mismatch: library\nscripts expect Tcl version 7.5b1 or later but the loaded version is\nonly [info patchlevel]" } ! package require -exact Tcl 7.6 if [catch {set auto_path $env(TCLLIBPATH)}] { set auto_path "" --- 16,20 ---- error "version mismatch: library\nscripts expect Tcl version 7.5b1 or later but the loaded version is\nonly [info patchlevel]" } ! package require -exact Tcl 8.0 if [catch {set auto_path $env(TCLLIBPATH)}] { set auto_path "" *** tk/aatk.tcl~ Wed Mar 5 07:41:01 1997 --- tk/aatk.tcl Thu Mar 5 16:44:54 1998 *************** *** 14,19 **** # Insist on running with compatible versions of Tcl and Tk. ! package require -exact Tk 4.2 ! package require -exact Tcl 7.6 # Add Tk's directory to the end of the auto-load search path, if it --- 14,19 ---- # Insist on running with compatible versions of Tcl and Tk. ! package require -exact Tk 8.0 ! package require -exact Tcl 8.0 # Add Tk's directory to the end of the auto-load search path, if it d127 2 a128 2 + * $Revision: 1.11 $ + * $Date: 1997/04/02 15:27:06 $ @