Skip to content

Instantly share code, notes, and snippets.

@jashkenas
Created February 20, 2009 04:15
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save jashkenas/67310 to your computer and use it in GitHub Desktop.
Save jashkenas/67310 to your computer and use it in GitHub Desktop.
A Demonstration of Minim in Ruby-Processing
# Sounder sounds for class
# Requires an active microphone to pick up anything
require 'ruby-processing'
class MinimTest < Processing::App
load_library "minim"
import "ddf.minim"
import "ddf.minim.analysis"
def setup
@minim = Minim.new(self)
@input = @minim.get_line_in
@fft = FFT.new(@input.left.size, 44100)
@beat = BeatDetect.new
@radius = 0
end
def draw
background 0
stroke 255
draw_beat
draw_waveform
draw_frequency
end
def draw_beat
@beat.detect @input.left
@radius = 100 if @beat.is_onset
@radius *= 0.95
oval width/2, height/2, @radius, @radius
end
def draw_waveform
scale = height / 4
(@input.buffer_size - 1).times do |i|
line(i, scale + @input.left.get(i)*scale,
i+1, scale + @input.left.get(i+1) * scale)
end
end
def draw_frequency
@fft.forward @input.left
scale = width / 50
50.times do |i|
@fft.scale_band i, i * 0.35 + 1
@fft.scale_band i, 0.3
line i*scale, height, i*scale, height - @fft.get_band(i)*4
end
end
end
MinimTest.new :width => 700, :height => 700, :title => "Minim Test"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment