0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

Processingでマイクを使う

Last updated at Posted at 2023-12-22

はじめに

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);
}

image.png

BeatDetector

下記、参考サイトをみるとBeatDetectorという気になる、機能があります。サイトにはないですが、Processingのサンプルに入っています。
image.png

必要最小限にサンプルを削り、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);
  }
}

参考

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?