Skip to content

oscillators: linear interpolation keeps a full-scale step in range - #1256

Merged
dpwe merged 2 commits into
shorepine:mainfrom
rt-rtos:fix/interp-linear-overflow
Nov 8, 2026
Merged

dpwe merged 2 commits into
shorepine:mainfrom
rt-rtos:fix/interp-linear-overflow

Conversation

@rt-rtos

@rt-rtos rt-rtos commented Nov 7, 2026

Copy link
Copy Markdown
Contributor

INTERP_LINEAR wraps in fixed point when two neighbouring table samples differ by full scale or more. MUL0_SS holds products in [-1.0, 1.0), and across a full-scale edge c - b reaches 2.0, so the sample lands 2.0 x the osc's amplitude off. This switches it to a new MUL1_SS for products in [-2.0, 2.0): the same multiply with one bit moved from the difference to the headroom, so no per-sample cost, and at most half an LSB of the 16-bit table lost.

Why it shows up now. MUL0_SS has had this form since 0b95071 (2023-11), but until WAVETABLE (a1a8055, 2026-02) nothing fed render_lut such steps: create_lutset keeps neighbouring steps under 0.77 of full scale. The default duty's frames 31/32 are clean on every shipped table, so it only shows when duty is set or swept toward the ends of the scan, on these frames, and on any loaded table with a hard edge:

table frames with a full-scale step
111 4, 10, 11, 20, 42, 50-52, 55-57
BRAIDS01 none
PPG_WA00 61-63
SINE2SAW 8-22, 38-63
VIRAL 24

amy.send(osc=0, wave=amy.WAVETABLE, duty=51/63, note=48, vel=1) (table 111, frame 51) buzzes before this change.

Verification. Host render (fixed point, 48 kHz) against the same render with the product in 64 bits: 111 frame 51 goes from -9 dB to -74 dB error, VIRAL frame 24 from -9 dB to -80 dB, and a clean frame differs by at most 1 LSB. That last bit may move the reference renders by 1 LSB; I haven't run the full test suite.

INTERP_LINEAR multiplied c - b by frac with MUL0_SS, whose 32-bit
product holds results in [-1.0, 1.0) and wraps beyond. Across a
full-scale edge c - b reaches 2.0, so |c - b| x frac passes 1.0 and the
sample lands 2.0 x the osc's amplitude off. The generated saw, triangle
and sine tables never step that far (create_lutset keeps at least 8
samples per cycle of the top harmonic), but a 256-sample wavetable frame
can: four of the five shipped wavetables have frames that do (111, PPG_WA00,
SINE2SAW, VIRAL; the default duty's frames 31/32 are clean on all of them),
and so can any loaded table with a hard edge.

MUL1_SS, for products in [-2.0, 2.0), is the same multiply with one bit
moved from the difference to the headroom, so it costs nothing per
sample; the difference loses its last bit, at most half an LSB of the
16-bit table, scaled by frac.

Host render, fixed point, 48 kHz, against the same render with the
product in 64 bits: 111 frame 51 goes from -9 dB to -74 dB error, VIRAL
frame 24 from -9 dB to -80 dB; a clean frame (SINE2SAW 31) differs by at
most 1 LSB.
…RP_LINEAR change

Both play LUT waves near full scale, where the bit MUL1_SS drops from
the difference moves samples by 1 LSB: -69.5 and -68.5 dB against the
old references, past the -70 dB threshold.
@dpwe
dpwe merged commit a3fcc77 into shorepine:main Nov 8, 2026
13 checks passed
@bwhitman

bwhitman commented Nov 8, 2026

Copy link
Copy Markdown
Collaborator

⛓️ tulipcc integration PR opened

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

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.

3 participants