ruby-processingでProcessing->Examples->Libraries->Minimの写経、その1
写経してみたw;
サウンド系のライブラリのようだが、http://dev.processing.org/に詳細がないよw;
load_library :minim case :ForwardFFT when :no def setup end def draw end when :ForwardFFT import 'ddf.minim' import 'ddf.minim.analysis' def setup size 512,200,P2D @minim = Minim.new self @jingle = @minim.load_file "jingle.mp3", 2048 @jingle.loop @fft = FFT.new @jingle.buffer_size,@jingle.sample_rate text_font(create_font("SanSerif",12)) @window_name = "None" end def draw background 0 stroke 255 @fft.forward(@jingle.mix) 0.step(@fft.spec_size-1){|i| line(i,height,i,height-@fft.get_band(i)*4) } fill 255 text "The window being used is: " + @window_name, 5, 20 end #どう設定すれば良いんだろう # def key_pressed # case key # when 'w' # @fft.window(FFT.HAMING) # @window_name = "Haming" # when 'e' # @fft.window(FFT.NONE) # @window_name = "None" # end # end def stop @jingle.close @minim.stop super.stop end when :BandPassFilter import 'ddf.minim' import 'ddf.minim.effects' def setup size 512,200 @minim = Minim.new self @groove = @minim.load_file("groove.mp3") @groove.loop @bpf = BandPass.new 440,20,@groove.sample_rate @groove.add_effect @bpf end def draw background 0 stroke 255 (@groove.right.size-1).times{|i| x1 = map(i, 0,@groove.buffer_size, 0,width) x2 = map(i+1, 0,@groove.buffer_size, 0,width) line x1,height/4-@groove.left.get(i)*50, x2,height/4-@groove.left.get(i+1)*50 line x1,3*height/4-@groove.left.get(i)*50, x2,3*height/4-@groove.left.get(i+1)*50 } no_stroke fill 255,0,0,60 rect mouse_x - @bpf.get_band_width/20, 0, @bpf.get_band_width/10, height end def mouse_moved pass_band = map(mouse_x,0,width,100,2000) pass_width = map(mouse_y,0,height,50,500) @bpf.set_freq pass_band @bpf.set_band_width pass_width @bpf.print_coeff end def stop @groove.close @minim.stop super.stop end when :AddListener import 'ddf.minim' class WaveFormRender include Java.ddf.minim.AudioListener def initialize @left = @right = nil end def samples samp @left = samp end def samples samp_l, samp_r @left,@right = samp_l,samp_r end def draw no_fill stroke 255 if @left and @right left_drow right_drow elsif @left left_drow end end def left_drow begin_shape 0.step(@left.length-1){|i| vertex i,height/4 + @left[i]*50 } end_shape end def right_drow begin_shape 0.step(@right.length-1){|i| vertex i,3*(height/4) + @right[i]*50 } end_shape end end def setup size 512,512,P2D @minim = Minim.new(self) @groove = @minim.loadFile "groove.mp3",1024*8 @groove.loop @waveform = WaveFormRender.new @groove.addListener(@waveform) end def draw background 0 @waveform.draw end def stop @groove.close @minim.stop super.stop end end