読者です 読者をやめる 読者になる 読者になる

Daily Creative Coding

元「30 min. Processing」。毎日、Creative Codingします。

Minimでマイク入力した音にディレイをかけてスピーカーから出力する

f:id:aa_debdeb:20151204222509j:plain
/**
* Delayed Sound Input to Output
*
* @author aa_debdeb
* @date 2015/12/15
*/

import ddf.minim.*;
import ddf.minim.analysis.*;
import ddf.minim.effects.*;
import ddf.minim.signals.*;
import ddf.minim.spi.*;
import ddf.minim.ugens.*;

Minim minim;
AudioOutput out;
LiveInput in;
Delay delay;


void setup(){
  size(512, 200);
  minim = new Minim(this);
  out = minim.getLineOut();
  AudioStream inputStream = minim.getInputStream(
                            out.getFormat().getChannels(),
                            out.bufferSize(),
                            out.sampleRate(),
                            out.getFormat().getSampleSizeInBits());
  in = new LiveInput(inputStream);
  delay = new Delay(0.4, 0.5, true, true);
  in.patch(delay).patch(out);
}

void draw(){
  background(0);
  
  stroke(128, 100);
  strokeWeight(1);
  line(mouseX, 0, mouseX, height);
  line(0, mouseY, width, mouseY);
  
  stroke(255);
  strokeWeight(1);
  for(int i = 0; i < out.bufferSize() - 1; i++){
    line(i, 50 + out.left.get(i) * 50, i + 1, 50 + out.left.get(i + 1) * 50);
    line(i, 150 + out.right.get(i) * 50, i + 1, 150 + out.right.get(i + 1) * 50);
  }
  
  textSize(12);
  text("delTime: " + delay.delTime.getLastValue(), 15, 15);
  text("delAmp: " + delay.delAmp.getLastValue(), 15, 30);
}

void mouseMoved(){
  float delTime = map(mouseX, 0, width, 0, 10.0);
  float delAmp = map(mouseY, 0, height, 0, 1.0);
  delay.setDelTime(delTime);
  delay.setDelAmp(delAmp);
}