はじめに
Processingでマイクからボリュームを取得して、円半径に反映させるサンプルです。
公式サイトのサンプルを少しいじったものです。
コード
import processing.sound.*;
Amplitude amp;
AudioIn in;
void setup() {
size(512, 512);
amp = new Amplitude(this);
in = new AudioIn(this, 0);
in.start();
amp.input(in);
}
void draw() {
background(0);
float volume = amp.analyze();
circle(width/2, height/2, 2000*volume);
rect(50, height-2000*volume, 50, height);
text(volume, 100, 100);
}
BeatDetector
下記、参考サイトをみるとBeatDetectorという気になる、機能があります。サイトにはないですが、Processingのサンプルに入っています。
必要最小限にサンプルを削り、beatDetector.isBeat()
だけにして、動作確認してみました。
口でビートを刻むと、ビートのタイミングで画面が瞬間、白くなります。
import processing.sound.*;
AudioIn in;
BeatDetector beatDetector;
void setup() {
size(512, 512);
in = new AudioIn(this, 0);
in.start();
beatDetector = new BeatDetector(this);
beatDetector.input(in);
beatDetector.sensitivity(140);
}
void draw() {
if (beatDetector.isBeat()) {
background(255);
} else {
background(0);
}
}
参考