toggle~ ?

Jan 11, 2013 at 3:07am

toggle~ ?

Hello,
In the signal domain, I need an object that would act like toggle: every time it receives a certain value in signal, it sends alternatively zero and one in signal.
I am pretty sure it is obvious, but I don’t know how to do and can’t find any leads…

I know I could use edge~ to bang a toggle and then use sig~ to go back in signal but I would rather stay in the signal domain all the way through.
Thanks

#65995
Jan 11, 2013 at 6:03am

What are you trying to do? Don’t forget that signals are essentially floating point numbers streaming through at the sampling rate, so when you say “sends alternatively zeros and ones:, you’ll need to specify how frequently you want them to switch. The help file for >~ shows you how to make a signal that alternates between 0 and 1. You could also look at the train~ object which goes from 0 and 1 as well. Here’s an example of what I think you are looking for:

– Pasted Max Patch, click to expand. –
#237619
Jan 11, 2013 at 11:24am

Maybe thresh~ is what you need

#237620
Jan 11, 2013 at 5:40pm

Thanks guys for your help.
I have an incoming signal that is constantly at 0 except for very short peaks at 1 (coming from the metronome samm~ by Eric Lyon).
I want to send 1 in signal to a sfplay~ the first time there is a peak from the metronome, and send it a zero the second time, and so on.
I ended up doing this with edge~, toggle and sig~

– Pasted Max Patch, click to expand. –

but I wonder if leaving the signal domain for a short time with edge~ and coming back with sig~ keeps the sample accurate precision of the sfplay~

#237621
Jan 11, 2013 at 9:51pm

Try this:

– Pasted Max Patch, click to expand. –
#237622
Jan 11, 2013 at 9:53pm

Oh thanks!!!

#237623
Jan 11, 2013 at 10:21pm

Or this:

– Pasted Max Patch, click to expand. –

Above toggle~ in GEN (the simplest way I can think about atm).
if [+=~] -> [%~] accumulates too much it would stop working (with 64bit floats it would take some time, but nevertheless…).

#237624
Jan 11, 2013 at 11:45pm

Thanks a lot this is very helpful!

#237625

You must be logged in to reply to this topic.