Skip to content

BLOCK_SIZE_BITS can be chosen at compile time - #1152

Merged
dpwe merged 2 commits into
mainfrom
block-size-compile-time
Sep 8, 2026
Merged

BLOCK_SIZE_BITS can be chosen at compile time#1152
dpwe merged 2 commits into
mainfrom
block-size-compile-time

Conversation

@bwhitman

@bwhitman bwhitman commented Sep 4, 2026

Copy link
Copy Markdown
Collaborator

amy.h defined the block size unconditionally -- 256, or 128 under AMY_DAISY -- so a host could not ask for anything else without editing the header.

Now -DBLOCK_SIZE_BITS=5 is honoured: the default sits behind #ifndef, AMY_BLOCK_SIZE is derived from it, and a size that is not a power of two from 32 to 1024 is an #error. Built with nothing passed, the result is byte-identical to before -- 256, and 128 on Daisy.

amy.h defined the block size unconditionally -- 256, or 128 under
AMY_DAISY -- so a host could not ask for anything else without editing
the header. tulip5 wants 128 and 64 on the ESP32-P4 for lower latency
(the P4's CPU is thought to have the headroom; the S3's does not), and
its only route was a patched shadow of amy/src.

Now `-DAMY_BLOCK_SIZE=128` is honoured: the default sits behind
`#ifndef`, BLOCK_SIZE_BITS is derived from it, and a size that is not a
power of two from 32 to 1024 is an #error. Built with nothing passed,
the result is byte-identical to before -- 256, and 128 on Daisy.

BLOCK_SIZE_BITS is derived as an expression rather than one literal per
size on purpose: `make amy/constants.py` greps every numeric #define
out of this header and the last one would win, so a ladder of literals
would have reported BLOCK_SIZE_BITS=10 to Python and the generated JS.
The expression is skipped by that grep and the two literals above it
still report the default.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
@dpwe

dpwe commented Sep 4, 2026

Copy link
Copy Markdown
Collaborator

I lean towards have AMY_BLOCK_SIZE_BITS as the thing that can be overridden, and #define AMY_BLOCK (1<<AMY_BLOCK_SIZE_BITS). Doesn't particularly help with constants.py, but this is profound enough to be a special case.

Having the human specify in terms of bits underlines the constraint that block size must be a power of 2. This is (probably) needed for fast indexing. (Should check the uses of BLOCK_SIZE_BITS in the code to see).

@bwhitman

bwhitman commented Sep 4, 2026

Copy link
Copy Markdown
Collaborator Author

Good point. Let me try that instead

dpwe's review: a host should choose the block in BITS, with the size
(1 << BLOCK_SIZE_BITS), because asking in bits is what says the block
has to be a power of two. Checked against the code and it does: every
use of BLOCK_SIZE_BITS is a shift -- the per-block amplitude ramps in
oscillators.c and the pan ramp in amy.c -- so a block that was not a
power of two would ramp to the wrong place with no error.

So -DBLOCK_SIZE_BITS=7 is the override, 5..10 is #error'd outside, and
AMY_BLOCK_SIZE is (1 << BLOCK_SIZE_BITS). Built with nothing passed it
is 8 (256), or 7 (128) on Daisy, as before.

The special case is amy/constants.py: it is a grep of the NUMERIC
#defines in amy.h, so a derived AMY_BLOCK_SIZE dropped out of it and
with it out of amy.render() and the generated JS API. The Makefile rule
now appends AMY_BLOCK_SIZE computed from the BLOCK_SIZE_BITS that
landed; constants.py and amy_api.generated.js are regenerated (the JS
diff is the one key moving to the end).

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
@bwhitman

bwhitman commented Sep 4, 2026

Copy link
Copy Markdown
Collaborator Author

Done!

@github-actions

github-actions Bot commented Sep 4, 2026

Copy link
Copy Markdown
Contributor

🎛️ AMY HW CI (AMYboard bench)

Flashed this PR's AMY (LoadTestChord: 6-voice Juno patch=1, one held note every 2 s) onto the physical AMYboard and measured the smoothed render load as the chord grows — back-to-back with the same sketch built at the PR's merge base, so Δ is this PR's own cost.

PASS — the bench ran the test to completion.

notes held main @ 0fb0a00 this PR Δ
1 1052 1048 -4
2 1223 1225 +2
3 1828 1828 +0
4 2003 2002 -1
5 2659 2659 +0
6 2823 2826 +3

Full chord settled render μs: 2822 (was 2822, Δ +0.0%) (peak 2826, 39 samples)

⬇️ Artifacts: serial log · load trace · report

Self-hosted bench (amyboardci). FAIL means only that the test could not run — the load values are informational, with no threshold and no audio compare. See tools/arduino_loadsweep/.

@bwhitman bwhitman changed the title AMY_BLOCK_SIZE can be chosen at compile time BLOCK_SIZE_BITS can be chosen at compile time Sep 4, 2026
@dpwe
dpwe merged commit 54b107c into main Sep 8, 2026
12 checks passed
@bwhitman

bwhitman commented Sep 8, 2026

Copy link
Copy Markdown
Collaborator Author

⛓️ tulipcc integration PR opened

This merge was pinned into tulipcc for full-system CI: shorepine/tulipcc#1348

Test it there and merge that PR to move tulipcc onto this AMY.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants