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

Daily Creative Coding

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

Minimで振幅変調

f:id:aa_debdeb:20160517000928j:plain
/**
* amplitude modulation
*
* @author aa_debddeb 
* @date 2016/05/23
*/

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, mod;

void setup(){
  size(512, 200);
  minim = new Minim(this);
  out = minim.getLineOut();
  wave = new Oscil(440, 1.0, Waves.SINE);
  mod = new Oscil(2, 0.5, Waves.SINE);
  mod.patch(wave.amplitude);
  wave.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 waveFreq = map(mouseX, 0, width, 1000, 10000);
  wave.setFrequency(waveFreq);  
  float modFreq = map(mouseY, 0, height, 2, 100);
  mod.setFrequency(modFreq);
}