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.

80 lines
2.4KB

  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;
  12. var oscillator, noise, filter, panner, mixer, frequency, qfactor, noise_level, osc_level, lagtime, output, dust;
  13. // Dynamic time of the module
  14. lagtime = 100 / (2**octave);
  15. // Oscillator/filter frequency
  16. frequency = 130 + (hue * 130) * (2 ** octave);
  17. frequency = Lag.kr(frequency, lagtime);
  18. // Filtered saw oscillator
  19. oscillator = SawDPW.ar(frequency);
  20. filter = DFM1.ar(oscillator, frequency*0.5, 0.8, 1.0, 0.0, 0.0006);
  21. // Noise
  22. qfactor = Lag.kr((1 - saturation)**4, lagtime);
  23. noise = Crackle.ar(1.99, 1.0);
  24. noise = BPF.ar(noise, frequency, qfactor);
  25. // Mix noise and saw
  26. mixer = Mix.ar([filter * saturation, noise*(1-saturation)]);
  27. // Apply pan
  28. panner = LinPan2.ar(mixer, pan);
  29. // Apply dynamics
  30. output = panner * Lag.kr(HPF.kr(value, 4 * hue / (lagtime)), lagtime);
  31. // Compress
  32. output = Compander.ar(output, output, 0.5, 0.3, 0.3, 0.1, lagtime);
  33. // Crank everything down
  34. output = output * 0.1;
  35. Out.ar(0, output);
  36. });
  37. module.load(s);
  38. s.sync;
  39. // Create multiple sound generators
  40. modules = Array.fill(12,
  41. {
  42. arg index;
  43. var pan, octave;
  44. pan = 0 - ((index % 4) - 1.5)/1.5;
  45. octave = (2 - (index / 4).floor) * 2;
  46. "Module %: Pan %, octave %\n".postf(index, pan.round(1e-1), octave.round(1e-1));
  47. Synth.new(\module,
  48. [\hue, 0.5, \saturation, 0.1, \value, 0.5, \pan, pan, \gain, 0.9, \octave, octave]
  49. )
  50. }
  51. );
  52. // Hook up OSC
  53. f = { |msg, time, addr|
  54. if(msg[0] == '/radio') {
  55. if(msg[1]<modules.size){
  56. modules[msg[1]].set(\hue, msg[2]);
  57. modules[msg[1]].set(\saturation, msg[3]);
  58. modules[msg[1]].set(\value, msg[4]);
  59. }
  60. }
  61. };
  62. thisProcess.addOSCRecvFunc(f);
  63. };