Advertisement
SoundEngraver

Dynamic Expression (Part 5)

Mar 22nd, 2024 (edited)
561
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //////////////////////////  Dynamic Amplitude, Part 5 //////////////////////////
  2.  
  3. s.boot;
  4.  
  5. s.meter;
  6. s.scope;
  7. s.plotTree;
  8.  
  9. s.reboot;
  10. s.quit;
  11.  
  12. // Bypassing Sound Files With Two Oscillators
  13.  
  14. // Review Oscillators
  15.  
  16. {SinOsc.ar(10)}.plot(1);
  17. {LFSaw.ar(10)}.plot(1); // for bypassing
  18. {LFTri.ar(10)}.plot(1);
  19. {LFPar.ar(10)}.plot(1);
  20. {LFCub.ar(10)}.plot(1);
  21. {LFPulse.ar(10)}.plot(1); // for bypassing
  22.  
  23. {Saw.ar(10)}.plot(1); // there's no phase argument.
  24. {Pulse.ar(10)}.plot(1); // don't forget the width argument!
  25.  
  26. {VarSaw.ar(10)}.plot(1); // there's a phase AND width argument!
  27.  
  28.  
  29. {[SinOsc.ar(10), LFSaw.ar(10)]}.plot(1);
  30. {[SinOsc.ar(10), LFPulse.ar(10)]}.plot(1);
  31. {[SinOsc.ar(10), LFPulse.ar(10, add: -0.5) * 2]}.plot(1); // or write like below
  32. {[SinOsc.ar(10), LFPulse.ar(10, mul: 2, add: -1)]}.plot(1);
  33.  
  34.  
  35.  
  36. // CAUTION: Be very careful using an amplitude modulator using things other than SinOsc. Pulse.ar, for example, stacks amplitude instances one after the other when you use a width modulation.
  37. // Same with Saw.
  38.  
  39.  
  40. // Add Sound File
  41.  
  42. ~patterns = Buffer.read(s, "insertaudiofilehere");
  43.  
  44. // Name it whatever you like! I chose "~patterns" for this demo's purposes.
  45.  
  46. ~patterns.play;
  47. ~patterns.free;
  48.  
  49. ~patterns.duration;
  50. ~patterns.numChannels;
  51.  
  52. ~patterns.sampleRate;
  53.  
  54.  
  55. (
  56. ~patternSynth = SynthDef.new(\play, {
  57.     arg amp=0.5, atk=0.001, rel=8, c1=1, c2(-1),
  58.     buf=0, rate=1, spos=0, pan=0, out=0;
  59.     var sig, env;
  60.     env = Env([0, 1, 0], [atk, rel], [c1, c2]).kr(2);
  61.     sig = PlayBuf.ar(2, buf, BufRateScale.kr(buf) * rate, spos);
  62.     sig = Pan2.ar(sig, pan, amp);
  63.     sig = sig * env;
  64.     Out.ar(out, sig);
  65. }).add;
  66. )
  67.  
  68. ~patternSynth.play;
  69.  
  70.  
  71. // Replace the Envelope variable with a modulator.
  72.  
  73. // LFSaw
  74.  
  75. (
  76. ~patternLFSaw = SynthDef.new(\play, {
  77.     arg lowSaw=1, minAmp=0.001, maxAmp=1,
  78.     buf=0, rate=1, spos=0, amp=0.5, pan=0, out=0;
  79.     var sig, modAmp;
  80.     modAmp = LFSaw.kr(lowSaw).exprange(minAmp, maxAmp);
  81.     sig = PlayBuf.ar(2, buf, BufRateScale.kr(buf) * rate, spos);
  82.     sig = Pan2.ar(sig, pan, amp);
  83.     sig = sig * modAmp;
  84.     Out.ar(out, sig);
  85. }).add;
  86. )
  87.  
  88. ~patternLFSaw = Synth(\play, [\buf, ~patterns]);
  89.  
  90. ~patternLFSaw.set(\lowSaw, 1/2); // Try random \pulse values.
  91. ~patternLFSaw.free; // Free the synth if you don't have an Env or doneAction value.
  92.  
  93.  
  94.  
  95. // LFPulse
  96.  
  97. (
  98. ~patternPulse = SynthDef.new(\play, {
  99.     arg pulse=1, minAmp=0.001, maxAmp=0.5,
  100.     buf=0, rate=1, spos=0, pan=0, amp=1, out=0;
  101.     var sig, modAmp;
  102.     modAmp = LFPulse.kr(pulse).exprange(minAmp, maxAmp);
  103.     sig = PlayBuf.ar(2, buf, BufRateScale.kr(buf) * rate, spos);
  104.     sig = Pan2.ar(sig, pan, amp);
  105.     sig = sig * modAmp;
  106.     Out.ar(out, sig);
  107. }).add;
  108. )
  109.  
  110. ~patternPulse = Synth(\play, [\buf, ~patterns]);
  111.  
  112. ~patternPulse.set(\pulse, 1/8); // Try random \pulse values.
  113. ~patternPulse.free; // Free the synth if you don't have an Env or doneAction value.
  114.  
  115.  
  116.  
  117. // Include doneAction value of 2 (which frees the synth).
  118. // Remember, doneAction is only evaluated if the loop in the PlayBuf is a value of 0.
  119.  
  120. (
  121. ~patternPulse = SynthDef.new(\play, {
  122.     arg pulse=1, minAmp=0.001, maxAmp=0.5,
  123.     buf=0, rate=1, spos=0, da=2, pan=0, amp=1, out=0;
  124.     var sig, modAmp;
  125.     modAmp = LFPulse.kr(pulse).exprange(minAmp, maxAmp);
  126.     sig = PlayBuf.ar(2, buf, BufRateScale.kr(buf) * rate, spos, doneAction: da);
  127.     sig = Pan2.ar(sig, pan, amp);
  128.     sig = sig * modAmp;
  129.     Out.ar(out, sig);
  130. }).add;
  131. )
  132.  
  133. ~patternPulse = Synth(\play, [\buf, ~patterns]);
  134. ~patternPulse.set(\pulse, 1/4);
  135.  
  136.  
  137.  
  138. // If you like arguments spelled out...
  139.  
  140. (
  141. ~patternPulse = SynthDef.new(\play, {
  142.     arg pulse=1, minAmp=0.001, maxAmp=0.5,
  143.     buf=0, rate=1, spos=0, da= 2, pan=0, amp=1, out=0;
  144.     var sig, modAmp;
  145.     modAmp = LFPulse.kr(pulse).exprange(minAmp, maxAmp);
  146.     sig = PlayBuf.ar(
  147.         numChannels: 2,
  148.         bufnum: buf,
  149.         rate: BufRateScale.kr(buf) * rate,
  150.         startPos: spos,
  151.         doneAction: da);
  152.     sig = Pan2.ar(sig, pan, amp);
  153.     sig = sig * modAmp;
  154.     Out.ar(out, sig);
  155. }).add;
  156. )
  157.  
  158. ~patternPulse = Synth(\play, [\buf, ~patterns]);
  159. ~patternPulse.set(\pulse, 1/4);
  160.  
  161.  
  162. // Loop it!
  163.  
  164. (
  165. ~patternPulse = SynthDef.new(\play, {
  166.     arg pulse=1, minAmp=0.001, maxAmp=0.5,
  167.     buf=0, rate=1, spos=0, loop=1, pan=0, amp=1, out=0;
  168.     var sig, modAmp;
  169.     modAmp = LFPulse.kr(pulse).exprange(minAmp, maxAmp);
  170.     sig = PlayBuf.ar(
  171.         numChannels: 2,
  172.         bufnum: buf,
  173.         rate: BufRateScale.kr(buf) * rate,
  174.         startPos: spos,
  175.         loop: loop); // A value of 1 means true, and a value of 0 means false.
  176.     sig = Pan2.ar(sig, pan, amp);
  177.     sig = sig * modAmp;
  178.     Out.ar(out, sig);
  179. }).add;
  180. )
  181.  
  182. ~patternPulse = Synth(\play, [\buf, ~patterns]);
  183. ~patternPulse.set(\pulse, 1/8); // 4 seconds of sound; 4 seconds of silence.
  184. ~patternPulse.set(\loop, 0); // The loop will stop after running through the sound file.
  185. ~patternPulse.free; // Free the synth if you don't have an Env or doneAction value.
  186.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement