Consider PCG in place of the voice LCG #6
Labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
bcox/tymbal#6
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
The per-voice random generator is an LCG stepping
x = 1664525x + 1013904223, indsp/layer.h. It is well suited to the target:one multiply, one add, no state beyond a word, and the draw takes the high bits
(
(int32)x >> 1), which sidesteps the classic low-bit weakness.Its real flaw showed up when voices were given distinct seeds: the LCG is
affine, so structure in the seed survives into the output. Seeding voice
iwith
i + 1spaced four voices 0.0008 apart — one value to any ear. Even thegolden-ratio constant produced an arithmetic progression (0.522, 0.572, 0.622,
0.672): a ramp across the chord, not independent draws.
Fixed in
6776866by running the index through a bit-mixing finalizer beforeit becomes a seed, so the affinity is broken before the generator sees it.
The proposal
PCG is an LCG plus an output permutation — the same mixing, applied to every
draw instead of once to the seed. That would make seeding robust by
construction: even
index + 1would then give decorrelated draws, and nobodyhas to remember why
SeedForlooks the way it does.Cost is a shift/xor/multiply per draw, still one word of state, still
synthesisable.
Why it is not urgent
The seed fix addresses the observed problem, and the test in
dsp/voice_allocator_test.ccasserts the shape — that the draws are not anarithmetic progression — so the affine failure mode cannot come back
unnoticed. Worth revisiting if per-voice or per-note correlation appears
somewhere the seed fix does not reach.