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

1.7     ! ratchov     1: /*     $OpenBSD: dev.h,v 1.6 2014/03/07 10:15:39 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.1       ratchov    31:        void (*onvol)(void *, unsigned int);    /* tell client vol changed */
                     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 */
                     42:        void *arg;                              /* user data for callbacks */
                     43:        struct aparams par;                     /* socket side params */
                     44:        struct {
                     45:                int weight;                     /* dynamic range */
                     46:                int maxweight;                  /* max dynamic range allowed */
                     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:
                     98: /*
                     99:  * audio device with plenty of slots
                    100:  */
                    101: struct dev {
                    102:        struct dev *next;
                    103:        struct slot *slot_list;                 /* audio streams attached */
                    104:        struct midi *midi;
                    105:
                    106:        /*
                    107:         * audio device (while opened)
                    108:         */
1.3       ratchov   109:        struct dev_sio sio;
1.1       ratchov   110:        struct aparams par;                     /* encoding */
                    111:        int pchan, rchan;                       /* play & rec channels */
                    112:        adata_t *rbuf;                          /* rec buffer */
                    113:        adata_t *pbuf;                          /* array of play buffers */
                    114: #define DEV_PBUF(d) ((d)->pbuf + (d)->poffs * (d)->pchan)
                    115:        int poffs;                              /* index of current play buf */
                    116:        struct conv enc;                        /* native->device format */
                    117:        struct conv dec;                        /* device->native format */
                    118:        unsigned char *encbuf;                  /* buffer for encoding */
                    119:        unsigned char *decbuf;                  /* buffer for decoding */
                    120:
                    121:        /*
                    122:         * preallocated audio sub-devices
                    123:         */
                    124: #define DEV_NSLOT      8
                    125:        struct slot slot[DEV_NSLOT];
                    126:        unsigned int serial;                    /* for slot allocation */
1.5       ratchov   127:
                    128:        /*
                    129:         * current position, relative to the current cycle
                    130:         */
                    131:        int delta;
1.1       ratchov   132:
                    133:        /*
                    134:         * desired parameters
                    135:         */
                    136:        unsigned int reqmode;                   /* mode */
                    137:        struct aparams reqpar;                  /* parameters */
                    138:        int reqpchan, reqrchan;                 /* play & rec chans */
                    139:        unsigned int reqbufsz;                  /* buffer size */
                    140:        unsigned int reqround;                  /* block size */
                    141:        unsigned int reqrate;                   /* sample rate */
                    142:        unsigned int hold;                      /* hold the device open ? */
                    143:        unsigned int autovol;                   /* auto adjust playvol ? */
                    144:        unsigned int refcnt;                    /* number of openers */
                    145: #define DEV_NMAX       16                      /* max number of devices */
                    146:        unsigned int num;                       /* device serial number */
                    147: #define DEV_CFG                0                       /* closed */
                    148: #define DEV_INIT       1                       /* stopped */
1.2       ratchov   149: #define DEV_RUN                2                       /* playin & recording */
1.1       ratchov   150:        unsigned int pstate;                    /* one of above */
                    151:        char *path;                             /* sio path */
                    152:
                    153:        /*
                    154:         * actual parameters and runtime state (i.e. once opened)
                    155:         */
                    156:        unsigned int mode;                      /* bitmap of MODE_xxx */
                    157:        unsigned int bufsz, round, rate;
                    158:        unsigned int prime;
                    159:
                    160:        /*
                    161:         * MIDI time code (MTC)
                    162:         */
                    163:        struct {
                    164:                unsigned int origin;            /* MTC start time */
                    165:                unsigned int fps;               /* MTC frames per second */
                    166: #define MTC_FPS_24     0
                    167: #define MTC_FPS_25     1
                    168: #define MTC_FPS_30     3
                    169:                unsigned int fps_id;            /* one of above */
                    170:                unsigned int hr;                /* MTC hours */
                    171:                unsigned int min;               /* MTC minutes */
                    172:                unsigned int sec;               /* MTC seconds */
                    173:                unsigned int fr;                /* MTC frames */
                    174:                unsigned int qfr;               /* MTC quarter frames */
                    175:                int delta;                      /* rel. to the last MTC tick */
                    176:                int refs;
                    177:        } mtc;
                    178:
                    179:        /*
                    180:         * MIDI machine control (MMC)
                    181:         */
                    182: #define MMC_OFF                0                       /* ignore MMC messages */
                    183: #define MMC_STOP       1                       /* stopped, can't start */
                    184: #define MMC_START      2                       /* attempting to start */
                    185: #define MMC_RUN                3                       /* started */
                    186:        unsigned int tstate;                    /* one of above */
                    187:        unsigned int master;                    /* master volume controller */
                    188: };
                    189:
                    190: extern struct dev *dev_list;
                    191:
                    192: void dev_log(struct dev *);
                    193: void dev_close(struct dev *);
                    194: struct dev *dev_new(char *, struct aparams *, unsigned int, unsigned int,
                    195:     unsigned int, unsigned int, unsigned int, unsigned int);
                    196: struct dev *dev_bynum(int);
                    197: void dev_del(struct dev *);
                    198: void dev_adjpar(struct dev *, int, int, int, int, int);
                    199: int  dev_init(struct dev *);
                    200: void dev_done(struct dev *);
                    201: int  dev_getpos(struct dev *);
                    202: unsigned int dev_roundof(struct dev *, unsigned int);
                    203:
                    204: /*
                    205:  * interface to hardware device
                    206:  */
                    207: void dev_onmove(struct dev *, int);
                    208: void dev_cycle(struct dev *);
                    209:
                    210: /*
                    211:  * midi & midi call-backs
                    212:  */
                    213: void dev_mmcstart(struct dev *);
                    214: void dev_mmcstop(struct dev *);
                    215: void dev_mmcloc(struct dev *, unsigned int);
                    216: void dev_master(struct dev *, unsigned int);
                    217: void dev_midi_vol(struct dev *, struct slot *);
                    218:
                    219: /*
                    220:  * sio_open(3) like interface for clients
                    221:  */
                    222: void slot_log(struct slot *);
                    223: struct slot *slot_new(struct dev *, char *, struct slotops *, void *, int);
                    224: void slot_del(struct slot *);
                    225: void slot_setvol(struct slot *, unsigned int);
                    226: void slot_start(struct slot *);
                    227: void slot_stop(struct slot *);
                    228: void slot_read(struct slot *);
                    229: void slot_write(struct slot *);
                    230:
                    231: #endif /* !defined(DEV_H) */