[BACK]Return to dev.h CVS log [TXT][DIR] Up to [local] / src / usr.bin / sndiod

Annotation of src/usr.bin/sndiod/dev.h, Revision 1.15

1.15    ! ratchov     1: /*     $OpenBSD: dev.h,v 1.14 2018/06/26 07:15:17 ratchov Exp $        */
1.1       ratchov     2: /*
                      3:  * Copyright (c) 2008-2012 Alexandre Ratchov <alex@caoua.org>
                      4:  *
                      5:  * Permission to use, copy, modify, and distribute this software for any
                      6:  * purpose with or without fee is hereby granted, provided that the above
                      7:  * copyright notice and this permission notice appear in all copies.
                      8:  *
                      9:  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
                     10:  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
                     11:  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
                     12:  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
                     13:  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
                     14:  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
                     15:  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
                     16:  */
                     17: #ifndef DEV_H
                     18: #define DEV_H
                     19:
                     20: #include "abuf.h"
                     21: #include "dsp.h"
                     22: #include "siofile.h"
                     23:
                     24: /*
                     25:  * audio stream state structure
                     26:  */
                     27:
                     28: struct slotops
                     29: {
1.7       ratchov    30:        void (*onmove)(void *);                 /* clock tick */
1.11      ratchov    31:        void (*onvol)(void *);          /* tell client vol changed */
1.1       ratchov    32:        void (*fill)(void *);                   /* request to fill a play block */
                     33:        void (*flush)(void *);                  /* request to flush a rec block */
                     34:        void (*eof)(void *);                    /* notify that play drained */
                     35:        void (*exit)(void *);                   /* delete client */
                     36: };
                     37:
                     38: struct slot {
                     39:        struct slotops *ops;                    /* client callbacks */
                     40:        struct slot *next;                      /* next on the play list */
                     41:        struct dev *dev;                        /* device this belongs to */
1.13      ratchov    42:        struct opt *opt;                        /* config used */
1.1       ratchov    43:        void *arg;                              /* user data for callbacks */
                     44:        struct aparams par;                     /* socket side params */
                     45:        struct {
1.10      ratchov    46:                int weight;                     /* dynamic range */
1.1       ratchov    47:                unsigned int vol;               /* volume within the vol */
                     48:                struct abuf buf;                /* socket side buffer */
                     49:                int bpf;                        /* byte per frame */
                     50:                int slot_cmin, slot_cmax;       /* slot source chans */
                     51:                int dev_cmin, dev_cmax;         /* device destination chans */
                     52:                struct cmap cmap;               /* channel mapper state */
                     53:                struct resamp resamp;           /* resampler state */
                     54:                struct conv dec;                /* format decoder params */
                     55:                int join;                       /* channel join factor */
                     56:                int expand;                     /* channel expand factor */
                     57:                void *resampbuf, *decbuf;       /* tmp buffers */
                     58:        } mix;
                     59:        struct {
                     60:                struct abuf buf;                /* socket side buffer */
1.5       ratchov    61:                int prime;                      /* initial cycles to skip */
1.1       ratchov    62:                int bpf;                        /* byte per frame */
                     63:                int slot_cmin, slot_cmax;       /* slot destination chans */
                     64:                int dev_cmin, dev_cmax;         /* device source chans */
                     65:                struct cmap cmap;               /* channel mapper state */
                     66:                struct resamp resamp;           /* buffer for resampling */
                     67:                struct conv enc;                /* buffer for encoding */
                     68:                int join;                       /* channel join factor */
                     69:                int expand;                     /* channel expand factor */
                     70:                void *resampbuf, *encbuf;       /* tmp buffers */
                     71:        } sub;
                     72:        int xrun;                               /* underrun policy */
1.5       ratchov    73:        int skip;                               /* cycles to skip (for xrun) */
1.1       ratchov    74:        int dup;                                /* mono-to-stereo and alike */
                     75: #define SLOT_BUFSZ(s) \
                     76:        ((s)->appbufsz + (s)->dev->bufsz / (s)->dev->round * (s)->round)
                     77:        int appbufsz;                           /* slot-side buffer size */
                     78:        int round;                              /* slot-side block size */
                     79:        int rate;                               /* slot-side sample rate */
                     80:        int delta;                              /* pending clock ticks */
                     81:        int delta_rem;                          /* remainder for delta */
                     82:        int mode;                               /* MODE_{PLAY,REC} */
                     83: #define SLOT_INIT      0                       /* not trying to do anything */
                     84: #define SLOT_START     1                       /* buffer allocated */
                     85: #define SLOT_READY     2                       /* buffer filled enough */
                     86: #define SLOT_RUN       3                       /* buffer attached to device */
                     87: #define SLOT_STOP      4                       /* draining */
                     88:        int pstate;
                     89:
                     90: #define SLOT_NAMEMAX   8
                     91:        char name[SLOT_NAMEMAX];                /* name matching [a-z]+ */
                     92:        unsigned int unit;                      /* instance of name */
                     93:        unsigned int serial;                    /* global unique number */
                     94:        unsigned int vol;                       /* current (midi) volume */
                     95:        unsigned int tstate;                    /* mmc state */
                     96: };
                     97:
1.12      ratchov    98: struct opt {
                     99:        struct opt *next;
                    100: #define OPT_NAMEMAX 11
                    101:        char name[OPT_NAMEMAX + 1];
                    102:        int maxweight;          /* max dynamic range for clients */
                    103:        int pmin, pmax;         /* play channels */
                    104:        int rmin, rmax;         /* recording channels */
                    105:        int mmc;                /* true if MMC control enabled */
                    106:        int dup;                /* true if join/expand enabled */
                    107:        int mode;               /* bitmap of MODE_XXX */
                    108: };
                    109:
1.1       ratchov   110: /*
                    111:  * audio device with plenty of slots
                    112:  */
                    113: struct dev {
                    114:        struct dev *next;
                    115:        struct slot *slot_list;                 /* audio streams attached */
1.12      ratchov   116:        struct opt *opt_list;
1.1       ratchov   117:        struct midi *midi;
                    118:
                    119:        /*
                    120:         * audio device (while opened)
1.10      ratchov   121:         */
1.3       ratchov   122:        struct dev_sio sio;
1.1       ratchov   123:        struct aparams par;                     /* encoding */
                    124:        int pchan, rchan;                       /* play & rec channels */
                    125:        adata_t *rbuf;                          /* rec buffer */
                    126:        adata_t *pbuf;                          /* array of play buffers */
                    127: #define DEV_PBUF(d) ((d)->pbuf + (d)->poffs * (d)->pchan)
                    128:        int poffs;                              /* index of current play buf */
1.8       ratchov   129:        int psize;                              /* size of play buffer */
1.1       ratchov   130:        struct conv enc;                        /* native->device format */
                    131:        struct conv dec;                        /* device->native format */
                    132:        unsigned char *encbuf;                  /* buffer for encoding */
                    133:        unsigned char *decbuf;                  /* buffer for decoding */
                    134:
                    135:        /*
                    136:         * preallocated audio sub-devices
                    137:         */
                    138: #define DEV_NSLOT      8
                    139:        struct slot slot[DEV_NSLOT];
                    140:        unsigned int serial;                    /* for slot allocation */
1.5       ratchov   141:
                    142:        /*
                    143:         * current position, relative to the current cycle
                    144:         */
                    145:        int delta;
1.1       ratchov   146:
                    147:        /*
                    148:         * desired parameters
                    149:         */
                    150:        unsigned int reqmode;                   /* mode */
                    151:        struct aparams reqpar;                  /* parameters */
                    152:        int reqpchan, reqrchan;                 /* play & rec chans */
                    153:        unsigned int reqbufsz;                  /* buffer size */
                    154:        unsigned int reqround;                  /* block size */
                    155:        unsigned int reqrate;                   /* sample rate */
                    156:        unsigned int hold;                      /* hold the device open ? */
                    157:        unsigned int autovol;                   /* auto adjust playvol ? */
                    158:        unsigned int refcnt;                    /* number of openers */
                    159: #define DEV_NMAX       16                      /* max number of devices */
                    160:        unsigned int num;                       /* device serial number */
                    161: #define DEV_CFG                0                       /* closed */
                    162: #define DEV_INIT       1                       /* stopped */
1.2       ratchov   163: #define DEV_RUN                2                       /* playin & recording */
1.1       ratchov   164:        unsigned int pstate;                    /* one of above */
                    165:        char *path;                             /* sio path */
                    166:
                    167:        /*
                    168:         * actual parameters and runtime state (i.e. once opened)
                    169:         */
                    170:        unsigned int mode;                      /* bitmap of MODE_xxx */
                    171:        unsigned int bufsz, round, rate;
                    172:        unsigned int prime;
                    173:
                    174:        /*
                    175:         * MIDI time code (MTC)
                    176:         */
                    177:        struct {
                    178:                unsigned int origin;            /* MTC start time */
                    179:                unsigned int fps;               /* MTC frames per second */
                    180: #define MTC_FPS_24     0
                    181: #define MTC_FPS_25     1
                    182: #define MTC_FPS_30     3
                    183:                unsigned int fps_id;            /* one of above */
                    184:                unsigned int hr;                /* MTC hours */
                    185:                unsigned int min;               /* MTC minutes */
                    186:                unsigned int sec;               /* MTC seconds */
                    187:                unsigned int fr;                /* MTC frames */
                    188:                unsigned int qfr;               /* MTC quarter frames */
                    189:                int delta;                      /* rel. to the last MTC tick */
                    190:                int refs;
                    191:        } mtc;
                    192:
                    193:        /*
                    194:         * MIDI machine control (MMC)
                    195:         */
                    196: #define MMC_OFF                0                       /* ignore MMC messages */
                    197: #define MMC_STOP       1                       /* stopped, can't start */
                    198: #define MMC_START      2                       /* attempting to start */
                    199: #define MMC_RUN                3                       /* started */
                    200:        unsigned int tstate;                    /* one of above */
                    201:        unsigned int master;                    /* master volume controller */
                    202: };
                    203:
                    204: extern struct dev *dev_list;
                    205:
                    206: void dev_log(struct dev *);
                    207: void dev_close(struct dev *);
                    208: struct dev *dev_new(char *, struct aparams *, unsigned int, unsigned int,
                    209:     unsigned int, unsigned int, unsigned int, unsigned int);
                    210: struct dev *dev_bynum(int);
                    211: void dev_del(struct dev *);
1.11      ratchov   212: void dev_adjpar(struct dev *, int, int, int);
1.1       ratchov   213: int  dev_init(struct dev *);
                    214: void dev_done(struct dev *);
1.9       ratchov   215: int dev_ref(struct dev *);
                    216: void dev_unref(struct dev *);
1.1       ratchov   217: int  dev_getpos(struct dev *);
                    218: unsigned int dev_roundof(struct dev *, unsigned int);
                    219:
                    220: /*
                    221:  * interface to hardware device
                    222:  */
                    223: void dev_onmove(struct dev *, int);
                    224: void dev_cycle(struct dev *);
                    225:
                    226: /*
                    227:  * midi & midi call-backs
                    228:  */
                    229: void dev_mmcstart(struct dev *);
                    230: void dev_mmcstop(struct dev *);
                    231: void dev_mmcloc(struct dev *, unsigned int);
                    232: void dev_master(struct dev *, unsigned int);
                    233: void dev_midi_vol(struct dev *, struct slot *);
                    234:
                    235: /*
                    236:  * sio_open(3) like interface for clients
                    237:  */
                    238: void slot_log(struct slot *);
1.14      ratchov   239: struct slot *slot_new(struct dev *, struct opt *, char *,
                    240:     struct slotops *, void *, int);
1.1       ratchov   241: void slot_del(struct slot *);
                    242: void slot_setvol(struct slot *, unsigned int);
                    243: void slot_start(struct slot *);
                    244: void slot_stop(struct slot *);
                    245: void slot_read(struct slot *);
                    246: void slot_write(struct slot *);
                    247:
                    248: #endif /* !defined(DEV_H) */