Index | Thread | Search

From:
George Koehler <kernigh@gmail.com>
Subject:
sndiod: unsigned sample 0 is not silent
To:
tech@openbsd.org
Cc:
ratchov@openbsd.org
Date:
Mon, 9 Dec 2024 00:45:22 -0500

Download raw body.

Thread
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

--gkoehler

Index: sock.c
===================================================================
RCS file: /cvs/src/usr.bin/sndiod/sock.c,v
diff -u -p -r1.51 sock.c
--- sock.c	25 Aug 2024 05:43:36 -0000	1.51
+++ sock.c	9 Dec 2024 05:02:40 -0000
@@ -1181,7 +1181,10 @@ sock_execmsg(struct sock *f)
 					panic();
 				}
 #endif
-				memset(data, 0, f->ralign);
+				if (s->par.sig)
+					memset(data, 0, f->ralign);
+				else
+					memset(data, 0x80, f->ralign);
 				abuf_wcommit(&s->mix.buf, f->ralign);
 				f->ralign = s->round * s->mix.bpf;
 			}