mirror of
https://github.com/ericonr/sndio.git
synced 2024-02-18 04:45:21 -06:00
Factor audio buffer allocation into a dedicated allocbuf routine.
This commit is contained in:
parent
934e1611e8
commit
42a25f2ca4
@ -140,6 +140,19 @@ char usagestr[] = "usage: aucat [-dn] [-b size] "
|
|||||||
"[-h fmt] [-i file] [-j flag] [-o file] [-p position] [-q port]\n\t"
|
"[-h fmt] [-i file] [-j flag] [-o file] [-p position] [-q port]\n\t"
|
||||||
"[-r rate] [-v volume]\n";
|
"[-r rate] [-v volume]\n";
|
||||||
|
|
||||||
|
static void *
|
||||||
|
allocbuf(int nfr, int nch)
|
||||||
|
{
|
||||||
|
size_t fsize;
|
||||||
|
|
||||||
|
if (nch < 0 || nch > NCHAN_MAX) {
|
||||||
|
log_puts("allocbuf: bogus channel count\n");
|
||||||
|
panic();
|
||||||
|
}
|
||||||
|
fsize = nch * sizeof(adata_t);
|
||||||
|
return xmalloc(nfr * fsize);
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
slot_log(struct slot *s)
|
slot_log(struct slot *s)
|
||||||
{
|
{
|
||||||
@ -315,14 +328,12 @@ slot_init(struct slot *s)
|
|||||||
if (s->afile.fmt != AFILE_FMT_PCM ||
|
if (s->afile.fmt != AFILE_FMT_PCM ||
|
||||||
!aparams_native(&s->afile.par)) {
|
!aparams_native(&s->afile.par)) {
|
||||||
dec_init(&s->conv, &s->afile.par, slot_nch);
|
dec_init(&s->conv, &s->afile.par, slot_nch);
|
||||||
s->convbuf =
|
s->convbuf = allocbuf(s->round, slot_nch);
|
||||||
xmalloc(s->round * slot_nch * sizeof(adata_t));
|
|
||||||
}
|
}
|
||||||
if (s->afile.rate != dev_rate) {
|
if (s->afile.rate != dev_rate) {
|
||||||
resamp_init(&s->resamp, s->afile.rate, dev_rate,
|
resamp_init(&s->resamp, s->afile.rate, dev_rate,
|
||||||
slot_nch);
|
slot_nch);
|
||||||
s->resampbuf =
|
s->resampbuf = allocbuf(dev_round, slot_nch);
|
||||||
xmalloc(dev_round * slot_nch * sizeof(adata_t));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (s->mode & SIO_REC) {
|
if (s->mode & SIO_REC) {
|
||||||
@ -340,13 +351,11 @@ slot_init(struct slot *s)
|
|||||||
if (s->afile.rate != dev_rate) {
|
if (s->afile.rate != dev_rate) {
|
||||||
resamp_init(&s->resamp, dev_rate, s->afile.rate,
|
resamp_init(&s->resamp, dev_rate, s->afile.rate,
|
||||||
slot_nch);
|
slot_nch);
|
||||||
s->resampbuf =
|
s->resampbuf = allocbuf(dev_round, slot_nch);
|
||||||
xmalloc(dev_round * slot_nch * sizeof(adata_t));
|
|
||||||
}
|
}
|
||||||
if (!aparams_native(&s->afile.par)) {
|
if (!aparams_native(&s->afile.par)) {
|
||||||
enc_init(&s->conv, &s->afile.par, slot_nch);
|
enc_init(&s->conv, &s->afile.par, slot_nch);
|
||||||
s->convbuf =
|
s->convbuf = allocbuf(s->round, slot_nch);
|
||||||
xmalloc(s->round * slot_nch * sizeof(adata_t));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -710,11 +719,11 @@ dev_open(char *dev, int mode, int bufsz, char *port)
|
|||||||
dev_round = par.round;
|
dev_round = par.round;
|
||||||
if (mode & SIO_PLAY) {
|
if (mode & SIO_PLAY) {
|
||||||
dev_pchan = par.pchan;
|
dev_pchan = par.pchan;
|
||||||
dev_pbuf = xmalloc(sizeof(adata_t) * dev_pchan * dev_round);
|
dev_pbuf = allocbuf(dev_round, dev_pchan);
|
||||||
}
|
}
|
||||||
if (mode & SIO_REC) {
|
if (mode & SIO_REC) {
|
||||||
dev_rchan = par.rchan;
|
dev_rchan = par.rchan;
|
||||||
dev_rbuf = xmalloc(sizeof(adata_t) * dev_rchan * dev_round);
|
dev_rbuf = allocbuf(dev_round, dev_rchan);
|
||||||
}
|
}
|
||||||
dev_pstate = DEV_STOP;
|
dev_pstate = DEV_STOP;
|
||||||
if (log_level >= 2) {
|
if (log_level >= 2) {
|
||||||
@ -1073,7 +1082,7 @@ offline(void)
|
|||||||
dev_bufsz = rate;
|
dev_bufsz = rate;
|
||||||
dev_round = rate;
|
dev_round = rate;
|
||||||
dev_pchan = dev_rchan = cmax + 1;
|
dev_pchan = dev_rchan = cmax + 1;
|
||||||
dev_pbuf = dev_rbuf = xmalloc(sizeof(adata_t) * dev_pchan * dev_round);
|
dev_pbuf = dev_rbuf = allocbuf(dev_round, dev_pchan);
|
||||||
dev_pstate = DEV_STOP;
|
dev_pstate = DEV_STOP;
|
||||||
for (s = slot_list; s != NULL; s = s->next)
|
for (s = slot_list; s != NULL; s = s->next)
|
||||||
slot_init(s);
|
slot_init(s);
|
||||||
|
Loading…
Reference in New Issue
Block a user