From bb63198e8b0c51f6ade3361517ac89e938926258 Mon Sep 17 00:00:00 2001 From: Alexandre Ratchov Date: Tue, 7 Nov 2017 12:26:46 +0100 Subject: [PATCH] prefill with silence the buffer when cmap_copy() stores samples rather than the slot/client buffer. Fixes initialized data being treated as recorded samples when resampling and/or format conversions are involved. --- aucat/aucat.c | 15 ++++++++++++++- sndiod/dev.c | 15 ++++++++++++++- 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/aucat/aucat.c b/aucat/aucat.c index caab35b..bd3f59e 100644 --- a/aucat/aucat.c +++ b/aucat/aucat.c @@ -346,7 +346,20 @@ slot_init(struct slot *s) enc_init(&s->conv, &s->afile.par, slot_nch); s->convbuf = xmalloc(s->round * slot_nch * sizeof(adata_t)); - enc_sil_do(&s->conv, s->buf.data, bufsz); + } + + /* + * cmap_copy() doesn't write samples in all channels, + * for instance when mono->stereo conversion is + * disabled. So we have to prefill cmap_copy() output + * with silence. + */ + if (s->resampbuf) { + memset(s->resampbuf, 0, + dev_round * slot_nch * sizeof(adata_t)); + } else if (s->convbuf) { + memset(s->convbuf, 0, + s->round * slot_nch * sizeof(adata_t)); } else { memset(s->buf.data, 0, bufsz * slot_nch * sizeof(adata_t)); diff --git a/sndiod/dev.c b/sndiod/dev.c index 4905eae..c448281 100644 --- a/sndiod/dev.c +++ b/sndiod/dev.c @@ -1710,7 +1710,20 @@ slot_attach(struct slot *s) enc_init(&s->sub.enc, &s->par, slot_nch); s->sub.encbuf = xmalloc(s->round * slot_nch * sizeof(adata_t)); - enc_sil_do(&s->sub.enc, s->sub.buf.data, s->appbufsz); + } + + /* + * cmap_copy() doesn't write samples in all channels, + * for instance when mono->stereo conversion is + * disabled. So we have to prefill cmap_copy() output + * with silence. + */ + if (s->sub.resampbuf) { + memset(s->sub.resampbuf, 0, + d->round * slot_nch * sizeof(adata_t)); + } else if (s->sub.encbuf) { + memset(s->sub.encbuf, 0, + s->round * slot_nch * sizeof(adata_t)); } else { memset(s->sub.buf.data, 0, s->appbufsz * slot_nch * sizeof(adata_t));