Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /////////////////////// FM SYNTHESIS | SOUND FILES ///////////////////////
- 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;
- /////////////////////// 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.
- */
- /////////////////////// Syntax For Locating Sound Files In Folders ///////////////////////
- ~bufPath = PathName.new(thisProcess.nowExecutingPath).parentPath ++ "ambient";
- // <-- insert your sound folder, in place of where my "ambient" folder is. Your folder can have any name.
- (
- b = PathName.new(~bufPath).entries.collect({
- arg pathname;
- Buffer.read(s, pathname.fullPath);
- });
- )
- // Make sure your sound files play back. You should see it on the scope and level meters.
- // I have 3 files in my "ambient" Folder. Thus, I have below: b[0], b[1], b[2].
- // 0, being the first sound file indexed in my Folder.
- b[0].play;
- b[1].play;
- b[2].play;
- b[0].duration;
- b[1].duration;
- b[2].duration;
- /////////////////////// SynthDefs ///////////////////////
- Env([0, 1, 0], [1, 1], [3, -1]).plot; // Envelope shape to reference.
- // First array, [0, 1, 0], are levels.
- // Second array, [1, 1], are times; in this case, you're crossing 1st array values in 1 second.
- // Third array, [3, -1], are curve values.
- (
- SynthDef.new(\play, {
- arg amp=0.5, atk=0.1, rel=1, c1=3, c2=(-1),
- buf=0, rate=1, spos=0, pan=0, out=0;
- var env, sig;
- env = Env([0, 1, 0], [atk, rel], [c1, c2]).kr(2);
- sig = PlayBuf.ar(2, buf, BufRateScale.kr(buf) * rate, spos);
- sig = sig * env;
- sig = Pan2.ar(sig, pan, amp);
- Out.ar(out, sig);
- }).add;
- )
- Synth(\play, [\buf, b[0], \amp, 0.5, \rel, 12]);
- // Feel free to change the number in your array.
- // For example: \buf, b[1], (or b[2]). Values depend on the number and order of files in your Folder.
- Synth(\play, [\buf, b[0], \amp, 0.5, \rate, 5.midiratio, \rel, 12]);
- // LFPar - Parabolic Oscillator
- Env([0, 1, 0], [1, 1], [3, -1]).plot;
- {LFPar.ar(2)}.plot(1); // LFPar is smooth.
- {LFCub.ar(2)}.plot(1); // Compare with LFPar.
- {LFSaw.ar(2)}.plot(1); // Compare with the above.
- {LFTri.ar(2)}.plot(1); // Compare with the above.
- {LFPulse.ar(2)}.plot(1); // Please use the Lag UGen to clean up any clipping.
- /* For a more comprehensive explanation on Lag, please check out the following YouTube videos.
- Eli Fieldsteel's:
- https://www.youtube.com/watch?v=JCqBPmpj8Gc
- My video: Basic Sound Syntheis (Lag UGen)
- https://www.youtube.com/watch?v=DM0zGrPQ5cc&t=580s
- */
- // Note: You can write out the PlayBuf UGen arguments vertically (I do for clarity).
- // The same is true for Env, or anything involving a list or an array.
- (
- SynthDef(\playPar, {
- arg amp=0.5, parFreq=3, atk=0.01, rel=10, c1=4, c2=(-2),
- buf=0, rate=1, spos=0, pan=0, out=0;
- var env, par, sig;
- par = LFPar.ar(parFreq);
- env = Env([0, 1, 0], [atk, rel], [c1, c2]).kr(2);
- sig = PlayBuf.ar(
- 2,
- buf,
- BufRateScale.kr(buf) * rate,
- spos
- );
- sig = sig * par * env;
- sig = Pan2.ar(sig, pan, amp);
- Out.ar(out, sig);
- }).add;
- )
- // As mentioned above, you can change argument values to your liking.
- // As also mentioned, be sure never to cross 0 when using exponentially dynamic methods.
- (
- Synth.new(\playPar, [
- \buf, b[0],
- \amp, rrand(0.1, 0.8),
- \rate, rrand(-12, 12).midiratio,
- \parFreq, rrand(1, 10),
- \rel, 10
- ]);
- )
- // Frequency Modulation
- // Be sure to expand the windows for better accuracy.
- {LFPar.ar(Line.kr(50, 500, 0.1))}.plot(0.1); // Example from LFPar Help doc.
- {LFPar.ar(Line.kr(200, 20, 10), 0, 1)}.plot(1); // decreasing frequency
- {LFPar.ar(Line.kr(20, 200, 10), 0, 0.5)}.plot(1); // increasing frequency
- // Increasing Frequency
- Env([0, 1, 0], [0.1, 10], [1, -3]).plot;
- // Here's another way of writing out the arguments.
- // Check PlayBuf in the Help browser, in order to see the designated argument names.
- (
- SynthDef(\parFM, {
- arg amp=0.5, atk=0.1, rel=1, c1=1, c2=(-3),
- buf=0, rate=1, spos=0, pan=0, out=0;
- var env, par, sig;
- env = Env([0, 1, 0], [atk, rel], [c1, c2]).kr(2);
- par = LFPar.ar(Line.kr(2, 200, 10));
- sig = PlayBuf.ar(
- numChannels: 2,
- bufnum: buf,
- rate: BufRateScale.kr(buf) * rate,
- startPos: spos
- );
- sig = sig * par * env;
- sig = Pan2.ar(sig, pan, amp);
- Out.ar(out, sig);
- }).add;
- )
- (
- Synth(\parFM, [
- \buf, b[1],
- \amp, rrand(0.1, 0.8),
- \rate, rrand(-12, 12).midiratio,
- \atk, 0.001,
- \rel, 1,
- ]);
- )
- // Add FM Control
- // Add a sustain argument (ASR Envelope):
- Env([0, 0.8, 1, 0], [0.1, 2, 1], [1, -3]).plot;
- (
- SynthDef(\parFMControl, {
- arg amp=0.5, atk=0.1, sus=2, rel=1, c1=1, c2=(-3),
- min=1, max=100, dur=10,
- buf=0, rate=1, spos=0, pan=0, out=0;
- var env, par, sig;
- env = Env([0, 0.8, 1, 0], [atk, sus, rel], [c1, c2]).kr(2);
- par = LFPar.ar(Line.kr(min, max, dur));
- sig = PlayBuf.ar(
- numChannels: 2,
- bufnum: buf,
- rate: BufRateScale.kr(buf) * rate,
- startPos: spos
- );
- sig = sig * par * env;
- sig = Pan2.ar(sig, pan, amp);
- Out.ar(out, sig);
- }).add;
- )
- (
- Synth(\parFMControl, [
- \buf, b[2],
- \amp, rrand(0.1, 0.8),
- \rate, rrand(0, 12).midiratio,
- \min, rrand(1, 20),
- \max, rrand(40, 80),
- \atk, 0.01,
- \sus, 2,
- \rel, 2
- ]);
- )
- // Decreasing Frequency
- (
- SynthDef(\parFMd, {
- arg amp=0.5, atk=0.1, sus=3, rel=10, c1=1, c2=(-3), c3=(-1),
- buf=0, rate=1, spos=0, pan=0, out=0;
- var env, par, sig;
- env = Env([0, 1, 1, 0], [atk, sus, rel], [c1, c2, c3]).kr(2);
- par = LFPar.kr(Line.kr(200, 4, 8));
- sig = PlayBuf.ar(
- numChannels: 2,
- bufnum: buf,
- rate: BufRateScale.kr(buf) * rate,
- startPos: spos
- );
- sig = sig * par * env;
- sig = Pan2.ar(sig, pan, amp);
- Out.ar(out, sig);
- }).add;
- )
- (
- Synth.new(\parFMd, [
- \buf, b[2],
- \amp, rrand(0.1, 1),
- \rate, rrand(-12, 18).midiratio,
- \sus, 12,
- \rel, 2
- ]);
- )
- // Add FM Control
- (
- SynthDef(\parFMdControl, {
- arg amp=0.5, atk=0.1, sus=3, rel=1, c1=1, c2=(-3), c3=(-1),
- max=100, min=2, dur=10,
- buf=0, rate=1, spos=0, pan=0, out=0;
- var env, par, sig;
- env = Env([0, 1, 1, 0], [atk, sus, rel], [c1, c2, c3]).kr(2);
- par = LFPar.ar(Line.kr(max, min, dur));
- sig = PlayBuf.ar(
- numChannels: 2,
- bufnum: buf,
- rate: BufRateScale.kr(buf) * rate,
- startPos: spos
- );
- sig = sig * par * env;
- sig = Pan2.ar(sig, pan, amp);
- Out.ar(out, sig);
- }).add;
- )
- // Add randomness
- (
- Synth.new(\parFMdControl, [
- \buf, b[0],
- \amp, rrand(0.1, 0.8),
- \rate, rrand(-4, 4).midiratio,
- \min, rrand(2, 8),
- \max, rrand(20, 80),
- \dur, rrand(10, 24),
- \atk, rrand(0.01, 1),
- \sus, rrand(10, 20),
- \rel, rrand(1, 4)
- ])
- )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement