add/fix comments

This commit is contained in:
Alexandre Ratchov 2012-11-11 17:46:21 +01:00
parent e43d03b3df
commit 832a0a5a1f
6 changed files with 132 additions and 66 deletions

View File

@ -291,6 +291,9 @@ dev_midi_full(struct dev *d)
midi_send(d->midi, (unsigned char *)&x, SYSEX_SIZE(full)); midi_send(d->midi, (unsigned char *)&x, SYSEX_SIZE(full));
} }
/*
* send a volume change MIDI message
*/
void void
dev_midi_vol(struct dev *d, struct slot *s) dev_midi_vol(struct dev *d, struct slot *s)
{ {
@ -302,6 +305,9 @@ dev_midi_vol(struct dev *d, struct slot *s)
midi_send(d->midi, msg, 3); midi_send(d->midi, msg, 3);
} }
/*
* send a master volume MIDI message
*/
void void
dev_midi_master(struct dev *d) dev_midi_master(struct dev *d)
{ {
@ -318,8 +324,11 @@ dev_midi_master(struct dev *d)
midi_send(d->midi, (unsigned char *)&x, SYSEX_SIZE(master)); midi_send(d->midi, (unsigned char *)&x, SYSEX_SIZE(master));
} }
/*
* send a sndiod-specific slot description MIDI message
*/
void void
dev_midi_mixinfo(struct dev *d, struct slot *s) dev_midi_slotdesc(struct dev *d, struct slot *s)
{ {
struct sysex x; struct sysex x;
@ -327,14 +336,14 @@ dev_midi_mixinfo(struct dev *d, struct slot *s)
x.start = SYSEX_START; x.start = SYSEX_START;
x.type = SYSEX_TYPE_EDU; x.type = SYSEX_TYPE_EDU;
x.id0 = SYSEX_AUCAT; x.id0 = SYSEX_AUCAT;
x.id1 = SYSEX_AUCAT_MIXINFO; x.id1 = SYSEX_AUCAT_SLOTDESC;
if (*s->name != '\0') { if (*s->name != '\0') {
snprintf((char *)x.u.mixinfo.name, SYSEX_NAMELEN, snprintf((char *)x.u.slotdesc.name, SYSEX_NAMELEN,
"%s%u", s->name, s->unit); "%s%u", s->name, s->unit);
} }
x.u.mixinfo.chan = s - d->slot; x.u.slotdesc.chan = s - d->slot;
x.u.mixinfo.end = SYSEX_END; x.u.slotdesc.end = SYSEX_END;
midi_send(d->midi, (unsigned char *)&x, SYSEX_SIZE(mixinfo)); midi_send(d->midi, (unsigned char *)&x, SYSEX_SIZE(slotdesc));
} }
void void
@ -346,7 +355,7 @@ dev_midi_dump(struct dev *d)
dev_midi_master(d); dev_midi_master(d);
for (i = 0, s = d->slot; i < DEV_NSLOT; i++, s++) { for (i = 0, s = d->slot; i < DEV_NSLOT; i++, s++) {
dev_midi_mixinfo(d, s); dev_midi_slotdesc(d, s);
dev_midi_vol(d, s); dev_midi_vol(d, s);
} }
x.start = SYSEX_START; x.start = SYSEX_START;
@ -1560,7 +1569,7 @@ found:
s->dup = 0; s->dup = 0;
s->appbufsz = d->bufsz; s->appbufsz = d->bufsz;
s->round = d->round; s->round = d->round;
dev_midi_mixinfo(d, s); dev_midi_slotdesc(d, s);
dev_midi_vol(d, s); dev_midi_vol(d, s);
return s; return s;
} }
@ -1590,7 +1599,7 @@ slot_del(struct slot *s)
} }
/* /*
* change the slot play volume; called by the slot or by MIDI * change the slot play volume; called either by the slot or by MIDI
*/ */
void void
slot_setvol(struct slot *s, unsigned int vol) slot_setvol(struct slot *s, unsigned int vol)
@ -1609,6 +1618,9 @@ slot_setvol(struct slot *s, unsigned int vol)
s->mix.vol = MIDI_TO_ADATA(s->vol); s->mix.vol = MIDI_TO_ADATA(s->vol);
} }
/*
* attach the slot to the device (ie start playing & recording
*/
void void
slot_attach(struct slot *s) slot_attach(struct slot *s)
{ {
@ -1722,6 +1734,10 @@ slot_attach(struct slot *s)
} }
} }
/*
* if MMC is enabled, and try to attach all slots synchronously, else
* simply attach the slot
*/
void void
slot_ready(struct slot *s) slot_ready(struct slot *s)
{ {
@ -1734,10 +1750,8 @@ slot_ready(struct slot *s)
} }
/* /*
* notify the MMC layer that the stream is attempting * setup buffers & conversion layers, prepare the slot to receive data
* to start. If other streams are not ready, 0 is returned meaning * (for playback) or start (recording).
* that the stream should wait. If other streams are ready, they
* are started, and the caller should start immediately.
*/ */
void void
slot_start(struct slot *s) slot_start(struct slot *s)
@ -1803,6 +1817,9 @@ slot_start(struct slot *s)
} }
} }
/*
* stop playback and recording, and free conversion layers
*/
void void
slot_detach(struct slot *s) slot_detach(struct slot *s)
{ {
@ -1839,6 +1856,10 @@ slot_detach(struct slot *s)
} }
} }
/*
* put the slot in stopping state (draining play buffers) or
* stop & detach if no data to drain.
*/
void void
slot_stop(struct slot *s) slot_stop(struct slot *s)
{ {
@ -1882,6 +1903,10 @@ slot_stop(struct slot *s)
s->tstate = MMC_STOP; s->tstate = MMC_STOP;
} }
/*
* notify the slot that we just wrote in the play buffer, must be called
* after each write
*/
void void
slot_write(struct slot *s) slot_write(struct slot *s)
{ {
@ -1897,7 +1922,11 @@ slot_write(struct slot *s)
} }
} }
/*
* notify the slot that we freed some space in the rec buffer
*/
void void
slot_read(struct slot *s) slot_read(struct slot *s)
{ {
/* nothing yet */
} }

View File

@ -176,7 +176,7 @@ aparams_init(struct aparams *par)
} }
/* /*
* Print the format/channels/encoding on stderr. * log the given format/channels/encoding
*/ */
void void
aparams_log(struct aparams *par) aparams_log(struct aparams *par)
@ -188,7 +188,7 @@ aparams_log(struct aparams *par)
} }
/* /*
* Return true if encoding can be represented as adata_t * return true if encoding corresponds to what we store in adata_t
*/ */
int int
aparams_native(struct aparams *par) aparams_native(struct aparams *par)
@ -198,6 +198,9 @@ aparams_native(struct aparams *par)
(par->bits == par->bps * 8 || !par->msb); (par->bits == par->bps * 8 || !par->msb);
} }
/*
* resample the given number of frames
*/
int int
resamp_do(struct resamp *p, adata_t *in, adata_t *out, int todo) resamp_do(struct resamp *p, adata_t *in, adata_t *out, int todo)
{ {
@ -290,6 +293,9 @@ resamp_do(struct resamp *p, adata_t *in, adata_t *out, int todo)
return oblksz - ofr; return oblksz - ofr;
} }
/*
* initialize resampler with ibufsz/obufsz factor and "nch" channels
*/
void void
resamp_init(struct resamp *p, unsigned int iblksz, unsigned int oblksz, int nch) resamp_init(struct resamp *p, unsigned int iblksz, unsigned int oblksz, int nch)
{ {
@ -315,6 +321,9 @@ resamp_init(struct resamp *p, unsigned int iblksz, unsigned int oblksz, int nch)
#endif #endif
} }
/*
* encode "todo" frames from native to foreign encoding
*/
void void
enc_do(struct conv *p, unsigned char *in, unsigned char *out, int todo) enc_do(struct conv *p, unsigned char *in, unsigned char *out, int todo)
{ {
@ -367,6 +376,9 @@ enc_do(struct conv *p, unsigned char *in, unsigned char *out, int todo)
} }
} }
/*
* store "todo" frames of silence in foreign encoding
*/
void void
enc_sil_do(struct conv *p, unsigned char *out, int todo) enc_sil_do(struct conv *p, unsigned char *out, int todo)
{ {
@ -412,6 +424,9 @@ enc_sil_do(struct conv *p, unsigned char *out, int todo)
} }
} }
/*
* initialize encoder from native to foreign encoding
*/
void void
enc_init(struct conv *p, struct aparams *par, int nch) enc_init(struct conv *p, struct aparams *par, int nch)
{ {
@ -443,6 +458,9 @@ enc_init(struct conv *p, struct aparams *par, int nch)
#endif #endif
} }
/*
* decode "todo" frames from from foreign to native encoding
*/
void void
dec_do(struct conv *p, unsigned char *in, unsigned char *out, int todo) dec_do(struct conv *p, unsigned char *in, unsigned char *out, int todo)
{ {
@ -495,6 +513,9 @@ dec_do(struct conv *p, unsigned char *in, unsigned char *out, int todo)
} }
} }
/*
* initialize decoder from foreign to native encoding
*/
void void
dec_init(struct conv *p, struct aparams *par, int nch) dec_init(struct conv *p, struct aparams *par, int nch)
{ {
@ -526,6 +547,9 @@ dec_init(struct conv *p, struct aparams *par, int nch)
#endif #endif
} }
/*
* mix "todo" input frames on the output with the given volume
*/
void void
cmap_add(struct cmap *p, void *in, void *out, int vol, int todo) cmap_add(struct cmap *p, void *in, void *out, int vol, int todo)
{ {
@ -569,6 +593,9 @@ cmap_add(struct cmap *p, void *in, void *out, int vol, int todo)
} }
} }
/*
* overwrite output with "todo" input frames with with the given volume
*/
void void
cmap_copy(struct cmap *p, void *in, void *out, int vol, int todo) cmap_copy(struct cmap *p, void *in, void *out, int vol, int todo)
{ {
@ -609,6 +636,10 @@ cmap_copy(struct cmap *p, void *in, void *out, int vol, int todo)
} }
} }
/*
* initialize channel mapper, to map a subset of input channel range
* into a subset of the output channel range
*/
void void
cmap_init(struct cmap *p, cmap_init(struct cmap *p,
int imin, int imax, int isubmin, int isubmax, int imin, int imax, int isubmin, int isubmax,

View File

@ -156,6 +156,9 @@ midi_del(struct midi *ep)
} }
} }
/*
* add the midi endpoint in the ``tag'' midi thru box
*/
void void
midi_tag(struct midi *ep, unsigned int tag) midi_tag(struct midi *ep, unsigned int tag)
{ {
@ -176,6 +179,9 @@ midi_tag(struct midi *ep, unsigned int tag)
} }
} }
/*
* remove the midi endpoint from the ``tag'' midi thru box
*/
void void
midi_untag(struct midi *ep, unsigned int tag) midi_untag(struct midi *ep, unsigned int tag)
{ {
@ -194,6 +200,9 @@ midi_untag(struct midi *ep, unsigned int tag)
} }
} }
/*
* broadcast the given message to other members of the thru box
*/
void void
midi_send(struct midi *iep, unsigned char *msg, int size) midi_send(struct midi *iep, unsigned char *msg, int size)
{ {
@ -249,6 +258,9 @@ midi_fill(struct midi *oep)
} }
} }
/*
* parse the give data chunk, and calling imsg() for each message
*/
void void
midi_parse(struct midi *iep, unsigned char *idata, int icount) midi_parse(struct midi *iep, unsigned char *idata, int icount)
{ {
@ -295,6 +307,9 @@ midi_parse(struct midi *iep, unsigned char *idata, int icount)
} }
} }
/*
* process input data stored in ep->ibuf
*/
int int
midi_in(struct midi *iep) midi_in(struct midi *iep)
{ {
@ -346,6 +361,9 @@ midi_in(struct midi *iep)
return idone; return idone;
} }
/*
* store the given message in the output buffer
*/
void void
midi_out(struct midi *oep, unsigned char *idata, int icount) midi_out(struct midi *oep, unsigned char *idata, int icount)
{ {
@ -435,7 +453,7 @@ port_exit(void *arg)
} }
/* /*
* Add a MIDI port to the device * create a new midi port
*/ */
struct port * struct port *
port_new(char *path, unsigned int mode) port_new(char *path, unsigned int mode)
@ -452,6 +470,9 @@ port_new(char *path, unsigned int mode)
return c; return c;
} }
/*
* destroy the given midi port
*/
void void
port_del(struct port *c) port_del(struct port *c)
{ {
@ -521,7 +542,7 @@ port_init(struct port *c)
void void
port_done(struct port *c) port_done(struct port *c)
{ {
/* XXX: drain */ /* XXX: drain? */
if (c->state != PORT_CFG) if (c->state != PORT_CFG)
port_close(c); port_close(c);
} }

View File

@ -25,6 +25,9 @@
struct opt *opt_list = NULL; struct opt *opt_list = NULL;
/*
* create a new audio sub-device "configuration"
*/
struct opt * struct opt *
opt_new(char *name, struct dev *dev, opt_new(char *name, struct dev *dev,
int pmin, int pmax, int rmin, int rmax, int pmin, int pmax, int rmin, int rmax,

View File

@ -14,16 +14,6 @@
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/ */
/*
* XXX:
*
* i/o never crosses buffer/message boundary, so factor
* sock_{wdata,wmsg} and sock_{rdata,rmsg}
*
* use a separate message for midi (requires protocol change)
*/
#include <sys/types.h> #include <sys/types.h>
#include <netinet/in.h> #include <netinet/in.h>
#include <errno.h> #include <errno.h>
@ -55,6 +45,9 @@ void sock_in(void *);
void sock_out(void *); void sock_out(void *);
void sock_hup(void *); void sock_hup(void *);
/*
* slot call-backs
*/
void sock_slot_onmove(void *, int); void sock_slot_onmove(void *, int);
void sock_slot_onvol(void *, unsigned int); void sock_slot_onvol(void *, unsigned int);
void sock_slot_fill(void *); void sock_slot_fill(void *);
@ -63,10 +56,14 @@ void sock_slot_eof(void *);
void sock_slot_mmcstart(void *); void sock_slot_mmcstart(void *);
void sock_slot_mmcstop(void *); void sock_slot_mmcstop(void *);
void sock_slot_mmcloc(void *, unsigned int); void sock_slot_mmcloc(void *, unsigned int);
void sock_exit(void *);
/*
* midi call-backs
*/
void sock_midi_imsg(void *, unsigned char *, int); void sock_midi_imsg(void *, unsigned char *, int);
void sock_midi_omsg(void *, unsigned char *, int); void sock_midi_omsg(void *, unsigned char *, int);
void sock_midi_fill(void *, int); void sock_midi_fill(void *, int);
void sock_exit(void *);
struct fileops sock_fileops = { struct fileops sock_fileops = {
"sock", "sock",
@ -270,10 +267,6 @@ sock_midi_fill(void *arg, int count)
f->fillpending += count; f->fillpending += count;
} }
/*
* Initialise socket in the SOCK_HELLO state with default
* parameters.
*/
struct sock * struct sock *
sock_new(int fd) sock_new(int fd)
{ {
@ -304,9 +297,6 @@ sock_new(int fd)
return f; return f;
} }
/*
* Attach the stream. Callback invoked when MMC start
*/
void void
sock_slot_mmcstart(void *arg) sock_slot_mmcstart(void *arg)
{ {
@ -320,9 +310,6 @@ sock_slot_mmcstart(void *arg)
#endif #endif
} }
/*
* Callback invoked by MMC stop
*/
void void
sock_slot_mmcstop(void *arg) sock_slot_mmcstop(void *arg)
{ {
@ -336,9 +323,6 @@ sock_slot_mmcstop(void *arg)
#endif #endif
} }
/*
* Callback invoked by MMC relocate, ignored
*/
void void
sock_slot_mmcloc(void *arg, unsigned int mmcpos) sock_slot_mmcloc(void *arg, unsigned int mmcpos)
{ {
@ -352,9 +336,6 @@ sock_slot_mmcloc(void *arg, unsigned int mmcpos)
#endif #endif
} }
/*
* Callback invoked when slot is gone
*/
void void
sock_exit(void *arg) sock_exit(void *arg)
{ {
@ -369,6 +350,9 @@ sock_exit(void *arg)
sock_close(f); sock_close(f);
} }
/*
* write on the socke fd and handle errors
*/
int int
sock_fdwrite(struct sock *f, void *data, int count) sock_fdwrite(struct sock *f, void *data, int count)
{ {
@ -376,10 +360,12 @@ sock_fdwrite(struct sock *f, void *data, int count)
n = write(f->fd, data, count); n = write(f->fd, data, count);
if (n < 0) { if (n < 0) {
#ifdef DEBUG
if (errno == EFAULT) { if (errno == EFAULT) {
log_puts("sock_fdwrite: fault\n"); log_puts("sock_fdwrite: fault\n");
panic(); panic();
} }
#endif
if (errno != EAGAIN) { if (errno != EAGAIN) {
if (log_level >= 1) { if (log_level >= 1) {
sock_log(f); sock_log(f);
@ -405,6 +391,9 @@ sock_fdwrite(struct sock *f, void *data, int count)
return n; return n;
} }
/*
* read from the socke fd and handle errors
*/
int int
sock_fdread(struct sock *f, void *data, int count) sock_fdread(struct sock *f, void *data, int count)
{ {
@ -412,10 +401,12 @@ sock_fdread(struct sock *f, void *data, int count)
n = read(f->fd, data, count); n = read(f->fd, data, count);
if (n < 0) { if (n < 0) {
#ifdef DEBUG
if (errno == EFAULT) { if (errno == EFAULT) {
log_puts("sock_fdread: fault\n"); log_puts("sock_fdread: fault\n");
panic(); panic();
} }
#endif
if (errno != EAGAIN) { if (errno != EAGAIN) {
if (log_level >= 1) { if (log_level >= 1) {
sock_log(f); sock_log(f);
@ -442,8 +433,7 @@ sock_fdread(struct sock *f, void *data, int count)
} }
/* /*
* Read a message from the file descriptor, return 1 if done, 0 * read the next message into f->rmsg, return 1 on success
* otherwise. The message is stored in f->rmsg.
*/ */
int int
sock_rmsg(struct sock *f) sock_rmsg(struct sock *f)
@ -454,7 +444,7 @@ sock_rmsg(struct sock *f)
#ifdef DEBUG #ifdef DEBUG
if (f->rtodo == 0) { if (f->rtodo == 0) {
sock_log(f); sock_log(f);
log_puts(": sock_rmsg: already read\n"); log_puts(": sock_rmsg: nothing to read\n");
panic(); panic();
} }
#endif #endif
@ -477,9 +467,7 @@ sock_rmsg(struct sock *f)
} }
/* /*
* Write a message to the file descriptor, return 1 if done, 0 * write the message in f->rmsg, return 1 on success
* otherwise. The "m" argument is f->rmsg or f->wmsg, and the "ptodo"
* points to the f->rtodo or f->wtodo respectively.
*/ */
int int
sock_wmsg(struct sock *f) sock_wmsg(struct sock *f)
@ -512,8 +500,7 @@ sock_wmsg(struct sock *f)
} }
/* /*
* Read data chunk from the file descriptor, return 1 if at least one * read data into the slot/midi ring buffer
* byte was read, 0 if the file blocked.
*/ */
int int
sock_rdata(struct sock *f) sock_rdata(struct sock *f)
@ -557,8 +544,7 @@ sock_rdata(struct sock *f)
} }
/* /*
* Write data chunk to the file descriptor, return 1 if at least one * read data into the slot/midi ring buffer
* byte was written, 0 if the file blocked.
*/ */
int int
sock_wdata(struct sock *f) sock_wdata(struct sock *f)
@ -942,8 +928,7 @@ sock_hello(struct sock *f)
} }
/* /*
* Execute message in f->rmsg and change the state accordingly; return 1 * execute the message in f->rmsg, return 1 on success
* on success, and 0 on failure, in which case the socket is destroyed.
*/ */
int int
sock_execmsg(struct sock *f) sock_execmsg(struct sock *f)
@ -1330,7 +1315,8 @@ sock_execmsg(struct sock *f)
} }
/* /*
* Create a new data/pos message. * build a message in f->wmsg, return 1 on success and 0 if
* there's nothing to do. Assume f->wstate is SOCK_WIDLE
*/ */
int int
sock_buildmsg(struct sock *f) sock_buildmsg(struct sock *f)
@ -1486,9 +1472,7 @@ sock_buildmsg(struct sock *f)
} }
/* /*
* Read from the socket file descriptor, fill input buffer and update * iteration of the socket reader loop, return 1 on success
* the state. Return 1 if at least one message or 1 data byte was
* processed, 0 if something blocked.
*/ */
int int
sock_read(struct sock *f) sock_read(struct sock *f)
@ -1543,9 +1527,7 @@ sock_read(struct sock *f)
} }
/* /*
* Write messages and data on the socket file descriptor. Return 1 if * iteration of the socket writer loop, return 1 on success
* at least one message or one data byte was processed, 0 if something
* blocked.
*/ */
int int
sock_write(struct sock *f) sock_write(struct sock *f)

View File

@ -49,7 +49,7 @@
* aucat-specific messages, in the "edu" namespace * aucat-specific messages, in the "edu" namespace
*/ */
#define SYSEX_AUCAT 0x23 /* aucat-specific */ #define SYSEX_AUCAT 0x23 /* aucat-specific */
#define SYSEX_AUCAT_MIXINFO 0x01 /* mixer info */ #define SYSEX_AUCAT_SLOTDESC 0x01 /* mixer info */
#define SYSEX_AUCAT_DUMPREQ 0x02 /* dump request */ #define SYSEX_AUCAT_DUMPREQ 0x02 /* dump request */
#define SYSEX_AUCAT_DUMPEND 0x03 /* end of dump */ #define SYSEX_AUCAT_DUMPEND 0x03 /* end of dump */
@ -101,13 +101,13 @@ struct sysex {
uint8_t fr; uint8_t fr;
uint8_t end; uint8_t end;
} full; } full;
struct sysex_mixinfo { struct sysex_slotdesc {
uint8_t chan; /* channel */ uint8_t chan; /* channel */
uint8_t vol; /* current volume */ uint8_t vol; /* current volume */
#define SYSEX_NAMELEN 10 /* \0 included */ #define SYSEX_NAMELEN 10 /* \0 included */
uint8_t name[SYSEX_NAMELEN]; /* stream name */ uint8_t name[SYSEX_NAMELEN]; /* stream name */
uint8_t end; uint8_t end;
} mixinfo; } slotdesc;
struct sysex_dumpreq { struct sysex_dumpreq {
uint8_t end; uint8_t end;
} dumpreq; } dumpreq;