A place to dump little or mid-sized snippets of SuperCollider code.
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.

142 lines
3.9 KiB

  1. (
  2. SynthDef(\snap, {
  3. arg out=0, gate=1, amp=0.1;
  4. var snd, aenv, cenv;
  5. snd = WhiteNoise.ar;
  6. aenv = EnvGen.ar(Env([0,1,1,0], [0.001,0.03,0.01]), gate: gate);
  7. snd = snd * aenv;
  8. snd = snd + (SinOsc.ar(Rand(6000,15000)) * EnvGen.ar(Env.perc(0, 0.05)));
  9. snd = HPF.ar(snd, Line.ar(500,3000,0.1));
  10. // env that contains doneAction MUST BE sustained for Pbind to work!
  11. cenv = EnvGen.ar(Env.adsr(0.001,0.1,0.9,0.01), gate: gate, doneAction:2);
  12. snd = CombN.ar(snd, 1, Rand(0.01,0.1), 10, mul:0.3) + snd;
  13. snd = snd * cenv * amp;
  14. snd = Pan2.ar(snd, Rand(-1,1) * 1/2);
  15. Out.ar(out, snd);
  16. }).add;
  17. SynthDef(\bdx, {
  18. arg out=0, gate=1, amp=0.1, freq=100;
  19. var snd, aenv, fltenf, frqenv;
  20. frqenv = EnvGen.ar(Env([5,1,0.5], [0.01,1]), gate);
  21. freq = freq * frqenv;
  22. snd = SinOsc.ar(freq) * Pulse.ar(freq/4).range(0.4,1);
  23. snd = snd +
  24. (WhiteNoise.ar * EnvGen.ar(Env.adsr(0.001,0.01,0.05), gate, 0.2));
  25. aenv = EnvGen.ar(Env.adsr(0.0001,0.2,0.5,0.01), gate, doneAction:2);
  26. snd = snd * aenv * amp;
  27. snd = snd.dup;
  28. Out.ar(out, snd);
  29. }).add;
  30. SynthDef(\sc808clap, { // from sc-808 project!
  31. arg amp=1, gate=1;
  32. var atkenv, atk, decay, sum, denv;
  33. atkenv = EnvGen.kr(Env.new([0.5,1,0],[0, 0.3], -160), doneAction:0);
  34. denv = EnvGen.kr(Env.dadsr(0.026, 0, 6, 0, 1, 1, curve:-157), doneAction:0);
  35. atk = WhiteNoise.ar * atkenv * 1.4;
  36. decay = WhiteNoise.ar * denv;
  37. sum = atk + decay * amp;
  38. sum = HPF.ar(sum, 500);
  39. sum = BPF.ar(sum, 1062, 0.5);
  40. sum = sum * EnvGen.ar(Env.asr(0.00001,1,0.0001), gate, doneAction:2);
  41. Out.ar(0, Pan2.ar(sum * 1.5, 0));
  42. }).add;
  43. SynthDef.new(\sc808sn, {
  44. arg amp=2, tone=340, tone2=189, snappy=0.3, gate=1, amp2=1;
  45. var noiseEnv, atkEnv, sig, noise, osc1, osc2, sum;
  46. noiseEnv = EnvGen.kr(Env.perc(0.001, 4.2, 1, -115), doneAction:0);
  47. atkEnv = EnvGen.kr(Env.perc(0.001, 0.8,curve:-95), doneAction:0);
  48. noise = WhiteNoise.ar;
  49. noise = HPF.ar(noise, 1800);
  50. noise = LPF.ar(noise, 8850);
  51. noise = noise * noiseEnv * snappy;
  52. osc1 = SinOsc.ar(tone2, pi/2) * 0.6;
  53. osc2 = SinOsc.ar(tone, pi/2) * 0.7;
  54. sum = (osc1+osc2) * atkEnv * amp2;
  55. sig = Pan2.ar((noise + sum) * amp * 2.5, 0);
  56. sig = HPF.ar(sig, 340);
  57. sig = sig * EnvGen.ar(Env.asr(0.00001,1,0.0001), gate, doneAction:2);
  58. Out.ar(0, sig);
  59. }).add;
  60. SynthDef.new(\sc808hh, {
  61. arg decay=0.42, amp=1, pan=0;
  62. var sig, sighi,siglow, sum, env, osc1, osc2, osc3, osc4, osc5, osc6;
  63. env = EnvGen.kr(Env.perc(0.005, decay, 1, -30),doneAction:2);
  64. osc1 = LFPulse.ar(203.52);
  65. osc2 = LFPulse.ar(366.31);
  66. osc3 = LFPulse.ar(301.77);
  67. osc4 = LFPulse.ar(518.19);
  68. osc5 = LFPulse.ar(811.16);
  69. osc6 = LFPulse.ar(538.75);
  70. sighi = (osc1 + osc2 + osc3 + osc4 + osc5 + osc6);
  71. siglow = (osc1 + osc2 + osc3 + osc4 + osc5 + osc6);
  72. sighi = BPF.ar(sighi, 8900, 1);
  73. sighi = HPF.ar(sighi, 9000);
  74. siglow = BBandPass.ar(siglow, 8900, 0.8);
  75. siglow = BHiPass.ar(siglow, 9000, 0.3);
  76. sig = BPeakEQ.ar((siglow+sighi), 9700, 0.8, 0.7);
  77. sig = sig * env * amp;
  78. sig = Pan2.ar(sig, pan);
  79. Out.ar(0, sig);
  80. }).add;
  81. )
  82. /////////// patterns ///////////////////////////////////////////////////
  83. (
  84. Pbindef(\psnap,
  85. \instrument, \snap,
  86. \dur, Pseq([3,Prand([3,2,1]),Prand([2,Pseq([1/2],2)])] * 1/4, inf),
  87. \amp, Prand([1,2,3]/4, inf),
  88. \legato, Prand([1,2,3]/6, inf)
  89. ).play;
  90. Pbindef(\pbdx,
  91. \instrument, \bdx,
  92. \dur, Pseq([3,Prand([3,2,1]),Prand([2,Pseq([1/2],2)])] * 1/4, inf),
  93. \legato, Prand((1..5) * 0.2, inf),
  94. \freq, 70 * Prand((1..9) + 120 * 0.01,inf),
  95. \amp, 0.7
  96. ).play;
  97. Pbindef(\pcl,
  98. \instrument, \sc808clap,
  99. \dur, Pseq([2,Prand([2,2.5])],inf),
  100. \amp, 2,
  101. ).play
  102. ;
  103. Pbindef(\psn,
  104. \instrument, \sc808sn,
  105. \dur, Prand([1.5,1.25,0.75],inf),
  106. \amp, 1,
  107. \legato, 0.04
  108. ).play
  109. ;
  110. Pbindef(\phh,
  111. \instrument, \sc808hh,
  112. \dur, Pseq([Prand([1,1/2]),1,1,3]/4, inf),
  113. \amp, 0.5
  114. ).play
  115. )