Advertisement
SoundEngraver

Dynamic Expression (Part 4)

Feb 7th, 2024 (edited)
1,437
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //////////////////////////  Dynamic Amplitude, Part 4 //////////////////////////
  2.  
  3. // You can find a YouTube demonstration here: https://youtu.be/D4klks4sbwU
  4.  
  5. s.boot;
  6.  
  7. s.meter;
  8. s.scope;
  9. s.plotTree;
  10.  
  11. s.reboot;
  12. s.quit;
  13.  
  14. // Drum Loop (Or Any Sound File)
  15.  
  16. ~drums = Buffer.read(s, "insertdrumloophere"); // (Or any other kind of sound file.)
  17.  
  18. // I use "~drums" for my drum loop file, but you can use any name with "~".
  19.  
  20. ~drums.play;
  21. ~drums.free; // Be sure to free synths as much as possible to free up CPU.
  22.  
  23. ~drums.duration; // If you would like to see the sound file's duration.
  24. ~drums.numChannels; // If you would like to see how many channels it has.
  25.  
  26.  
  27. // Explore loopNode
  28.  
  29. // Release node is node 2. Loop node is node 0.
  30. // So it loops around nodes 0 (levels 0 to 1, dur 4) and 1 (levels 1 to 0.1, dur 0.5) until released after 12 seconds.
  31.  
  32. (
  33. Env([0, 1, 0.1, 0] * 0.25,
  34.     // This mono sine tone may be high in volume.
  35.     // Scale it back by a value, like 0.25 (25% the given amplitude)
  36.     [4, 0.5, 2],
  37.     'lin',
  38.     2,
  39.     0
  40. ).test(10).plot; // I chose a value of 10, as my drum loop for this demo is 10 seconds.
  41. )
  42.  
  43. // Here's a different way of writing it.
  44.  
  45. (
  46. Env(
  47.     [0, 1, 0.1, 0] * 0.25,
  48.     [1, 0.1, 2],
  49.     // Notice my first two time levels are shorter. This is more effective for my own drums. Explore different values for different sound files.
  50.     'linear',
  51.     2,
  52.     loopNode: 0
  53. ).test(10).plot
  54. )
  55.  
  56. //////////// Apply To Drum Loop ////////////
  57.  
  58. (
  59. ~tortoDrums = SynthDef(\play, {
  60.     arg amp=1, atk=1, sus=0.1, rel=2, buf=0, rate=1,
  61.     spos=0, pan=0, out=0;
  62.     var sig, env;
  63.     env = Env(
  64.         [0, 1, 0.1, 0],
  65.         [atk, sus, rel],
  66.         curve: 'linear',
  67.         releaseNode: 2,
  68.         loopNode: 0
  69.     ).kr(2);
  70.     sig = PlayBuf.ar(
  71.         2,
  72.         buf,
  73.         BufRateScale.ir(buf) * rate,
  74.         spos
  75.     );
  76.     sig = sig * env;
  77.     pan = Pan2.ar(sig, pan, amp);
  78.     Out.ar(out, sig);
  79. }).add;
  80. )
  81.  
  82. ~tortoDrums = Synth(\play, [\buf, ~drums]);
  83. ~tortoDrums.free; // Free the synth if you don't have an Env or doneAction value.
  84.  
  85.  
  86. (
  87. Env(
  88.     [0, 1, 0.2, 0.3, 0] * 0.25, // Be sure to use low amplitude for this test.
  89.     [2, 3, 1, 4] * 0.25, // Here's quick way to shorten time levels.
  90.     8, // Explore both positive and negative values for different effects.
  91.     releaseNode: 2,
  92.     loopNode: 0
  93. ).test(10).plot;
  94. )
  95.  
  96. (
  97. ~tortoDrums = SynthDef(\play, {
  98.     arg amp=1, atk=2, sus=3, decay=1, rel=4,
  99.     buf=0, rate=1, spos=0, pan=0, out=0;
  100.     var sig, env;
  101.     env = Env(
  102.         [0, 0.3, 0.2, 1, 0] * 0.75,
  103.         // Use a multiplier less than 1 for a lower output (if necessary).
  104.         [atk, sus, decay, rel] * 0.25,
  105.         8, // Always explore different curve values!
  106.         releaseNode: 3
  107.     ).kr(2);
  108.     sig = PlayBuf.ar(
  109.         2,
  110.         buf,
  111.         rate: BufRateScale.ir(buf) * rate,
  112.         startPos: spos
  113.     );
  114.     sig = sig * env;
  115.     pan = Pan2.ar(sig, pan, amp);
  116.     Out.ar(out, sig);
  117. }).add;
  118. )
  119.  
  120. ~tortoDrums = Synth(\play, [\buf, ~drums]);
  121. ~tortoDrums.free; // Free the synth if you don't have an Env or doneAction value.
  122.  
  123. (
  124. Env(
  125.     [0, 1, 0.01, 0.5, 0.05, 0.8, 0] * 0.25,
  126.     [1, 1, 1, 1, 1, 1],
  127.     2,
  128.     releaseNode: 3,
  129.     loopNode: 1
  130. ).test(10).plot;
  131. )
  132.  
  133. // If you like arguments spelled out...
  134.  
  135. (
  136. ~tortoDrums = SynthDef(\play, {
  137.     arg atk=1, sus1=3, sus2=1, sus3=1, decay=1, rel=1,
  138.     buf=0, rate=1, spos=0, pan=0, amp=1, out=0;
  139.     var sig, env;
  140.     env = Env(
  141.         [0, 1, 0.01, 0.5, 0.05, 0.8, 0],
  142.         [atk, sus1, sus2, sus3, decay, rel],
  143.         5,
  144.         releaseNode: 3,
  145.         loopNode: 1,
  146.     ).kr(2);
  147.     sig = PlayBuf.ar(
  148.         numChannels: 2,
  149.         bufnum: buf,
  150.         rate: BufRateScale.ir(buf),
  151.         startPos: spos
  152.     );
  153.     sig = sig * env;
  154.     pan = Pan2.ar(sig, pan, amp);
  155.     Out.ar(out, sig);
  156. }).add;
  157. )
  158.  
  159. ~tortoDrums = Synth(\play, [\buf, ~drums]);
  160. ~tortoDrums.free; // Free the synth if you don't have an Env or doneAction value.
  161.  
  162. // To release the synth with a doneAction value, you need one in the PlayBuf.
  163. // The Envelope in this scenario is for the amplitude. It does not release the synth.
  164. // For a further explanation, stay tuned for Part 5.
  165.  
  166.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement