【Processing】minimを使ってみる(2)

 

curveVertex()を使ってるが同じ座標で3回使ってカーブ描かなかった。

 

てか、まさかだけどminimってwavファイル使えないのか、、?

使えなかったら使い物にならんけど。

 

import ddf.minim.analysis.*;
import ddf.minim.*;

Minim minim;
AudioPlayer player;
FFT fft;
int specSize;
float volume;
int aaa = 512;
float[] xxx = new float[aaa];
float[] yyy = new float[aaa];

void setup() {
  size(800, 800);
  background(255);
  blendMode(MULTIPLY);
  for (int i = 0; i<aaa; i++) {
    xxx[i] = random(width);
    yyy[i] = random(height);
  }

  minim = new Minim(this);
  player = minim.loadFile("music3.aiff", aaa);
  // フーリエ変換のインスタンスを生成
  fft = new FFT(player.bufferSize(), player.sampleRate());
  player.play();
}

void draw() {

  background(255);
  strokeWeight(0);
  noStroke();

  // FFTで波形から周波数のスペクトルに変換
  fft.forward(player.mix);
  specSize =  fft.specSize();

  for (int bbb = 0; bbb < 3; bbb++) {
    if (bbb == 0 ) {
      fill(0,100);
    }
    if (bbb == 1 ) {
      fill(0, 100);
    }
    if (bbb == 2 ) {
      fill(0, 100);
    }
    beginShape();

    for (int i = 0; i < specSize; i+=20) {
      volume = fft.getBand(i);

      int w = (int)((int)volume * (20));

      xxx[i+bbb] += w*random(-1, 1);
      yyy[i+bbb] += w*random(-1, 1);

      curveVertex(xxx[i+bbb], yyy[i+bbb]);
      curveVertex(xxx[i+bbb], yyy[i+bbb]);
      curveVertex(xxx[i+bbb], yyy[i+bbb]);
    }
    curveVertex(xxx[0], yyy[0]);
    endShape(CLOSE);
  }
}



void stop() {
  player.close();
  minim.stop();
  super.stop();
}