good sources for gen dsp code online?

Wetterberg's icon

I've looked at musicdsp.org but there wasn't much usable code - I'm guessing there are quite a few forums with useful stuff out there, I just don't really know what to search for?

woyteg's icon

I don't know of any good gen~repository, but nearly everytime i need something concrete i find a lot of papers discribing the math, and then the implementation is not very hard anymore. I guess that doesn't help a lot..

stringtapper's icon

I took a class on delay-based signal processing using Gen last fall and the way we got our feet in the door was to take a bunch of block diagrams of a range of filters and effects and just start recreating them in Gen.

Here's a link to the PDF of block diagrams that we used for the course.

Wetterberg's icon

aw stringtapper, not only does that class sound absolutely flippin' amazing (!!!), that doc is fantastic - got like a primer for which gen~ functions correspond to the blocks?

I'm particularly looking for the raw synthesis bits.

dtr's icon

please excuse the noobness but what's Z^-1 in those schematics. looks like fun...

stringtapper's icon

Here's a little key I had in my notes for the class:

x(n) = input

y(n) = output

(n) = "sample of the moment"

(n-1) = delay of one sample

z-1 = single sample delay (history operator)

z-n = some variable sample delay (delay operator)

z-m = "moving" delay (delay operator w/modulation of delay time)

triangle = multiply (*~ or * in Gen)

small '-' sign = invert a value (subtract instead of add)

circle with "+" = addition operator

black dot = branching point

stringtapper's icon

@dtr: Z^-1 (z-1 in my notes above) is a single sample delay. Use the history operator.

@Andreas: The class was amazing! I ended my graduate coursework on a (physically modeled) high note for sure. The way that Gen allows you to just piece these kinds of diagrams together still floors me.

bertrandfraysse's icon

great informations, thank you very much.

Rodrigo's icon

That is pretty cool!

Somewhat related for gen code, has anyone come across a codebox matrix~ equivalent?

dtr's icon

tanx!

bertrandfraysse's icon

here is a faust code for a matrix, if it can help...

import("music.lib");
Fader(in) = db2linear(vslider("Input %in", -10, -96, 4, 0.1));
Mixer(N,out) = hgroup("Output %out", par(in, N, *(Fader(in)) ) :> _ );
Matrix(N,M) = tgroup ("Matrix %N x %M", par(in, N, _)
process = Matrix(8, 8);

to make a matrix~ equivalent, we would need to dynamically change the inlet numbers of a codebox or a gen patcher, I'm afraid you have to make it by hand.

Graham Wakefield's icon

@stringtapper: who/where this course? Curious... :-)

stringtapper's icon

University of North Texas
Composition faculty Jon Christopher Nelson was the instructor.
"Delay Based Signal Processing"

It was a one-off graduate seminar for the "Topics in Electroacoustic Music" course offered here once a year. We focused mainly on using Gen with a little Csound thrown in. We went from building simple filters to physical modeling.

Wetterberg's icon

Got... got any patches to share? even, like, scraps?

stringtapper's icon

Here are two biquads, one for each form, built in Gen.

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

Direct Form I Biquad

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

Direct Form II Biquad

oli larkin's icon

nice set of diagrams in that pdf! If anyone is interested here's an all-pass interpolated delay line, for comb filters and waveguides

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

oli

Wetterberg's icon

hi Oli,

your patch doesn't seem to work...

oli larkin's icon

needs to be pasted inside a gen~ object

Wetterberg's icon

ah yes, forgot how that worked, sorry :)

Peter McCulloch's icon

Late to the party, but I found a lot of useful things on KVRAudio.

@Stringtapper: Dr. Nelson taught a cool one-off class on granular synthesis in sampling when I was there. (almost a decade ago...)

Wetterberg's icon

Hi Peter, do you have any direct links? KVR is kind of a huge place, hehe

Peter McCulloch's icon

I don't have the links archived on my new machine, unfortunately.

The ones I found most interesting were the threads on anti-aliasing and envelopes. Envelopes are a hard thing to figure out, especially with extra features.

I also found those discussions helpful as a way of finding out the pros and cons of particular methods. I'd often start at MusicDSP then move over to KVR to see what had happened to that idea. Sorry, this is all really vague.

Is there something particular you're looking for?

Anthony Palomba's icon

This is a good way to learn gen! I would love to see more implementations of these block diagrams.

Wetterberg's icon

Peter: I'm looking to start building some "analogue delay emulation" things, so it's saturation, compression, delays and filters that are on my radar (preferably simpler than the big ladder examples ;) ), as well as weird osc/envelope things.

Basically, I've found out that I can actually learn gen~ by taking things apart. It really works for me.

Peter McCulloch's icon

Some things that might be useful:

For saturation: the distortion algorithms patch posted in the projects section a year or two ago.
For delays: are you thinking bucket brigade or tape? (I'm guessing tape) I have a non-pitchchanging algorithm if you're interested. You might also consider using an allpass delay to progressively smear the phase.
For filters: you probably just need something pretty simple, like a one pole lowpass, if it's inside the feedback loop.
For compression: rebuild the compressor example in gen~...

(I'd also add that a lot of these things can be done just in MSP, but if you want some weirder behavior, then gen~ obliges...)

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

Also, something I've found really helpful in aggressive feedback loops that works way better than clipping:

It's a tanh approximation for x close to 0, but it asymptotically approaches 0 (instead of ±1) as x approaches infinity, which makes it a fantastic feedback killer/compressor.

Wetterberg's icon

You and other heroes like stkr really are making me smile about max every damn day.

Peter McCulloch's icon

Glad to be helpful; many others have done the same for me. Here's a fun one with the faux-tanh shaper:

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

If you turn the output gain up slowly, you can use it with a live mic with no problems for controlled feedback. I use this with my classes to demonstrate how powerful feedback can be when you can properly control it. (it's also a quick demo of what Max can do that normal effects don't)

mda's icon

Details

Task One - if you're brave enough to take it.

1) implement the First filter in the attached PDF and create a gen~ version. Annotate with comments to make the process clear.

3) extra notes from max/msp forum user stringtapper (source of document):

STRINGTAPPER
April 21, 2013 | 12:03 am

Here’s a little key I had in my notes for the class:
x(n) = input
y(n) = output
(n) = "sample of the moment"
(n-1) = delay of one sample
z-1 = single sample delay (history operator)
z-n = some variable sample delay (delay operator)
z-m = "moving" delay (delay operator w/modulation of delay time)
triangle = multiply (*~ or * in Gen)
small ‘-‘ sign = invert a value (subtract instead of add)
circle with "+" = addition operator
black dot = branching point
note: Z^-1 (z-1 in my notes above) is a single sample delay. Use the history

Full thread at: https://cycling74.com/forums/good-sources-for-gen-dsp-code-online
__________________________________
dl.dropboxusercontent.com
https://dl.dropboxusercontent.com/u/1042370/ClassBlockDiagrams.pdf
DL.DROPBOXUSERCONTENT.COM
___________________________________

screenshots ok, but please use code to Submit final ideas and work in progress.

all videos welcome, TY, Vimeo, whatever.

this is not a one on one, collaborations are encouraged. As are discussions when people get stuck. This is the point, to encourage discussion and learning. Anyone want to do a tutorial, feel welcome, especially from established YTbrrs Max etc.
got an idea, upload your code, see what feedback you get, perhaps join a crew!
_____________________________________

there are no winners except those who complete the challenge successfully in one way or another. A post will be made for these discussions. Bon chance meine leibling patchers.

Please make use of the discussions there to ispire and collaborate! :-)

Ernest's icon

Was working on other projects a while, thinking of doing some more gen~ work. A small gathering of patches here:

Hope you enjoy my mild site redesign.

vichug's icon

your url begins with "localhost" !...

Ernest's icon

I'm so sorry, I copied if from my dev server by mistake. Maybe I am too old to do any more work in gen~, I make alot of silly mistakes like that these days. Here is the correct url:

I had to remove my Mac build of Godel from my server, as it was >64MB. Has Cycling74 done anything to improve the size of standalones yet? I have been waiting since Max 6, if it hasnt maybe I should file a request.

mda's icon

Hi Boys and Girls,

Trying to complete Task Three on the Facebook Gen~ group:

Where the triangles are *~ in gen so all the a's are just multiplication coefficients, what does the "-" on the b coefficients imply? That they should be multiplying below 0 (i.e. division)? or does the "-" mean subtract? If "-" means subtract, why would it be on a triangle (which is multiplication)?

Ta

mda's icon

Hi Boys and Girls,

Got it I think coefficients b must always be below 1 for stability. I hope. Please correct me if I am wrong.

Thanks people,

MDA

Peter McCulloch's icon

Triangle = multiply (I'm guessing this is historically related to the use of op-amps). The negative sign indicates inversion.

The coefficients don't necessarily have to be less than one--that depends on the design of the filter. In a onepole, yes, but not in some biquad implementations. (the so-called "triangle of stability") For example in the highpass coefficients on the page below, there are some coefficients that could individually exceed +/-1.

mda's icon

Hi Peter,

When you say inversion you mean phase right (180° kinda)? Would this need specifically implementing with [-] operators or just as a result of the multiplication being below 0?

I get nothing out of the patch. Zip. It may just be settings of the coefficients, don't know.

I've tried to paste the patch as text but I can't seem to get it to work. Where I'm at so far is attached if you have time to have a look and tell me the obvious errors I've made.

Thanks. :-)

Task3sofar.maxpat.zip
zip
SmokeDoepferEveryday's icon

can anyone kindly relink the block diagram pdf?

All the current dropboxes in this thread give a 404, Thanks.

Ernest's icon

I believe the synthcore library is now stable, although I haven't been able to test on Max8 yet, for Max7 it now has 1,500 users and so far, no problems have been reported with the 2.1 version. The available functions are as follows. Link at end.

// UTILITY FUNCTION SIGNATURES *********************************** //
out = qsin(in); // quick transcendental calcs
out = qcos(in);
out = qtan(in);
gain= db2a(db); // quick level conversion
db = a2dB(gain);
out = smoothermsecs(in);// predelay smoother, 0~0.24
out = smoother1(val){ // smoothing over ~46 clock cycles
out = smoother2(val); // smoothing over ~400 clock cycles
out = smoother3(val); // slowest smoothing for long delay line times
out = pan3db(x); // pan with -3dB center
out = powerfade(in1L, i2L, in1R, in2R, x); // ganged fader with exp crossfade
out = stereomix(in1L, in2L, in1R, in2R, x);// stereo ganged mix
out = ramp(inc); // quickest ramp generator, 0 to 1 over inc cycles
out = ramptrig(msecs, trg);// triggered 1-shot ramp, time in msecs
// OSCILLATOR FUNCTION SIGNATURES******************************** //
out = parasine(inc); // a sine osc approximation. with much lower cpu
out = triwave(ramp, width); // variable tri/saw with simple AA
out = karplus(impulse, P, dampen); // Karplus oscillator
out = karplusd(impulse, P, diffuse); // diffused Karplus
out = karplusm(impulse, fc, mod); // mod Karplus
out = noiseosc(type, p, fc, q); //lp/bp/hp/notch white/pink noise
out = waveset(sel, width, ramp, wavesets); // waveset oscillator, crosswave interp.
out = eptr3x(ramp, inc, width, eptr); // 3x-oversampled AA Pulse, table-based calcs
out = eptrx(ramp, inc, width, eptr); //antialiasing slope for pulse osc
out = lfo(sel, Fc, wid, snc_en, trg); // basic LFO
out = lfopoly(sel, Fc, sprd, sprdlvl, sprdtype, wid, sncen, trg); // LFO, voice spread
// ENVELOPES FUNCTION SIGNATURES ********************************** //
out = adsr(gate,predelay,att,dec,sus,susn,rel); basic ADSR
out = adsrloop(trg,gate,predelay,att,dec,sus,susn,rel,mode);// ADSR with loop mode
out = padsrloop(trg,gate,pre1, pre2,att,dec,sus,rel,mode); // PADSR, loop & predelay
out = adbdsrloop(trg,gate,predelay,att,dec1,brk,dec2,sus,rel,mode); // ADBDSR, loop
out = padbdsrloop)trg,gate,pre1,pre2,att,dec1,brk,dec2,sus,rel,mode); // PADBDSR. predelay & loop
// FILTER FUNCTIONS ----------------------------------------------------
out = lo1pole1 (in, P); // 6db lowpass filter
out = hi1pole1(in, P); // 6db highpass filter
out1, out2 = lo1pole2 (in1, in2, P); // stereo 6db lowpass filter
out1, out2 = hi1pole2(in1, in2, P); // stereo 6db highpass filter
out = loshelf(in, P, dB); // 12dB/oct lo shelf, +/-12dB range
out = hishelf(in, P, dB); // 12dB/oct hi shelf, +/-12dB range
out = loshelf2(in, P, dB); // 24dB/oct lo shelf, +/-12dB range
out = hishelf2(in, P, dB); // 24dB/oct hi shelf, +/-12dB range
out1, out2 = hishelfStereo(in1, in2, P, dB); // stereo hishelf
out1, out2 = loshelfStereo(in1, in2, P dB); //stereo lowshelf
out = biquad0 (in, a0, a1, a2, b1, b2); // biquad direct form 1
out = biquad (in, a0, a1, a2, b1, b2); // biquad optimized form 2
out = biquadresonant(in, P, Q); //resonant
out = biquadgainresonant(in, P, Q, gain); //gain resonant
out = biquadlo (in, Fc, Q); // biquad lowpass, simple
out = biquadlp1 (in, Fc, Q); // tuned lowpass
out = biquadlo2 (in, P, Q); // biquad lowpass, MIDI pitch Fc,
out = biquadlo3 (in, P, Q); // biquad lowpass, qain-limiting
out = biquadband (in, Fc, Q); // biquad bandpass, simple
out = biquadbp1 (in, Fc, Q); // tuned bandpass
out = biquadband2(in, P, Q); // biquad bandpass, MIDI pitch Fc,
out = biquadband3(in, P, Q); // biquad bandpass, gain limiting
out = biquadband4(in, P, Q); // biquad bandpass, unity gain
out = biquadbandgain(in, Fc, Q, gain); // biquad bandpass gain
out = biquadhi (in, Fc, Q); // biquad highpass, simple
out = biquadhp1 (in, Fc, Q); // tuned highpass
out = biquadhi2 (in, P, Q); // biquad highpass, MIDI pitch Fc,
out = biquadhi3 (in, P, Q); // biquad highpass, gain limiting
out = biquadhigain(P, Q, gain); // biquad gain hipass
out = biquadnotch(in, Fc, Q); // biquad notch, somple
out = biquadgainbandstop(in, P, Q, gain); //gain gandstop
out = biquadbandstop(in, P, Q); // biquad bandstop
out = biquadpeaknotch(in, Fc, Q, gain); // biquad peak/notch
out = biquadallpass(in, P, Q); // biquad allpass
out = biquadgainallpass(in, P, Q, gain); // gain allpass
val = biquadamp (w, a0, a1, a2, b1, b2); // biquad gain @ specfic fc
out = filt5d(in, P, Q, type, poles, drive); // 3x-oversampled 5d filter
out1, out2, out3 = upsample(in); // 3x upsampling with sinc coefficients
out = downsample(out1, out2, out3); // 3x downsampling with sinc coefficients
out = comb(input, delay, feedback, lvl); // feedforward comb filter
// EFFECTS FUNCTION SIGNATURES ************************************* //
out1, out2 = ping0(L, R, delayL, delayR, cross, feedback); // simple stereo delay
out1, out2 = ping1(L, R, delayL, delayR, cross, feedback,
locut, hicut); // stereo delay, 1pole filter
out1, out2 = ping3(L, R, delayL, delayR, cross, feedback,
loP, loG, midP, midG, midQ, hiP, hiG); // stereo delay with 3band EQ
out1, out2 = chorus(in1, in2, del, deep, sprd, mix); // dual quad-band chorus
out = diffdelay(in, delay, diff); // basic diffusion delay
out = diffdelSmall(in, depth, time); // small diffusion delay
out = diffdelBig(in, depth, time); // large diffusion delay
out = earlydelF(in, Dffs, size, ha1, hb0, hb1, la1, lb0, lb1); // biquad diff delay
out = tankLeft(in, damp, decay); // left late reflections
out = tankRight(in, damp, decay); // right late reflections
out1, out2 = reverb(in1, in2, pre, cut, damp, decay, lvl);//acoustic reverb
out1, out2 = rev66(in1, in2, pre, cut, latemix, size, time, inc,
spin, rndm, hishelf, loshelf); // production-quality reverb
out1, out2 = limit(in1, in2, lvl, window, attlo, atthi, rello, relhi); // stereo limiter
// ***************************************************************** //

Ernest's icon

Yofiel's gen~ Synthcore 2.1 library shall remain $15 until Tuesday June 12th. Synhcore v2.2 will include a phase-banked vocoder. Top-level structure of Yofiel's Bowie phase-banked AV vocoder is illustrated below (now in alpha stage). By default, Bowie provides up to 32 detuned voices with a common dual quad-band vocoder for each voice. Changes in vocoder settings alter the video frame pointer. With felicitations to Berlin on 2018 Memorial Day weekend. And with a nod to Reaktor 6 in vst~. Hope you enjoy the free instruments for MacOS Yosemite, High Sierra, and Windows 10 on https://www.yofiel.com. Top-down design of first to third levels is below. Enjoy :)