Gen: Slope Detector

cocamon's icon

Hello!

Max Patch
Copy patch and select New From Clipboard in Max.

i'm trying to make something like the Serge slope detector for a project (http://www.cgs.synth.net/modules/cgs62_sd.html) and have gotten caught up on the implementation of the sensitivity parameter. This should "allow the slope detector to work with either relatively fast events, like the edges of a square wave pulse train, or very slow events, such as the sine output of an LFO being used to drive filter/phaser sweep", which to me souds like a downsampling of the input signal which could be done with a sample and hold. However, i can't get delta to respond to sah very well in the gen domain. Anyone have an idea of how to go about this? Here's the patch at the moment

Cheers, Camilo.

bertrandfraysse's icon

The slope detector works using a capacitor which charges and discharges.
I think you could emulate its behavior using something like rampsmooth~, the ramp inputs corresponding to the sensitivity knob.

Here's my version written in a codebox in gen~, it's stripped down version of my try on emulating the serge slope generator.
It seems the sensitivity has to carefully be tuned to the input... in other words, it doesn't work very well...

Max Patch
Copy patch and select New From Clipboard in Max.

bertrandfraysse's icon

separating the rising and falling parameters allows to generate some nice rhythmic pulse. the good thing is it is always rhythmically related to the input.

Max Patch
Copy patch and select New From Clipboard in Max.

cocamon's icon

cheers, Bertrandfraysse! I'm really impressed by the musicality of the example with individual rise and fall slew. Rhythms galore! I'm pretty new to gen, so i can't quite make out what is going on in the codebox, but will be looking into it. Is the algorithm based on Ken Stone's op amp implementation?

bertrandfraysse's icon

nice to hear that you like it.
it's not an analog imitation, but an algorithmic imitation of the serge slope generator.

here is a patch using the slope generator as a triggered envelope generator.

Max Patch
Copy patch and select New From Clipboard in Max.

bertrandfraysse's icon

another version with two generators

Max Patch
Copy patch and select New From Clipboard in Max.

bertrandfraysse's icon

I think this one is better as a slope detector.
The previous one were especially made to be triggered and of constant amplitude.

You can use the following one as the smoothed section of the serge smooth/stepped generator.

Max Patch
Copy patch and select New From Clipboard in Max.

cocamon's icon

Thanks again for these examples, Bertrandfraysse. Would you mind commenting on what each section is doing in the patch or describing the algorithm? I would have thought all one needs is a simple lowpass filter and a derivative, but i'm very curious about your implementation.

bertrandfraysse's icon

Yes, you are right a lowpass filter and a derivative will do what you want.
Actually, this slope generator is kind of a lowpass filter.

The last patch is the simpler, It's really like rampsmooth~
The second input, named rate is the increment to add or remove from the current output value (output).
If the input > output, it adds the increment to the current output, and tells it's rising.
If the input < output, it removes the increment to the current value, and tells it's falling.
That's it.

I hope it helps.

cocamon's icon
Max Patch
Copy patch and select New From Clipboard in Max.

Thanks again! while i also believe(d) that the idea with slew + derivative should work, i'm finding the response a bit limited (patch is at the end). As for the gen code (first example : slew for rise and fall separate), i did want to ask: what is the basic principle of using the History type throughout? is it a buffer that can be rewritten only when conditions are met or is it always the previous sample/ condition which is getting compared to the current?

bertrandfraysse's icon

History can be used for two things, the first and most common one is to allow feedback.

yes, it isa buffer that can be rewritten only when conditions are met. The if statements use independent values than the outside of the if, so history is a buffer allowing to store the value even if the condition is not met anymore. It's kind of a sample and hold.