Smol or mid-sized snippets of SuperCollider code that start in SuperCollider's Workspace Emacs buffer from scratch.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

152 lines
3.8 KiB

  1. (
  2. // before boot, raise memory?
  3. #[\internal, \local].do { |s|
  4. s = Server.perform(s);
  5. s.options.memSize = 2097152; // 2 gigs
  6. };
  7. Server.default.waitForBoot {
  8. fork {
  9. // SynthDefs ////////////////////////////////////////////
  10. // sawtoothwave-based droney pad
  11. SynthDef(\sawLine, {
  12. arg out=0, freq=440, gate=1, amp=1, cutoff=10;
  13. var snd, env, gen, numosc;
  14. numosc = 10;
  15. cutoff = cutoff * 0.1;
  16. env = Env.adsr(4, 0, 1, 10, 1, \lin);
  17. gen = EnvGen.kr(env, gate, doneAction:2);
  18. // using Array.fill multiplies number of oscilators
  19. snd = Array.fill(numosc, {
  20. var local, lfreq;
  21. lfreq = [freq, freq*2.01, freq/1.99 ];
  22. local = Saw.ar( rrand(lfreq, lfreq * 1.02)
  23. * LFNoise1.kr(0.3).range(1, 1.01), -10.dbamp * [0.5, 0.3, 0.3]);
  24. local = Mix(local);
  25. });
  26. snd = Splay.ar(snd); // Splay mixes-down all arrays to 2ch - stereo
  27. snd = LPF.ar(snd, LFNoise1.ar(0.06).exprange(3000,10000) * cutoff);
  28. // another delay with variing delay times to add to harmonic offsets
  29. snd = CombL.ar(snd, 1, LFNoise1.ar(0.1).range([0.5,0.65],[0.53,0.68]), 15, -1.dbamp) + snd;
  30. snd = snd * gen * amp;
  31. Out.ar(out, snd);
  32. }).add;
  33. // a sinewave-ish beep with a home-made reverb
  34. SynthDef(\revBeep, {
  35. arg freq=440, amp = 0.3, gate=1, pan=0, revwet=0.1;
  36. var snd, env, rev, del, in;
  37. snd = LFCub.ar(freq);
  38. env = EnvGen.ar(Env.asr(0.01, 1, 0.1), gate,
  39. doneAction:0);
  40. snd = snd * env * amp;
  41. // ## reverb ##
  42. del = DelayN.ar(snd, 0.048);
  43. // mix/fill 16 instances of short delay with CombL:
  44. rev = Mix.ar(Array.fill(16,{ CombL.ar(del, 0.1, LFNoise1.kr(0.001.rand, 0.04, 0.05), 15) }));
  45. // add delays to the signal recursively with AllPassN 4x:
  46. 6.do({ rev = AllpassN.ar(rev, 0.050, [0.050.rand, 0.050.rand], 1) });
  47. // adjust volume:
  48. rev = rev * revwet * 0.1; // carefull
  49. snd = snd + rev;
  50. // the end of the sound determined by silence. free synth.
  51. DetectSilence.ar(snd, amp: 0.0001, doneAction:2);
  52. Out.ar(0, snd);
  53. }).add;
  54. // s.scope(16)
  55. // a beep sound with a delay/echo
  56. SynthDef(\delBeep, {
  57. arg freq=200, amp = 0.3, gate = 1, pan = 0;
  58. var snd, env;
  59. snd = Pulse.ar(freq)!2;
  60. env = EnvGen.ar(Env.perc(0.01, 0.1), doneAction:0);
  61. snd = snd * env * amp;
  62. // delay:
  63. snd = CombN.ar(snd, 1, [0.39,0.51], 10, mul:0.3) + snd;
  64. DetectSilence.ar(snd, time:0.5, doneAction:2);
  65. Out.ar(0, snd);
  66. }).add;
  67. SynthDef(\hh, {
  68. arg amp=0.1, outBus=0, gate=1, sustain=0.2, cutoff=2000, pan=0;
  69. var snd, env;
  70. snd = WhiteNoise.ar;
  71. snd = HPF.ar(snd, cutoff);
  72. env = EnvGen.ar(Env.perc(0, sustain), doneAction:2);
  73. snd = snd * env * amp;
  74. snd = Pan2.ar(snd, pan);
  75. Out.ar(outBus, snd);
  76. }).add;
  77. // end of SynthDef-initions. /////////////////////////////////////////
  78. s.sync; // sync server before moving on //
  79. // let's pattern! ////////////////////////////////////////////////////
  80. Pbindef(\delBeepPat,
  81. \instrument, \delBeep,
  82. \degree, Pseq([7,0], inf),
  83. \dur, Pseq([0.1,15.9], inf),
  84. \sustain, 0.1,
  85. \amp, 0.05
  86. ).play;
  87. Pbindef(\hhPat,
  88. \instrument, \hh,
  89. \dur, 2,
  90. \amp, Pseq([0.5,0.3],inf),
  91. \pan, Pseq([-1,1], inf),
  92. \sustain, 0.1,
  93. \cutoff, 12000
  94. ).play;
  95. Pbindef(\revBeepPat,
  96. \instrument, \beep1,
  97. \dur, Pseq([1,2,3] * 4, inf) * Prand([1/4,1/8,1/2,1],inf),
  98. \degree, Prand([0,3,-2,4],inf),
  99. \octave, 6,
  100. \sustain, Prand((2..6)*0.1, inf),
  101. \amp, 0.04,
  102. \revwet, 1,
  103. \scale, Scale.minor(\just),
  104. \pan, Pseg([-1, 1, -1], 20, \lin, inf)
  105. ).play;
  106. Pbindef(\padPat,
  107. \instrument, \sawLine,
  108. \dur, Pseq([Rest(32), Pn(8)]),
  109. \degree, Prand([[0,9],[0,8],[0,10]],inf),
  110. \octave, [4,5,6],
  111. \amp, Pseq([0, Pseq((1..5) ++ (4..2) * 0.1, inf)]),
  112. \cutoff, Pseq((1..7)++(6..2),inf),
  113. \scale, Scale.minor(\just)
  114. ).play;
  115. } // end of fork.
  116. }
  117. )
  118. // --------------------------------------------------------------------