NetBSD Problem Report #60719
From www@netbsd.org Fri Sep 11 23:19:24 2026
Return-Path: <www@netbsd.org>
Received: from mail.netbsd.org (mail.netbsd.org [199.233.217.200])
(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
key-exchange X25519 server-signature RSA-PSS (2048 bits)
client-signature RSA-PSS (2048 bits))
(Client CN "mail.netbsd.org", Issuer "YR1" (not verified))
by mollari.NetBSD.org (Postfix) with ESMTPS id AC5781A923B
for <gnats-bugs@gnats.NetBSD.org>; Fri, 11 Sep 2026 23:19:24 +0000 (UTC)
Message-Id: <20260911231923.A3EB81A923C@mollari.NetBSD.org>
Date: Fri, 11 Sep 2026 23:19:23 +0000 (UTC)
From: raytran08@gmail.com
Reply-To: raytran08@gmail.com
To: gnats-bugs@NetBSD.org
Subject: mac68k: ascaudio(4) capture gain wraps, causing noise recorded audio above a quarter of full scale
X-Send-Pr-Version: www-1.0
X-From4GNATS: "raytran08@gmail.com via gnats" <gnats-admin@NetBSD.org>
>Number: 60719
>Category: port-mac68k
>Synopsis: mac68k: ascaudio(4) capture gain wraps, causing noise recorded audio above a quarter of full scale
>Confidential: no
>Severity: serious
>Priority: medium
>Responsible: nat
>State: closed
>Class: sw-bug
>Submitter-Id: net
>Arrival-Date: Fri Sep 11 23:20:00 +0000 2026
>Closed-Date: Thu Oct 15 15:35:04 +0000 2026
>Last-Modified: Thu Oct 15 15:35:04 +0000 2026
>Originator: Ray Tran
>Release: 11.0
>Organization:
Diamond Creek Digital
>Environment:
Hardware: Apple Macintosh Centris 650
Kernel: NetBSD 11.0 and CURRENT
>Description:
In the capture half of ascaudio_intr() each byte from FIFO A is read
into an int8_t, flipped to signed, and scaled:
val = val * sc->sc_recvol / 64;
*sc->sc_rptr++ = val;
val is int8_t and sc_recvol is uint8_t. The product is computed as an
int and then stored back into the int8_t. sc_recvol defaults to 255
(the mixer's inputs.dac), which makes the scale factor almost four: an
input of 33 becomes 131, which stores as -125, and an input of -100
becomes -398, which stores as 114. Every sample whose magnitude is
above 32 comes out with the wrong sign and a random-looking magnitude,
so anything but near-silence records as noise. Only a gain of 64 or
less avoids it, and the mixer's default is the worst case.
>How-To-Repeat:
Record anything with a real signal at the default gain:
audiorecord -t 5 -e slinear_be -P 8 -s 22050 -c 1 out.au
and listen, or look at the samples. Loud passages are garbage; only
quiet ones survive. mixerctl -w inputs.dac=64 makes it record cleanly,
which shows the arithmetic rather than the hardware is at fault.
>Fix:
Applies to sys/arch/mac68k/obio/ascaudio.c. It is independent of the
other ascaudio PRs from this machine (port-mac68k/60701 and 60702),
which change other parts of the file.
On a Centris 650 (EASC 0xbb) with nothing in the microphone jack the
FIFO delivers a constant 0x7e, and a capture at gain 64 stores it as -2
while one at gain 255 stores -7, as the expression reads. A signal
large enough to show the wrap was not to hand, so the defect rests on
the arithmetic above. The patch does not change the result for any
sample that did not overflow. The patched driver builds
under NetBSD 11.0. The same patch applies to -current.
Applies with "patch -p1" from the top of usr/src; verified with -F0
(no fuzz) against NetBSD-current 11.99.8 (20260830003849Z) and 11.0.
--- a/sys/arch/mac68k/obio/ascaudio.c
+++ b/sys/arch/mac68k/obio/ascaudio.c
@@ -811,7 +811,7 @@
struct ascaudio_softc *sc = arg;
uint8_t status;
int8_t val;
- int loc_a, loc_b, total, count, i;
+ int loc_a, loc_b, total, count, i, scaled;
if (!sc)
return;
@@ -857,8 +857,19 @@
val = bus_space_read_1(sc->sc_tag,
sc->sc_handle, loc_a);
val ^= 0x80;
- val = val * sc->sc_recvol / 64;
- *sc->sc_rptr++ = val;
+ scaled = val * sc->sc_recvol / 64;
+ if (scaled > INT8_MAX)
+ scaled = INT8_MAX;
+ else if (scaled < INT8_MIN)
+ scaled = INT8_MIN;
+ *sc->sc_rptr++ = scaled;
if (loc_b) {
(void)bus_space_read_1
(sc->sc_tag, sc->sc_handle, loc_b);
>Release-Note:
>Audit-Trail:
Responsible-Changed-From-To: port-mac68k-maintainer->nat
Responsible-Changed-By: nat@NetBSD.org
Responsible-Changed-When: Tue, 15 Sep 2026 00:41:40 +0000
Responsible-Changed-Why:
Take.
State-Changed-From-To: open->needs-pullups
State-Changed-By: nat@NetBSD.org
State-Changed-When: Wed, 16 Sep 2026 03:06:14 +0000
State-Changed-Why:
Patch applied. Thanks to Ray Tran for the patch and for testing.
From: Nathanial Sloss <nathanialsloss@yahoo.com.au>
To: gnats-bugs@netbsd.org
Cc: netbsd-bugs@netbsd.org,
gnats-admin@netbsd.org,
raytran08@gmail.com
Subject: Re: port-mac68k/60719 (mac68k: ascaudio(4) capture gain wraps, causing noise recorded audio above a quarter of full scale)
Date: Wed, 16 Sep 2026 15:52:32 +1000
Opps forgot to quote the PR with the commit.
CVS commit: src/sys/arch/mac68k/obio
To: source-changes%NetBSD.org@localhost
Subject: CVS commit: src/sys/arch/mac68k/obio
From: "Nathanial Sloss" <nat%netbsd.org@localhost>
Date: Wed, 16 Sep 2026 02:52:55 +0000
Module Name: src
Committed By: nat
Date: Wed Sep 16 02:52:55 UTC 2026
Modified Files:
src/sys/arch/mac68k/obio: ascaudio.c
Log Message:
Respect maximum and minimum values when recording.
Patch and testing by Ray Tran.
To generate a diff of this commit:
cvs rdiff -u -r1.21 -r1.22
src/sys/arch/mac68k/obio/ascaudio.c
Please note that diffs are not public domain; they are
subject
to the
copyright notices on the relevant files.
State-Changed-From-To: needs-pullups->pending-pullups
State-Changed-By: nat@NetBSD.org
State-Changed-When: Wed, 14 Oct 2026 06:11:06 +0000
State-Changed-Why:
Pullup -11 #527
State-Changed-From-To: pending-pullups->closed
State-Changed-By: nat@NetBSD.org
State-Changed-When: Thu, 15 Oct 2026 15:35:04 +0000
State-Changed-Why:
Pullups complete. Thanks for the report and patch.
>Unformatted:
(Contact us)
$NetBSD: query-full-pr,v 1.51 2026/08/10 02:28:17 riastradh Exp $
$NetBSD: gnats_config.sh,v 1.10 2026/05/13 22:00:09 riastradh Exp $
Copyright © 1994-2026
The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.