Advertisement
SoundEngraver

Dynamic Expression (Part 2)

Jan 15th, 2024 (edited)
1,634
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //////////////////////////  Dynamic Amplitude, Part 2 //////////////////////////
  2.  
  3. s.boot;
  4.  
  5. s.meter;
  6. s.scope;
  7. s.plotTree;
  8.  
  9. s.reboot;
  10. s.quit;
  11.  
  12.  
  13. (
  14. ~triAmp = {
  15.     var sig;
  16.     sig = LFTri.ar(300, 0, 0.01)!2;
  17. }.play;
  18. )
  19.  
  20. ~triAmp.free;
  21.  
  22. // Adding arguments.
  23.  
  24. (
  25. ~triAmp = {
  26.     arg freq=300, amp=0.03;
  27.     var sig;
  28.     sig = LFTri.ar(freq, 0, amp)!2;
  29. }.play;
  30. )
  31.  
  32. ~triAmp.free;
  33.  
  34. // Adding variables to control the frequency modulation in the sawtooth wave.
  35.  
  36. (
  37. ~triAmp = {
  38.     arg freq=300, amp=0.03;
  39.     var sig, freqNoise;
  40.     freqNoise = LFNoise0.kr(8).range(100, 1000);
  41.     sig = LFTri.ar(freqNoise, 0, amp)!2;
  42. }.play;
  43. )
  44.  
  45. ~triAmp.free;
  46.  
  47. // Add another variable for amplitude modulation.
  48.  
  49. (
  50. ~triAmp = {
  51.     arg sine=1, noise=4;
  52.     var sig, freqNoise, modAmp;
  53.     modAmp = SinOsc.kr(sine).exprange(0.001, 0.3);
  54.     freqNoise = LFNoise0.kr(noise).range(100, 1000);
  55.     sig = LFTri.ar(freqNoise, 0, modAmp)!2;
  56. }.play
  57. )
  58.  
  59. ~triAmp.set(\sine, 1/8);
  60. ~triAmp.set(\noise, 9);
  61.  
  62. ~triAmp.free;
  63.  
  64.  
  65. (
  66. ~triAmp = {
  67.     arg sine=1, noise=4, modMin=0.001, modMax=0.3,
  68.     freqMin=100, freqMax=1000;
  69.     var sig, freqNoise, modAmp;
  70.     modAmp = SinOsc.kr(sine).exprange(modMin, modMax);
  71.     freqNoise = LFNoise0.kr(noise).range(freqMin, freqMax);
  72.     sig = LFTri.ar(freqNoise, 0, modAmp)!2;
  73. }.play
  74. )
  75.  
  76.  
  77. ~triAmp.set(\sine, 1/4);
  78. ~triAmp.set(\noise, 18);
  79. ~triAmp.set(\modMin, 0.01);
  80. ~triAmp.set(\modMax, 0.2);
  81.  
  82. ~triAmp.free;
  83.  
  84.  
  85. // 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.
  86. // Same with Saw.
  87.  
  88. // SinOsc
  89.  
  90. (
  91. ~sineAmp = {
  92.     arg sine=1, noise=4;
  93.     var sig, freqNoise, modAmp;
  94.     modAmp = SinOsc.kr(sine).exprange(0.001, 0.1);
  95.     freqNoise = SinOsc.kr(noise).range(100, 1000);
  96.     sig = SinOsc.ar(freqNoise, 0, modAmp)!2;
  97. }.play
  98. )
  99.  
  100. ~sineAmp.set(\sine, 6);
  101. ~sineAmp.set(\noise, 2);
  102.  
  103. ~sineAmp.free;
  104.  
  105. // LFSaw
  106.  
  107. (
  108. ~sawAmp = {
  109.     arg sine=1, noise=4;
  110.     var sig, freqNoise, modAmp;
  111.     modAmp = SinOsc.kr(sine).exprange(0.001, 0.1);
  112.     freqNoise = SinOsc.kr(noise).range(100, 1000);
  113.     sig = LFSaw.ar(freqNoise, 0, modAmp)!2;
  114. }.play
  115. )
  116.  
  117. ~sawAmp.set(\sine, 1/8);
  118. ~sawAmp.set(\noise, 7);
  119.  
  120. ~sawAmp.free;
  121.  
  122. // LFTri
  123.  
  124. (
  125. ~triAmp = {
  126.     arg sine=1, noise=4;
  127.     var sig, freqNoise, modAmp;
  128.     modAmp = SinOsc.kr(sine).exprange(0.001, 0.1);
  129.     freqNoise = SinOsc.kr(noise).range(100, 1000);
  130.     sig = LFTri.ar(freqNoise, 0, modAmp)!2;
  131. }.play
  132. )
  133.  
  134. ~triAmp.set(\sine, 8);
  135. ~triAmp.set(\noise, 20);
  136.  
  137. ~triAmp.free;
  138.  
  139. // LFPar
  140.  
  141. (
  142. ~parAmp = {
  143.     arg sine=1, noise=4;
  144.     var sig, freqNoise, modAmp;
  145.     modAmp = SinOsc.kr(sine).exprange(0.001, 0.1);
  146.     freqNoise = SinOsc.kr(noise).range(100, 1000);
  147.     sig = LFPar.ar(freqNoise, 0, modAmp)!2;
  148. }.play
  149. )
  150.  
  151. ~parAmp.set(\sine, 1/4);
  152. ~parAmp.set(\noise, 12);
  153.  
  154. ~parAmp.free;
  155.  
  156. // Pulse
  157.  
  158. (
  159. ~pulseTest = {
  160.     arg sine=1, noise=4;
  161.     var sig, freqNoise, modAmp;
  162.     modAmp = SinOsc.kr(sine).exprange(0.001, 0.1);
  163.     freqNoise = SinOsc.kr(noise).range(100, 1000);
  164.     sig = Pulse.ar(freqNoise, 0.5, modAmp)!2;
  165. }.play
  166. )
  167.  
  168. ~pulseTest.set(\sine, 1/8);
  169. ~pulseTest.set(\noise, 1);
  170.  
  171. ~pulseTest.free;
  172.  
  173. // LFPulse
  174.  
  175. (
  176. ~pulseAmp = {
  177.     arg sine=1, noise=4;
  178.     var sig, freqNoise, modAmp;
  179.     modAmp = SinOsc.kr(sine).exprange(0.001, 0.1);
  180.     freqNoise = SinOsc.kr(noise).range(100, 1000);
  181.     sig = LFPulse.ar(freqNoise, 0, 0.5, modAmp)!2;
  182. }.play
  183. )
  184.  
  185. ~pulseAmp.set(\sine, 8);
  186. ~pulseAmp.set(\noise, 20);
  187.  
  188. ~pulseAmp.free;
  189.  
  190. // LFCub
  191.  
  192. (
  193. ~cubAmp = {
  194.     arg sine=1, noise=4;
  195.     var sig, freqNoise, modAmp;
  196.     modAmp = SinOsc.kr(sine).exprange(0.001, 0.1);
  197.     freqNoise = SinOsc.kr(noise).range(100, 1000);
  198.     sig = LFCub.ar(freqNoise, 0, modAmp)!2;
  199. }.play
  200. )
  201.  
  202. ~cubAmp.set(\sine, 12);
  203. ~cubAmp.set(\noise, 1);
  204.  
  205. ~cubAmp.free;
  206.  
  207. // Saw
  208.  
  209. (
  210. ~sawTest = {
  211.     arg sine=1, noise=4;
  212.     var sig, freqNoise, modAmp;
  213.     modAmp = SinOsc.kr(sine).exprange(0.001, 0.1);
  214.     freqNoise = SinOsc.kr(noise).range(100, 1000);
  215.     sig = Saw.ar(freqNoise, modAmp)!2;
  216. }.play
  217. )
  218.  
  219. ~sawTest.set(\sine, 8);
  220. ~sawTest.set(\noise, 1/2);
  221.  
  222. ~sawTest.free;
  223.  
  224. // VarSaw
  225.  
  226. (
  227. ~varAmp = {
  228.     arg sine=1, noise=4;
  229.     var sig, freqNoise, modAmp;
  230.     modAmp = SinOsc.kr(sine).exprange(0.001, 0.1);
  231.     freqNoise = SinOsc.kr(noise).range(100, 1000);
  232.     sig = VarSaw.ar(freqNoise, 0, 0.5, modAmp)!2; // Don't forget the width argument!
  233. }.play
  234. )
  235.  
  236. ~varAmp.set(\sine, 1/2);
  237. ~varAmp.set(\noise, 1/16);
  238.  
  239. ~varAmp.free;
  240.  
  241.  
  242. // Apply this to noise.
  243.  
  244. (
  245. ~pinkNoise = {
  246.     arg freq=0.25, amp=0.2;
  247.     var sig, mod;
  248.     mod = SinOsc.ar(freq: freq, phase: pi, mul: 0.5, add: 0.5);
  249.     sig = PinkNoise.ar(amp)!2; // Go between PinkNoise and BrownNoise.
  250.     sig = sig * mod;
  251. };
  252. )
  253.  
  254. x = ~pinkNoise.play;
  255. x.release(8);
  256.  
  257. (
  258. ~pinkNoiseCtrl = {
  259.     arg sine=4, amp=1;
  260.     var sig, modAmp;
  261.     modAmp = LFPar.kr(sine).exprange(0.001, 0.1);
  262.     // Change waveform (e.g, LFTri, LFSaw, etc.)
  263.     sig = PinkNoise.ar(amp)!2;
  264.     sig = sig * modAmp;
  265. }.play
  266. )
  267.  
  268. ~pinkNoiseCtrl.set(\sine, 3);
  269. ~pinkNoiseCtrl.free;
  270.  
  271.  
  272. // Add Sound File
  273.  
  274. ~ice = Buffer.read(s, "insertaudiofilehere");
  275.  
  276. // My original audio file is an icy synth. Hence the name ~ice.
  277. // You can name a sound anything with "~".
  278.  
  279. ~ice.play;
  280. ~ice.free;
  281.  
  282. ~ice.duration;
  283. ~ice.numChannels;
  284.  
  285.  
  286. // Play Synth
  287.  
  288. (
  289. ~ice = SynthDef.new(\play, {
  290.     arg amp=1, atk=0.001, rel=3, c1=1, c2(-1),
  291.     buf=0, rate=1, spos=0, pan=0, out=0;
  292.     var sig, env;
  293.     env = Env([0, 1, 0], [atk, rel], [c1, c2]).kr(2);
  294.     sig = PlayBuf.ar(
  295.         2,
  296.         buf,
  297.         BufRateScale.ir(buf),
  298.         spos
  299.     );
  300.     sig = sig * env;
  301.     pan = Pan2.ar(sig, pan, amp);
  302.     Out.ar(out, sig);
  303. }).add;
  304. )
  305.  
  306. ~ice.play;
  307.  
  308. // Replace the Envelope variable with a modulator.
  309.  
  310. // SinOsc
  311.  
  312. (
  313. ~iceSine = SynthDef.new(\play, {
  314.     arg sine=1, minAmp=0.001, maxAmp=1,
  315.     buf=0, rate=1, spos=0, pan=0, amp=1, out=0;
  316.     var sig, modAmp;
  317.     modAmp = SinOsc.kr(sine).exprange(minAmp, maxAmp);
  318.     sig = PlayBuf.ar(
  319.         2,
  320.         buf,
  321.         BufRateScale.ir(buf),
  322.         spos
  323.     );
  324.     sig = sig * modAmp;
  325.     pan = Pan2.ar(sig, pan, amp);
  326.     Out.ar(out, sig);
  327. }).add;
  328. )
  329.  
  330. ~iceSine = Synth(\play, [\buf, ~ice]);
  331.  
  332. ~iceSine.set(\sine, 1/4);
  333. ~iceSine.free;
  334.  
  335. // Saw (I like this one!)
  336.  
  337. (
  338. ~iceSaw = SynthDef.new(\play, {
  339.     arg saw=1, minAmp=0.001, maxAmp=1,
  340.     buf=0, rate=1, spos=0, pan=0, amp=1, out=0;
  341.     var sig, modAmp;
  342.     modAmp = Saw.kr(saw).exprange(minAmp, maxAmp);
  343.     sig = PlayBuf.ar(
  344.         2,
  345.         buf,
  346.         BufRateScale.ir(buf),
  347.         spos
  348.     );
  349.     sig = sig * modAmp;
  350.     pan = Pan2.ar(sig, pan, amp);
  351.     Out.ar(out, sig);
  352. }).add;
  353. )
  354.  
  355. ~iceSaw = Synth(\play, [\buf, ~ice]);
  356.  
  357. ~iceSaw.set(\saw, 15);
  358. ~iceSaw.free;
  359.  
  360. // LFSaw
  361.  
  362. (
  363. ~iceLFSaw = SynthDef.new(\play, {
  364.     arg lowSaw=1, minAmp=0.001, maxAmp=0.8,
  365.     buf=0, rate=1, spos=0, pan=0, amp=1, out=0;
  366.     var sig, modAmp;
  367.     modAmp = LFSaw.kr(lowSaw).exprange(minAmp, maxAmp);
  368.     sig = PlayBuf.ar(
  369.         2,
  370.         buf,
  371.         BufRateScale.ir(buf),
  372.         spos
  373.     );
  374.     sig = sig * modAmp;
  375.     pan = Pan2.ar(sig, pan, amp);
  376.     Out.ar(out, sig);
  377. }).add;
  378. )
  379.  
  380. ~iceLFSaw = Synth(\play, [\buf, ~ice]);
  381.  
  382. ~iceLFSaw.set(\lowSaw, 32);
  383. ~iceLFSaw.free;
  384.  
  385. // LFTri
  386.  
  387. (
  388. ~iceTri = SynthDef.new(\play, {
  389.     arg tri=1, minAmp=0.001, maxAmp=0.8,
  390.     buf=0, rate=1, spos=0, pan=0, amp=1, out=0;
  391.     var sig, modAmp;
  392.     modAmp = LFTri.kr(tri).exprange(minAmp, maxAmp);
  393.     sig = PlayBuf.ar(
  394.         2,
  395.         buf,
  396.         BufRateScale.ir(buf),
  397.         spos
  398.     );
  399.     sig = sig * modAmp;
  400.     pan = Pan2.ar(sig, pan, amp);
  401.     Out.ar(out, sig);
  402. }).add;
  403. )
  404.  
  405. ~iceTri = Synth(\play, [\buf, ~ice]);
  406.  
  407. ~iceTri.set(\tri, 8);
  408. ~iceTri.free;
  409.  
  410. // LFCub
  411.  
  412. (
  413. ~iceCube = SynthDef.new(\play, {
  414.     arg cube=1, minAmp=0.001, maxAmp=0.8,
  415.     buf=0, rate=1, spos=0, pan=0, amp=1, out=0;
  416.     var sig, modAmp;
  417.     modAmp = LFCub.kr(cube).exprange(minAmp, maxAmp);
  418.     sig = PlayBuf.ar(
  419.         2,
  420.         buf,
  421.         BufRateScale.ir(buf),
  422.         spos
  423.     );
  424.     sig = sig * modAmp;
  425.     pan = Pan2.ar(sig, pan, amp);
  426.     Out.ar(out, sig);
  427. }).add;
  428. )
  429.  
  430. ~iceCube = Synth(\play, [\buf, ~ice]);
  431.  
  432. ~iceCube.set(\cube, 2);
  433. ~iceCube.free;
  434.  
  435. // VarSaw
  436.  
  437. (
  438. ~iceVarSaw = SynthDef.new(\play, {
  439.     arg varSaw=1, minAmp=0.001, maxAmp=0.8,
  440.     buf=0, rate=1, spos=0, pan=0, amp=1, out=0;
  441.     var sig, modAmp;
  442.     modAmp = VarSaw.kr(varSaw).exprange(minAmp, maxAmp);
  443.     sig = PlayBuf.ar(
  444.         2,
  445.         buf,
  446.         BufRateScale.ir(buf),
  447.         spos
  448.     );
  449.     sig = sig * modAmp;
  450.     pan = Pan2.ar(sig, pan, amp);
  451.     Out.ar(out, sig);
  452. }).add;
  453. )
  454.  
  455. ~iceVarSaw = Synth(\play, [\buf, ~ice]);
  456.  
  457. ~iceVarSaw.set(\varSaw, 1/16);
  458. ~iceVarSaw.free;
  459.  
  460. // LFPulse
  461.  
  462. (
  463. ~icePulse = SynthDef.new(\play, {
  464.     arg pulse=1, minAmp=0.001, maxAmp=0.1,
  465.     buf=0, rate=1, spos=0, pan=0, amp=1, out=0;
  466.     var sig, modAmp;
  467.     modAmp = LFPulse.kr(pulse).exprange(minAmp, maxAmp);
  468.     sig = PlayBuf.ar(
  469.         2,
  470.         buf,
  471.         BufRateScale.ir(buf),
  472.         spos
  473.     );
  474.     sig = sig * modAmp;
  475.     pan = Pan2.ar(sig, pan, amp);
  476.     Out.ar(out, sig);
  477. }).add;
  478. )
  479.  
  480. ~icePulse = Synth(\play, [\buf, ~ice]);
  481.  
  482. ~icePulse.set(\pulse, 4); // an idea for bypassing?
  483. ~icePulse.free;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement