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

Daily Creative Coding

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

MinimのWaveShaperを使ってみる

サウンド
f:id:aa_debdeb:20161117201746j:plain
/**
* Minim WaveShaper 
*
* @author aa_debdeb
* @date 2016/11/24
*/

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;
AudioOutput out;
Oscil wave;
WaveShaper shaper;

void setup(){
  size(512, 200);
  minim = new Minim(this);
  out = minim.getLineOut();
  wave = new Oscil(440, 1.0, Waves.SINE);
  shaper = new WaveShaper(0.7, 0.5, Waves.SAW);
  wave.patch(shaper);
  shaper.patch(out);
}

void draw(){
  background(0);
  stroke(255);
  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);
  }
}

void mouseMoved(){
  float frequency = map(mouseX, 0, width, 220, 880);
  wave.setFrequency(frequency);
  float mapAmp = map(mouseY, 0, height, 0.0, 5.0);
  shaper.mapAmplitude.setLastValue(mapAmp);
}