Buffer.indexOfPeak is wrong
-
@Christoph-Hart It seems that
Buffer.indexOfPeak()
always throw the last sampleit uses the same search I've made by script but they don't throw the same index (far from this in fact)
except that in my case I don't need an abs value (but this is not the issue since the value atindexOfPeak
is close to 0 anyway so it shouldn't be this one)for (i = 1; i < buffer.length; i++) { if (buffer[i] > max) { index = i; max = buffer[i]; } }
-
Hasn't been resolved
const var buffer = Buffer.create(64); buffer[31] = 0.6; buffer[42] = 0.1; Console.print(buffer.indexOfPeak()); // 42 instead of 31
-
@ustk Yeah, that was a silly one. Can you spot the mistake?
int index = 0; int maxValue = 0.0f; for (int i = 0; i < numSamples; i++) { auto thisValue = std::abs(ptr[i]); if (thisValue > maxValue) { maxValue = thisValue; index = i; } }
I needed to debug it because I couldn't solve it just from staring at the code :)
-
@christoph-hart Hmm... Maybe dereference the read pointer?
std::abs(*ptr[i]);
-
@ustk Nope. A hint: number types :)
-
PS: The solution is in the commit :)
-
@christoph-hart Oh of course...
int
-
@christoph-hart Too evident to jump at the eyes :)