Hi all,
When I run the following two bits of code, one after the other, about 5-10% of the time, the frequency calculated by DegreeToKey is inf
instead of the expected value. With slightly different versions, I’ve also gotten nan
or really large numbers like 3.68935e+19
. In these cases, the bad value is also produced for any negative index that corresponds to an octave below the root (e.g. index = -10, -15, etc). The problem does not occur for positive index values.
What’s most disturbing about this problem is the inconsistency. If I re-evaluate these two chunks (allocating a new buffer and overwriting the language reference), the code will usually work fine — but not always.
This vaguely feels like a rounding/precision error to me, but it’s just a guess. I also noticed that if I load the buffer and a bad value is produced, this behavior is consistent so long as I continue using the most recently-allocated buffer. If I load the buffer and the sound behaves normally, this is also consistent as long as I don’t mess with the buffer. So it seems like the rounding error (if that is what’s happening) occurs during the buffer writing process.
SinOsc doesn’t seem bothered by wacky freq
values, so I think the following code is pretty safe, but as you can imagine, it blows the lid off lots of other UGens.
Can anyone reproduce and/or explain this behavior? Is DegreeToKey not meant to receive negative indices? I’m on SC 3.11.2, macOS 10.14.6.
Eli
s.boot;
~scale = Buffer.loadCollection(s, [0,3,5,7,10]);
(
{
var sig, freq;
freq = DegreeToKey.kr(~scale, -5, add:84).midicps;
freq.poll;
sig = SinOsc.ar(freq, mul:0.25!2);
}.play;
)