Advertisement
SoundEngraver

Dynamic Expression (Part 1)

Jan 8th, 2024 (edited)
830
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // How To Dynamically Change Amplitude
  2.  
  3. // This could be a great expression for sound.
  4. // Control variables will function like an Envelope.
  5.  
  6. // For a demonstration, here's my YouTube video: https://youtu.be/FDiig0taAwM
  7.  
  8. s.boot;
  9.  
  10. s.meter;
  11. s.scope;
  12. s.plotTree;
  13.  
  14. s.reboot;
  15. s.quit;
  16.  
  17. // Here's a Function for a simple synth.
  18.  
  19. {SinOsc.ar(300, 0, 0.2)}.play;
  20.  
  21. // Cmd Period for a hard stop.
  22.  
  23. // Give this Function a name.
  24. // Change mono to stereo, by using shortcut "!2"
  25.  
  26. (
  27. ~mySine = {
  28.     var sig;
  29.     sig = SinOsc.ar(300, 0, 0.05)!2;
  30. }.play;
  31. )
  32.  
  33. ~mySine.free;
  34.  
  35. // Use arguments to change values in real time. SC won't keep stacking synths this way.
  36.  
  37. (
  38. ~mySine = {
  39.     arg freq=300, amp=0.1;
  40.     var sig;
  41.     sig = SinOsc.ar(freq, 0, amp)!2;
  42. }.play;
  43. )
  44.  
  45. ~mySine.set(\freq, rrand(300, 1000));
  46. ~mySine.set(\amp, rand(0.1, 1));
  47.  
  48. ~mySine.free;
  49.  
  50. // Let's control the signal with other variables.
  51. // For testing, I recommend low amplitude.
  52.  
  53. (
  54. ~myNoise = {
  55.     arg amp=0.1;
  56.     var sig, freqNoise;
  57.     freqNoise = LFNoise0.kr(8).range(200, 1000); // step noise osc to control sine wave
  58.     sig = SinOsc.ar(freqNoise, 0, amp)!2;
  59. }.play;
  60. )
  61.  
  62. ~myNoise.set(\amp, rrand(0.05, 0.3));
  63.  
  64. ~myNoise.free;
  65.  
  66. // Let's modulate the amplitude.
  67.  
  68. (
  69. ~myAmp = { // Notice, we don't need an arg for amplitude.
  70.     var sig, freqNoise, modAmp;
  71.     modAmp = SinOsc.kr(1).exprange(0.01, 0.5); // Suggestion: Go between SinOsc values, 1/8 and 1.
  72.     freqNoise = LFNoise0.kr(8).range(200, 1000);
  73.     sig = SinOsc.ar(freqNoise, 0, modAmp)!2;
  74. }.play;
  75. )
  76.  
  77. ~myAmp.free;
  78.  
  79. // Let's randomize the amplitude.
  80.  
  81. (
  82. ~myAmp = {
  83.     var sig, freqNoise, ampNoise;
  84.     ampNoise = LFNoise0.kr(4).exprange(0.05, 0.5);
  85.     freqNoise = LFNoise0.kr(4).range(200, 1000);
  86.     sig = SinOsc.ar(freqNoise, 0, ampNoise)!2;
  87. }.play;
  88. )
  89.  
  90. ~myAmp.free;
  91.  
  92. // Let's add more arguments to change values in real time.
  93.  
  94. (
  95. ~myAmp = {
  96.     arg ampCtrl=8, minAmp=0.05, maxAmp=0.5,
  97.     freqCtrl=8, minFreq=200, maxFreq=1000;
  98.     var sig, freqNoise, ampNoise;
  99.     ampNoise = LFNoise0.kr(ampCtrl).exprange(minAmp, maxAmp);
  100.     freqNoise = LFNoise0.kr(freqCtrl).range(minFreq, maxFreq);
  101.     sig = SinOsc.ar(freqNoise, 0, ampNoise)!2;
  102. }.play;
  103. )
  104.  
  105. ~myAmp.set(\ampCtrl, rrand(1, 4), \freqCtrl, rrand(4, 8));
  106. ~myAmp.set(\minAmp, rrand(0.01, 0.01), \maxAmp, rrand(0.1, 0.3));
  107. ~myAmp.set(\minFreq, rrand(100, 1000), \maxFreq, rrand(1000, 3000));
  108.  
  109. ~myAmp.free;
  110.  
  111.  
  112. // Let's play with other UGens for the same amplitude modulator, starting with this model below.
  113.  
  114. //////////////////////////////////////////////////////////////////////////////
  115.  
  116. // Plot the different control UGens to see the cycles' default phase.
  117.  
  118. {SinOsc.ar(10)}.plot(1);
  119. {LFSaw.ar(10)}.plot(1);
  120. {LFTri.ar(10)}.plot(1);
  121. {LFPar.ar(10)}.plot(1);
  122. {LFCub.ar(10)}.plot(1);
  123. {LFPulse.ar(10)}.plot(1);
  124.  
  125. {Saw.ar(10)}.plot(1); // there's no phase argument.
  126. {Pulse.ar(10)}.plot(1); // don't forget the width argument!
  127.  
  128. {VarSaw.ar(10)}.plot(1); // there's a phase AND width argument!
  129.  
  130. {[SinOsc.ar(10), LFSaw.ar(10)]}.plot(1);
  131. {[SinOsc.ar(10), LFTri.ar(10)]}.plot(1);
  132. {[SinOsc.ar(10), LFPar.ar(10)]}.plot(1); // NOTE: LFPar.ar(10) is SinOsc.ar(10, pi/2)
  133. {[SinOsc.ar(10), LFCub.ar(10)]}.plot(1); // Default phase value creates the same result.
  134. {[SinOsc.ar(10), LFPulse.ar(10, width: 0.5, mul: 2, add: -1)]}.plot(1); // Try Lag UGen for this.
  135. {[SinOsc.ar(10), VarSaw.ar(10)]}.plot(1);
  136.  
  137.  
  138. // Mix and match. Don't forget to change the phase values.
  139. // Phase value types (refer to the Pink Noise doc): 0, pi, 3pi/2, pi/2
  140. // Mul and add values will help keep the bipolarity (-1 to 1, crossing 0).
  141.  
  142. {[LFPar.ar(10), LFCub.ar(10)]}.plot(1);
  143. {[LFTri.ar(10), LFSaw.ar(10)]}.plot(1);
  144. {[LFSaw.ar(10), VarSaw.ar(10)]}.plot(1);
  145. {[LFTri.ar(10), VarSaw.ar(10)]}.plot(1);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement