Advertisement

Interactive Music II ProcessingとSuperColliderの連携 -2

neet at Freelance
Jan. 15, 2014
Advertisement

More Related Content

Advertisement

More from Atsushi Tadokoro(20)

Advertisement

Interactive Music II ProcessingとSuperColliderの連携 -2

  1. Interactive Music II ProcessingとSuperColliderの連携2 東京藝術大学芸術情報センター (AMC) 2014年1月16日 田所 淳
  2. 最終課題 ‣ 課題 : ‣ SuperCollider、またはSuperColliderとProcessingを連携して 表現する ‣ 音、または音と連動した映像 ‣ テーマは自由 ‣ 時間: 30分以内であれば、自由 ! ‣ 次週(1月23日)の授業で発表してください
  3. 先週の復習
  4. SuperCollider client for Processing ‣ ProcessingとSuperColliderの連携には、SuperCollider client for Processingが便利 ‣ OSCp5よりも簡単に、SuperColliderとProcessingの連携が可 能となる
  5. SuperCollider client for Processing ‣ SuperCollider側: 「test_inst」を定義 SynthDef("test_inst",{ arg freq=440, length=1.0, amp=0.5; var env, out; env = Env.perc(0.01, length); out = SinOsc.ar([freq,freq*1.001]) * EnvGen.kr(env, doneAction:2) * amp; Out.ar(0, out); }).store;
  6. SuperCollider client for Processing ‣ Processing側: クリックで音が鳴るように import supercollider.*; import oscP5.*; ! Synth synth; ! void setup () { size(600, 400); } ! void draw() { background(0); } ! //マウスクリックに反応 void mouseReleased() { //新規に楽器を定義(まだ生成はされず) synth = new Synth("test_inst"); //引数を設定 synth.set("amp", 0.5); synth.set("freq", map(mouseY, height, 0, 20, 8000)); //楽器を生成 synth.create(); }
  7. SuperCollider client for Processing ‣ たとえば、ここに円が拡がるアニメーションをつけてみる
  8. SuperCollider client for Processing ‣ Processing側: import supercollider.*; import oscP5.*; ! Synth synth; int NUM = 100; float[] radius = new float[NUM]; PVector[] pos = new PVector[NUM]; int counter = 0; ! void setup () { size(800, 600); frameRate(60); noFill(); stroke(31, 127, 255); strokeWeight(3); for (int i = 0; i < NUM; i++) { radius[i] = 0; pos[i] = new PVector(width*2, width*2); } }
  9. SuperCollider client for Processing ‣ Processing側: void draw() { background(0); for (int i = 0; i < NUM; i++) { ellipse(pos[i].x, pos[i].y, radius[i], radius[i]); radius[i] += 1; if(radius[i] > width*1.5){ radius[i] = 0; pos[i].x = width*2; pos[i].y = width*2; } } } ! void mouseReleased() { synth = new Synth("test_inst"); synth.set("amp", 0.5); synth.set("freq", map(mouseY, height, 0, 20, 8000)); synth.create(); int n = counter % NUM; radius[n] = 0; pos[n].x = mouseX; pos[n].y = mouseY; counter++; }
  10. SuperCollider client for Processing ‣ 完成!!
  11. SuperCollider client for Processing ‣ SuperColliderの楽器はそのままで、さらに別の例
  12. SuperCollider client for Processing ‣ Processing側: import supercollider.*; import oscP5.*; ! int NUM = 400; //配列の数 //位置のベクトルの配列 PVector[] location = new PVector[NUM]; //速度のベクトルの配列 PVector[] velocity = new PVector[NUM]; //塗りの色の配列 color[] col = new color[NUM]; //円の大きさ(直径)の配列 float[] diameter = new float[NUM]; ! void setup() { size(640, 480); //640x480pixelの画面を生成 frameRate(60); //フレームレート noStroke(); for (int i = 0; i < NUM; i++) { //配列の数だけ繰り返し //位置のベクトルの初期設定 location[i] = new PVector(random(width), random(height)); //速度のベクトルの初期設定 velocity[i] = new PVector(random(-4, 4), random(-4, 4)); //色の初期設定 col[i] = color(random(255), random(255), random(255), 127); //大きさの初期設定 } } diameter[i] = random(3, 40);
  13. SuperCollider client for Processing ‣ Processing側: void draw() { background(15); //背景を描画 //配列の数だけ繰り返し for (int i = 0; i < NUM; i++) { fill(col[i]); //色を指定 //指定した位置に円を描画 ellipse(location[i].x, location[i].y, diameter[i], diameter[i]); //位置のベクトルに速度のベクトルを加算、次の位置になる location[i].add(velocity[i]); //もし画面の左端、または右端に到達したら if ((location[i].x > width) || (location[i].x < 0)) { velocity[i].x *= -1; //X方向のスピドを反転 playSynth(location[i].x, location[i].y); } //もし画面の下端、または上端に到達したら if ((location[i].y > height) || (location[i].y < 0)) { velocity[i].y *= -1; //Y方向のスピードを反転 } } } playSynth(location[i].x, location[i].y); ! void playSynth(float x, float y) { //新規に楽器を定義(まだ生成はされず) Synth synth = new Synth("test_inst"); //引数を設定 synth.set("amp", 0.1); synth.set("freq", map(x, height, 0, 20, 8000)); //楽器を生成
  14. SuperCollider client for Processing ‣ Processing側: ! void playSynth(float x, float y) { //新規に楽器を定義(まだ生成はされず) Synth synth = new Synth("test_inst"); //引数を設定 synth.set("amp", 0.1); synth.set("freq", map(x, height, 0, 20, 8000)); //楽器を生成 } synth.create();
  15. SuperCollider client for Processing ‣ ボールのバウンドに反応
  16. SuperCollider client for Processing ‣ Processing側: import supercollider.*; import oscP5.*; ! Synth synth; int NUM = 100; float[] radius = new float[NUM]; PVector[] pos = new PVector[NUM]; int counter = 0; ! void setup () { size(800, 600); frameRate(60); noFill(); stroke(31, 127, 255); strokeWeight(3); for (int i = 0; i < NUM; i++) { radius[i] = 0; pos[i] = new PVector(width*2, width*2); } }
  17. いろいろサンプル
  18. SuperCollider client for Processing ‣ 拡がる四角形と、FM
  19. SuperCollider client for Processing ‣ 拡がる四角形と、FM - Processing側: import supercollider.*; import oscP5.*; ! int NUM = 100; int count = 0; ! PVector pos[] = new PVector[NUM]; float size[] = new float[NUM]; Synth fm[] = new Synth[NUM]; ! void setup() { size(640, 480); frameRate(60); for (int i = 0; i < NUM; i++) { pos[i] = new PVector(width*2, height*2); size[i] = 0; } rectMode(CENTER); }
  20. SuperCollider client for Processing ‣ 拡がる四角形と、FM - Processing側: void draw() { background(0); stroke(255, 127); noFill(); strokeWeight(3); for (int i = 0; i < NUM; i++) { rect(pos[i].x, pos[i].y, size[i], size[i]); if (size[i] > 0) { size[i] += 1; fm[i].set("index", size[i]); } if (size[i] > width/4) { size[i] = 1; } } }
  21. SuperCollider client for Processing ‣ 拡がる四角形と、FM - Processing側: void mouseReleased() { int n = count % NUM; pos[n].x = mouseX; pos[n].y = mouseY; size[n] = 1; count++; fm[n] = new Synth("fm1"); fm[n].set("amp", 0.2); fm[n].set("freq", map(mouseY, height, 0, 40, 800)); fm[n].set("pan", map(mouseX, 0, width, -1.0, 1.0)); fm[n].set("modPartial", map(mouseY, 0, height, 1.0, 20.0)); fm[n].set("index", 0.0); fm[n].create(); }
  22. SuperCollider client for Processing ‣ 拡がる四角形と、FM - SuperCollider側: //FM SynthDef("fm1", { arg freq = 440, detune = 2, carPartial = 1, modPartial = 1, index = 3, mul = 0.2, pan=0.0, amp=0.5; var mod, car; mod = SinOsc.ar( [freq, freq+detune] * modPartial, 0, freq * index * LFNoise1.kr(10.reciprocal).abs ); car = Pan2.ar(SinOsc.ar((freq * carPartial) + mod, 0, mul), pan, amp); Out.ar(0, car); }).add;
  23. SuperCollider client for Processing ‣ 左右に動く帯と、持続音
  24. SuperCollider client for Processing ‣ 左右に動く帯と、持続音 - Processing側: import supercollider.*; import oscP5.*; ! int BAR_NUM = 100; int count = 0; ! float[] float[] float[] color[] ! x = new float[BAR_NUM]; xSpeed = new float[BAR_NUM]; bWidth = new float[BAR_NUM]; bColor = new color[BAR_NUM]; void setup() { size(640, 480); frameRate(30); colorMode(HSB, 360, 100, 100, 100); noStroke(); for (int i=0; i<BAR_NUM; i++) { x[i] = width * 2; xSpeed[i] = random(-4, 4); bWidth[i] = 0; bColor[i] = color(random(360), random(90, 100), random(50, 100), 20); } //FX Synth synth = new Synth("fx"); synth.create(); }
  25. SuperCollider client for Processing ‣ 左右に動く帯と、持続音 - Processing側: void draw() { background(0); for (int i=0; i<BAR_NUM; i++) { fill(bColor[i]); rect(x[i], 0, bWidth[i], height); x[i] += xSpeed[i]; if (x[i] > width || x[i] < -bWidth[i]) { xSpeed[i] *= -1; } } } ! void mouseReleased() { int n = int(random(1, 12)); x[count] = mouseX; bWidth[count] = n * 40; count++; Synth synth = new Synth("mySaw"); synth.set("n", n); synth.set("gate", 1); synth.create(); }
  26. SuperCollider client for Processing ‣ 左右に動く帯と、持続音 - SuperCollider側: ! SynthDef("mySaw", { arg fadeTime = 10, n = 0, rq = 0.3, detune = 0.001, base = 20, ratio = 1.5, harm = 1.5, amp = 0.2, gate=0; var lfo, env, out; env = EnvGen.kr(Env.new([0,1], [fadeTime], 'sine')); lfo = SinOsc.ar(rrand(0.03, 0.05), 0, 100, 600); out = Saw.ar([base+detune.rand, base+detune.rand] * (ratio ** n)) * amp + Saw.ar([base*harm+detune.rand, base*harm+detune.rand] * (ratio ** n)) * amp; out = out * env; out = RLPF.ar(out, lfo * (1.5 ** n), rq).clip2 * 0.5; out = out * EnvGen.kr(Env.adsr(releaseTime:20), gate, doneAction: 2); Out.ar(0, out); }).store; ! //エフェクト SynthDef("fx", { arg lpf=440, rq=0.5, amp=0.8; var in, out; in = In.ar(0, 2); 12.do({ in = AllpassL.ar(in, 0.1, LFNoise2.kr([rrand(0.0, 0.1),rrand(0.0, 0.1)], 0.01,0.06), 4.0) }); out = CompanderD.ar(in) * amp; ReplaceOut.ar(0, out); }).store;
  27. SuperCollider client for Processing ‣ 課題の方向性 ‣ シンプルなアニメーションと、簡単な楽器 ‣ 組合せて、足しあわせることで、面白い結果を ! ‣ 残り時間は、質問受付にします!
Advertisement