jruby + processing + audioinput

さっきは会社でこっそりカメラを叩いたのだけど、コミューン(仮住まい)でオーディオまわりをば。使うライブラリは↓これ。

Minim: An Audio Library for Processing | Compartmental

require "java"

include_class "processing.core.PApplet"

include_class "ddf.minim.Minim"
include_class "ddf.minim.AudioInput"
include_class "org.tritonus.share.sampled.FloatSampleBuffer"

class Sketch < PApplet
  
  def setup
    size(320,240)
    
    Minim.start(self)
    @inp = Minim.getLineIn(Minim::MONO, 320, 44100, 16)
  end
  
  def draw
    background(0)
    stroke(255)
    
    (@inp.left.size-1).times do |i|
      line(i, 50+@inp.left.get(i)*50, i+1, 50+@inp.left.get(i+1)*50)
    end
  end
  
  def stop
    Minim.stop
    super stop
  end
  
end

JFrame = javax.swing.JFrame

def run applet
	frame = JFrame.new applet.class.to_s
	frame.content_pane.add applet
	frame.default_close_operation = JFrame::EXIT_ON_CLOSE
	applet.init
	frame.pack
	frame.visible = true
end

if $0 == __FILE__
	run Sketch.new
end

examplesにあった内蔵マイクからの音声入力波形を表示。これもいけた。