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.

117 lines
3.0 KiB

  1. // #looptober 2020 02
  2. // by Luka Prinčič <luka@lukaprincic.si>
  3. // free to use, remix, etc under conditions of peer production licence:
  4. // https://wiki.p2pfoundation.net/Peer_Production_License
  5. // please support my work via https://lukaprincic.si/support
  6. ( // load samples
  7. var smpPath = PathName(thisProcess.nowExecutingPath.dirname +/+ "samples");
  8. // free all buffers to restart buffer count
  9. ~smpBuffers.do(_.free);
  10. // create Dictionary
  11. ~smpBuffers = Dictionary();
  12. // load samples
  13. "\n--- load samples: ...".postln;
  14. // iterate over each file in the folder
  15. smpPath.filesDo({ |smpfile,i|
  16. // tell me what you are loading:
  17. postln(" " + i + smpfile.fileName );
  18. // add a sample into a buffer, store object to Dictionary
  19. ~smpBuffers.add(smpfile.fileName -> Buffer.readChannel(s,
  20. smpfile.fullPath, channels:[0]));
  21. });
  22. // function to partially match filename for buffers
  23. ~getSmp = { |regexp|
  24. ~smpBuffers.detect { |buf|
  25. regexp.matchRegexp(buf.path)
  26. }
  27. };
  28. // synthdefs: ///////////////////////////////////////////////////////////////////////
  29. SynthDef(\bgrain, { |out = 0, gate = 1, amp = 0, bufnum, gfreq=90, rate=0.5|
  30. var snd, pan, env, freqdev;
  31. pan = LFNoise1.kr(0.1).range(-1, 1) * LFNoise0.kr(gfreq).range(0.2,1);
  32. env = EnvGen.kr(
  33. Env([0, 1, 0], [1, 1], \sin, 1),
  34. gate,
  35. doneAction: Done.freeSelf);
  36. snd = GrainBuf.ar(
  37. numChannels:2,
  38. trigger:Impulse.kr(LFNoise1.kr(gfreq).range(0.8,1) * gfreq),
  39. dur: 0.2 * LFNoise0.kr(gfreq).range(1,1.2),
  40. sndbuf: bufnum,
  41. rate: [rate * LFNoise1.kr.range(0.99, 1), rate * LFNoise1.kr.range(0.99, 1)],
  42. pos: LFNoise2.kr(0.05).range(0, 1) * LFNoise0.kr(gfreq).range(1,1.02),
  43. //pos: LFTri.kr(0.25),
  44. interp: 2,
  45. pan: pan);
  46. snd = RLPF.ar(snd, freq: LFNoise2.kr(0.1).exprange(400,10000));
  47. snd = snd * LFTri.ar(0.073).range(0.1,1);
  48. snd = snd * env * amp;
  49. Out.ar(out, snd);
  50. }).add;
  51. SynthDef(\verbDelayFX, {
  52. arg inBus, out=0, revWet=0.8, dlyWet=0.8, feedback = 0.5 ;
  53. var snd = In.ar(inBus, 2);
  54. var verb = JPverb.ar(snd);
  55. var delay = Greyhole.ar(snd, feedback: feedback);
  56. snd = snd + (verb * revWet) + (delay * dlyWet) * 0.5;
  57. Out.ar(out, snd);
  58. }).add;
  59. );
  60. // -----------------------------------------------------------------
  61. // create a reverb/delay send bus
  62. ~reverBus = Bus.audio(s,2);
  63. // create processing verb/delay plugin/synth
  64. ~reverbDelay = Synth(\verbDelayFX, [\inBus, ~reverBus], addAction: \addAfter);
  65. // free them if necessary:
  66. // ~reverbDelay.free
  67. // ~reverBus.free
  68. // -----------------------------------------------------------------
  69. (
  70. // granulation 1
  71. ~amygran = Synth(\bgrain,
  72. [\out, ~reverBus, \bufnum, ~getSmp.("amywars"), \amp, 0.5],
  73. addAction: \addToHead);
  74. )
  75. (
  76. // granulation 2
  77. ~romantiq = Synth(\bgrain,
  78. [\out, ~reverBus, \bufnum, ~getSmp.("romant"), \amp, 0.05],
  79. addAction: \addToHead);
  80. )
  81. // play with arguments:
  82. ~amygran.set(\amp, 0.5)
  83. ~romantiq.set(\amp, 0.05)
  84. ~romantiq.set(\rate, 1)
  85. // fadeout
  86. ~amygran.release(10)
  87. ~romantiq.release(10)
  88. // -----------------------------------------------------------------