Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /////////////////////// FM SYNTHESIS | FM Basics (Part 3) ///////////////////////
- s.boot;
- // Run these methods below for visual cues.
- s.meter;
- s.scope;
- s.plotTree;
- // I use the following only when necessary.
- s.reboot;
- s.quit;
- // In Part 2, I cover Amplitude Modulation (AM). Let's move on to Frequency Modulation (FM).
- ////////////////// Things To Know Before Running Code //////////////////
- /*
- All my original SC documents are in the "dracula" color.
- To find or change this, go To SuperCollider ––> Preferences ––> Editor ––> Font & Colors.
- ––> Select under Color, dracula.
- Arguments in Synths are represented with a backslash, "\", in green under the "dracula" color font. Values presented with these arguments can be changed. Only remember to NEVER cross 0, when using an exponential method like "exprand."
- Arguments also precede a colon ":", as seen in a list of a UGen following a variable, "var."
- Example: sig = PlayBuf.ar(2, buf, rate, startPos: spos);
- Argument and variable names can be changed to your liking.
- Please be careful with volume output. Always have SuperCollider run through headphones. If you're unsure what the output will be, keep headphones away, with your main volume all the way down. Check your level meter and Stethoscope for visual cues. If everything looks safe (e.g. level meter is NOT in the red), proceed.
- You can always execute a hard stop with Command Period.
- */
- // SynthDefs
- Env([0, 1, 0], [0.1, 3], [1, -5]).plot; // Envelope shape to reference.
- // First array, [0, 1, 0], are levels.
- // Second array, [0.1, 3], are times traversing between levels.
- // Third array, [1, -5], are curve values.
- {SinOsc.ar(SinOsc.kr(1, 0, 400, 800), 0, 0.25)}.plot;
- // Let's put this in a SynthDef with designated names for the arguments.
- (
- SynthDef.new(\sinSine, {
- arg sinCtrl=1, mulCtrl=80, addCtrl=800, ampCtrl=0.25, out=0;
- var sig;
- sig = SinOsc.ar(SinOsc.kr(sinCtrl, 0, mulCtrl, addCtrl), 0, ampCtrl);
- // With default values, the line of code reads as: sig = SinOsc.ar(SinOsc.kr(1, 0, 80, 800), 0.25).
- // FM occurs with the signal traveling up from 800Hz to 880Hz, then down to 720Hz, in the course of 1 second, with the amplitude of 0.25. Contrast this with Part 2, where the given control values produce AM.
- sig = sig!2;
- Out.ar(out, sig);
- }).add;
- )
- Synth(\sinSine);
- // Execute hard stop with Command Period. (You may need to reevaluate the SynthDef.)
- Synth(\sinSine, [\sinCtrl, rrand(1, 10)]); // Don't run this more than once at a time.
- // This causes the signal to traverse through default values between 1 and 10 times per second.
- // Let's add an Envelope. Please note, it's easy to confuse the Release of an Envelope with Amplitude Modulation, because the sound is decreasing to nothing over the length of the Release.
- Env([0, 1, 0], [0.1, 8], [1, -5]).plot;
- (
- SynthDef.new(\sinSine1, {
- arg atk=0.1, rel=8, c1=1, c2=(-5),
- sinCtrl=1, mulCtrl=80, addCtrl=800, ampCtrl=0.25, out=0;
- var sig, env;
- env = Env([0, 1, 0], [atk, rel], [c1, c2]).kr(2);
- sig = SinOsc.ar(SinOsc.kr(sinCtrl, 0, mulCtrl, addCtrl), 0, ampCtrl);
- sig = sig * env;
- sig = sig!2;
- Out.ar(out, sig);
- }).add;
- )
- Synth(\sinSine1);
- // Because the Envelope releases the Synth, you may evaluate a few times or more, simultaneously.
- // Just be careful with volume.
- (
- Synth(\sinSine1, [
- \sinCtrl, rrand(1, 10),
- \mulCtrl, rrand(20, 200),
- \addCtrl, rrand(400, 1000),
- \ampCtrl, rrand(0.1, 0.35),
- \rel, rrand(2, 8)
- ]);
- )
- {SinOsc.ar(XLine.kr(200, 2000, 8), 0, 0.1)}.play; // mono;
- {SinOsc.ar(XLine.kr(200, 2000, 8), 0, 0.1)!2}.play; // stereo
- // Above is a sine tone ascending from 200 to 2000Hz in the course of 8 seconds.
- // Add an oscillation control variable.
- // Here, 200Hz is traveling to 2000Hz in the course of 8 seconds. Simultaneously, an FM control is traversing between 1 and 8 cycles per second, in the course of 8 seconds. We have no Envelope to release the Synth.
- (
- SynthDef.new(\sineAscend, {
- arg out=0;
- var sig, line, env;
- line = SinOsc.ar(XLine.kr(1, 8, 8), 0, 0.25); // mul arg functions as amplitude
- sig = SinOsc.ar(XLine.kr(200, 2000, 8), 0, 0.5); // mul arg functions as amplitude
- sig = sig * line;
- sig = sig!2;
- Out.ar(out, sig);
- }).add;
- )
- Synth(\sineAscend);
- // Execute hard stop with Command Period. (You may need to reevaluate the SynthDef.)
- // Add Envelope
- Env([0, 1, 0], [1, 8], [1, -1]).plot;
- (
- SynthDef.new(\sineAscend, {
- arg atk=1, rel=8, c1=1, c2=(-1), out=0;
- var sig, line, env;
- env = Env([0, 1, 0], [atk, rel], [c1, c2]).kr(2);
- line = SinOsc.ar(XLine.kr(1, 8, 8), 0, 0.25); // mul arg functions as amplitude
- sig = SinOsc.ar(XLine.kr(200, 2000, 8), 0, 0.5); // mul arg functions as amplitude
- sig = sig * line * env;
- sig = sig!2;
- Out.ar(out, sig);
- }).add;
- )
- Synth(\sineAscend);
- (
- SynthDef.new(\sineDescend, {
- arg atk=1, rel=8, c1=1, c2=(-1), out=0;
- var sig, line, env;
- env = Env([0, 1, 0], [atk, rel], [c1, c2]).kr(2);
- line = SinOsc.ar(XLine.kr(8, 1, 8), 0, 0.25); // mul arg functions as amplitude
- sig = SinOsc.ar(XLine.kr(2000, 200, 8), 0, 0.5); // mul arg functions as amplitude
- sig = sig * line * env;
- sig = sig!2;
- Out.ar(out, sig);
- }).add;
- )
- Synth(\sineDescend);
- // Add Argument Names
- (
- SynthDef.new(\sineAscend, {
- arg sineStart=1, sineEnd=10, sigStart=200, sigEnd=2000, sineDur=8, sigDur=8,
- atk=1, rel=8, c1=1, c2=(-1), sineAmp=0.5, sigAmp=0.5, out=0;
- var sig, sine, env;
- env = Env([0, 1, 0], [atk, rel], [c1, c2]).kr(2);
- sine = SinOsc.ar(XLine.kr(sineStart, sineEnd, sineDur), 0, sineAmp);
- sig = SinOsc.ar(XLine.kr(sigStart, sigEnd, sigDur), 0, sigAmp);
- sig = sig * sine * env;
- sig = sig!2;
- Out.ar(out, sig);
- }).add;
- )
- Synth(\sineAscend);
- // Don't run this too many times at once. I'd keep the amp values low when experimenting.
- (
- Synth(\sineAscend, [
- \sineStart, rrand(1, 10),
- \sineEnd, rrand(10, 100),
- \sigStart, rrand(100, 200),
- \sigEnd, rrand(500, 2000),
- \sineAmp, rrand(0.01, 0.3),
- \sigAmp, rrand(0.01, 0.5),
- \sineDur, rrand(4, 8),
- \sigDur, rrand(4, 8),
- \atk, rrand(0.1, 1),
- \rel, rrand(2, 12),
- \c1, rrand(1, 4),
- \c2, rrand(-1, -8),
- ]);
- )
- // Add Argument Names For Descension
- (
- SynthDef.new(\sineDescend, {
- arg sineStart=1, sineEnd=10, sigStart=2000, sigEnd=200, sineDur=8, sigDur=8,
- atk=1, rel=10, c1=1, c2=(-1), sineAmp=0.5, sigAmp=0.5, out=0;
- var sig, sine, env;
- env = Env([0, 1, 0], [atk, rel], [c1, c2]).kr(2);
- sine = SinOsc.ar(XLine.kr(sineStart, sineEnd, sineDur), 0, sineAmp);
- sig = SinOsc.ar(XLine.kr(sigStart, sigEnd, sigDur), 0, sigAmp);
- sig = sig * sine * env;
- sig = sig!2;
- Out.ar(out, sig);
- }).add;
- )
- Synth(\sineDescend);
- // Don't run this too many times at once. I'd keep the amp values low when experimenting.
- (
- Synth(\sineDescend, [
- \sineStart, rrand(1, 10),
- \sineEnd, rrand(10, 100),
- \sigStart, rrand(1000, 5000),
- \sigEnd, rrand(10, 1000),
- \sineAmp, rrand(0.05, 0.3),
- \sigAmp, rrand(0.1, 0.3),
- \sineDur, rrand(4, 8),
- \sigDur, rrand(4, 8),
- \atk, rrand(0.1, 1),
- \rel, rrand(2, 12),
- \c1, rrand(1, 4),
- \c2, rrand(-1, -8),
- ]);
- )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement