[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.22

1.22    ! ratchov     1: /*     $OpenBSD: dev.h,v 1.21 2019/07/12 06:30:55 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 */
1.19      ratchov    50:                int nch;                        /* number of play chans */
1.1       ratchov    51:                struct cmap cmap;               /* channel mapper state */
                     52:                struct resamp resamp;           /* resampler state */
                     53:                struct conv dec;                /* format decoder params */
                     54:                int join;                       /* channel join factor */
                     55:                int expand;                     /* channel expand factor */
                     56:                void *resampbuf, *decbuf;       /* tmp buffers */
                     57:        } mix;
                     58:        struct {
                     59:                struct abuf buf;                /* socket side buffer */
1.5       ratchov    60:                int prime;                      /* initial cycles to skip */
1.1       ratchov    61:                int bpf;                        /* byte per frame */
1.19      ratchov    62:                int nch;                        /* number of rec chans */
1.1       ratchov    63:                struct cmap cmap;               /* channel mapper state */
                     64:                struct resamp resamp;           /* buffer for resampling */
                     65:                struct conv enc;                /* buffer for encoding */
                     66:                int join;                       /* channel join factor */
                     67:                int expand;                     /* channel expand factor */
                     68:                void *resampbuf, *encbuf;       /* tmp buffers */
                     69:        } sub;
                     70:        int xrun;                               /* underrun policy */
1.5       ratchov    71:        int skip;                               /* cycles to skip (for xrun) */
1.1       ratchov    72: #define SLOT_BUFSZ(s) \
                     73:        ((s)->appbufsz + (s)->dev->bufsz / (s)->dev->round * (s)->round)
                     74:        int appbufsz;                           /* slot-side buffer size */
                     75:        int round;                              /* slot-side block size */
                     76:        int rate;                               /* slot-side sample rate */
                     77:        int delta;                              /* pending clock ticks */
                     78:        int delta_rem;                          /* remainder for delta */
                     79:        int mode;                               /* MODE_{PLAY,REC} */
                     80: #define SLOT_INIT      0                       /* not trying to do anything */
                     81: #define SLOT_START     1                       /* buffer allocated */
                     82: #define SLOT_READY     2                       /* buffer filled enough */
                     83: #define SLOT_RUN       3                       /* buffer attached to device */
                     84: #define SLOT_STOP      4                       /* draining */
                     85:        int pstate;
                     86:
                     87: #define SLOT_NAMEMAX   8
                     88:        char name[SLOT_NAMEMAX];                /* name matching [a-z]+ */
                     89:        unsigned int unit;                      /* instance of name */
                     90:        unsigned int serial;                    /* global unique number */
                     91:        unsigned int vol;                       /* current (midi) volume */
1.21      ratchov    92:        unsigned int id;                        /* process id */
1.1       ratchov    93: };
                     94:
1.12      ratchov    95: struct opt {
                     96:        struct opt *next;
                     97: #define OPT_NAMEMAX 11
                     98:        char name[OPT_NAMEMAX + 1];
                     99:        int maxweight;          /* max dynamic range for clients */
                    100:        int pmin, pmax;         /* play channels */
                    101:        int rmin, rmax;         /* recording channels */
                    102:        int mmc;                /* true if MMC control enabled */
                    103:        int dup;                /* true if join/expand enabled */
                    104:        int mode;               /* bitmap of MODE_XXX */
                    105: };
                    106:
1.1       ratchov   107: /*
                    108:  * audio device with plenty of slots
                    109:  */
                    110: struct dev {
                    111:        struct dev *next;
                    112:        struct slot *slot_list;                 /* audio streams attached */
1.12      ratchov   113:        struct opt *opt_list;
1.1       ratchov   114:        struct midi *midi;
                    115:
                    116:        /*
                    117:         * audio device (while opened)
1.10      ratchov   118:         */
1.3       ratchov   119:        struct dev_sio sio;
1.1       ratchov   120:        struct aparams par;                     /* encoding */
                    121:        int pchan, rchan;                       /* play & rec channels */
                    122:        adata_t *rbuf;                          /* rec buffer */
                    123:        adata_t *pbuf;                          /* array of play buffers */
                    124: #define DEV_PBUF(d) ((d)->pbuf + (d)->poffs * (d)->pchan)
                    125:        int poffs;                              /* index of current play buf */
1.8       ratchov   126:        int psize;                              /* size of play buffer */
1.1       ratchov   127:        struct conv enc;                        /* native->device format */
                    128:        struct conv dec;                        /* device->native format */
                    129:        unsigned char *encbuf;                  /* buffer for encoding */
                    130:        unsigned char *decbuf;                  /* buffer for decoding */
                    131:
                    132:        /*
                    133:         * preallocated audio sub-devices
                    134:         */
                    135: #define DEV_NSLOT      8
                    136:        struct slot slot[DEV_NSLOT];
                    137:        unsigned int serial;                    /* for slot allocation */
1.5       ratchov   138:
                    139:        /*
                    140:         * current position, relative to the current cycle
                    141:         */
                    142:        int delta;
1.1       ratchov   143:
                    144:        /*
                    145:         * desired parameters
                    146:         */
                    147:        unsigned int reqmode;                   /* mode */
                    148:        struct aparams reqpar;                  /* parameters */
                    149:        int reqpchan, reqrchan;                 /* play & rec chans */
                    150:        unsigned int reqbufsz;                  /* buffer size */
                    151:        unsigned int reqround;                  /* block size */
                    152:        unsigned int reqrate;                   /* sample rate */
                    153:        unsigned int hold;                      /* hold the device open ? */
                    154:        unsigned int autovol;                   /* auto adjust playvol ? */
                    155:        unsigned int refcnt;                    /* number of openers */
                    156: #define DEV_NMAX       16                      /* max number of devices */
                    157:        unsigned int num;                       /* device serial number */
                    158: #define DEV_CFG                0                       /* closed */
                    159: #define DEV_INIT       1                       /* stopped */
1.2       ratchov   160: #define DEV_RUN                2                       /* playin & recording */
1.1       ratchov   161:        unsigned int pstate;                    /* one of above */
1.22    ! ratchov   162:        struct name *path_list;
1.1       ratchov   163:
                    164:        /*
                    165:         * actual parameters and runtime state (i.e. once opened)
                    166:         */
                    167:        unsigned int mode;                      /* bitmap of MODE_xxx */
                    168:        unsigned int bufsz, round, rate;
                    169:        unsigned int prime;
                    170:
                    171:        /*
                    172:         * MIDI time code (MTC)
                    173:         */
                    174:        struct {
                    175:                unsigned int origin;            /* MTC start time */
                    176:                unsigned int fps;               /* MTC frames per second */
                    177: #define MTC_FPS_24     0
                    178: #define MTC_FPS_25     1
                    179: #define MTC_FPS_30     3
                    180:                unsigned int fps_id;            /* one of above */
                    181:                unsigned int hr;                /* MTC hours */
                    182:                unsigned int min;               /* MTC minutes */
                    183:                unsigned int sec;               /* MTC seconds */
                    184:                unsigned int fr;                /* MTC frames */
                    185:                unsigned int qfr;               /* MTC quarter frames */
                    186:                int delta;                      /* rel. to the last MTC tick */
                    187:                int refs;
                    188:        } mtc;
                    189:
                    190:        /*
                    191:         * MIDI machine control (MMC)
                    192:         */
                    193: #define MMC_STOP       1                       /* stopped, can't start */
                    194: #define MMC_START      2                       /* attempting to start */
                    195: #define MMC_RUN                3                       /* started */
                    196:        unsigned int tstate;                    /* one of above */
                    197:        unsigned int master;                    /* master volume controller */
                    198: };
                    199:
                    200: extern struct dev *dev_list;
                    201:
                    202: void dev_log(struct dev *);
                    203: void dev_close(struct dev *);
1.22    ! ratchov   204: int dev_reopen(struct dev *);
1.1       ratchov   205: struct dev *dev_new(char *, struct aparams *, unsigned int, unsigned int,
                    206:     unsigned int, unsigned int, unsigned int, unsigned int);
                    207: struct dev *dev_bynum(int);
                    208: void dev_del(struct dev *);
1.11      ratchov   209: void dev_adjpar(struct dev *, int, int, int);
1.1       ratchov   210: int  dev_init(struct dev *);
                    211: void dev_done(struct dev *);
1.9       ratchov   212: int dev_ref(struct dev *);
                    213: void dev_unref(struct dev *);
1.1       ratchov   214: int  dev_getpos(struct dev *);
                    215: unsigned int dev_roundof(struct dev *, unsigned int);
                    216:
                    217: /*
                    218:  * interface to hardware device
                    219:  */
                    220: void dev_onmove(struct dev *, int);
                    221: void dev_cycle(struct dev *);
                    222:
                    223: /*
                    224:  * midi & midi call-backs
                    225:  */
                    226: void dev_mmcstart(struct dev *);
                    227: void dev_mmcstop(struct dev *);
                    228: void dev_mmcloc(struct dev *, unsigned int);
                    229: void dev_master(struct dev *, unsigned int);
                    230: void dev_midi_vol(struct dev *, struct slot *);
                    231:
                    232: /*
                    233:  * sio_open(3) like interface for clients
                    234:  */
                    235: void slot_log(struct slot *);
1.21      ratchov   236: struct slot *slot_new(struct dev *, struct opt *, unsigned int, char *,
1.14      ratchov   237:     struct slotops *, void *, int);
1.1       ratchov   238: void slot_del(struct slot *);
                    239: void slot_setvol(struct slot *, unsigned int);
                    240: void slot_start(struct slot *);
                    241: void slot_stop(struct slot *);
                    242: void slot_read(struct slot *);
                    243: void slot_write(struct slot *);
                    244:
                    245: #endif /* !defined(DEV_H) */