2015年7月25日土曜日

Processing Sound (day 3)


Day1 にて紹介したライン入力にpatch()メソッドを適用する方法としてもっとシンプルな方法がわかったので紹介します。

minimのreferencesのVocoderの部分にあったやり方です。
Vocoder reference in -> http://code.compartmental.net/minim/vocoder_class_vocoder.html

以下ソース
import ddf.minim.*;
import ddf.minim.ugens.*;
import ddf.minim.spi.*;

Minim minim;
LiveInput in;
AudioOutput out;
AudioRecorder recorder;

void setup(){
  size(1024,200);
  //initialize the minim and out objects
  int buffer_size = 512;
  minim = new Minim(this);
  minim.debugOn();
  out = minim.getLineOut(Minim.STEREO,buffer_size);

  AudioStream inputStream = minim.getInputStream( Minim.STEREO, 
                                                  out.bufferSize(), 
                                                  out.sampleRate(), 
                                                  out.getFormat().getSampleSizeInBits()
                                                 );
  in = new LiveInput(inputStream);
  out = minim.getLineOut(Minim.STEREO,buffer_size);
  in.patch(out);
}

void draw(){
  // erase the window to dark grey
  background( 64 );
  // draw using a light gray stroke
  stroke( 192 );
  // draw the waveforms
  for( int i = 0; i < out.bufferSize() - 1; i++ )
  {
    // find the x position of each buffer value
    float x1  =  map( i, 0, out.bufferSize(), 0, width );
    float x2  =  map( i+1, 0, out.bufferSize(), 0, width );
    // draw a line from one buffer position to the next for both channels
    line( x1, 50 + out.left.get(i)*50, x2, 50 + out.left.get(i+1)*50);
    line( x1, 150 + out.right.get(i)*50, x2, 150 + out.right.get(i+1)*50);
  }
}

この方法でスマートにpatch()を適用することができ、Day2のようなエフェクトの追加が可能です。

0 件のコメント:

コメントを投稿