Always-on computer music
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.

103 lines
3.7KB

  1. // SVNVimStart
  2. s = Server.local;
  3. s.waitForBoot {
  4. var module, msg, modules;
  5. // Connect to OSC
  6. thisProcess.openUDPPort(5005);
  7. n = NetAddr.new("0.0.0.0", 5005);
  8. o = OSCFunc({ arg msg, time, addr, recvPort; [msg, time, addr, recvPort].postln; }, '/radio', n);
  9. // Create the synth definition and load it
  10. module = SynthDef.new(\module, {
  11. arg hue, saturation, value, pan, gain, octave, notefreq;
  12. var oscillator, noise, filter, panner, mixer, frequency, qfactor, lagtime, output, amplitude;
  13. // Dynamic time of the module
  14. lagtime = 100 / (2**octave);
  15. // Oscillator/filter frequency
  16. // frequency = notefreq * (1 + (hue*0.1));
  17. frequency = notefreq * (1 + (hue*5)) * (2**(octave-2));
  18. //frequency = (130 + (hue * 130)) * (2 ** octave);
  19. //frequency = 130 * Scale.major.ratios[(hue * 12).asInteger];
  20. //frequency = (130 * frequency) * (2**octave);
  21. frequency = Lag.kr(frequency, lagtime/10);
  22. // Filtered saw oscillator
  23. // oscillator = Mix.ar([SawDPW.ar(frequency), SawDPW.ar(frequency/2+0.5)]);
  24. oscillator = Mix.ar([DPW3Tri.ar(frequency), DPW3Tri.ar(frequency/2+0.5)]);
  25. filter = DFM1.ar(oscillator, frequency, saturation/2, 1.0, 0.0, 0.0006);
  26. // Noise
  27. qfactor = Lag.kr((1 - saturation)**2, lagtime);
  28. noise = Crackle.ar(1.9, 1.0);
  29. noise = BPF.ar(noise, frequency, qfactor);
  30. // Mix noise and saw
  31. mixer = Mix.ar([filter * saturation.sqrt(), 3* noise*(1-saturation)]);
  32. // Apply pan
  33. panner = LinPan2.ar(mixer, pan);
  34. // Apply dynamics
  35. amplitude = Lag.kr(HPF.kr(value, 4 * hue / (lagtime)), lagtime);
  36. output = panner * amplitude;
  37. // Compress
  38. output = Compander.ar(output, output, 0.5, 0.3, 0.3, 0.1, lagtime);
  39. // Fade in on boot
  40. output = output * Lag.kr(gain, lagtime);
  41. // Crank everything down
  42. output = output * 0.3;
  43. Out.ar(0, output);
  44. });
  45. module.load(s);
  46. s.sync;
  47. // Create multiple sound generators
  48. modules = Array.fill(12,
  49. {
  50. arg index;
  51. var pan, octave;
  52. pan = 0 - ((index % 4) - 1.5)/1.5;
  53. octave = (2 - (index / 4).floor);
  54. "Module %: Pan %, octave %\n".postf(index, pan.round(1e-1), octave.round(1e-1));
  55. Synth.new(\module,
  56. [\hue, 0.5, \saturation, 0.1, \value, 0.5, \pan, pan, \gain, 0.0, \octave, octave, \notefreq, Scale.major.degreeToFreq(index, 48.midicps, octave)]
  57. )
  58. }
  59. );
  60. // Turn up gain after some time
  61. SystemClock.schedAbs(8, {modules[0].set(\gain, 1)});
  62. SystemClock.schedAbs(8, {modules[1].set(\gain, 1)});
  63. SystemClock.schedAbs(8, {modules[2].set(\gain, 1)});
  64. SystemClock.schedAbs(8, {modules[3].set(\gain, 1)});
  65. SystemClock.schedAbs(16, {modules[4].set(\gain, 1)});
  66. SystemClock.schedAbs(16, {modules[5].set(\gain, 1)});
  67. SystemClock.schedAbs(16, {modules[6].set(\gain, 1)});
  68. SystemClock.schedAbs(16, {modules[7].set(\gain, 1)});
  69. SystemClock.schedAbs(32, {modules[8].set(\gain, 1)});
  70. SystemClock.schedAbs(32, {modules[9].set(\gain, 1)});
  71. SystemClock.schedAbs(32, {modules[10].set(\gain, 1)});
  72. SystemClock.schedAbs(32, {modules[11].set(\gain, 1)});
  73. SystemClock.schedAbs(32, {modules[12].set(\gain, 1)});
  74. // Hook up OSC
  75. f = { |msg, time, addr|
  76. if(msg[0] == '/radio') {
  77. if(msg[1]<modules.size){
  78. modules[msg[1]].set(\hue, msg[2]);
  79. modules[msg[1]].set(\saturation, msg[3]);
  80. modules[msg[1]].set(\value, msg[4]);
  81. }
  82. }
  83. };
  84. thisProcess.addOSCRecvFunc(f);
  85. };