euclidean-rhythms
euclidean-rhythms copied to clipboard
Phase issue when pulses == steps-1
I've produced a test suite of all the patterns from Toussaint's paper, which I'll include here.
let test_suite = [
[[3,2], [1, 1, 0]],
[[4,3], [1, 1, 1, 0]],
[[5,2], [1, 0, 1, 0, 0]],
[[5,3], [1, 0, 1, 0, 1]],
[[5,4], [1, 1, 1, 1, 0]],
[[6,5], [1, 1, 1, 1, 1, 0]],
[[7,2], [1, 0, 0, 1, 0, 0, 0]],
[[7,3], [1, 0, 1, 0, 1, 0, 0]],
[[7,4], [1, 0, 1, 0, 1, 0, 1]],
[[7,5], [1, 0, 1, 1, 0, 1, 1]],
[[7,6], [1, 1, 1, 1, 1, 1, 0]],
[[8,3], [1, 0, 0, 1, 0, 0, 1, 0]],
[[8,5], [1, 0, 1, 1, 0, 1, 1, 0]],
[[8,7], [1, 1, 1, 1, 1, 1, 1, 0]],
[[9,4], [1, 0, 1, 0, 1, 0, 1, 0, 0]],
[[9,5], [1, 0, 1, 0, 1, 0, 1, 0, 1]],
[[9,7], [1, 0, 1, 1, 1, 0, 1, 1, 1]],
[[10,3], [1, 0, 0, 1, 0, 0, 1, 0, 0, 0]],
[[10,7], [1, 0, 1, 1, 0, 1, 1, 0, 1, 1]],
[[11,3], [1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0]],
[[11,4], [1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0]],
[[11,5], [1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 0]],
[[12,5], [1, 0, 0, 1, 0, 1, 0, 0, 1, 0, 1, 0]],
[[12,7], [1, 0, 1, 1, 0, 1, 0, 1, 1, 0, 1, 0]],
[[12,11],[1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0]],
[[13,5], [1, 0, 0, 1, 0, 1, 0, 0, 1, 0, 1, 0, 0]],
[[13,6], [1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 0]],
[[13,9], [1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0,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 1, 0, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 0, 1]],
[[34,15],[1, 0, 0, 1, 0, 1, 0, 1, 0, 1, 0, 0, 1, 0, 1, 0, 1, 0, 1, 0, 0, 1, 0, 1, 0, 1, 0, 1, 0, 0, 1, 0, 1, 0 ]],
];
I've found that there is a discrepancy between Bjorklund's algorithm (which several implementations use) and Toussaint's examples, in that patterns like (4,5) in which the pulses are one less than the steps, are produced with a different rotation. So for example, for 4/5, Toussaint shows (1,1,1,1,0) and several implementations of Bjorklund's algorithm give (1,0,1,1,1). Your algorithm also outputs (1,0,1,1,1).
I would not call this a bug in your code, as it appears to be a property of Bjorklund's algorithm, but it is something to be aware of. I have a python implementation which corrects this issue, which matches Toussaint's slightly different result, which I can provide on request.