MM – More interesting FM synthesis.

A generative song using FM in a controlled random way. :)

///////////////////////////////////////////////////////////////////////////////

// MM - More interesting FM Synthesis / 2020 Matias Monteagudo.

///////////////////////////////////////////////////////////////////////////////

(
Server.local.options.device = "ASIO : ASIO PreSonus FireStudio";
Server.local.options.sampleRate=48000;
Server.local.options.hardwareBufferSize=128;
)

///////////////////////////////////////////////////////////////////////////////
//Reverb.
///////////////////////////////////////////////////////////////////////////////
(
(
SynthDef(\verb, {
	|in, predelay=1, revtime=5, lpf=7000,mix=0.5,amp=1,out=0|
	var dry,wet,temp,sig;
	dry = In.ar(in, 2);
	temp = In.ar(in, 2);
	wet=0;
	temp=DelayN.ar(temp, 0.2, predelay);
	32.do {temp=AllpassN.ar(temp, 0.05, {Rand(0.001,0.05)}!2,revtime);
		temp=LPF.ar(temp,lpf);
		wet=wet+temp;
	};
	sig=XFade2.ar(dry,wet,mix*2-1,amp);
	sig=Limiter.ar(sig,0.9);
	Out.ar(out,sig);
}).add;
);

(
ServerTree.removeAll;
~revBus = Bus.audio(s,2);
~createReverb={~reverbSynth=Synth(\verb, [\mix,0.2, \in, ~revBus])};
ServerTree.add(~createReverb);
s.freeAll;
s.scope;
s.freqscope;
s.plotTree;
);
)


ServerTree.removeAll;

///////////////////////////////////////////////////////////////////////////////
//Synths.
///////////////////////////////////////////////////////////////////////////////

//FM Synth
(
SynthDef(\fm1, {
	|gate=1, freq=200, amp=1, atk=0.01, rel=5, cur= -2,pan=0,spr=1,mFq1=1000,mAmp1=0.1,mFq2=2000,mAmp2=0.1|
	var env,op1,op2,op3,op4,sig,mod1,mod2;
	mod1=Pulse.ar(ExpRand(4,500),mul:Rand(100,1000));
	mod2=SinOsc.ar(Rand(-0.3,0.3),mul:Rand(100,2000));
	env=EnvGen.kr(Env.adsr(atk, 0.01,1,rel,amp,cur),gate,doneAction:2);
	op1=SinOsc.ar(mFq1+SinOsc.ar(Rand(-0.3,0.3),mul:Rand(100,2000)),mul:mAmp1);
	op2=SinOsc.ar(mFq2+rrand(mod1,mod2), op1,mul:mAmp2);
	op3=SinOsc.ar(freq+3, op2,mul:env);
	op4=SinOsc.ar(freq-3, op3,mul:env);
	sig=Mix.ar({[op3,op4,op4,op3]}!4);
	sig=Splay.ar(sig, spr, env, pan);
	sig=LeakDC.ar(sig);
	Out.ar(~revBus, sig*0.15);
}).add;
)

//Noise Synth
(
SynthDef(\noise, {
	|gate=1,amp=1,atk=0.001,rel=1,cur= -2,pan=0,spr=1,lpCt=3000,lpRes=0.5|
	var sig;
	sig=Gendy2.ar(Rand(0.1,1),Rand(0.1,1),Rand(0.2,1),Rand(0.1,1),Rand(400,1000),4000,
		Rand(0.1,1),Rand(0.1,1),Rand(5,12),Rand(2,24),Rand(0.5,1.2),Rand(0.1,0.5),
		EnvGen.kr(Env.adsr(atk,0.001,1,rel,amp,cur),gate,doneAction:2));
	sig={BPF.ar(sig,ExpRand(lpCt,lpCt+2000),lpRes)}!3;
	sig=Splay.ar(sig,spr,center:pan);
	Out.ar(~revBus, sig*4);
}).add
);

// Kick
(
SynthDef(\kick, {
	|gate=1,freq=30,amp=1,rel=1,cur= -2|
	var sig,env;
	env=(EnvGen.kr(Env.adsr(0.001,0.001,1,rel,amp,cur),gate,doneAction:2));
	sig=SinOsc.ar(freq+Line.ar(1,0,0.3,40)).distort(1);
	Out.ar(0,sig!2*env);
}).add;
)

(

///////////////////////////////////////////////////////////////////////////////
//Patterns.
///////////////////////////////////////////////////////////////////////////////

//Melody
TempoClock.tempo=117/120;
(
Pdefn(\p1oct, Prand([4,5],inf));
Pdefn(\p1deg, Prand([-6,-3,1,6,9,11,13,18,20,21].mirror1,inf));
Pdefn(\p1dur, Pseq([Prand([1,1/2,1/4,1/8],24), Prand([1/8],8)],inf));
Pdefn(\p1leg, Prand([0.05, 1/4],inf));
Pdefn(\p1amp, Pwhite(0.4, 0.7));
Pdefn(\p1pan, Pwhite(-0.4,0.4));
Pdefn(\p1atk, Pwhite(0.001, 0.01));
Pdefn(\p1rel, Pwhite(0.2,2));
Pdefn(\p1cur, Pwhite(-20,-2));
Pdefn(\p1mFq1, Pwhite(20,30));
Pdefn(\p1mAmp1, Pwhite(0.01,0.8));
Pdefn(\p1mFq2, Pwhite(20,3000));
Pdefn(\p1mAmp2, Pwhite(0.01,0.8));
~p1=Pbindef(\p1, \instrument, \fm1,
	\legato, Pdefn(\p1leg),
	\dur, Pdefn(\p1dur),
	\scale, Scale.chromatic,
	\octave, Pdefn(\p1oct),
	\degree, Pdefn(\p1deg),
	\amp, Pdefn(\p1amp),
	\pan, Pdefn(\p1pan),
	\atk, Pdefn(\p1atk),
	\rel, Pdefn(\p1rel),
	\cur, Pdefn(\p1cur),
	\mFq1, Pdefn(\p1mFq1),
	\mAmp1, Pdefn(\p1mAmp1),
	\mFq2, Pdefn(\p1mFq2),
	\mAmp2, Pdefn(\p1mAmp2)
);
);

//Bass
(
Pdefn(\p2oct, 2);
Pdefn(\p2deg, Prand([1,5,11,13,18].mirror1,inf));
Pdefn(\p2dur, Pseq([Prand([1/2,1/4],24),Pseq([1/8],4), Pseq([1/2],2), Pseq([1/8],4)],inf));
Pdefn(\p2leg, 0.1);
Pdefn(\p2amp, Pwhite(0.8, 1.2));
Pdefn(\p2pan, Pwhite(-0.4,0.4));
Pdefn(\p2atk, 0.001);
Pdefn(\p2rel, Pwhite(0.2,3));
Pdefn(\p2cur, Pwhite(-30,-2));
Pdefn(\p2mFq1, Pwhite(20,30));
Pdefn(\p2mAmp1, Pwhite(0.001,0.2));
Pdefn(\p2mFq2, Pwhite(20,3000));
Pdefn(\p2mAmp2, Pwhite(0.001,0.2));
~p2=Pbindef(\p2, \instrument, \fm1,
	\legato, Pdefn(\p2leg),
	\dur, Pdefn(\p2dur),
	\scale, Scale.chromatic,
	\octave, Pdefn(\p2oct),
	\degree, Pdefn(\p2deg),
	\amp, Pdefn(\p2amp),
	\pan, Pdefn(\p2pan),
	\atk, Pdefn(\p2atk),
	\rel, Pdefn(\p2rel),
	\cur, Pdefn(\p2cur),
	\mFq1, Pdefn(\p2mFq1),
	\mAmp1, Pdefn(\p2mAmp1),
	\mFq2, Pdefn(\p2mFq2),
	\mAmp2, Pdefn(\p2mAmp2)
);
);

//Perc
(
Pdefn(\p3oct, Pseq([11,11,22,15,11,16,17,18].stutter(16),inf));
Pdefn(\p3deg, Prand([-2,3,11,13,15,23].mirror1,inf));
Pdefn(\p3dur, 1/8);
Pdefn(\p3leg, 0.1);
Pdefn(\p3amp, Pwhite(0.2, 0.8));
Pdefn(\p3pan, Pwhite(-1,1));
Pdefn(\p3atk, 0.001);
Pdefn(\p3rel, Pwhite(0.0001,001));
Pdefn(\p3cur, Pwhite(-20, 2));
Pdefn(\p3mFq1, Pwhite(1000,3000));
Pdefn(\p3mAmp1, Pwhite(0.5,0.1));
Pdefn(\p3mFq2, Pwhite(1000,3000));
Pdefn(\p3mAmp2, Pwhite(0.5,0.1));
~p3=Pbindef(\p3, \instrument, \fm1,
	\legato, Pdefn(\p3leg),
	\dur, Pdefn(\p3dur),
	\scale, Scale.chromatic,
	\octave, Pdefn(\p3oct),
	\degree, Pdefn(\p3deg),
	\amp, Pdefn(\p3amp),
	\pan, Pdefn(\p3pan),
	\atk, Pdefn(\p3atk),
	\rel, Pdefn(\p3rel),
	\cur, Pdefn(\p3cur),
	\mFq1, Pdefn(\p3mFq1),
	\mAmp1, Pdefn(\p3mAmp1),
	\mFq2, Pdefn(\p3mFq2),
	\mAmp2, Pdefn(\p3mAmp2)
);
);

//Pads
(
Pdefn(\p4oct, 4);
Pdefn(\p4deg, Prand(#[[0,3,6],rest,[09,13,15],rest,[12,15,18,21,25],rest,[21,25,27,30],rest],inf));
Pdefn(\p4dur, Prand([6,4],inf));
Pdefn(\p4leg, 4);
Pdefn(\p4amp, 0.1);
Pdefn(\p4pan, Pwhite(-1,1));
Pdefn(\p4atk, 3);
Pdefn(\p4rel, 3);
Pdefn(\p4mFq1, Pwhite(1000,3000));
Pdefn(\p4mAmp1, Pwhite(0.5,0.2));
Pdefn(\p4mFq2, Pwhite(1000,3000));
Pdefn(\p4mAmp2, Pwhite(0.5,0.2));
~p4=Pbindef(\p4, \instrument, \fm1,
	\legato, Pdefn(\p4leg),
	\dur, Pdefn(\p4dur),
	\scale, Scale.chromatic,
	\octave, Pdefn(\p4oct),
	\degree, Pdefn(\p4deg),
	\amp, Pdefn(\p4amp),
	\pan, Pdefn(\p4pan),
	\atk, Pdefn(\p4atk),
	\rel, Pdefn(\p4rel),
	\mFq1, Pdefn(\p4mFq1),
	\mAmp1, Pdefn(\p4mAmp1),
	\mFq2, Pdefn(\p4mFq2),
	\mAmp2, Pdefn(\p4mAmp2)
);
);

//noise perc.
(
Pdefn(\p5dur, Prand([1/8,1/4],inf));
Pdefn(\p5leg, 0.1);
Pdefn(\p5amp, Pwhite(0.05, 0.1));
Pdefn(\p5pan, Pwhite(-1,1));
Pdefn(\p5atk, Prand([0.001,0.5],inf));
Pdefn(\p5rel, Prand([0.001,1],inf));
Pdefn(\p5cur, Pwhite(-20, -8));
Pdefn(\p5lpCt, Pseq([Phprand(300, 1000,16), Phprand(300, 8000,16)],inf));
Pdefn(\p5lpRes, Pwhite(0.1,0.8));
~p5=Pbindef(\p5, \instrument, \noise,
	\legato, Pdefn(\p5leg),
	\dur, Pdefn(\p5dur),
	\scale, Scale.chromatic,
	\octave, Pdefn(\p5oct),
	\degree, Pdefn(\p5deg),
	\amp, Pdefn(\p5amp),
	\pan, Pdefn(\p5pan),
	\atk, Pdefn(\p5atk),
	\rel, Pdefn(\p5rel),
	\cur, Pdefn(\p5cur),
	\lpCt, Pdefn(\p5lpCt),
	\lpRes, Pdefn(\p5lpRes)
);
);

//Perc2
(
Pdefn(\p6oct, Pseq([11,11,22,15,11,16,17,18].stutter(16)+7,inf));
Pdefn(\p6deg, Prand([-2,3,11,13,15,23].mirror1,inf));
Pdefn(\p6dur, 1/8);
Pdefn(\p6leg, 0.1);
Pdefn(\p6amp, Pwhite(0.6, 0.8));
Pdefn(\p6pan, Pwhite(-1,1));
Pdefn(\p6atk, 0.001);
Pdefn(\p6rel, Pwhite(0.0001,001));
Pdefn(\p6cur, Pwhite(-20, 2));
Pdefn(\p6mFq1, Pwhite(40,500));
Pdefn(\p6mAmp1, Pwhite(0.5,0.8));
Pdefn(\p6mFq2, Pwhite(40,500));
Pdefn(\p6mAmp2, Pwhite(0.5,0.4));
~p6=Pbindef(\p6, \instrument, \fm1,
	\legato, Pdefn(\p6leg),
	\dur, Pdefn(\p6dur),
	\scale, Scale.chromatic,
	\octave, Pdefn(\p6oct),
	\degree, Pdefn(\p6deg),
	\amp, Pdefn(\p6amp),
	\pan, Pdefn(\p6pan),
	\atk, Pdefn(\p6atk),
	\rel, Pdefn(\p6rel),
	\cur, Pdefn(\p6cur),
	\mFq1, Pdefn(\p6mFq1),
	\mAmp1, Pdefn(\p6mAmp1),
	\mFq2, Pdefn(\p6mFq2),
	\mAmp2, Pdefn(\p6mAmp2)
);
);

//A bit of hearbeat kick for good measure.
(
Pdefn(\p7deg, Pseq(#[6,0,rest,rest],inf));
Pdefn(\p7dur, 1/4);
Pdefn(\p7leg, 0.1);
Pdefn(\p7amp, Pseq([0.6,0.3],inf));
Pdefn(\p7rel, 0.5);
Pdefn(\p7cur, -10);
~p7=Pbindef(\p7, \instrument, \kick,
	\legato, Pdefn(\p7leg),
	\dur, Pdefn(\p7dur),
	\scale, Scale.chromatic,
	\octave, 1,
	\degree, Pdefn(\p7deg),
	\amp, Pdefn(\p7amp),
	\rel, Pdefn(\p7rel),
	\cur, Pdefn(\p7cur)
);
);

(
~p1.play(quant:1);
~p2.play(quant:1);
~p3.play(quant:1);
~p4.play(quant:1);
~p5.play(quant:1);
);
)

//Phrase with low perc instead.
(
~p3.stop;
~p7.stop;
~p1.play(quant:1);
~p2.play(quant:1);
~p4.play(quant:1);
~p5.play(quant:1);
~p6.play(quant:1);
);

//Back to original phrase.
(
~p6.stop;
~p7.stop;
~p1.play(quant:1);
~p2.play(quant:1);
~p3.play(quant:1);
~p4.play(quant:1);
~p5.play(quant:1);
);

//All Perc on.
(
~p7.stop;
~p1.play(quant:1);
~p2.play(quant:1);
~p3.play(quant:1);
~p4.play(quant:1);
~p6.play(quant:1);
~p5.play(quant:1);
);

//Heartbeat, no bass.
(
~p2.stop;
~p3.stop;
~p1.play(quant:1);
~p4.play(quant:1);
~p5.play(quant:1);
~p6.play(quant:1);
~p7.play(quant:1);
);

//Only perc.
(
~p1.stop;
~p2.stop;
~p4.stop;
)

//Stop perc.
(
~p3.stop;
~p5.stop;
)

~p6.stop;

~p7.stop
Author
418 PM
  • Platform:
  • Category: Composition Synthesizer
  • Revision: 1.0
  • License: Academic Free License v3.0
  • Views: 310
  • Modified: 4 months ago
Chat about this patch on Discord!
Appreciate 1

Leave a Reply