Class: MorseCode::Sample
- Inherits:
-
Object
- Object
- MorseCode::Sample
- 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
-
#frequency ⇒ Object
readonly
Returns the value of attribute frequency.
-
#message ⇒ Object
readonly
Returns the value of attribute message.
-
#sample_rate ⇒ Object
readonly
Returns the value of attribute sample_rate.
Instance Method Summary collapse
-
#initialize(message, frequency = 600, sample_rate = 8000) ⇒ Sample
constructor
A new instance of Sample.
-
#pcm_samples ⇒ Object
8-bit unsigned PCM format.
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(, frequency = 600, sample_rate = 8000) @message = @frequency = frequency @sample_rate = sample_rate end |
Instance Attribute Details
#frequency ⇒ Object (readonly)
Returns the value of attribute frequency.
9 10 11 |
# File 'lib/morse_code/sample.rb', line 9 def frequency @frequency end |
#message ⇒ Object (readonly)
Returns the value of attribute message.
9 10 11 |
# File 'lib/morse_code/sample.rb', line 9 def @message end |
#sample_rate ⇒ Object (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_samples ⇒ Object
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 |