Class: MorseCode::Wave

Inherits:
Object
  • Object
show all
Includes:
WaveFile
Defined in:
lib/morse_code/wave.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(message, frequency = 600, sample_rate = 8000) ⇒ Wave

Returns a new instance of Wave.



9
10
11
12
13
# File 'lib/morse_code/wave.rb', line 9

def initialize(message, frequency = 600, sample_rate = 8000)
  @message = message
  @sample_rate = sample_rate
  @sample = MorseCode::Sample.new(message, frequency, sample_rate)
end

Instance Attribute Details

#messageObject (readonly)

Returns the value of attribute message.



7
8
9
# File 'lib/morse_code/wave.rb', line 7

def message
  @message
end

Instance Method Details

#generateObject



15
16
17
18
19
20
21
# File 'lib/morse_code/wave.rb', line 15

def generate
  buffer = WaveFile::Buffer.new(pcm_samples, WaveFile::Format.new(:mono, :float, @sample_rate))
  WaveFile::Writer.new(filepath, WaveFile::Format.new(:mono, :pcm_16, @sample_rate)) do |writer|
    writer.write(buffer)
  end
  filepath
end