Class: Feep::Base
- Inherits:
-
Object
- Object
- Feep::Base
- Defined in:
- lib/feep.rb
Instance Method Summary collapse
-
#configure_sound(options) ⇒ Object
takes CLI options, massages them, and passes them to the sound generation methods.
-
#initialize(options) ⇒ Base
constructor
main entry point.
Constructor Details
#initialize(options) ⇒ Base
main entry point
13 14 15 16 |
# File 'lib/feep.rb', line 13 def initialize() @options = configure_sound() end |
Instance Method Details
#configure_sound(options) ⇒ Object
takes CLI options, massages them, and passes them to the sound generation methods
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/feep.rb', line 20 def configure_sound() ### A. Check non-essential options if !WAVE_TYPES.include?([:waveform]) print_error(ERROR_MSG[:invalid_waveform]) end # Convert ms to secs in order to multiply the sample rate by duration_s = ([:duration].to_f / 1000) # Make the samples to write a nice integer samples_to_write = (SAMPLE_RATE * duration_s).to_i ### B. Set frequency/note, or group of frequencies/notes, to play # Is it a chord, scale, or single note? if [:freq_or_note].include?(',') # yes, it's a chord, so create threads threads = [] [:freq_or_note].split(',').each do |note| sound_to_play = Utils.convert_note_to_freq(note) output_filename = "#{[:waveform]}_#{sound_to_play}Hz_#{[:volume].to_f}_#{[:duration]}.wav" threads << Thread.new { SoundPlayer.new.play_note(sound_to_play, output_filename, samples_to_write, ) } end threads.each { |th| th.join } else # it's a scale if [:scale] Feep::Scale.new.play_scale() else # no, it's a single note sound_to_play = Utils.convert_note_to_freq([:freq_or_note]) output_filename = "#{[:waveform]}_#{sound_to_play}Hz_#{[:volume].to_f}_#{[:duration]}.wav" SoundPlayer.new.play_note(sound_to_play, output_filename, samples_to_write, ) end end end |