Advertisement
SoundEngraver

FM Synthesis | FM Basics (Part 2)

Feb 15th, 2023 (edited)
864
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /////////////////////// FM SYNTHESIS | FM Basics (Part 2) ///////////////////////
  2.     ///////////////////////////// FM or AM? ///////////////////////////////
  3.  
  4.  
  5. // Question: FM or AM? What's the difference?
  6.  
  7. // LFO is Low Frequency Oscillator, an oscillation control of 20Hz and below (inaudible).
  8. // Question: Can you see where I'm implementing an LFO in the SynthDef below?
  9.  
  10. s.boot;
  11.  
  12. // Run these methods below for visual cues.
  13.  
  14. s.meter;
  15. s.scope;
  16. s.plotTree;
  17.  
  18. // I use the following only when necessary.
  19.  
  20. s.reboot;
  21. s.quit;
  22.  
  23. /////////////////////// Things To Know Before Running Code ///////////////////////
  24.  
  25. /*
  26.  
  27. All my original SC documents are in the "dracula" color.
  28. To find or change this, go To SuperCollider ––> Preferences ––> Editor ––> Font & Colors.
  29. ––> Select under Color, dracula.
  30.  
  31. Arguments in Synths are represented with a backslash, "\", in green under the "dracula" color font.
  32. Values presented with these arguments can be changed. Only remember to NEVER cross 0, when using an exponential method like "exprand."
  33.  
  34. Argument and variable names can be changed to your liking.
  35.  
  36. 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.
  37.  
  38. */
  39.  
  40.  
  41. // SynthDefs
  42.  
  43. Env([0, 1, 0], [0.1, 3], [1, -5]).plot; // Envelope shape to reference.
  44. // First array, [0, 1, 0], are levels.
  45. // Second array, [0.1, 3], are times traversing between levels.
  46. // Third array, [1, -5], are curve values.
  47.  
  48. (
  49. SynthDef.new(\sine, {
  50.     arg atk=0.1, rel=3, c1=1, c2=(-5),
  51.     freq=400, amp=0.3, out=0; // Be careful with amp values (0-1).
  52.     var sig, sine, env;
  53.     env = Env([0, 1, 0], [atk, rel], [c1, c2]).kr(2); // Env().kr(2) is a shortcut for "doneAction: 2"
  54.     sig = SinOsc.ar(freq);
  55.     sig = sig * env * amp;
  56.     sig = sig!2;
  57.     Out.ar(out, sig);
  58. }).add;
  59. )
  60.  
  61. Synth(\sine);
  62.  
  63.  
  64. // SinOsc (SinOsc Control Variable)
  65. // IMPORTANT: The "sinCtrl" argument below is causing the synth to perform amplitude modulation (AM).
  66.  
  67. (
  68. SynthDef.new(\sinSine, {
  69.     arg atk=0.1, rel=3, c1=1, c2=(-5),
  70.     sinCtrl=1, sinFreq=400, amp=0.5, out=0;
  71.     var sig, sine, env;
  72.     env = Env([0, 1, 0], [atk, rel], [c1, c2]).kr(2);
  73.     sine = SinOsc.ar(sinCtrl); // control value is 1Hz; this is effectively an LFO (e.g. < 20Hz).
  74.     // traversing through these sine tone values in 1 second: (from, 0 to 0.5, then to -0.5, then back to 0).
  75.           // Remember, 0.5 is my amp value here.
  76.     // Use this following line of code for your reference: {SinOsc.ar(400, 0, 0.5)}.plot;
  77.     sig = SinOsc.ar(sinFreq); // 400 Hz is the default.
  78.     sig = sig * sine * env * amp;
  79.     sig = sig!2; // Converts this to a stereo signal.
  80.     // See the SynthDef below (\sinSine1) for another way to convert signal to stereo.
  81.     Out.ar(out, sig);
  82. }).add;
  83. )
  84.  
  85. {SinOsc.ar(400, 0, 0.5)}.plot; // This is the reference for the current sine oscillator given.
  86. // Reminder: The "sinCtrl" argument here is causing the synth to perform AM, not FM.
  87. // Be sure to listen for the dip in volume as the sine tone of 400Hz crosses amp values, 0, 0.5, and -0.5.
  88.  
  89.  
  90. Synth(\sinSine);
  91. Synth(\sinSine, [\amp, 0.3, \rel, 8]); // Change amp values between 0 and 1 (..but, don't do 0).
  92.  
  93. // Be careful with amp values. Anything exceeding 0.5, in this case, is fairly loud.
  94.  
  95. // Here's another way to convert the signal to stereo.
  96.  
  97. (
  98. SynthDef.new(\sinSine1, { // Note the name change for our SynthDef. Always check your names!
  99.     arg atk=0.1, rel=8, c1=1, c2=(-5),
  100.     sinCtrl=1, sinFreq=400, amp=0.5, out=0;
  101.     var sig, sine, env;
  102.     env = Env([0, 1, 0], [atk, rel], [c1, c2]).kr(2);
  103.     sine = SinOsc.ar(sinCtrl);
  104.     sig = SinOsc.ar(sinFreq)!2; // Create a stereo signal.
  105.     sig = sig * sine * env * amp;
  106.     Out.ar(out, sig);
  107. }).add;
  108. )
  109.  
  110. Synth(\sinSine1);
  111. Synth(\sinSine1, [\amp, 0.4, \rel, rrand(2, 8)]); // Release ranges between 2 and 8 seconds.
  112.  
  113. (
  114. Synth(\sinSine1, [
  115.     \amp, rrand(0.1, 0.4),
  116.     \sinCtrl, rrand(0.25, 4), // AM ranges between 1 cycle per 4 seconds to 4 cycles per second.
  117.     \sinFreq, rrand(200, 1000), // Frequency ranges from 200Hz to 1000Hz.
  118. ]);
  119. )
  120.  
  121. // By now you see that we have been working with Amplitude Modulation, not Frequency Modulation.
  122. // Be sure to check out Part 3 of FM Basics, for a more in-depth review of FM. To be posted soon. Thank you!
Tags: fm synthesis
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement