33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
|
# File 'lib/audio_stream/audio_input_metronome.rb', line 33
def each(&block)
Enumerator.new do |y|
period = @soundinfo.samplerate.to_f / @soundinfo.window_size * 60.0 / @bpm
repeat_count = 0.0
beat_count = 0
Range.new(0, @repeat).each {|_|
if repeat_count<1
if beat_count==0
@synth.note_on(Synthesizer::Note.new(81))
else
@synth.note_on(Synthesizer::Note.new(69))
end
beat_count = (beat_count + 1) % @beat
end
y << @synth.next
repeat_count = (repeat_count + 1) % period
}
end.each(&block)
end
|