Daily Creative Coding

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

Minimでいろいろなノイズを鳴らす

f:id:aa_debdeb:20151201133428j:plain

キー入力でノイズの種類を変更できる

  • 1: ホワイトノイズ
  • 2: ブラウンノイズ
  • 3: ピンクノイズ
  • 4: レッドノイズ

ブラウンノイズとレッドノイズは同じ?

/**
* Minim Noise Sound
*
* @author aa_debdeb
* @date 2015/12/05
*/

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;
Noise noise;

void setup(){
  size(512, 200);
  minim = new Minim(this);
  out = minim.getLineOut();
  
  noise = new Noise(1.0, Noise.Tint.WHITE);
  noise.patch(out);
}

void draw(){
  background(0);
  
  color c = color(255);
  switch(noise.getTint()){
    case WHITE:
      c = color(255);
      break;
    case BROWN:
      c = color(109, 76, 51);
      break;
    case PINK:
      c = color(247, 171, 166);
      break;
    case RED:
      c = color(255, 0, 0);
      break;
  }
  stroke(c);
  strokeWeight(1);
  noFill();
  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 keyPressed(){
  switch(key){
    case '1':
      noise.setTint(Noise.Tint.WHITE);
      break;
    case '2':
      noise.setTint(Noise.Tint.BROWN);
      break;
    case '3':
      noise.setTint(Noise.Tint.PINK);
      break;
    case '4':
      noise.setTint(Noise.Tint.RED);
      break;
  }
}