Forums > MaxMSP

toggle~ ?

Jan 11 2013 | 3:07 am

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.

Jan 11 2013 | 6:03 am

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. --

Jan 11 2013 | 11:24 am

Maybe thresh~ is what you need

Jan 11 2013 | 5:40 pm

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~

Jan 11 2013 | 9:51 pm

Try this:

-- Pasted Max Patch, click to expand. --

Jan 11 2013 | 9:53 pm

Oh thanks!!!

Jan 11 2013 | 10:21 pm

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…).

Jan 11 2013 | 11:45 pm

Thanks a lot this is very helpful!

Viewing 8 posts - 1 through 8 (of 8 total)

Forums > MaxMSP