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

Daily Creative Coding

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

Minimのボコーダーを使う

サウンド
f:id:aa_debdeb:20151203002416j:plain

キーボード入力でボコーダーのキャリアを変更可能

  • 1: デフォルト
  • 2: 三角波
  • 3: 矩形波
  • 4: ノコギリ波
  • 5: ホワイトノイズ

ただ,デフォルト以外は同じ音に聞こえる.もっとキャリアを作りこまなければならないのかも.

/**
* Vocoder
*
* @author aa_debdeb
* @date 2015/12/11
*/

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;
Vocoder vocoder;
UGen triangleV, squareV, sawV, noiseV;
Noise noise;
int carier;

void setup(){
  size(512, 200);
  minim = new Minim(this);
  out = minim.getLineOut();
  Oscil triangle = new Oscil(440, 1.0, Waves.TRIANGLE);
  Oscil square = new Oscil(440, 1.0, Waves.SQUARE);
  Oscil saw = new Oscil(440, 1.0, Waves.SAW);
  Noise noise = new Noise(1.0, Noise.Tint.WHITE);
  carier = 1;
  
  AudioStream inputStream = minim.getInputStream(
                            out.getFormat().getChannels(),
                            out.bufferSize(),
                            out.sampleRate(),
                            out.getFormat().getSampleSizeInBits());
  in = new LiveInput(inputStream);
  vocoder = new Vocoder(1024, 8);
  in.patch(vocoder.modulator);
  in.patch(out);
  triangleV = triangle.patch(vocoder);
  squareV = square.patch(vocoder);
  sawV = saw.patch(vocoder);
  noiseV = noise.patch(vocoder);
}

void draw(){
  background(0);

  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);
  }
  
  fill(255, 0, 0);
  switch(carier){
   case 1:
     text("default", 10, 20);
     break;
   case 2:
     text("triangle", 10, 20);
     break;
   case 3:
     text("square", 10, 20);
     break;
   case 4:
     text("saw", 10, 20);
     break;
   case 5:
     text("noise", 10, 20);
     break;
  }
  
}

void keyPressed(){
      
  switch(key){
    case '1':
      unpatch(carier);
      in.patch(out);
      carier = 1;
      break;
    case '2':
      unpatch(carier);
      triangleV.patch(out);
      carier = 2;
      break;
    case '3':
      unpatch(carier);
      squareV.patch(out);
      carier = 3;
      break;
    case '4':
      unpatch(carier);
      sawV.patch(out);
      carier = 4;
      break;
    case '5':
      unpatch(carier);
      noiseV.patch(out);
      carier = 5;
      break;
  }  
}

void unpatch(int preCarier){
  switch(preCarier){
   case 1:
     in.unpatch(out);
     break;
   case 2:
     triangleV.unpatch(out);
     break;
   case 3:
     squareV.unpatch(out);
     break;
   case 4:
     sawV.unpatch(out);
     break;
   case 5:
     noiseV.unpatch(out);
     break;
  }
}