I’m trying to implement a pitch detection system, and one of the things I want to do is compare the UGen output from Pitch.kr
to an existing frequency.
Here is some sample code I’ve tried. The idea is that when the second bin of Pitch.kr
outputs 1 (i.e. it has detected a pitch), the resulting pitch will be polled. Otherwise nothing will be output.
However, I’m not getting any output. Any ideas what I’m overlooking? I’ve already tried comparing the UGen output to the number 1, and this attempt compares it to the output of a Line.kr
that is always set to 1. Neither of these seem to work.
{
var sig, pitchSig, currentPitch, triggerComp;
currentPitch = 0;
sig = SoundIn.ar(\in.kr(0));
triggerComp = Line.kr(1, 1, inf);
pitchSig = Pitch.kr(sig);
triggerComp.poll;
pitchSig[1].poll;
if(pitchSig[1] == triggerComp, {
pitchSig.poll;
});
}.play;