← f_ notebook · docs/f-reference/f_wavetable.md

f_wavetable ​

A waveform generator whose waveform is a texture. One cycle of the wave is read along the x axis of a table, a stack of frames lies along y, and the result draws as stripes (aspect-correct, rotatable) the way vs_wfg_3 does. It is a generator: with nothing patched it draws stripes from a built-in table.

Phase menu (Stateless / Accumulate). Stateless is the stripe module described below. In Accumulate every pixel keeps its own phase: each frame the phase advances by rate plus rate_gain times the FM texture (so FM is a real, integrated rate input), relaxes back to the starting phase by leak, and the table is read at that phase. A moving texture on FM leaves a memory of its motion in the pattern; reset clears it. See "Accumulate mode".

Written 2026-11-25 (Claude, offline) from src/f_wavetable/definition.py, src/f_wavetable/codebox_wavetable.gen, .specify/f_wavetable/{spec,plan,tasks}.md and the mirror tests/modules/wavetable/wavetable_mirror.py. Not looked at in Max. Stateless codebox benched 10/10 on the single-pass build (tests/logs/20261125-192655-bench.log). Updated 2026-11-26 (Claude, offline) for the Accumulate mode: the module is now three stages (hold, step, the primary); the rebuilt module, the new codeboxes and the Accumulate mode have NOT been benched or opened in Max (the bench cases are written, tests/modules/wavetable/bench_wavetable.py, not run).


Inputs and outputs ​

PortTypeWhat it is
Inlet 1texture + controltable A: x is one cycle of the wave, y is a stack of frames. Nothing patched = the built-in table
Inlet 2texture (optional)table B, crossfaded in by blend. Ignored without table A
Inlet 3texture (optional)position modulation: added to position per pixel
Inlet 4texture (optional)FM. Stateless: frequency times 1 + fm * input. Accumulate: the per-pixel rate input (cycles per frame at full white, times rate_gain)
Inlet 5texture (optional)PM: phase shifted by pm * input cycles
Inlet 6texture (optional)PWM: skews the cycle, see below
Outlet 1texture, float32the waveform, 0 to 1 replicated to RGB, A = 1
Outlet 2texture, float321 - outlet 1, A = 1

Each optional inlet has its own vs_inState; unconnected, it reads black = 0 = no modulation. The flag lags about 180 ms at connect and disconnect (G15), so patching or unpatching a table shows a brief wrong table. The output is the render size (render_dim).

The table convention ​

  • x is the wave, one full cycle, left to right. y is the frame index; position 0 is the first row, 1 the last, linear between, clamped.
  • The read is a wrapped linear interpolation of two texels at texel centers (the wave is periodic: the last texel blends into the first). A table that is not periodic has a visible seam once per stripe; there is no seam crossfade in v1 (G10).
  • Values are taken as given and the output is clamped to 0..1. Table: Bipolar maps -1..1 to 0..1 first (0.5 + 0.5 v) and applies to a patched table only.
  • Use a float32 table. A char table quantizes the wave to 256 levels (visible stepping).
  • A one-frame table (a 128 x 1 f_util_profile row) makes position do nothing.
  • Table size is a control. A codebox cannot read a texture's size, so Tbl W and Tbl H must be set to the table's real width and height in texels (defaults 128 x 1). A wrong size reads the wrong texels. Table B is read at the same size values (so A and B must be the same size in this version).

Parameters ​

ParamRangeDefaultMeaning
wt_mode (Mode)menu: Wavetable, AdditiveWavetableAdditive: texel k - 1 of the row is the amplitude of harmonic k
tbl_pol (Table)menu: Unipolar, BipolarUnipolarpolarity of a patched table
freq0 to 406cycles across the frame height
rotation0 to 3600stripe angle in degrees
position (Pos; pix Param frame_pos)0 to 10frame scan; the position inlet adds to it; clamps
blend (pix Param tbl_blend)0 to 10table A to table B; no effect without table B
harmonics1 to 6416Additive: harmonics summed. The sum is divided by the sum of the amplitudes, so the wave stays in 0..1
fm0 to 50FM depth
pm0 to 50PM depth (cycles)
pwm-1 to 10PWM depth; 0 is the plain read
phase0 to 10Stateless: phase offset in cycles. Accumulate: the starting phase every pixel resets and leaks to, read as given (not subtracted as in Stateless)
speed-10 to 100animation speed through Vsynth's vs_newTime (global time times speed, wrapped); 0 freezes; trig_res resets. Units: Hz (Matt, 2026-11-25, stated; not measured by Claude)
table_w, table_h1 to 4096128, 1the table's size in texels
phase_mode (Phase)menu: Stateless, AccumulateStatelessAccumulate: per-pixel phase state (below). Stateless is unchanged. Switching to Accumulate starts from the flat starting phase
rate-0.1 to 0.10.01Accumulate: phase added to every pixel each frame, in cycles per frame (60 fps assumed; 0.01 is about 0.6 cycles per second). PROVISIONAL
rate_gain (R.gain)-0.1 to 0.10.05Accumulate: cycles per frame the FM texture adds at full white; negative runs the other way. PROVISIONAL
leak0 to 10.02Accumulate: how fast each pixel's phase relaxes to the starting phase, the short way round the cycle; 0 never, 1 snaps back each frame; about 1 / leak frames to fade. PROVISIONAL
resetgate buttonAccumulate: every pixel back on the starting phase on the press edge; a held press resets once
bypasspilloffoutlet 1 black, outlet 2 white (a generator has no source)

Formulas ​

p  = fract(x*freq*(1 + fm*in_fm) + pm*in_pm - phase + time)     x = rotated, aspect-correct stripe axis
w  = clamp(0.5 + pwm*in_pwm, 0.02, 0.98);  p' = p < w ? 0.5 p/w : 0.5 + 0.5 (p - w)/(1 - w)
Wavetable: value = wrapped linear read of row(position) at p'
Additive:  s = sum_k a_k sin(2 pi k p') / max(sum a_k, 1e-6), a_k = max(texel k-1, 0); value = 0.5 + 0.5 s
out1 = clamp(value, 0, 1), non-finite -> 0;  out2 = 1 - out1

Accumulate mode ​

Designed with Matt 2026-11-26 (.specify/f_wavetable/tasks.md Phase 6, User Story 9). Stateless draws stripes because its phase is a spatial ramp read from a 1D cycle, and vs_wfg_3 already bends such stripes with PM, FM and PWM. What it lacks is state: in audio, FM integrates a frequency, while the stateless fm only scales a phase. Accumulate adds that.

phi1 = phi + rate + rate_gain * in_fm          rate in cycles per frame; in_fm 0 when the FM inlet is unconnected
phi2 = phi1 + leak * wrapdiff(seed - phi1)     wrapdiff(d) = d - floor(d + 0.5), in [-0.5, 0.5); seed = fract(phase)
phi  = fract(phi2)                             one float32 state per pixel at the render size: R phase, A load flag
read = fract(phi + pm * in_pm), then the PWM warp, the table read (Wavetable or Additive), blend, polarity, outlets as Stateless
  • First frame, reset, Stateless. A frame that is the first (a texture nothing has written reads 0, 0, 0, 1), the press edge of reset, or any frame in Stateless puts every pixel on the seed with no integration that frame. So Accumulate always starts from the flat seed and the frame cycles through the table in unison at rate until a texture on FM makes the rate differ per pixel.
  • Wind-up. With a static FM texture each pixel's phase grows linearly, so the spatial phase gradient grows without bound and the pattern gets finer until it aliases; leak is what holds it back, and reset clears it. Neighbor coupling (self-organizing waves) is not built (gate P-wavetable-couple).
  • Stages. hold (identity, the loop break), step (the formulas above, inlets: the held state, the FM texture), and the primary (the existing codebox with the state as a seventh pix inlet). The FM texture goes to both the primary and step. Bypass keeps the state running underneath (outlet 1 black, outlet 2 white as before); reset still works under bypass.
  • Not used in Accumulate: freq, rotation, fm (the depth dial; rate_gain replaces it), speed and the sync messages. They stay on the panel and do nothing in this mode.
  • Seed and the sign of Phase. In Accumulate phase is the starting phase as read; in Stateless it is subtracted. A seed texture inlet and a Stripes seed are parked (gate P-wavetable-seed).
  • Mirror and tests. tests/modules/wavetable/wavetable_mirror.py (accumulate_step, wavetable_accum) and 10 tests (the old 28 plus these, 38/38 on 2026-11-26, tests/logs/20261126-202508-offline.log). Non-finite is NaN, infinite or |x| >= 1e30, matching the codebox guard.

Built-in table ​

Nothing on inlet 1: four frames, sine, triangle, saw, pulse (duty 0.5), scanned by position with linear interpolation (position 0 sine, 1 pulse). In Additive mode with no table the amplitudes are 1 / k (a saw spectrum). table, table_w, table_h and blend do not apply.

Limits and notes ​

  • No anti-aliasing in v1: Additive at a high harmonic count and a high freq aliases (G17).
  • Additive cost grows with harmonics (max 64 sines per pixel per table). Measured live 2026-11-26 at 1080p: about 1.9 to 2.2 ms per pass in Wavetable mode and Additive 16, 7.7 to 9.2 ms at 64 harmonics; bypassed 0.6 ms (the loops are skipped when bypass_gate is on). 512 x 512: 0.3 to 0.4 ms, 1.2 ms at 64. See .specify/f_wavetable/tasks.md Cost record.
  • Time comes from vs_newTime (speed, global trig_res reset); not yet seen moving in Max.
  • Sync messages from vs_sync, as vs_wfg_3 (no panel control): sync_lock 0 to 3 sets rotation to 0, 45, 90, 135 (so it overrides the dial); time is a time-division index 0 to 10 that sets speed (through vs_oldTime and timediv.txt); sync_invert 1 flips its sign. Wired offline, not seen live.
  • Accumulate costs two extra full-size float32 passes (hold, step) that run all the time, Stateless included. Measured live 2026-11-26 at 1080p: step and hold each at most 0.73 ms (upper bound), the primary reading the state 1.94 ms. A seventh pix inlet and the dual archetype with a pix_chain are first uses; neither has been opened in Max.
  • NaN and infinite table texels are contained: the output stays finite and in 0..1.

Status ​

Claude, 2026-11-25 (Stateless, before the Accumulate rebuild): bench 10/10, contract bench 2/2, mirror 28/28 (tests/modules/wavetable), drift 16/16, contracts clean for this module. Live looks passed (Matt, 2026-11-25, no details).

Claude, 2026-11-26 (offline, after the Accumulate rebuild): mirror 38/38 (tests/logs/20261126-202508-offline.log); drift ok and test_drift 16/16, test_overrides 12/12, conventions 40/40, render_dim 13/13, test_generate_menu 14/14, test_launch 8/8 (tests/logs/20261126-202703-offline.log); the rebuilt patcher's wiring read from its JSON (hold to step, step back to hold, step to the primary's seventh inlet, FM to the primary and step). NOT done: any bench or contract-bench run on the rebuilt module, a look in Max, the Accumulate live look. See .specify/f_wavetable/tasks.md Phase 6.

References ​

  • Wavetable synthesis: a standard technique. Here: wrapped linear interpolation of a table row, and a normalized harmonic sum for Additive mode (algorithms used directly, written from the closed forms above).
  • Stripes, FM, PM, time and sync follow the Vsynth WFG vs_wfg_3 (Kevin Kripper, 2020; read offline from the installed package).
  • The pulse-width phase warp and the additive normalization are original to this module, derived in development, not from an external source.