Zero-Crossing Instrument

Hi all,

I’m trying to think of a design for a kind of zero-crossing instrument, which detects when a recorded a-rate signal crosses its horizontal axis or 0 point. Each time that happens, I need an oscillator to switch value from 1 to 0 (or 0 to 1, if already at 1).

To achieve this, I was thinking of using the rms opcode to track input signal amplitude, and have some sort of conditional block with a built-in flagging system to get the output signal to switch when the rms value is at or close to 0; however, I would theoretically need to track at a-rate, and that doesn’t seem possible with rms.

Another design idea was to write the signal to an f-table and ‘find’ the 0 (or close to 0) values through table lookup, then apply those results to my output signal (i.e. get it to switch if a 0 or close to 0 value is detected).

Has anyone attempted this before, and if so, any advice or suggestions? Perhaps I’m missing the barn door in front of me, and there’s a brutally simple way of doing it…

Any help greatly appreciated.

Mark F.

Hi Mark. Can you not write a UDO with setksmps 1 that will check each sample, and output a 0/1 each time a sample values changes from plus to minus? Or am i over simplifying this?

I’m sure it’s been attempted before, but not by me I’m afraid!

[some time later…]

opcode ZeroCross, k,a
    setksmps 1
    aSig xin
    kSwitch init 0
    kSampleValue = aSig

    if kSampleValue > 0 then
        kSwitch = 1
        kSwitch = 0

    xout kSwitch

instr 1
    a1, a2 diskin2 "DutchLadyTalking.aif", 1, 0, 1

    kSwitch ZeroCross a1

    if changed(kSwitch) == 1 then
        //it just crossed zero....

Hi Rory,

This is the barn door I mentioned, sitting right in front of me. Sure enough, there’s a simpler way.

Big, big thanks for your help on this; I’ll have a run through the code later on.

Kindest regards,

I was getting worried I missed the barn door myself :laughing:

1 Like

Nope, that’s perfect! I tend to over-complicate these things, so just wanted to check with the community. Nice work with the forum, btw; looks great!

i hear dutch ladies talking all day…

1 Like

perhaps in your udo you just have to wrap the trigger opcode with kmode=2.

Thanks, Joachim: hadn’t thought of using the trigger opcode.

Hi Mark,

I’m also interested in zero-crossing because I plan to detect external trigger. I have been waiting for Expert Sleepers ES-9 over months!
You might be interested in schmitt trigger for stable zero-crossing detection. It is available as sound-plugin.

1 Like

That’s also very helpful, Tetsuya, and greatly appreciated!

:laughing: I’ve been using that sample for nearly 20 years. She’s been with me a long time!

Yes, I hadn’t either. There are so many utility opcodes that I just never remember :see_no_evil: