/* Resonz examples and filter banks */ ( SynthDef(\resonz, {arg dur, freq, amp; var env, pulse, numharms, bw, reson, bal; env = EnvGen.kr( Env([0, 1, 1, 0], [0.01, dur - 0.02, 0.01], \sin), doneAction: 2); numharms = (SampleRate.ir * 0.4) / freq; // a pulse generator pulse = Blip.ar(freq, numharms.floor, amp.dbamp); // in EnvGen, timeScale will scale the time values in the envelope. // if these values are percentages, this can be a useful way to alter // envelopes based on a notes duration. bw will control the bandwidth bw = EnvGen.kr( Env([10000, 10000, 1, 1], [0.2, 0.6, 0.2]), timeScale: dur); // Resonz.ar(arg in, freq, rq, mul, add); // rq is the reciprocal of q, or bandwidth / centerfreq. reson = Resonz.ar(pulse, freq, (bw / freq)); bal = Balance.ar(reson, pulse, 20); Out.ar(0, bal * env); }).load(s); ) s = Server.internal.boot; FreqScope.new; z = s.scope(1); s.sendBundle(0.1, [\s_new, \resonz, -1, 0, 0, \dur, 5, \freq, 440, \amp, -18]); ( SynthDef(\resonz2, {arg dur, freq, amp; var env, pulse, numharms, cf, reson, bal; env = EnvGen.kr( Env([0, 1, 1, 0], [0.01, dur - 0.02, 0.01], \sin), doneAction: 2); numharms = (SampleRate.ir * 0.4) / freq; // a pulse generator pulse = Blip.ar(freq, numharms.floor, amp.dbamp); // leveScale will scale the values in the level array. So, the output of this // evnvelope will start at 4 * freq, and will move to 5 * freq over 0.2 * dur in time. cf = EnvGen.kr( Env([4, 5, 1, 2], [0.2, 0.7, 0.1]), levelScale: freq, timeScale: dur); // bw is always 1% of the cf. This can be plugged straight into the rq argument since: // (0.01 * cf) / cf = 0.01 reson = Resonz.ar(pulse, cf, 0.01, 1); // Here, the balance greatly affects the output! Try both; reson = Balance.ar(reson, pulse, 50); Out.ar(0, reson * env); }).load(s); ) s.sendBundle(0.1, [\s_new, \resonz2, -1, 0, 0, \dur, 5, \freq, 440, \amp, -18]); ( SynthDef(\resonz3, {arg dur, freq, amp; var env, src, numharms, bw, reson, bal; env = EnvGen.kr( Env([0, 1, 1, 0], [0.01, dur - 0.02, 0.01], \sin), doneAction: 2); // a WhiteNoise gen src = WhiteNoise.ar(amp.dbamp); bw = EnvGen.kr( Env([10000, 10000, 1, 1], [0.2, 0.4, 0.4]), timeScale: dur); reson = Resonz.ar(src, freq, (bw / freq)); Out.ar(0, reson * env); }).load(s); ) s.sendBundle(0.1, [\s_new, \resonz3, -1, 0, 0, \dur, 5, \freq, 440, \amp, -18]); ( SynthDef(\resonz4, {arg dur, freq, amp; var env, src, numharms, cf, reson; env = EnvGen.kr( Env([0, 1, 1, 0], [0.01, dur - 0.02, 0.01], \sin), doneAction: 2); // Noise src = WhiteNoise.ar(amp.dbamp); cf = EnvGen.kr( Env([4, 5, 1, 2], [0.2, 0.7, 0.1]), levelScale: freq, timeScale: dur); // bw is fixed at 50Hz reson = Resonz.ar(src, cf, 50.0 / cf, 1); Out.ar(0, reson * env); }).load(s); ) s.sendBundle(0.1, [\s_new, \resonz4, -1, 0, 0, \dur, 5, \freq, 440, \amp, -12]); // multi channel expansion, .sum and banks of filters ( SynthDef(\resonz5, {arg dur, basefreq, amp; var env, src, freqs, reson; env = EnvGen.kr( Env([0, 1, 1, 0], [0.01, dur - 0.02, 0.01], \sin), doneAction: 2); // Noise src = WhiteNoise.ar(amp.dbamp); // this creates an array of 6 members freqs = basefreq * [1, 2.1, 3.9, 4.1, 7, 8]; // this will create a 6 channel output, based on the six channel array reson = Resonz.ar(src, freqs, 1 / freqs, 0.2); // .sum will mix everything in that array down to a single channel Out.ar(0, reson.sum * env); }).load(s); ) s.sendBundle(0.1, [\s_new, \resonz5, -1, 0, 0, \dur, 5, \basefreq, 440, \amp, 6]); // multi channel expansion, .sum and banks of filters ( SynthDef(\resonz6, {arg dur, basefreq, amp; var env, src, freqs, reson; env = EnvGen.kr( Env([0, 1, 1, 0], [0.01, dur - 0.02, 0.01], \sin), doneAction: 2); // Noise src = WhiteNoise.ar(amp.dbamp); // this creates an array of 6 members freqs = basefreq * Array.fill(6, {IRand.new(1, 16)}); // this will create a 6 channel output, based on the six channel array reson = Resonz.ar(src, freqs, 1 / freqs, freqs.size.reciprocal); // .sum will mix everything in that array down to a single channel Out.ar(0, reson.sum * env); }).load(s); ) s.sendBundle(0.1, [\s_new, \resonz6, -1, 0, 0, \dur, 5, \basefreq, 440, \amp, 6]); // every time this runs, a new set of partials will be created // execute the following lines one after another... eventually, a "buzz-y" sound will result s.sendBundle(0.1, [\s_new, \resonz6, -1, 0, 0, \dur, 5, \basefreq, 440, \amp, 3]); s.sendBundle(0.1, [\s_new, \resonz6, -1, 0, 0, \dur, 5, \basefreq, 440, \amp, 3]); s.sendBundle(0.1, [\s_new, \resonz6, -1, 0, 0, \dur, 5, \basefreq, 440, \amp, 3]); s.sendBundle(0.1, [\s_new, \resonz6, -1, 0, 0, \dur, 5, \basefreq, 440, \amp, 3]); s.sendBundle(0.1, [\s_new, \resonz6, -1, 0, 0, \dur, 5, \basefreq, 440, \amp, 3]); s.sendBundle(0.1, [\s_new, \resonz6, -1, 0, 0, \dur, 5, \basefreq, 440, \amp, 3]); s.sendBundle(0.1, [\s_new, \resonz6, -1, 0, 0, \dur, 5, \basefreq, 440, \amp, 3]); z.window.close;