Always-on computer music
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

59 lines
1.8KB

  1. s = Server.local;
  2. s.waitForBoot {
  3. var module, sound, msg, modules;
  4. // Connect to OSC
  5. thisProcess.openUDPPort(5005);
  6. n = NetAddr.new("0.0.0.0", 5005);
  7. o = OSCFunc({ arg msg, time, addr, recvPort; [msg, time, addr, recvPort].postln; }, '/radio', n);
  8. //OSCFunc.trace(true);
  9. // Create the synth definition and load it
  10. module = SynthDef.new("module", {
  11. arg hue, saturation, value, pan;
  12. var oscillator, noise, filter, panner, mixer, frequency, qfactor, noise_level, osc_level;
  13. // Calculate some parameters
  14. frequency = 200 + 800*hue;
  15. qfactor = (1 - saturation)**4;
  16. osc_level = saturation;
  17. noise_level = 1 - osc_level;
  18. // Generate some sounds
  19. noise = WhiteNoise.ar(1);
  20. filter = BPF.ar(noise, frequency, qfactor) * noise_level;
  21. oscillator = SinOsc.ar(frequency) * osc_level;
  22. mixer = Mix.ar([filter, oscillator]);
  23. panner = LinPan2.ar(mixer, 2*pan - 1, value);
  24. Out.ar(0, panner);
  25. });
  26. module.load(s);
  27. s.sync;
  28. modules = [];
  29. modules.add(Synth.new("module", [\hue, 0.5, \saturation, 0.9, \value, 0.5, \pan, 0.5]));
  30. modules.add(Synth.new("module", [\hue, 0.9, \saturation, 0.9, \value, 0.5, \pan, 0.5]));
  31. // Make a sound
  32. // modules = [];
  33. // 5.do({
  34. // arg index;
  35. // var synth;
  36. // synth = Synth.new("module", [\hue, 0.5, \saturation, 0.1, \value, 0.5, \pan, 0.5]);
  37. // modules.add(synth);
  38. // });
  39. // Hook up OSC
  40. f = { |msg, time, addr|
  41. if(msg[0] == '/radio') {
  42. "Got data: % % % % %".postf(msg[1], msg[2], msg[3], msg[4], msg[5]);
  43. sound.set("hue", msg[1]);
  44. sound.set("saturation", msg[2]);
  45. sound.set("value", msg[3]);
  46. sound.set("pan", msg[4]);
  47. }
  48. };
  49. thisProcess.addOSCRecvFunc(f);
  50. };