Advertisement
SoundEngraver

Pink Noise

May 31st, 2023 (edited)
582
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ///////////////////////////////// PINK NOISE /////////////////////////////////
  2.  
  3. s.boot;
  4.  
  5. s.meter;
  6. s.scope;
  7. s.plotTree;
  8.  
  9.  
  10. // Only use when necessary. It isn't always needed.
  11.  
  12. s.reboot;
  13. s.quit;
  14.  
  15.  
  16. ///////////////////// Things To Know Before Running Code /////////////////////
  17.  
  18. /*
  19.  
  20. All my original SC documents are in the "dracula" color.
  21. To find or change this, go To SuperCollider ––> Preferences ––> Editor ––> Font & Colors.
  22. ––> Select under Color, dracula.
  23.  
  24. Arguments in Synths are represented with a backslash, "\", in green under the "dracula" color font. Values presented with these arguments can be changed. Only remember to NEVER cross 0, when using an exponential method like "exprand."
  25.  
  26. Arguments also precede a colon ":", as seen in a list of a UGen following a variable, "var."
  27. Example: sig = PlayBuf.ar(2, buf, rate, startPos: spos);
  28.  
  29. Argument and variable names can be changed to your liking.
  30.  
  31. 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.
  32.  
  33. You can always execute a hard stop with Command Period.
  34.  
  35. */
  36.  
  37.  
  38.  
  39. ////////////////////////////// Pink Noise Function ///////////////////////////////
  40.  
  41. {PinkNoise.ar(mul: 0.2, add: 0.0)}.play; // mono
  42.  
  43. // Press Cmd Period to stop the synth instantaneously. Or Windows Period.
  44.  
  45. // The argument names followed by a ":" isn't necessary.
  46. // Arguments in the UGen array must be in order (e.g. mul, then add)
  47. // If you do not write in the arguments, it outputs the default values (which you can bring up with keying Shift+Cmd+Space, or Shift+Windows+Space, for Windows).
  48.  
  49. // You can convert the mono signal to a stereo signal, using "!2."
  50.  
  51. {PinkNoise.ar(0.2)!2}.play; // stereo
  52.  
  53. // Evaluate the following code to see the new array:
  54.  
  55. PinkNoise.ar(0.2)!2
  56.  
  57. // Compare it with the previous function, without the "!2."
  58.  
  59. PinkNoise.ar(0.2)
  60.  
  61.  
  62. (
  63. ~pink = {
  64.     arg mul=0.2;
  65.     var sig;
  66.     sig = PinkNoise.ar(mul)!2;
  67. };
  68. )
  69.  
  70. x = ~pink.play;
  71. x.release(3); // release the synth over 3 seconds
  72.  
  73.  
  74. x = ~pink.play;
  75. x.set(\mul, 0.05);
  76. x.release(1);
  77.  
  78.  
  79. // OCEAN WAVE
  80.  
  81. // Add the control variable, SinOsc, to create the effect of ocean waves.
  82. // Note, using the ".kr" method is less CPU expensive than using ".ar".
  83. // The ".ar" method is typically used for an audio signal (e.g., output we can hear), because its smoothness is greater than that produced by ".kr."
  84. // NOTE: We will not need smoothness for this kind of noise generation.
  85.  
  86.  
  87. (
  88. ~pinkNoise = {
  89.     arg freq=1/4, mul=0.5; // 1/4 translates into 1 wave every 4 seconds
  90.     var sig, mod;
  91.     mod = SinOsc.kr(freq: freq, phase: 0, mul: mul, add: 0);
  92.     sig = PinkNoise.ar(mul)!2;
  93.     sig = sig * mod;
  94. };
  95. )
  96.  
  97. x = ~pinkNoise.play;
  98. x.release(8);
  99.  
  100. // It's a good sound, but let's compare different phase values.
  101.  
  102. // phase: 0
  103. {SinOsc.ar(phase: 0)}.plot;
  104. {SinOsc.kr(phase: 0)}.plot;
  105.  
  106.  
  107. // Compare the smoothness of the two rate methods.
  108.  
  109. (
  110. {[SinOsc.ar(phase: 0), SinOsc.kr(phase: 0)]}.plot;
  111. )
  112.  
  113. // phase: 2pi is the same as phase: 0.
  114. // See below.
  115.  
  116. (
  117. {[SinOsc.ar(phase: 0), SinOsc.ar(phase: 2pi)]}.plot;
  118. )
  119.  
  120. // phase: pi
  121. {SinOsc.ar(phase: pi)}.plot;
  122. {SinOsc.kr(phase: pi)}.plot;
  123.  
  124. // Compare the smoothness of the two rate methods.
  125.  
  126. (
  127. {[SinOsc.ar(phase: pi), SinOsc.kr(phase: pi)]}.plot;
  128. )
  129.  
  130. // We want the contrary motion, the rising to +1 in the bipolar cycle.
  131.  
  132. {SinOsc.ar(phase: 3pi/2)}.plot;
  133. {SinOsc.kr(phase: 3pi/2)}.plot;
  134.  
  135. // Compare the smoothness of the two rate methods.
  136.  
  137. (
  138. {[SinOsc.ar(phase: 3pi/2), SinOsc.kr(phase: 3pi/2)]}.plot;
  139. )
  140.  
  141. // Compare 0 and 3pi/2 for phase (using ".ar"):
  142.  
  143. (
  144. {[SinOsc.ar(phase: 0), SinOsc.ar(phase: 3pi/2)]}.plot;
  145. )
  146.  
  147. // 3pi/2 on the bottom panel is the motion I'm looking for. But it still starts at -1 before crossing 0. Reduce the output by half, by giving "mul" the value of 0.5.
  148.  
  149. // For the record, we'll keep this SinOsc with an audio rate.
  150.  
  151. {SinOsc.ar(phase: 3pi/2, mul: 0.5)}.plot;
  152.  
  153. // Now give the "add" argument the value, 0.5, so that the intial sample will begin on 0.
  154.  
  155. {SinOsc.ar(phase: 3pi/2, mul: 0.5, add: 0.5)}.plot;
  156.  
  157. // With this, we should have our "ocean wave" start at 0, rising to 1, and falling to 0, in the duration provided (e.g. using the "freq" argument).
  158.  
  159. // Note, pi/2 is the opposite motion. Compare the two different phases.
  160.  
  161. {SinOsc.ar(phase: pi/2, mul: 0.5, add: 0.5)}.plot;
  162. {SinOsc.ar(phase: 3pi/2, mul: 0.5, add: 0.5)}.plot;
  163.  
  164.  
  165. (
  166. {[SinOsc.ar(phase: pi/2, mul: 0.5, add: 0.5), SinOsc.ar(phase: 3pi/2, mul: 0.5, add: 0.5)]}.plot;
  167. )
  168.  
  169.  
  170. (
  171. ~pinkNoise = {
  172.     arg freq=0.25, amp=0.2;
  173.     // 0.25 (or 1/4) is translated into 1 wave every 4 seconds.
  174.     // Notice, I'm leaving for now the "mul" argument value fixed at 0.5.
  175.     // The argument name for amplitude is now "amp." This is for our signal, PinkNoise.
  176.     var sig, mod;
  177.     mod = SinOsc.ar(freq: freq, phase: 3pi/2, mul: 0.5, add: 0.5);
  178.     sig = PinkNoise.ar(amp)!2;
  179.     sig = sig * mod;
  180. };
  181. )
  182.  
  183. x = ~pinkNoise.play;
  184. x.release(8);
  185.  
  186.  
  187. // Condensed
  188.  
  189. FreqScope.new; // To reference the frequency spectrum.
  190.  
  191. (
  192. ~pinkNoise = {
  193.     arg freq=0.25, amp=0.2;
  194.     var sig, mod;
  195.     mod = SinOsc.ar(freq: freq, phase: 3pi/2, mul: 0.5, add: 0.5);
  196.     sig = PinkNoise.ar(amp)!2; // Go between PinkNoise and BrownNoise.
  197.     sig = sig * mod;
  198. };
  199. )
  200.  
  201. x = ~pinkNoise.play;
  202. x.release(8);
  203.  
  204.  
  205. // Here's the Function with the different phase values.
  206. // Level meter is a good visual indicator to see where in the cycle it starts, (e.g. s.meter;)
  207.  
  208. (
  209. ~pinkNoise = {
  210.     arg freq=0.25, amp=0.2;
  211.     var sig, mod;
  212.     mod = SinOsc.ar(freq: freq, phase: pi/2, mul: 0.5, add: 0.5);
  213.     sig = PinkNoise.ar(amp)!2; // Go between PinkNoise and BrownNoise.
  214.     sig = sig * mod;
  215. };
  216. )
  217.  
  218. // Remember, pi/2 is the opposite cyclic motion of 3pi/2.
  219.  
  220. x = ~pinkNoise.play;
  221. x.release(8);
  222.  
  223. (
  224. ~pinkNoise = {
  225.     arg freq=0.25, amp=0.2;
  226.     var sig, mod;
  227.     mod = SinOsc.ar(freq: freq, phase: 0, mul: 0.5, add: 0.5);
  228.     sig = PinkNoise.ar(amp)!2; // Go between PinkNoise and BrownNoise.
  229.     sig = sig * mod;
  230. };
  231. )
  232.  
  233. x = ~pinkNoise.play;
  234. x.release(8);
  235.  
  236. (
  237. ~pinkNoise = {
  238.     arg freq=0.25, amp=0.2;
  239.     var sig, mod;
  240.     mod = SinOsc.ar(freq: freq, phase: pi, mul: 0.5, add: 0.5);
  241.     sig = PinkNoise.ar(amp)!2; // Go between PinkNoise and BrownNoise.
  242.     sig = sig * mod;
  243. };
  244. )
  245.  
  246. x = ~pinkNoise.play;
  247. x.release(8);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement