Subject: Re: PCM8 vs. PCM16/LINEAR?
To: None <tech-kern@NetBSD.ORG>
From: Mike Long <mike.long@analog.com>
List: tech-kern
Date: 08/17/1995 11:45:15
>Date: Sun, 06 Aug 1995 00:28:47 -0400
>From: John Brezak <brezak@apollo.hp.com>

>[I wrote:]
>> Sun's audio_prinfo_t includes a bitfield called 'avail_ports'.  They
>> define the symbols AUDIO_SPEAKER, AUDIO_HEADPHONE, and AUDIO_LINE_OUT
>> for output ports; and AUDIO_MICROPHONE and AUDIO_LINE_IN for input
>> ports.  We could do something similar, and add something like
>> AUDIO_OTHER so that apps can use another ioctl to get string(s).
>Look at VoxWare for even more.

VoxWare mixes sound sources/sinks (e.g. microphone) with mixer
settings (e.g. bass, treble).  Gag.

>You might also look at AF (Dec's audio server).

Where is it?

>True. But Sun really didn't get things right. They work ok for the limited
>audio capabilities of their workstations, but the PC audio cards today
>are way beyond that. In the NetBSD mixer design, there was a alot of thought
>put in for flexability and capability for compat. I think it has both. I
>looked at many mixers, and thought that the Windows one really had the
>most flexability. The Sun one, well it was for a Sun.

I haven't touched the /dev/mixer i/f, mostly because I don't
understand it yet. :-)

>One other source base to look at is VoxWare. There are probably more
>audio apps based on this these days.

I'm wary of taking anything from VoxWare.  Core punted it for two
reasons:

1) It's GPL.
2) It's icky.

We have to make sure that our audio stuff can't be classified as a
derivative work because of (1), and (2) should be stringently
avoided.

The diffs below reflect my current ideas for changes to audioio.h.
I gave up on the string stuff.  Possible remaining issues:

1) Endian issues if precision > 8
2) Additional formats: MPEG, Rockwell ADPCM, Zyxel ADPCM
3) Sun struct audio_{,pr}info fields still missing: buffer_size,
   balance, monitor_gain, output_muted
4) ?

*** audioio.h.orig	Thu Jul 13 17:12:40 1995
--- audioio.h	Wed Aug 16 16:35:01 1995
***************
*** 45,53 ****
  	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 */
--- 45,54 ----
  	u_int	channels;	/* number of channels, usually 1 or 2 */
  	u_int	precision;	/* number of bits/sample */
! 	u_int	encoding;	/* data encoding (AUDIO_ENCODING_* below) */
  	u_int	gain;		/* volume level */
! 	u_int	port;		/* selected I/O port (see below) */
  	u_long	seek;		/* BSD extension */
! 	u_int	avail_ports;	/* available I/O ports (see below) */
! 	u_int	ispare[2];
  	/* Current state of device: */
  	u_int	samples;	/* number of samples */
***************
*** 95,113 ****
   */
  /* 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
   */
--- 96,129 ----
   */
  /* Encoding ID's */
! #define AUDIO_ENCODING_NONE	(0) /* no encoding assigned */
! #define AUDIO_ENCODING_ULAW	(1) /* ITU G.711 mu-law */
! #define AUDIO_ENCODING_ALAW	(2) /* ITU G.711 A-law */
! #define AUDIO_ENCODING_LINEAR	(3) /* signed linear PCM */
! #define AUDIO_ENCODING_ULINEAR	(4) /* unsigned linear PCM */
! #define AUDIO_ENCODING_LINEAR8	AUDIO_ENCODING_ULINEAR
! #define AUDIO_ENCODING_DVI	(5) /* DVI ADPCM */
  
  typedef struct audio_encoding {
  	int index;
+ 	int encoding;
+ 	int precision;
  	char name[MAX_AUDIO_DEV_LEN];
  } audio_encoding_t;
  
  /*
+  * Audio ports selectable via AUDIO_[GS]ETINFO
+  * (more may be available through mixer i/f)
+  */
+ #define AUDIO_OTHER		(0x08)	/* must use mixer i/f to access */
+ /* output ports */
+ #define AUDIO_SPEAKER		(0x01)	/* amplified output */
+ #define AUDIO_HEADPHONE		(0x02)
+ #define AUDIO_LINE_OUT		(0x04)	/* line-level output */
+ /* input ports */
+ #define AUDIO_MICROPHONE	(0x01)	/* microphone input */
+ #define AUDIO_LINE_IN		(0x02)	/* line-level input */
+ #define AUDIO_INTERNAL_CD_IN	(0x04)	/* CD audio input */
+ 
+ /*
   * Audio device operations
   */
***************
*** 126,131 ****
   * Mixer device
   */
! #define AUDIO_MIN_GAIN	0
! #define AUDIO_MAX_GAIN	255
  
  typedef struct mixer_level {
--- 142,147 ----
   * Mixer device
   */
! #define AUDIO_MIN_GAIN	(0)
! #define AUDIO_MAX_GAIN	(255)
  
  typedef struct mixer_level {
***************
*** 133,139 ****
  	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
  
  /*
--- 149,155 ----
  	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)
  
  /*
***************
*** 150,160 ****
  	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 {
--- 166,176 ----
  	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 {
***************
*** 230,239 ****
  #define AudioNmixerout	"mixerout"
  
! #define AudioElinear "linear"
! #define AudioEmulaw "mulaw"
! #define AudioEalaw "alaw"
! #define AudioEpcm16 "PCM-16"
! #define AudioEpcm8 "PCM-8"
! #define AudioEadpcm "ADPCM"
  
  #define AudioCInputs	"Inputs"
--- 246,254 ----
  #define AudioNmixerout	"mixerout"
  
! #define AudioElinear	"linear"
! #define AudioEulinear	"unsigned linear"
! #define AudioEmulaw	"mu-law"
! #define AudioEalaw	"A-law"
! #define AudioEdvi	"DVI ADPCM"
  
  #define AudioCInputs	"Inputs"

-- 
Mike Long <mike.long@analog.com>           http://www.shore.net/~mikel
VLSI Design Engineer         finger mikel@shore.net for PGP public key
Analog Devices, CPD Division          CCBF225E7D3F7ECB2C8F7ABB15D9BE7B
Norwood, MA 02062 USA                assert(*this!=opinionof(Analog));