Repository navigation
audiograph: round without lrintf so RP2350 CircuitPython links (#311) - #314
Merged
Merged
Conversation
CircuitPython's raspberry_pi_pico2 port links no lrintf, so building audiodsp there failed at link with an undefined reference from audiodsp_graph.o. The graph runner called it in two places: turning a sample-and-hold rate in Hz into a whole number, and rounding a clamped float sample to int16. Both now go through a small static inline that rounds to nearest, ties to even, which is what lrintf does in the default rounding mode. It matches lrintf for every float up to 2^24 in magnitude (checked exhaustively), so the render is the same on every build.
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.
Building audiodsp into CircuitPython for an RP2350 board, such as the Raspberry Pi Pico 2, failed at link with
undefined reference to 'lrintf'fromaudiodsp_graph.o. The RP2350 port doesn't link that libm function, so the README's claim that every module builds into CircuitPython 11 didn't hold there.The graph runner called
lrintfin two places: to turn a sample-and-hold rate in Hz into a whole number, and to round a clamped float sample to int16. Both now use a smallstatic inlineinaudiodsp_graph.cthat rounds to nearest, ties to even, which is whatlrintfdoes in the default rounding mode. This is the same approachaudiodsp_trigtook forfmodon the RP2040 (#210, #225).Nothing changes on other builds. The helper agrees with
lrintffor every float up to 2^24 in magnitude, both signs (about 2.5 billion values, checked exhaustively), which covers any sample rate and any int16 sample. No otherlrintorfmodcall remains insrc/sharedorsrc/circuitpython_spike.How it was checked, with CircuitPython main at
fb98f214cand arm-gnu-toolchain 14.2.rel1:raspberry_pi_pico2: before the change, the link fails with fiveundefined reference to 'lrintf'. After it, the link is clean and the.uf2is 1,995,776 bytes (997,804 bytes of flash used).pimoroni_pico_plus2w: links clean with every audiodsp module,.uf2of 3,079,680 bytes (1,539,772 bytes of flash used).test_cpython_audiograph.pyandtest_cpython_audiograph_nodes.py(25 passed),graph_probe.pyon a unix MicroPython build (GRAPH PASS), andverify_graph.pycomparing CPython with that MicroPython at a tolerance of 0 counts (0 samples differ). Each planted fault in both gates still fails.Fixes #311