Home | History | Annotate | Line # | Download | only in audio
audiovar.h revision 1.5.2.1
      1  1.5.2.1     ad /*	$NetBSD: audiovar.h,v 1.5.2.1 2020/01/17 21:47:30 ad Exp $	*/
      2      1.2  isaki 
      3      1.2  isaki /*-
      4      1.2  isaki  * Copyright (c) 2002 The NetBSD Foundation, Inc.
      5      1.2  isaki  * All rights reserved.
      6      1.2  isaki  *
      7      1.2  isaki  * This code is derived from software contributed to The NetBSD Foundation
      8      1.2  isaki  * by TAMURA Kent
      9      1.2  isaki  *
     10      1.2  isaki  * Redistribution and use in source and binary forms, with or without
     11      1.2  isaki  * modification, are permitted provided that the following conditions
     12      1.2  isaki  * are met:
     13      1.2  isaki  * 1. Redistributions of source code must retain the above copyright
     14      1.2  isaki  *    notice, this list of conditions and the following disclaimer.
     15      1.2  isaki  * 2. Redistributions in binary form must reproduce the above copyright
     16      1.2  isaki  *    notice, this list of conditions and the following disclaimer in the
     17      1.2  isaki  *    documentation and/or other materials provided with the distribution.
     18      1.2  isaki  *
     19      1.2  isaki  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     20      1.2  isaki  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     21      1.2  isaki  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     22      1.2  isaki  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     23      1.2  isaki  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     24      1.2  isaki  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     25      1.2  isaki  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     26      1.2  isaki  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     27      1.2  isaki  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     28      1.2  isaki  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     29      1.2  isaki  * POSSIBILITY OF SUCH DAMAGE.
     30      1.2  isaki  */
     31      1.2  isaki 
     32      1.2  isaki /*
     33      1.2  isaki  * Copyright (c) 1991-1993 Regents of the University of California.
     34      1.2  isaki  * All rights reserved.
     35      1.2  isaki  *
     36      1.2  isaki  * Redistribution and use in source and binary forms, with or without
     37      1.2  isaki  * modification, are permitted provided that the following conditions
     38      1.2  isaki  * are met:
     39      1.2  isaki  * 1. Redistributions of source code must retain the above copyright
     40      1.2  isaki  *    notice, this list of conditions and the following disclaimer.
     41      1.2  isaki  * 2. Redistributions in binary form must reproduce the above copyright
     42      1.2  isaki  *    notice, this list of conditions and the following disclaimer in the
     43      1.2  isaki  *    documentation and/or other materials provided with the distribution.
     44      1.2  isaki  * 3. All advertising materials mentioning features or use of this software
     45      1.2  isaki  *    must display the following acknowledgement:
     46      1.2  isaki  *	This product includes software developed by the Computer Systems
     47      1.2  isaki  *	Engineering Group at Lawrence Berkeley Laboratory.
     48      1.2  isaki  * 4. Neither the name of the University nor of the Laboratory may be used
     49      1.2  isaki  *    to endorse or promote products derived from this software without
     50      1.2  isaki  *    specific prior written permission.
     51      1.2  isaki  *
     52      1.2  isaki  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     53      1.2  isaki  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     54      1.2  isaki  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     55      1.2  isaki  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     56      1.2  isaki  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     57      1.2  isaki  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     58      1.2  isaki  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     59      1.2  isaki  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     60      1.2  isaki  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     61      1.2  isaki  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     62      1.2  isaki  * SUCH DAMAGE.
     63      1.2  isaki  *
     64      1.2  isaki  *	From: Header: audiovar.h,v 1.3 93/07/18 14:07:25 mccanne Exp  (LBL)
     65      1.2  isaki  */
     66      1.2  isaki 
     67      1.2  isaki #ifndef _SYS_DEV_AUDIO_AUDIOVAR_H_
     68      1.2  isaki #define _SYS_DEV_AUDIO_AUDIOVAR_H_
     69      1.2  isaki 
     70      1.2  isaki #include <sys/condvar.h>
     71      1.2  isaki #include <sys/proc.h>
     72      1.2  isaki #include <sys/queue.h>
     73      1.2  isaki 
     74      1.2  isaki #include <dev/audio/audio_if.h>
     75      1.2  isaki #include <dev/audio/audiofil.h>
     76      1.2  isaki 
     77      1.2  isaki /*
     78      1.2  isaki  * Whether supports [US]LINEAR24/24 as userland format.
     79      1.2  isaki  */
     80      1.2  isaki /* #define AUDIO_SUPPORT_LINEAR24 */
     81      1.2  isaki 
     82      1.2  isaki /*
     83      1.2  isaki  * Frequency range.
     84      1.2  isaki  * For lower limit, there are some antique machines who supports under
     85      1.2  isaki  * 4000Hz, so that we accept 1000Hz as lower limit, regardless of
     86      1.2  isaki  * practicality(?).
     87      1.2  isaki  * For upper limit, there are some devices who supports 384000Hz, but
     88      1.2  isaki  * I don't have them. :-)
     89      1.2  isaki  */
     90      1.2  isaki #define AUDIO_MIN_FREQUENCY (1000)
     91      1.2  isaki #define AUDIO_MAX_FREQUENCY (192000)
     92      1.2  isaki 
     93      1.2  isaki typedef struct audio_file audio_file_t;
     94      1.2  isaki typedef struct audio_trackmixer audio_trackmixer_t;
     95      1.2  isaki 
     96      1.2  isaki /* ring buffer */
     97      1.2  isaki typedef struct {
     98      1.2  isaki 	audio_format2_t fmt;	/* format */
     99      1.2  isaki 	int  capacity;		/* capacity by frame */
    100      1.2  isaki 	int  head;		/* head position in frame */
    101      1.2  isaki 	int  used;		/* used frame count */
    102      1.2  isaki 	void *mem;		/* sample ptr */
    103      1.2  isaki } audio_ring_t;
    104      1.2  isaki 
    105      1.2  isaki #define AUDIO_N_PORTS 4
    106      1.2  isaki 
    107      1.2  isaki struct au_mixer_ports {
    108      1.2  isaki 	int	index;		/* index of port-selector mixerctl */
    109      1.2  isaki 	int	master;		/* index of master mixerctl */
    110      1.2  isaki 	int	nports;		/* number of selectable ports */
    111      1.2  isaki 	bool	isenum;		/* selector is enum type */
    112      1.2  isaki 	u_int	allports;	/* all aumasks or'd */
    113      1.2  isaki 	u_int	aumask[AUDIO_N_PORTS];	/* exposed value of "ports" */
    114      1.2  isaki 	int	misel [AUDIO_N_PORTS];	/* ord of port, for selector */
    115      1.2  isaki 	int	miport[AUDIO_N_PORTS];	/* index of port's mixerctl */
    116      1.2  isaki 	bool	isdual;		/* has working mixerout */
    117      1.2  isaki 	int	mixerout;	/* ord of mixerout, for dual case */
    118      1.2  isaki 	int	cur_port;	/* the port that gain actually controls when
    119      1.2  isaki 				   mixerout is selected, for dual case */
    120      1.2  isaki };
    121      1.2  isaki 
    122      1.2  isaki struct audio_softc {
    123      1.2  isaki 	/* Myself (e.g.; audio0, audio1, ...) */
    124      1.2  isaki 	device_t	sc_dev;
    125      1.2  isaki 
    126      1.2  isaki 	/* Hardware device struct (e.g.; sb0, hdafg0, ...) */
    127      1.2  isaki 	device_t	hw_dev;
    128      1.2  isaki 
    129      1.2  isaki 	/*
    130      1.2  isaki 	 * Hardware interface and driver handle.
    131      1.2  isaki 	 * hw_if == NULL means that the device is (attached but) disabled.
    132      1.2  isaki 	 */
    133      1.2  isaki 	const struct audio_hw_if *hw_if;
    134      1.2  isaki 	void		*hw_hdl;
    135      1.2  isaki 
    136      1.2  isaki 	/*
    137      1.3  isaki 	 * Properties obtained by get_props().
    138      1.3  isaki 	 * No need any locks to read this variable.
    139      1.3  isaki 	 */
    140      1.3  isaki 	int sc_props;
    141      1.3  isaki 
    142      1.3  isaki 	/*
    143      1.2  isaki 	 * List of opened descriptors.
    144      1.5  isaki 	 * Must be protected by sc_lock || sc_intr_lock for traversal(FOREACH).
    145      1.5  isaki 	 * Must be protected by sc_lock && sc_intr_lock for insertion/removal.
    146      1.2  isaki 	 */
    147      1.2  isaki 	SLIST_HEAD(, audio_file) sc_files;
    148      1.2  isaki 
    149      1.2  isaki 	/*
    150      1.2  isaki 	 * Blocksize in msec.
    151      1.2  isaki 	 * Must be protected by sc_lock.
    152      1.2  isaki 	 */
    153      1.2  isaki 	int sc_blk_ms;
    154      1.2  isaki 
    155      1.2  isaki 	/*
    156      1.2  isaki 	 * Track mixer for playback and recording.
    157      1.2  isaki 	 * If null, the mixer is disabled.
    158      1.2  isaki 	 */
    159      1.2  isaki 	audio_trackmixer_t *sc_pmixer;
    160      1.2  isaki 	audio_trackmixer_t *sc_rmixer;
    161      1.2  isaki 
    162      1.2  isaki 	/*
    163      1.2  isaki 	 * Opening track counter.
    164      1.2  isaki 	 * Must be protected by sc_lock.
    165      1.2  isaki 	 */
    166      1.2  isaki 	int sc_popens;
    167      1.2  isaki 	int sc_ropens;
    168      1.2  isaki 
    169      1.2  isaki 	/*
    170      1.2  isaki 	 * true if the track mixer is running.
    171      1.2  isaki 	 * Must be protected by sc_lock.
    172      1.2  isaki 	 */
    173      1.2  isaki 	bool sc_pbusy;
    174      1.2  isaki 	bool sc_rbusy;
    175      1.2  isaki 
    176      1.2  isaki 	/*
    177      1.2  isaki 	 * These four are the parameters sustained with /dev/sound.
    178      1.2  isaki 	 * Must be protected by sc_lock.
    179      1.2  isaki 	 */
    180      1.2  isaki 	audio_format2_t sc_sound_pparams;
    181      1.2  isaki 	audio_format2_t sc_sound_rparams;
    182      1.2  isaki 	bool 		sc_sound_ppause;
    183      1.2  isaki 	bool		sc_sound_rpause;
    184      1.2  isaki 
    185      1.2  isaki 	/* recent info for /dev/sound */
    186      1.2  isaki 	/* XXX TODO */
    187      1.2  isaki 	struct audio_info sc_ai;
    188      1.2  isaki 
    189      1.2  isaki 	/*
    190      1.2  isaki 	 * Playback(write)/Recording(read) selector.
    191      1.2  isaki 	 * Must be protected by sc_lock.
    192      1.2  isaki 	 */
    193      1.2  isaki 	struct selinfo sc_wsel;
    194      1.2  isaki 	struct selinfo sc_rsel;
    195      1.2  isaki 
    196      1.2  isaki 	/*
    197  1.5.2.1     ad 	 * Processes who want mixer SIGIO.
    198  1.5.2.1     ad 	 * sc_am is an array of pids, or NULL if empty.
    199  1.5.2.1     ad 	 * sc_am_capacity is the number of allocated elements.
    200  1.5.2.1     ad 	 * sc_am_used is the number of elements actually used.
    201      1.2  isaki 	 * Must be protected by sc_lock.
    202      1.2  isaki 	 */
    203  1.5.2.1     ad 	pid_t *sc_am;
    204  1.5.2.1     ad 	int sc_am_capacity;
    205  1.5.2.1     ad 	int sc_am_used;
    206      1.2  isaki 
    207      1.2  isaki 	/*
    208      1.2  isaki 	 * Thread lock and interrupt lock obtained by get_locks().
    209      1.2  isaki 	 */
    210      1.2  isaki 	kmutex_t *sc_lock;
    211      1.2  isaki 	kmutex_t *sc_intr_lock;
    212      1.2  isaki 
    213      1.2  isaki 	/*
    214      1.2  isaki 	 * Critical section.
    215      1.2  isaki 	 * Must be protected by sc_lock.
    216      1.2  isaki 	 */
    217      1.2  isaki 	int sc_exlock;
    218      1.2  isaki 	kcondvar_t sc_exlockcv;
    219      1.2  isaki 
    220      1.2  isaki 	/*
    221      1.2  isaki 	 * Must be protected by sc_lock (?)
    222      1.2  isaki 	 */
    223      1.2  isaki 	bool		sc_dying;
    224      1.2  isaki 
    225      1.2  isaki 	/*
    226      1.2  isaki 	 * If multiuser is false, other users who have different euid
    227      1.2  isaki 	 * than the first user cannot open this device.
    228      1.2  isaki 	 * Must be protected by sc_lock.
    229      1.2  isaki 	 */
    230      1.2  isaki 	bool sc_multiuser;
    231      1.2  isaki 	kauth_cred_t sc_cred;
    232      1.2  isaki 
    233      1.2  isaki 	struct sysctllog *sc_log;
    234      1.2  isaki 
    235      1.2  isaki 	mixer_ctrl_t	*sc_mixer_state;
    236      1.2  isaki 	int		sc_nmixer_states;
    237      1.2  isaki 	struct au_mixer_ports sc_inports;
    238      1.2  isaki 	struct au_mixer_ports sc_outports;
    239      1.2  isaki 	int		sc_monitor_port;
    240      1.2  isaki 	u_int	sc_lastgain;
    241      1.2  isaki };
    242      1.2  isaki 
    243      1.2  isaki #ifdef DIAGNOSTIC
    244      1.2  isaki #define DIAGNOSTIC_filter_arg(arg) audio_diagnostic_filter_arg(__func__, (arg))
    245      1.2  isaki #define DIAGNOSTIC_format2(fmt)	audio_diagnostic_format2(__func__, (fmt))
    246      1.2  isaki extern void audio_diagnostic_filter_arg(const char *,
    247      1.2  isaki 	const audio_filter_arg_t *);
    248      1.2  isaki extern void audio_diagnostic_format2(const char *, const audio_format2_t *);
    249      1.2  isaki #else
    250      1.2  isaki #define DIAGNOSTIC_filter_arg(arg)
    251      1.2  isaki #define DIAGNOSTIC_format2(fmt)
    252      1.2  isaki #endif
    253      1.2  isaki 
    254      1.2  isaki /*
    255      1.2  isaki  * Return true if 'fmt' is the internal format.
    256      1.2  isaki  * It does not check for frequency and number of channels.
    257      1.2  isaki  */
    258      1.2  isaki static __inline bool
    259      1.2  isaki audio_format2_is_internal(const audio_format2_t *fmt)
    260      1.2  isaki {
    261      1.2  isaki 
    262      1.2  isaki 	if (fmt->encoding != AUDIO_ENCODING_SLINEAR_NE)
    263      1.2  isaki 		return false;
    264      1.2  isaki 	if (fmt->precision != AUDIO_INTERNAL_BITS)
    265      1.2  isaki 		return false;
    266      1.2  isaki 	if (fmt->stride != AUDIO_INTERNAL_BITS)
    267      1.2  isaki 		return false;
    268      1.2  isaki 	return true;
    269      1.2  isaki }
    270      1.2  isaki 
    271      1.2  isaki /*
    272      1.2  isaki  * Return true if fmt's encoding is one of LINEAR.
    273      1.2  isaki  */
    274      1.2  isaki static __inline bool
    275      1.2  isaki audio_format2_is_linear(const audio_format2_t *fmt)
    276      1.2  isaki {
    277      1.2  isaki 	return (fmt->encoding == AUDIO_ENCODING_SLINEAR_LE)
    278      1.2  isaki 	    || (fmt->encoding == AUDIO_ENCODING_SLINEAR_BE)
    279      1.2  isaki 	    || (fmt->encoding == AUDIO_ENCODING_ULINEAR_LE)
    280      1.2  isaki 	    || (fmt->encoding == AUDIO_ENCODING_ULINEAR_BE);
    281      1.2  isaki }
    282      1.2  isaki 
    283      1.2  isaki /*
    284      1.2  isaki  * Return true if fmt's encoding is one of SLINEAR.
    285      1.2  isaki  */
    286      1.2  isaki static __inline bool
    287      1.2  isaki audio_format2_is_signed(const audio_format2_t *fmt)
    288      1.2  isaki {
    289      1.2  isaki 	return (fmt->encoding == AUDIO_ENCODING_SLINEAR_LE)
    290      1.2  isaki 	    || (fmt->encoding == AUDIO_ENCODING_SLINEAR_BE);
    291      1.2  isaki }
    292      1.2  isaki 
    293      1.2  isaki /*
    294      1.2  isaki  * Return fmt's endian as LITTLE_ENDIAN or BIG_ENDIAN.
    295      1.2  isaki  */
    296      1.2  isaki static __inline int
    297      1.2  isaki audio_format2_endian(const audio_format2_t *fmt)
    298      1.2  isaki {
    299      1.2  isaki 	if (fmt->stride == 8) {
    300      1.2  isaki 		/* HOST ENDIAN */
    301      1.2  isaki 		return BYTE_ORDER;
    302      1.2  isaki 	}
    303      1.2  isaki 
    304      1.2  isaki 	if (fmt->encoding == AUDIO_ENCODING_SLINEAR_LE ||
    305      1.2  isaki 	    fmt->encoding == AUDIO_ENCODING_ULINEAR_LE) {
    306      1.2  isaki 		return LITTLE_ENDIAN;
    307      1.2  isaki 	}
    308      1.2  isaki 	if (fmt->encoding == AUDIO_ENCODING_SLINEAR_BE ||
    309      1.2  isaki 	    fmt->encoding == AUDIO_ENCODING_ULINEAR_BE) {
    310      1.2  isaki 		return BIG_ENDIAN;
    311      1.2  isaki 	}
    312      1.2  isaki 	return BYTE_ORDER;
    313      1.2  isaki }
    314      1.2  isaki 
    315      1.2  isaki /* Interfaces for audiobell. */
    316      1.4  isaki int audiobellopen(dev_t, audio_file_t **);
    317      1.4  isaki int audiobellsetrate(audio_file_t *, u_int);
    318      1.2  isaki int audiobellclose(audio_file_t *);
    319      1.2  isaki int audiobellwrite(audio_file_t *, struct uio *);
    320      1.2  isaki 
    321      1.2  isaki #endif /* !_SYS_DEV_AUDIO_AUDIOVAR_H_ */
    322