Class: ALSA::Sine
- Inherits:
-
Object
- Object
- ALSA::Sine
- Defined in:
- lib/alsa/sine.rb
Instance Attribute Summary collapse
-
#frequency ⇒ Object
Returns the value of attribute frequency.
-
#sample_rate ⇒ Object
Returns the value of attribute sample_rate.
Instance Method Summary collapse
- #frames(length) ⇒ Object
-
#initialize(frequency, sample_rate) ⇒ Sine
constructor
A new instance of Sine.
- #memory_pointer(length) ⇒ Object
Constructor Details
#initialize(frequency, sample_rate) ⇒ Sine
Returns a new instance of Sine.
5 6 7 8 |
# File 'lib/alsa/sine.rb', line 5 def initialize(frequency, sample_rate) @frequency = frequency @sample_rate = sample_rate end |
Instance Attribute Details
#frequency ⇒ Object
Returns the value of attribute frequency.
3 4 5 |
# File 'lib/alsa/sine.rb', line 3 def frequency @frequency end |
#sample_rate ⇒ Object
Returns the value of attribute sample_rate.
3 4 5 |
# File 'lib/alsa/sine.rb', line 3 def sample_rate @sample_rate end |
Instance Method Details
#frames(length) ⇒ Object
10 11 12 13 14 |
# File 'lib/alsa/sine.rb', line 10 def frames(length) (0...length).collect do |frame| 0x7F000000 * Math.sin(2 * Math::PI * frequency * frame / sample_rate) end end |
#memory_pointer(length) ⇒ Object
16 17 18 19 |
# File 'lib/alsa/sine.rb', line 16 def memory_pointer(length) buffer = MemoryPointer.new(:int, length_count) buffer.write_array_of_int frames(length_count) end |