Download raw body.
sndiod: unsigned sample 0 is not silent
On Mon, Dec 09, 2024 at 12:45:22AM -0500, George Koehler wrote: > I had some trouble playing unsigned 8-bit (u8) audio. I heard noise > at the end of the audio. sndiod(8) was reading u8 from the socket and > filled the last round with bytes of 0. These 0s are not silent in u8. > > I am now running this diff, which fills the last round with bytes of > 0x80 if the samples aren't signed. My diff is wrong for other > unsigned formats but seems to work for u8. > > Reproduce using audio/sox to write a .wav with u8 (-e unsigned) or > s16 (-e signed) and play it. I wrote a u8. There was noise, > > $ sox sample.wav -e un un.wav trim 0 1 vol 0.5 > $ play un.wav > > I converted my u8 to s16. The noise went away, > > $ sox un.wav -e si si.wav > $ play si.wav > thank you for the fix and the test case. To make it work for any unsigned encoding we could use enc_sil_do() instead of memset(). diff --git a/sndiod/sock.c b/sndiod/sock.c index af0cb72..443052d 100644 --- a/sndiod/sock.c +++ b/sndiod/sock.c @@ -986,6 +986,7 @@ sock_execmsg(struct sock *f) struct ctl *c; struct slot *s = f->slot; struct amsg *m = &f->rmsg; + struct conv conv; unsigned char *data; unsigned int size, ctl; int cmd; @@ -1182,7 +1183,8 @@ sock_execmsg(struct sock *f) panic(); } #endif - memset(data, 0, f->ralign); + enc_init(&conv, &s->par, s->mix.nch); + enc_sil_do(&conv, data, f->ralign / s->mix.bpf); abuf_wcommit(&s->mix.buf, f->ralign); f->ralign = s->round * s->mix.bpf; }
sndiod: unsigned sample 0 is not silent