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.

141 lines
3.2 KiB

  1. ( fork {
  2. // acid bass synthdef
  3. SynthDef(\bz, {
  4. arg gate=1, freq=440, amp=0.1, cutoff=1000, rq=0.1;
  5. var snd, env, cutoffenv;
  6. // slight detuning into stereo. will cause channel expansion later.
  7. freq = [freq, freq * 1.02];
  8. // amplitude envelope. doneAction:2 frees the synth at the end of env.
  9. env = EnvGen.ar(
  10. envelope: Env.adsr(0.01, 0.1, 0.5, 0.5),
  11. gate: gate,
  12. doneAction:2 );
  13. // main oscilation - sawtooth wave and squarewave
  14. snd = Pulse.ar(freq);
  15. snd = Saw.ar(freq * 0.98) + (snd * 0.5);
  16. // add some saturation/distortion
  17. snd = snd * 5;
  18. snd = snd.softclip;
  19. // cutoff frequency envelope for low-pass
  20. cutoffenv = EnvGen.ar( Env.adsr(decayTime: 0.1,
  21. sustainLevel: 0.5, releaseTime:0.5),
  22. gate: gate );
  23. cutoff = cutoff * cutoffenv;
  24. cutoff = cutoff.max(50);
  25. // resonating low-pass filter
  26. snd = RLPF.ar(snd, cutoff, rq);
  27. // finalize (low (0.1) rq (high resonance) can cause loud spikes)
  28. snd = Limiter.ar(snd);
  29. snd = snd * env * amp;
  30. // output
  31. Out.ar(0, snd);
  32. }).add;
  33. SynthDef(\hh, {
  34. arg amp=0.1, outBus=0, gate=1, sustain;
  35. var snd, env;
  36. // simple noise
  37. snd = WhiteNoise.ar;
  38. // high-pass filter
  39. snd = HPF.ar(snd, 2000);
  40. // amplitude envelope
  41. env = EnvGen.ar(Env.perc(0, sustain), doneAction:2);
  42. // put it together
  43. snd = snd * env * amp;
  44. // output
  45. Out.ar(outBus, snd!2);
  46. }).add;
  47. SynthDef(\snare, {
  48. arg amp = 0.2;
  49. var snd, env;
  50. // Generates noise which results from flipping random bits in a word.
  51. // This type of noise has a high RMS level relative to its peak to
  52. // peak level. The spectrum is emphasized towards lower frequencies.
  53. snd = GrayNoise.ar.dup;
  54. // amplitude envelope
  55. env = EnvGen.ar(Env([0,1,0], [0.001, 0.2], curve: -4), doneAction:2);
  56. // put it together and output
  57. snd = snd * env * amp;
  58. Out.ar(0, snd);
  59. }).add;
  60. s.sync;
  61. // bassline pattern // --
  62. Pbindef(\bzPat,
  63. \instrument, \bz,
  64. \amp, 0.6,
  65. // the main rhythmic sequence
  66. \dur, Pseq([1/2, 1/4, 1/4] , inf)
  67. * Pseq([Pseq([1, 1/2],20),1/2,1,1/2,1/2], inf),
  68. // playing first three notes in a scale
  69. \degree, Pseq([0, 1, 2], inf),
  70. // of minor
  71. \scale, Scale.minor,
  72. // stay in 3rd octave, only occasionaly veer to 2 or 4
  73. \octave, Pwrand([2, 3, 4], [0.1, 0.8, 0.1], inf),
  74. // randomly change length of notes
  75. \legato, Pxrand( (1..9) / 10, inf),
  76. // Pseg creates segments in time. this is main 2min "composition"
  77. \cutoff, Pseq([
  78. Pseg([100,8000,500],[20,10], \exp, 1),
  79. Pseg([500, 4000, 1000, 8000, 800, 2000, 500], 5, \exp, 1),
  80. Pseg([500,8000,100], [10,20], \exp, 1)
  81. ]),
  82. // randomly change resonance
  83. \rq, Prand((1..9) * 0.1, inf),
  84. ).play;
  85. // high hat pattern // --
  86. Pbindef(\hhPat,
  87. \instrument, \hh,
  88. // make it ... er.. "human", by variation in amplitude
  89. \amp, Prand((2..4) * 0.05, inf),
  90. // specific number of 8th notes - 1.5 minute
  91. \dur, Pseq([1/8], 8 * 60 * 1.5),
  92. // by making third note longer, sounds like closed and open hats
  93. \legato, Pseq([0.5, 0.5, 1, 0.5],inf),
  94. ).play;
  95. // snare pattern // --
  96. Pbindef(\snPat,
  97. \instrument, \snare,
  98. // main rhythm. it's 2 and a quarter note long loopo
  99. \dur, Pseq([Rest(1/2), 1/2, Rest(7/8), 3/8 ], inf),
  100. // fade in and fade out using Pseg(ment)
  101. \amp, Pseg([0,0.4,0.4,0] + 0.0001, [15, 60, 15], \exp),
  102. ).play;
  103. } )