From fe0cee90f9bd4caa60b907e502aec4cc0daa4b60 Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Tue, 17 Nov 2026 00:05:36 -0300 Subject: audio: the voice mix plays at true volume below a knee and is limited only above it MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Every mixed sample went through x/(1 + |x|), so one voice at 0.5 played at 0.33, bent. The mix now passes through untouched up to 0.75 (-2.5 dBFS) and above it follows knee + (1 - knee)·u/(1 + u), u the excess over the room left (the old curve is its knee-0 case): same value and slope at the knee, rising, tending to 1. A clip normalised to full scale only has its peaks bent (1 plays at 0.875); two at full scale sum to 0.958. Per sample, no state, no lookahead, on the frame thread as before. A unit test checks the curve: identity to the bit below the knee (every 997th float, both signs), rising and at most 1 from the knee to infinity (every float near the knee), odd, slope 1 at the knee; `zig build test-audio` runs the mixer's tests alone. The README says what the mixer does, and that SDL clips the total of the voice mix and the streams. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_016Y9MNBECMWcJD5pdS4SR6T --- README.md | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'README.md') diff --git a/README.md b/README.md index 1400f2a..f9ad615 100644 --- a/README.md +++ b/README.md @@ -434,6 +434,13 @@ while declared, and the next frame's `input.microphone` holds what it heard `host.samples(audio)` gives a loaded sound's samples, mono at `input.sample_rate`. +The host sums the voices and limits the sum, sample by sample: below +0.75 (-2.5 dBFS) it plays at true volume, to the bit; above, it bends +smoothly (same value and slope at 0.75) toward 1 and never past it, so a +full-scale peak plays at 0.875 and any number of loud voices stays +bounded. Streams are not limited: SDL adds each, as pushed, to the voice +mix and clips the total at ±1. + Sounds decode with single-file C libraries in `vendor/` (dr_wav, dr_flac, stb_vorbis): WAV, FLAC and Ogg Vorbis, chosen by content. -- cgit v1.3