lib/mml2wav/parser.rb in mml2wav-0.0.5 vs lib/mml2wav/parser.rb in mml2wav-0.0.6
- old
+ new
@@ -9,16 +9,15 @@
@bpm = options[:bpm] || 120
@velocity = options[:velocity] || 5
@octave = options[:octave] || 4
@default_length = options[:default_length] || 4.0
@octave_reverse = options[:octave_reverse] || false
- @cursor = 0
end
- def wave!
- @cursor.upto(@sounds.size - 1) do |i|
- sound = @sounds[i]
+ def parse
+ infos = []
+ @sounds.each do |sound|
base_sec = 60.0 * 4
length = @default_length
case sound
when /\AT(\d+)/i
@bpm = $1.to_i
@@ -58,25 +57,17 @@
end
amplitude = @velocity.to_f / 10
frequency = Scale::FREQUENCIES[sound.downcase]
next unless frequency
frequency *= (2 ** @octave)
- wave = sine_wave(frequency, @sampling_rate, sec, amplitude)
- @cursor = i + 1
- return wave
+ infos << {
+ sound: sound.downcase,
+ frequency: frequency,
+ sampling_rate: @sampling_rate,
+ sec: sec,
+ amplitude: amplitude,
+ }
end
- nil
- end
-
- private
- def sine_wave(frequency, sampling_rate, sec, amplitude=0.5)
- max = sampling_rate * sec
- if frequency == 0
- return Array.new(max) { 0.0 }
- end
- base_x = 2.0 * Math::PI * frequency / sampling_rate
- 1.upto(max).collect do |n|
- amplitude * Math.sin(base_x * n)
- end
+ infos
end
end
end