Class: MorseCode::Sample

Inherits:
Object
  • Object
show all
Defined in:
lib/morse_code/sample.rb

Constant Summary collapse

DIT_LENGTH =
60
DAH_LENGTH =
3 * DIT_LENGTH
DIT_SPACE =
DIT_LENGTH
CHAR_SPACE =
3 * DIT_LENGTH
WORD_SPACE =
7 * DIT_LENGTH

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of Sample.



11
12
13
14
15
# File 'lib/morse_code/sample.rb', line 11

def initialize(message, frequency = 600, sample_rate = 8000)
  @message = message
  @frequency = frequency
  @sample_rate = sample_rate
end

Instance Attribute Details

#frequencyObject (readonly)

Returns the value of attribute frequency.



9
10
11
# File 'lib/morse_code/sample.rb', line 9

def frequency
  @frequency
end

#messageObject (readonly)

Returns the value of attribute message.



9
10
11
# File 'lib/morse_code/sample.rb', line 9

def message
  @message
end

#sample_rateObject (readonly)

Returns the value of attribute sample_rate.



9
10
11
# File 'lib/morse_code/sample.rb', line 9

def sample_rate
  @sample_rate
end

Instance Method Details

#pcm_samplesObject

8-bit unsigned PCM format



18
19
20
21
22
# File 'lib/morse_code/sample.rb', line 18

def pcm_samples
  @pcm_samples ||= [].tap do |pcm_samples|
    samples.each { |sample| pcm_samples.push(128 + (127 * sample).round) }
  end
end