Repository navigation
audiograph: round a sample with two adds instead of a branchy helper - #359
Merged
Merged
Conversation
Every sample every node writes goes through sat16, and since #314 its rounding was round_even: a dozen instructions and two branches, there so RP2350 CircuitPython links without lrintf. Adding and subtracting 1.5 * 2^23 rounds a clamped sample to nearest, ties to even, exactly as round_even does: all 2^32 float bit patterns give the same int16 either way, and a ties-away version planted in the same check differs on 32,770 of them. On the P4 DEV-KIT (128-frame blocks, Poly106 with six notes held), graph.run goes from 24.65 to 23.12 ms per 1024 frames; a two-input mix from 23.7 to 19.2 us a block, noise from 19.6 to 14.4, the VCA from 17.3 to 13.2. The board's renders of Poly106, Poly6, Mono101, Poly8 and PolyA6 hash the same before and after, and every graph probe prints the same bytes on CPython. A target that evaluates float wider than float (x87) keeps round_even.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Every sample every graph node writes is rounded by
sat16. Since #314 that went throughround_even, a dozen instructions and two branches per sample. This rounds a clamped sample by adding and subtracting 1.5 × 2^23, which gives the same answer.Same bytes: all 2^32 float bit patterns give the same int16 through the old and new
sat16; a ties-away version planted in that check differs on 32,770 of them. Every graph probe (graph_parity,graph_nodes,graph_source,graph_carry,graph_probe) and both ladder probes print identical output on CPython before and after. On an ESP32-P4, renders of five instruments (Poly106, Poly6, Mono101, Poly8, PolyA6) hash the same before and after.Faster: on the ESP32-P4 at 128-frame blocks, Poly106 with six notes held spends 23.12 ms per 1024 frames in
graph.run, down from 24.65. Per block: a two-input mix 19.2 µs (was 23.7), noise 14.4 (19.6), the VCA 13.2 (17.3), the LFO 29.5 (34.3).A target that evaluates floats wider than float (
FLT_EVAL_METHODother than 0, as x87 does) keepsround_even.