Home | History | Annotate | Line # | Download | only in audio
      1  1.13  mlelstv /*	$NetBSD: audiovar.h,v 1.13 2023/04/23 08:06:05 mlelstv 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.8    isaki #include <sys/pserialize.h>
     73   1.8    isaki #include <sys/psref.h>
     74   1.2    isaki #include <sys/queue.h>
     75   1.2    isaki 
     76   1.2    isaki #include <dev/audio/audio_if.h>
     77   1.2    isaki #include <dev/audio/audiofil.h>
     78   1.2    isaki 
     79   1.2    isaki /*
     80   1.2    isaki  * Whether supports [US]LINEAR24/24 as userland format.
     81   1.2    isaki  */
     82  1.13  mlelstv #define AUDIO_SUPPORT_LINEAR24
     83   1.2    isaki 
     84   1.2    isaki /*
     85   1.2    isaki  * Frequency range.
     86   1.2    isaki  * For lower limit, there are some antique machines who supports under
     87   1.2    isaki  * 4000Hz, so that we accept 1000Hz as lower limit, regardless of
     88   1.2    isaki  * practicality(?).
     89   1.2    isaki  * For upper limit, there are some devices who supports 384000Hz, but
     90   1.2    isaki  * I don't have them. :-)
     91   1.2    isaki  */
     92   1.2    isaki #define AUDIO_MIN_FREQUENCY (1000)
     93   1.2    isaki #define AUDIO_MAX_FREQUENCY (192000)
     94   1.2    isaki 
     95   1.2    isaki typedef struct audio_file audio_file_t;
     96   1.2    isaki typedef struct audio_trackmixer audio_trackmixer_t;
     97   1.2    isaki 
     98   1.2    isaki /* ring buffer */
     99   1.2    isaki typedef struct {
    100   1.2    isaki 	audio_format2_t fmt;	/* format */
    101   1.2    isaki 	int  capacity;		/* capacity by frame */
    102   1.2    isaki 	int  head;		/* head position in frame */
    103   1.2    isaki 	int  used;		/* used frame count */
    104   1.2    isaki 	void *mem;		/* sample ptr */
    105   1.2    isaki } audio_ring_t;
    106   1.2    isaki 
    107   1.2    isaki #define AUDIO_N_PORTS 4
    108   1.2    isaki 
    109   1.2    isaki struct au_mixer_ports {
    110   1.2    isaki 	int	index;		/* index of port-selector mixerctl */
    111   1.2    isaki 	int	master;		/* index of master mixerctl */
    112   1.2    isaki 	int	nports;		/* number of selectable ports */
    113   1.2    isaki 	bool	isenum;		/* selector is enum type */
    114   1.2    isaki 	u_int	allports;	/* all aumasks or'd */
    115   1.2    isaki 	u_int	aumask[AUDIO_N_PORTS];	/* exposed value of "ports" */
    116   1.2    isaki 	int	misel [AUDIO_N_PORTS];	/* ord of port, for selector */
    117   1.2    isaki 	int	miport[AUDIO_N_PORTS];	/* index of port's mixerctl */
    118   1.2    isaki 	bool	isdual;		/* has working mixerout */
    119   1.2    isaki 	int	mixerout;	/* ord of mixerout, for dual case */
    120   1.2    isaki 	int	cur_port;	/* the port that gain actually controls when
    121   1.2    isaki 				   mixerout is selected, for dual case */
    122   1.2    isaki };
    123   1.2    isaki 
    124   1.2    isaki struct audio_softc {
    125   1.2    isaki 	/* Myself (e.g.; audio0, audio1, ...) */
    126   1.2    isaki 	device_t	sc_dev;
    127   1.2    isaki 
    128   1.2    isaki 	/* Hardware device struct (e.g.; sb0, hdafg0, ...) */
    129   1.2    isaki 	device_t	hw_dev;
    130   1.2    isaki 
    131   1.2    isaki 	/*
    132   1.2    isaki 	 * Hardware interface and driver handle.
    133   1.2    isaki 	 * hw_if == NULL means that the device is (attached but) disabled.
    134   1.2    isaki 	 */
    135   1.2    isaki 	const struct audio_hw_if *hw_if;
    136   1.2    isaki 	void		*hw_hdl;
    137   1.2    isaki 
    138   1.2    isaki 	/*
    139   1.3    isaki 	 * Properties obtained by get_props().
    140   1.3    isaki 	 * No need any locks to read this variable.
    141   1.3    isaki 	 */
    142   1.3    isaki 	int sc_props;
    143   1.3    isaki 
    144   1.3    isaki 	/*
    145   1.2    isaki 	 * List of opened descriptors.
    146   1.5    isaki 	 * Must be protected by sc_lock || sc_intr_lock for traversal(FOREACH).
    147   1.5    isaki 	 * Must be protected by sc_lock && sc_intr_lock for insertion/removal.
    148   1.2    isaki 	 */
    149   1.2    isaki 	SLIST_HEAD(, audio_file) sc_files;
    150   1.2    isaki 
    151   1.2    isaki 	/*
    152   1.2    isaki 	 * Blocksize in msec.
    153  1.11    isaki 	 * Must be protected by sc_exlock.
    154   1.2    isaki 	 */
    155   1.2    isaki 	int sc_blk_ms;
    156   1.2    isaki 
    157   1.2    isaki 	/*
    158   1.2    isaki 	 * Track mixer for playback and recording.
    159   1.2    isaki 	 * If null, the mixer is disabled.
    160  1.11    isaki 	 * Must be protected by sc_exlock.
    161   1.2    isaki 	 */
    162   1.2    isaki 	audio_trackmixer_t *sc_pmixer;
    163   1.2    isaki 	audio_trackmixer_t *sc_rmixer;
    164   1.2    isaki 
    165   1.2    isaki 	/*
    166   1.2    isaki 	 * Opening track counter.
    167  1.11    isaki 	 * Must be protected by sc_lock && sc_exlock for modifying.
    168  1.11    isaki 	 * Must be protected by sc_lock || sc_exlock for reference.
    169   1.2    isaki 	 */
    170   1.2    isaki 	int sc_popens;
    171   1.2    isaki 	int sc_ropens;
    172   1.2    isaki 
    173   1.2    isaki 	/*
    174   1.2    isaki 	 * true if the track mixer is running.
    175  1.11    isaki 	 * Must be protected by sc_exlock && sc_intr_lock for modifying.
    176  1.11    isaki 	 * Must be protected by sc_exlock || sc_intr_lock for reference.
    177   1.2    isaki 	 */
    178   1.2    isaki 	bool sc_pbusy;
    179   1.2    isaki 	bool sc_rbusy;
    180   1.2    isaki 
    181   1.2    isaki 	/*
    182   1.2    isaki 	 * These four are the parameters sustained with /dev/sound.
    183  1.11    isaki 	 * Must be protected by sc_exlock.
    184   1.2    isaki 	 */
    185   1.2    isaki 	audio_format2_t sc_sound_pparams;
    186   1.2    isaki 	audio_format2_t sc_sound_rparams;
    187   1.2    isaki 	bool 		sc_sound_ppause;
    188   1.2    isaki 	bool		sc_sound_rpause;
    189   1.2    isaki 
    190   1.2    isaki 	/* recent info for /dev/sound */
    191   1.2    isaki 	/* XXX TODO */
    192   1.2    isaki 	struct audio_info sc_ai;
    193   1.2    isaki 
    194   1.2    isaki 	/*
    195   1.2    isaki 	 * Playback(write)/Recording(read) selector.
    196   1.2    isaki 	 * Must be protected by sc_lock.
    197   1.2    isaki 	 */
    198   1.2    isaki 	struct selinfo sc_wsel;
    199   1.2    isaki 	struct selinfo sc_rsel;
    200   1.2    isaki 
    201   1.2    isaki 	/*
    202   1.7    isaki 	 * Processes who want mixer SIGIO.
    203   1.7    isaki 	 * sc_am is an array of pids, or NULL if empty.
    204   1.7    isaki 	 * sc_am_capacity is the number of allocated elements.
    205   1.7    isaki 	 * sc_am_used is the number of elements actually used.
    206  1.11    isaki 	 * Must be protected by sc_exlock.
    207   1.2    isaki 	 */
    208   1.7    isaki 	pid_t *sc_am;
    209   1.7    isaki 	int sc_am_capacity;
    210   1.7    isaki 	int sc_am_used;
    211   1.2    isaki 
    212   1.2    isaki 	/*
    213   1.2    isaki 	 * Thread lock and interrupt lock obtained by get_locks().
    214   1.2    isaki 	 */
    215   1.2    isaki 	kmutex_t *sc_lock;
    216   1.2    isaki 	kmutex_t *sc_intr_lock;
    217   1.2    isaki 
    218   1.2    isaki 	/*
    219   1.2    isaki 	 * Critical section.
    220   1.2    isaki 	 * Must be protected by sc_lock.
    221   1.2    isaki 	 */
    222   1.2    isaki 	int sc_exlock;
    223   1.2    isaki 	kcondvar_t sc_exlockcv;
    224   1.2    isaki 
    225   1.2    isaki 	/*
    226   1.8    isaki 	 * Passive reference to prevent a race between detach and fileops.
    227   1.8    isaki 	 * pserialize_perform(sc_psz) must be protected by sc_lock.
    228   1.8    isaki 	 */
    229   1.8    isaki 	pserialize_t sc_psz;
    230   1.8    isaki 	struct psref_target sc_psref;
    231   1.8    isaki 
    232   1.8    isaki 	/*
    233   1.2    isaki 	 * Must be protected by sc_lock (?)
    234   1.2    isaki 	 */
    235   1.2    isaki 	bool		sc_dying;
    236   1.2    isaki 
    237   1.2    isaki 	/*
    238  1.12    isaki 	 * Indicates that about to suspend.
    239  1.12    isaki 	 * Must be protected by sc_lock.
    240  1.12    isaki 	 */
    241  1.12    isaki 	bool		sc_suspending;
    242  1.12    isaki 
    243  1.12    isaki 	/*
    244   1.2    isaki 	 * If multiuser is false, other users who have different euid
    245   1.2    isaki 	 * than the first user cannot open this device.
    246  1.11    isaki 	 * Must be protected by sc_exlock.
    247   1.2    isaki 	 */
    248   1.2    isaki 	bool sc_multiuser;
    249   1.2    isaki 	kauth_cred_t sc_cred;
    250   1.2    isaki 
    251   1.2    isaki 	struct sysctllog *sc_log;
    252   1.2    isaki 
    253   1.2    isaki 	mixer_ctrl_t	*sc_mixer_state;
    254   1.2    isaki 	int		sc_nmixer_states;
    255   1.2    isaki 	struct au_mixer_ports sc_inports;
    256   1.2    isaki 	struct au_mixer_ports sc_outports;
    257   1.2    isaki 	int		sc_monitor_port;
    258   1.2    isaki 	u_int	sc_lastgain;
    259   1.2    isaki };
    260   1.2    isaki 
    261   1.2    isaki #ifdef DIAGNOSTIC
    262   1.2    isaki #define DIAGNOSTIC_filter_arg(arg) audio_diagnostic_filter_arg(__func__, (arg))
    263   1.2    isaki #define DIAGNOSTIC_format2(fmt)	audio_diagnostic_format2(__func__, (fmt))
    264   1.2    isaki extern void audio_diagnostic_filter_arg(const char *,
    265   1.2    isaki 	const audio_filter_arg_t *);
    266   1.2    isaki extern void audio_diagnostic_format2(const char *, const audio_format2_t *);
    267   1.2    isaki #else
    268   1.2    isaki #define DIAGNOSTIC_filter_arg(arg)
    269   1.2    isaki #define DIAGNOSTIC_format2(fmt)
    270   1.2    isaki #endif
    271   1.2    isaki 
    272   1.2    isaki /*
    273   1.2    isaki  * Return true if 'fmt' is the internal format.
    274   1.2    isaki  * It does not check for frequency and number of channels.
    275   1.2    isaki  */
    276   1.2    isaki static __inline bool
    277   1.2    isaki audio_format2_is_internal(const audio_format2_t *fmt)
    278   1.2    isaki {
    279   1.2    isaki 
    280   1.2    isaki 	if (fmt->encoding != AUDIO_ENCODING_SLINEAR_NE)
    281   1.2    isaki 		return false;
    282   1.2    isaki 	if (fmt->precision != AUDIO_INTERNAL_BITS)
    283   1.2    isaki 		return false;
    284   1.2    isaki 	if (fmt->stride != AUDIO_INTERNAL_BITS)
    285   1.2    isaki 		return false;
    286   1.2    isaki 	return true;
    287   1.2    isaki }
    288   1.2    isaki 
    289   1.2    isaki /*
    290   1.2    isaki  * Return true if fmt's encoding is one of LINEAR.
    291   1.2    isaki  */
    292   1.2    isaki static __inline bool
    293   1.2    isaki audio_format2_is_linear(const audio_format2_t *fmt)
    294   1.2    isaki {
    295   1.2    isaki 	return (fmt->encoding == AUDIO_ENCODING_SLINEAR_LE)
    296   1.2    isaki 	    || (fmt->encoding == AUDIO_ENCODING_SLINEAR_BE)
    297   1.2    isaki 	    || (fmt->encoding == AUDIO_ENCODING_ULINEAR_LE)
    298   1.2    isaki 	    || (fmt->encoding == AUDIO_ENCODING_ULINEAR_BE);
    299   1.2    isaki }
    300   1.2    isaki 
    301   1.2    isaki /*
    302   1.2    isaki  * Return true if fmt's encoding is one of SLINEAR.
    303   1.2    isaki  */
    304   1.2    isaki static __inline bool
    305   1.2    isaki audio_format2_is_signed(const audio_format2_t *fmt)
    306   1.2    isaki {
    307   1.2    isaki 	return (fmt->encoding == AUDIO_ENCODING_SLINEAR_LE)
    308   1.2    isaki 	    || (fmt->encoding == AUDIO_ENCODING_SLINEAR_BE);
    309   1.2    isaki }
    310   1.2    isaki 
    311   1.2    isaki /*
    312   1.2    isaki  * Return fmt's endian as LITTLE_ENDIAN or BIG_ENDIAN.
    313   1.2    isaki  */
    314   1.2    isaki static __inline int
    315   1.2    isaki audio_format2_endian(const audio_format2_t *fmt)
    316   1.2    isaki {
    317   1.2    isaki 	if (fmt->stride == 8) {
    318   1.2    isaki 		/* HOST ENDIAN */
    319   1.2    isaki 		return BYTE_ORDER;
    320   1.2    isaki 	}
    321   1.2    isaki 
    322   1.2    isaki 	if (fmt->encoding == AUDIO_ENCODING_SLINEAR_LE ||
    323   1.2    isaki 	    fmt->encoding == AUDIO_ENCODING_ULINEAR_LE) {
    324   1.2    isaki 		return LITTLE_ENDIAN;
    325   1.2    isaki 	}
    326   1.2    isaki 	if (fmt->encoding == AUDIO_ENCODING_SLINEAR_BE ||
    327   1.2    isaki 	    fmt->encoding == AUDIO_ENCODING_ULINEAR_BE) {
    328   1.2    isaki 		return BIG_ENDIAN;
    329   1.2    isaki 	}
    330   1.2    isaki 	return BYTE_ORDER;
    331   1.2    isaki }
    332   1.2    isaki 
    333   1.2    isaki /* Interfaces for audiobell. */
    334   1.4    isaki int audiobellopen(dev_t, audio_file_t **);
    335   1.4    isaki int audiobellsetrate(audio_file_t *, u_int);
    336   1.2    isaki int audiobellclose(audio_file_t *);
    337   1.2    isaki int audiobellwrite(audio_file_t *, struct uio *);
    338   1.2    isaki 
    339   1.2    isaki #endif /* !_SYS_DEV_AUDIO_AUDIOVAR_H_ */
    340