Comparing UGen output using conditionals

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;

Sadly if statements don’t work inside SynthDefs (see User FAQ | SuperCollider 3.12.2 Help)

this line: ( pitchSig[0] * pitchSig[1] ).poll;

will display the pitch (if detected) and 0 otherwise…

…but to do exactly what you ask have a look at SendTrig: SendTrig | SuperCollider 3.12.2 Help

1 Like