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

Daily Creative Coding

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

Minimで音を録音する

f:id:aa_debdeb:20161112150034j:plain
/**
* record & play
*
* @author aa_debdeb
* @date 2016/11/18
*/

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

Minim minim;
AudioInput in;
AudioOutput out;
AudioRecorder recorder;
FilePlayer player;

void setup(){
  size(300, 200);
  minim = new Minim(this);
  in = minim.getLineIn();
  out = minim.getLineOut();
}

void draw(){
  if(recorder != null && recorder.isRecording()){
    background(255, 0, 0);
  } else {
    background(128);
  }
}

void mousePressed(){
  if(recorder != null && recorder.isRecording()){
    recorder.endRecord();
  } else {
    recorder = minim.createRecorder(in, "record.wav");
    recorder.beginRecord();
  }
}

void keyPressed(){
  if(recorder != null){
    player = new FilePlayer(recorder.save());
    player.patch(out);
    player.play();
  }
}