A long time ago I needed something that would toggle between 1 and -1 at audio rate whenever its input decreases in value (as would happen when driven by a [phasor~]). This is what I came up with:
Screenshot 2025-11-23 104947.png
The blocksize has to be small enough to accomodate the highest frequency toggling that you need to support.

I was convinced that this was the only way possible, and so was completely surprised when I stumbled across this:
Screenshot 2025-11-23 105017.png flipflop2~.pd
Seems so obvious in retrospect! :)

Edit: OMG, I posted a similar solution 3 years ago and forgot about it. I'm now accepting nursing home recommendations.