New audio subsystem

This commit is contained in:
brezak 1995-02-21 01:35:58 +00:00
parent 1e81015d0c
commit 1f5bdc75a9
6 changed files with 2208 additions and 2 deletions

View File

@ -1,4 +1,4 @@
# $NetBSD: GENERIC,v 1.11 1995/01/25 04:58:18 cgd Exp $
# $NetBSD: GENERIC,v 1.12 1995/02/21 01:43:02 brezak Exp $
#
# GENERIC -- everything that's currently supported
#
@ -149,6 +149,8 @@ ie0 at isa? port 0x360 iomem 0xd0000 irq 7 # StarLAN & 3C507 ethernet cards
#le0 at isa? port 0x320 irq 10 drq 7 # IsoLan, NE2100, and DEPCA
sb0 at isa? port 0x220 irq 7 drq 1 # SoundBlaster
wss0 at isa? port 0x530 irq 10 drq 0 # Windows Sound System
pas0 at isa? port 0x220 irq 7 drq 1 # ProAudio Spectrum
#spkr0 at isa? ...
pseudo-device loop 1 # network loopback

View File

@ -1,4 +1,4 @@
# $NetBSD: files.newconf,v 1.34 1995/01/25 04:48:09 cgd Exp $
# $NetBSD: files.newconf,v 1.35 1995/02/21 01:35:58 brezak Exp $
# @(#)files.newconf 7.5 (Berkeley) 5/10/93
@ -7,6 +7,7 @@ define disk
define tape
define ifnet
define tty
define audio
# net device attributes - we have generic code for ether.
# we should have imp but right now it is a pseudo-device.
@ -59,6 +60,7 @@ file ddb/db_trap.c ddb
file ddb/db_variables.c ddb
file ddb/db_watch.c ddb
file ddb/db_write_cmd.c ddb
file dev/audio.c audio needs-flag
file dev/vnd.c vnd needs-flag
file isofs/cd9660/cd9660_bmap.c cd9660
file isofs/cd9660/cd9660_lookup.c cd9660

1712
sys/dev/audio.c Normal file

File diff suppressed because it is too large Load Diff

133
sys/dev/audio_if.h Normal file
View File

@ -0,0 +1,133 @@
/* $NetBSD: audio_if.h,v 1.1 1995/02/21 01:36:58 brezak Exp $ */
/*
* Copyright (c) 1994 Havard Eidnes.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted 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 Systems
* Engineering Group at Lawrence Berkeley Laboratory.
* 4. Neither the name of the University nor of the Laboratory may be used
* to endorse or promote products derived from this software without
* specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS 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 REGENTS 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.
*
* $Id: audio_if.h,v 1.1 1995/02/21 01:36:58 brezak Exp $
*/
/*
* Generic interface to hardware driver.
*/
struct audio_hw_if {
int (*open)__P((dev_t, int)); /* open hardware */
void (*close)__P((caddr_t)); /* close hardware */
int (*drain)__P((caddr_t)); /* Optional: drain buffers */
/* Sample rate */
int (*set_in_sr)__P((caddr_t, u_long));
u_long (*get_in_sr)__P((caddr_t));
int (*set_out_sr)__P((caddr_t, u_long));
u_long (*get_out_sr)__P((caddr_t));
/* Encoding. */
/* XXX should we have separate in/out? */
int (*query_encoding)__P((caddr_t, struct audio_encoding *));
int (*set_encoding)__P((caddr_t, u_int));
int (*get_encoding)__P((caddr_t));
/* Precision = bits/sample, usually 8 or 16 */
/* XXX should we have separate in/out? */
int (*set_precision)__P((caddr_t, u_int));
int (*get_precision)__P((caddr_t));
/* Channels - mono(1), stereo(2) */
int (*set_channels)__P((caddr_t, int));
int (*get_channels)__P((caddr_t));
/* Hardware may have some say in the blocksize to choose */
int (*round_blocksize)__P((caddr_t, int));
/* Ports (in/out ports) */
int (*set_out_port)__P((caddr_t, int));
int (*get_out_port)__P((caddr_t));
int (*set_in_port)__P((caddr_t, int));
int (*get_in_port)__P((caddr_t));
/*
* Changing settings may require taking device out of "data mode",
* which can be quite expensive. Also, audiosetinfo() may
* change several settings in quick succession. To avoid
* having to take the device in/out of "data mode", we provide
* this function which indicates completion of settings
* adjustment.
*/
int (*commit_settings)__P((caddr_t));
/* Return silence value for encoding */
u_int (*get_silence)__P((int));
/* Software en/decode functions, set if SW coding required by HW */
void (*sw_encode)__P((int, u_char *, int));
void (*sw_decode)__P((int, u_char *, int));
/* Start input/output routines. These usually control DMA. */
int (*start_output)__P((caddr_t, void *, int, void (*)(), void *));
int (*start_input)__P((caddr_t, void *, int, void (*)(), void *));
int (*halt_output)__P((caddr_t));
int (*halt_input)__P((caddr_t));
int (*cont_output)__P((caddr_t));
int (*cont_input)__P((caddr_t));
int (*speaker_ctl)__P((caddr_t, int));
#define SPKR_ON 1
#define SPKR_OFF 0
int (*getdev)__P((caddr_t, struct audio_device *));
int (*setfd)__P((caddr_t, int));
/* Mixer (in/out ports) */
int (*set_port)__P((caddr_t, mixer_ctrl_t *));
int (*get_port)__P((caddr_t, mixer_ctrl_t *));
int (*query_devinfo)__P((caddr_t, mixer_devinfo_t *));
int full_duplex; /* non-null if HW is able to do full-duplex */
int audio_unit;
};
/* Register / deregister hardware driver */
extern int audio_hardware_attach __P((struct audio_hw_if *, caddr_t));
extern int audio_hardware_detach __P((struct audio_hw_if *));
/* Device identity flags */
#define SOUND_DEVICE 0
#define AUDIO_DEVICE 0x80
#define MIXER_DEVICE 0x10
#define ISDEVAUDIO(x) ((minor(x)&0xf0) == AUDIO_DEVICE)
#define ISDEVSOUND(x) ((minor(x)&0xf0) == SOUND_DEVICE)
#define ISDEVMIXER(x) ((minor(x)&0xf0) == MIXER_DEVICE)
#define AUDIOUNIT(x) (minor(x)&0x0f)
#define AUDIODEV(x) (minor(x)&0xf0)

122
sys/dev/audiovar.h Normal file
View File

@ -0,0 +1,122 @@
/* $NetBSD: audiovar.h,v 1.1 1995/02/21 01:36:59 brezak Exp $ */
/*
* Copyright (c) 1991-1993 Regents of the University of California.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted 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 Systems
* Engineering Group at Lawrence Berkeley Laboratory.
* 4. Neither the name of the University nor of the Laboratory may be used
* to endorse or promote products derived from this software without
* specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS 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 REGENTS 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.
*
* From: Header: audiovar.h,v 1.3 93/07/18 14:07:25 mccanne Exp (LBL)
* $Id: audiovar.h,v 1.1 1995/02/21 01:36:59 brezak Exp $
*/
/*
* Initial/default block duration is both configurable and patchable.
*/
#ifndef AUDIO_BLK_MS
#define AUDIO_BLK_MS 20 /* 20 ms */
#endif
#ifndef AUDIO_BACKLOG
#define AUDIO_BACKLOG 3 /* 60 ms */
#endif
/*
* Use a single page as the size of the audio ring buffers, so that
* the data won't cross a page boundary. This way the dma carried out
* in the hardware module will be efficient (i.e., at_dma() won't have
* to make a copy).
*/
#ifndef AU_RING_SIZE
#define AU_RING_SIZE NBPG
#endif
#define AU_RING_MOD(k) ((k) & (AU_RING_SIZE - 1))
#define AU_RING_EMPTY(rp) ((rp)->hp == (rp)->tp)
#define AU_RING_FULL(rp) (AU_RING_MOD((rp)->tp + 1) == (rp)->hp)
#define AU_RING_LEN(rp) (AU_RING_MOD((rp)->tp - (rp)->hp))
#define AU_RING_INIT(rp) { \
(rp)->nblk = (rp)->au_stamp = 0; \
(rp)->hp = (rp)->tp = (rp)->bp; \
}
struct audio_buffer {
u_char *hp; /* head */
u_char *tp; /* tail */
u_char *bp; /* start of buffer */
u_char *ep; /* end of buffer */
int nblk; /* number of active blocks in buffer */
int maxblk; /* max # of active blocks in buffer */
u_long au_stamp; /* number of audio samples read/written */
u_short cb_pause; /* io paused */
u_long cb_drops; /* missed samples from over/underrun */
u_long cb_pdrops; /* paused samples */
};
/*
* Software state, per audio device.
*/
struct audio_softc {
caddr_t hw_hdl; /* Hardware driver handle */
struct audio_hw_if *hw_if; /* Hardware interface */
u_char sc_open; /* single use device */
#define AUOPEN_READ 0x01
#define AUOPEN_WRITE 0x02
u_char sc_mode; /* bitmask for RECORD/PLAY */
struct selinfo sc_wsel; /* write selector */
struct selinfo sc_rsel; /* read selector */
/* Sleep channels for reading and writing. */
int sc_rchan;
int sc_wchan;
/* Ring buffers, separate for record and play. */
struct audio_buffer rr; /* Record ring */
struct audio_buffer pr; /* Play ring */
u_char sc_rbus; /* input dma in progress */
u_char sc_pbus; /* output dma in progress */
u_long sc_wseek; /* timestamp of last frame written */
u_long sc_rseek; /* timestamp of last frame read */
int sc_blksize; /* recv block (chunk) size in bytes */
int sc_smpl_in_blk; /* # samples in a block */
int sc_50ms; /* # of samples for 50ms? */
int sc_backlog; /* # blks of xmit backlog to generate */
int sc_lowat; /* xmit low water mark (for wakeup) */
int sc_hiwat; /* xmit high water mark (for wakeup) */
int sc_rblks; /* number of phantom record blocks */
int sc_pencoding; /* current encoding; play */
int sc_rencoding; /* current encoding; record */
};

235
sys/sys/audioio.h Normal file
View File

@ -0,0 +1,235 @@
/* $NetBSD: audioio.h,v 1.1 1995/02/21 01:37:22 brezak Exp $ */
/*
* Copyright (c) 1991-1993 Regents of the University of California.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted 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 Systems
* Engineering Group at Lawrence Berkeley Laboratory.
* 4. Neither the name of the University nor of the Laboratory may be used
* to endorse or promote products derived from this software without
* specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS 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 REGENTS 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.
*
* $Header: /cvsroot/src/sys/sys/audioio.h,v 1.1 1995/02/21 01:37:22 brezak Exp $ (LBL)
*/
#ifndef _AUDIOIO_H_
#define _AUDIOIO_H_
/*
* Audio device
*/
struct audio_prinfo {
u_int sample_rate; /* sample rate in bit/s */
u_int channels; /* number of channels, usually 1 or 2 */
u_int precision; /* number of bits/sample */
u_int encoding; /* data encoding (AUDIO_ENCODING_* above) */
u_int gain; /* volume level */
u_int port; /* selected I/O port */
u_long seek; /* BSD extension */
u_int ispare[3];
/* Current state of device: */
u_int samples; /* number of samples */
u_int eof; /* End Of File (zero-size writes) counter */
u_char pause; /* non-zero if paused, zero to resume */
u_char error; /* non-zero if underflow/overflow ocurred */
u_char waiting; /* non-zero if another process hangs in open */
u_char cspare[3];
u_char open; /* non-zero if currently open */
u_char active; /* non-zero if I/O is currently active */
};
struct audio_info {
struct audio_prinfo play; /* Info for play (output) side */
struct audio_prinfo record; /* Info for record (input) side */
u_int __spare;
/* BSD extensions */
u_int blocksize; /* input blocking threshold */
u_int hiwat; /* output high water mark */
u_int lowat; /* output low water mark */
u_int backlog; /* samples of output backlog to gen. */
u_int mode; /* bitmask of AUMODE_* values */
/* (Some devices can do both simultaneously) */
#define AUMODE_PLAY 0
#define AUMODE_RECORD 1
};
typedef struct audio_info audio_info_t;
#define AUDIO_INITINFO(p)\
(void)memset((void *)(p), 0xff, sizeof(struct audio_info))
/*
* Parameter for the AUDIO_GETDEV ioctl to determine current
* audio devices.
*/
#define MAX_AUDIO_DEV_LEN 16
typedef struct audio_device {
char name[MAX_AUDIO_DEV_LEN];
char version[MAX_AUDIO_DEV_LEN];
char config[MAX_AUDIO_DEV_LEN];
} audio_device_t;
/*
* Supported audio encodings
*/
/* Encoding ID's */
#define AUDIO_ENCODING_NONE 0 /* no encoding assigned */
#define AUDIO_ENCODING_ULAW 1
#define AUDIO_ENCODING_ALAW 2
#define AUDIO_ENCODING_PCM16 3
#define AUDIO_ENCODING_LINEAR AUDIO_ENCODING_PCM16
#define AUDIO_ENCODING_PCM8 4
#define AUDIO_ENCODING_ADPCM 5
typedef struct audio_encoding {
int index;
char name[MAX_AUDIO_DEV_LEN];
int format_id;
} audio_encoding_t;
/*
* Audio device operations
*/
#define AUDIO_GETINFO _IOR('A', 21, struct audio_info)
#define AUDIO_SETINFO _IOWR('A', 22, struct audio_info)
#define AUDIO_DRAIN _IO('A', 23)
#define AUDIO_FLUSH _IO('A', 24)
#define AUDIO_WSEEK _IOR('A', 25, u_long)
#define AUDIO_RERROR _IOR('A', 26, int)
#define AUDIO_GETDEV _IOR('A', 27, struct audio_device)
#define AUDIO_GETENC _IOWR('A', 28, struct audio_encoding)
#define AUDIO_GETFD _IOR('A', 29, int)
#define AUDIO_SETFD _IOWR('A', 30, int)
/*
* Mixer device
*/
#define AUDIO_MIN_GAIN 0
#define AUDIO_MAX_GAIN 255
typedef struct mixer_level {
int num_channels;
u_char level[8]; /* [num_channels] */
} mixer_level_t;
#define AUDIO_MIXER_LEVEL_MONO 0
#define AUDIO_MIXER_LEVEL_LEFT 0
#define AUDIO_MIXER_LEVEL_RIGHT 1
/*
* Device operations
*/
typedef struct audio_mixer_name {
char name[MAX_AUDIO_DEV_LEN];
int msg_id;
} audio_mixer_name_t;
typedef struct mixer_devinfo {
int index;
audio_mixer_name_t label;
int type;
#define AUDIO_MIXER_CLASS 0
#define AUDIO_MIXER_ENUM 1
#define AUDIO_MIXER_SET 2
#define AUDIO_MIXER_VALUE 3
int mixer_class;
int next, prev;
#define AUDIO_MIXER_LAST -1
union {
struct audio_mixer_enum {
int num_mem;
struct {
audio_mixer_name_t label;
int ord;
} member[32];
} e;
struct audio_mixer_set {
int num_mem;
struct {
audio_mixer_name_t label;
int mask;
} member[32];
} s;
struct audio_mixer_value {
audio_mixer_name_t units;
int num_channels;
} v;
} un;
} mixer_devinfo_t;
typedef struct mixer_ctrl {
int dev;
int type;
union {
int ord; /* enum */
int mask; /* set */
mixer_level_t value; /* value */
} un;
} mixer_ctrl_t;
/*
* Mixer operations
*/
#define AUDIO_MIXER_READ _IOWR('M', 0, mixer_ctrl_t)
#define AUDIO_MIXER_WRITE _IOWR('M', 1, mixer_ctrl_t)
#define AUDIO_MIXER_DEVINFO _IOWR('M', 2, mixer_devinfo_t)
/*
* Well known device names
*/
#define AudioNmicrophone "mic"
#define AudioNline "line"
#define AudioNcd "CD"
#define AudioNdac "DAC"
#define AudioNrecord "record"
#define AudioNvolume "volume"
#define AudioNmonitor "monitor"
#define AudioNtreble "treble"
#define AudioNbass "bass"
#define AudioNspeaker "speaker"
#define AudioNheadphone "headphones"
#define AudioNoutput "output"
#define AudioNinput "input"
#define AudioNmaster "master"
#define AudioNstereo "stereo"
#define AudioNmono "mono"
#define AudioNspatial "spatial"
#define AudioNsurround "surround"
#define AudioNpseudo "pseudo"
#define AudioNmute "mute"
#define AudioNenhanced "enhanced"
#define AudioNon "on"
#define AudioNoff "off"
#define AudioNmode "mode"
#define AudioNsource "source"
#define AudioCInputs "Inputs"
#define AudioCOutputs "Outputs"
#define AudioCRecord "Record"
#define AudioCMonitor "Monitor"
#define AudioCEqualization "Equalization"
#endif /* _AUDIOIO_H_ */