The Design and Implementation of the FreeBSD Operating System, Second Edition
Now available: The Design and Implementation of the FreeBSD Operating System (Second Edition)


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]

FreeBSD/Linux Kernel Cross Reference
sys/dev/audio_if.h

Version: -  FREEBSD  -  FREEBSD-13-STABLE  -  FREEBSD-13-0  -  FREEBSD-12-STABLE  -  FREEBSD-12-0  -  FREEBSD-11-STABLE  -  FREEBSD-11-0  -  FREEBSD-10-STABLE  -  FREEBSD-10-0  -  FREEBSD-9-STABLE  -  FREEBSD-9-0  -  FREEBSD-8-STABLE  -  FREEBSD-8-0  -  FREEBSD-7-STABLE  -  FREEBSD-7-0  -  FREEBSD-6-STABLE  -  FREEBSD-6-0  -  FREEBSD-5-STABLE  -  FREEBSD-5-0  -  FREEBSD-4-STABLE  -  FREEBSD-3-STABLE  -  FREEBSD22  -  l41  -  OPENBSD  -  linux-2.6  -  MK84  -  PLAN9  -  xnu-8792 
SearchContext: -  none  -  3  -  10 

    1 /*      $NetBSD: audio_if.h,v 1.61 2006/04/19 14:10:58 jmcneill Exp $   */
    2 
    3 /*
    4  * Copyright (c) 1994 Havard Eidnes.
    5  * All rights reserved.
    6  *
    7  * Redistribution and use in source and binary forms, with or without
    8  * modification, are permitted provided that the following conditions
    9  * are met:
   10  * 1. Redistributions of source code must retain the above copyright
   11  *    notice, this list of conditions and the following disclaimer.
   12  * 2. Redistributions in binary form must reproduce the above copyright
   13  *    notice, this list of conditions and the following disclaimer in the
   14  *    documentation and/or other materials provided with the distribution.
   15  * 3. All advertising materials mentioning features or use of this software
   16  *    must display the following acknowledgement:
   17  *      This product includes software developed by the Computer Systems
   18  *      Engineering Group at Lawrence Berkeley Laboratory.
   19  * 4. Neither the name of the University nor of the Laboratory may be used
   20  *    to endorse or promote products derived from this software without
   21  *    specific prior written permission.
   22  *
   23  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
   24  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
   25  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
   26  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
   27  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
   28  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
   29  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
   30  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
   31  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
   32  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   33  * SUCH DAMAGE.
   34  *
   35  */
   36 
   37 #ifndef _SYS_DEV_AUDIO_IF_H_
   38 #define _SYS_DEV_AUDIO_IF_H_
   39 #include <sys/types.h>
   40 #include <sys/audioio.h>
   41 
   42 /* check we have an audio(4) configured into kernel */
   43 #if defined(_KERNEL_OPT)
   44 #include "audio.h"
   45 
   46 #if (NAUDIO == 0) && (NMIDI == 0) && (NMIDIBUS == 0)
   47 #error "No 'audio* at audiobus?' or 'midi* at midibus?' or similar configured"
   48 #endif
   49 
   50 #endif /* _KERNEL_OPT */
   51 
   52 /*
   53  * Interfaces for hardware drivers and MI audio.
   54  */
   55 
   56 struct audio_softc;
   57 
   58 /**
   59  * audio stream format
   60  */
   61 typedef struct audio_params {
   62         u_int   sample_rate;    /* sample rate */
   63         u_int   encoding;       /* e.g. mu-law, linear, etc */
   64         u_int   precision;      /* bits/subframe */
   65         u_int   validbits;      /* valid bits in a subframe */
   66         u_int   channels;       /* mono(1), stereo(2) */
   67 } audio_params_t;
   68 
   69 /* The default audio mode: 8 kHz mono mu-law */
   70 extern const struct audio_params audio_default;
   71 
   72 /**
   73  * audio stream buffer
   74  */
   75 typedef struct audio_stream {
   76         size_t bufsize;         /* allocated memory */
   77         uint8_t *start;         /* start of buffer area */
   78         uint8_t *end;           /* end of valid buffer area */
   79         uint8_t *inp;           /* address to be written next */
   80         const uint8_t *outp;    /* address to be read next */
   81         int used;               /* valid data size in this stream */
   82         audio_params_t param;   /* represents this stream */
   83         boolean_t loop;
   84 } audio_stream_t;
   85 
   86 static __inline int
   87 audio_stream_get_space(const audio_stream_t *s)
   88 {
   89         return (s->end - s->start) - s->used;
   90 }
   91 
   92 static __inline int
   93 audio_stream_get_used(const audio_stream_t *s)
   94 {
   95         return s->used;
   96 }
   97 
   98 static __inline uint8_t *
   99 audio_stream_add_inp(audio_stream_t *s, uint8_t *v, int diff)
  100 {
  101         s->used += diff;
  102         v += diff;
  103         if (v >= s->end)
  104                 v -= s->end - s->start;
  105         return v;
  106 }
  107 
  108 static __inline const uint8_t *
  109 audio_stream_add_outp(audio_stream_t *s, const uint8_t *v, int diff)
  110 {
  111         s->used -= diff;
  112         v += diff;
  113         if (v >= s->end)
  114                 v -= s->end - s->start;
  115         return v;
  116 }
  117 
  118 /**
  119  * an interface to fill a audio stream buffer
  120  */
  121 typedef struct stream_fetcher {
  122         int (*fetch_to)(struct stream_fetcher *, audio_stream_t *, int);
  123 } stream_fetcher_t;
  124 
  125 /**
  126  * audio stream filter.
  127  * This must be an extension of stream_fetcher_t.
  128  */
  129 typedef struct stream_filter {
  130 /* public: */
  131         stream_fetcher_t base;
  132         void (*dtor)(struct stream_filter *);
  133         void (*set_fetcher)(struct stream_filter *, stream_fetcher_t *);
  134         void (*set_inputbuffer)(struct stream_filter *, audio_stream_t *);
  135 /* private: */
  136         stream_fetcher_t *prev;
  137         audio_stream_t *src;
  138 } stream_filter_t;
  139 
  140 /**
  141  * factory method for stream_filter_t
  142  */
  143 typedef stream_filter_t *stream_filter_factory_t(struct audio_softc *,
  144         const audio_params_t *, const audio_params_t *);
  145 
  146 /**
  147  * filter pipeline request
  148  *
  149  * filters[0] is the first filter for playing or the last filter for recording.
  150  * The audio_params_t instance for the hardware is filters[0].param.
  151  */
  152 #ifndef AUDIO_MAX_FILTERS
  153 # define AUDIO_MAX_FILTERS      8
  154 #endif
  155 typedef struct stream_filter_list {
  156         void (*append)(struct stream_filter_list *, stream_filter_factory_t,
  157                        const audio_params_t *);
  158         void (*prepend)(struct stream_filter_list *, stream_filter_factory_t,
  159                         const audio_params_t *);
  160         void (*set)(struct stream_filter_list *, int, stream_filter_factory_t,
  161                     const audio_params_t *);
  162         int req_size;
  163         struct stream_filter_req {
  164                 stream_filter_factory_t *factory;
  165                 audio_params_t param; /* from-param for recording,
  166                                          to-param for playing */
  167         } filters[AUDIO_MAX_FILTERS];
  168 } stream_filter_list_t;
  169 
  170 struct malloc_type;
  171 struct audio_hw_if {
  172         int     (*open)(void *, int);   /* open hardware */
  173         void    (*close)(void *);       /* close hardware */
  174         int     (*drain)(void *);       /* Optional: drain buffers */
  175 
  176         /* Encoding. */
  177         /* XXX should we have separate in/out? */
  178         int     (*query_encoding)(void *, audio_encoding_t *);
  179 
  180         /* Set the audio encoding parameters (record and play).
  181          * Return 0 on success, or an error code if the
  182          * requested parameters are impossible.
  183          * The values in the params struct may be changed (e.g. rounding
  184          * to the nearest sample rate.)
  185          */
  186         int     (*set_params)(void *, int, int, audio_params_t *,
  187                     audio_params_t *, stream_filter_list_t *,
  188                     stream_filter_list_t *);
  189 
  190         /* Hardware may have some say in the blocksize to choose */
  191         int     (*round_blocksize)(void *, int, int, const audio_params_t *);
  192 
  193         /*
  194          * Changing settings may require taking device out of "data mode",
  195          * which can be quite expensive.  Also, audiosetinfo() may
  196          * change several settings in quick succession.  To avoid
  197          * having to take the device in/out of "data mode", we provide
  198          * this function which indicates completion of settings
  199          * adjustment.
  200          */
  201         int     (*commit_settings)(void *);
  202 
  203         /* Start input/output routines. These usually control DMA. */
  204         int     (*init_output)(void *, void *, int);
  205         int     (*init_input)(void *, void *, int);
  206         int     (*start_output)(void *, void *, int,
  207                                     void (*)(void *), void *);
  208         int     (*start_input)(void *, void *, int,
  209                                    void (*)(void *), void *);
  210         int     (*halt_output)(void *);
  211         int     (*halt_input)(void *);
  212 
  213         int     (*speaker_ctl)(void *, int);
  214 #define SPKR_ON         1
  215 #define SPKR_OFF        0
  216 
  217         int     (*getdev)(void *, struct audio_device *);
  218         int     (*setfd)(void *, int);
  219 
  220         /* Mixer (in/out ports) */
  221         int     (*set_port)(void *, mixer_ctrl_t *);
  222         int     (*get_port)(void *, mixer_ctrl_t *);
  223 
  224         int     (*query_devinfo)(void *, mixer_devinfo_t *);
  225 
  226         /* Allocate/free memory for the ring buffer. Usually malloc/free. */
  227         void    *(*allocm)(void *, int, size_t, struct malloc_type *, int);
  228         void    (*freem)(void *, void *, struct malloc_type *);
  229         size_t  (*round_buffersize)(void *, int, size_t);
  230         paddr_t (*mappage)(void *, void *, off_t, int);
  231 
  232         int     (*get_props)(void *); /* device properties */
  233 
  234         int     (*trigger_output)(void *, void *, void *, int,
  235                     void (*)(void *), void *, const audio_params_t *);
  236         int     (*trigger_input)(void *, void *, void *, int,
  237                     void (*)(void *), void *, const audio_params_t *);
  238         int     (*dev_ioctl)(void *, u_long, caddr_t, int, struct lwp *);
  239         int     (*powerstate)(void *, int);
  240 #define AUDIOPOWER_ON   1
  241 #define AUDIOPOWER_OFF  0
  242 };
  243 
  244 struct audio_attach_args {
  245         int     type;
  246         const void *hwif;       /* either audio_hw_if * or midi_hw_if * */
  247         void    *hdl;
  248 };
  249 #define AUDIODEV_TYPE_AUDIO     0
  250 #define AUDIODEV_TYPE_MIDI      1
  251 #define AUDIODEV_TYPE_OPL       2
  252 #define AUDIODEV_TYPE_MPU       3
  253 #define AUDIODEV_TYPE_AUX       4
  254 
  255 /* Attach the MI driver(s) to the MD driver. */
  256 struct device *audio_attach_mi(const struct audio_hw_if *, void *,
  257     struct device *);
  258 int     audioprint(void *, const char *);
  259 
  260 /* Device identity flags */
  261 #define SOUND_DEVICE            0
  262 #define AUDIO_DEVICE            0x80
  263 #define AUDIOCTL_DEVICE         0xc0
  264 #define MIXER_DEVICE            0x10
  265 
  266 #define AUDIOUNIT(x)            (minor(x)&0x0f)
  267 #define AUDIODEV(x)             (minor(x)&0xf0)
  268 
  269 #define ISDEVSOUND(x)           (AUDIODEV((x)) == SOUND_DEVICE)
  270 #define ISDEVAUDIO(x)           (AUDIODEV((x)) == AUDIO_DEVICE)
  271 #define ISDEVAUDIOCTL(x)        (AUDIODEV((x)) == AUDIOCTL_DEVICE)
  272 #define ISDEVMIXER(x)           (AUDIODEV((x)) == MIXER_DEVICE)
  273 
  274 #if !defined(__i386__) && !defined(__arm32__) && !defined(IPL_AUDIO)
  275 #define splaudio splbio         /* XXX */
  276 #define IPL_AUDIO IPL_BIO       /* XXX */
  277 #endif
  278 
  279 /*
  280  * USB Audio specification defines 12 channels:
  281  *      L R C LFE Ls Rs Lc Rc S Sl Sr T
  282  */
  283 #define AUDIO_MAX_CHANNELS      12
  284 
  285 #endif /* _SYS_DEV_AUDIO_IF_H_ */
  286 

Cache object: ed6c0757bbe2b5487348896468f738bc


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]


This page is part of the FreeBSD/Linux Linux Kernel Cross-Reference, and was automatically generated using a modified version of the LXR engine.