Class: ALSA::Sine

Inherits:
Object
  • Object
show all
Defined in:
lib/alsa/sine.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#frequencyObject

Returns the value of attribute frequency.



3
4
5
# File 'lib/alsa/sine.rb', line 3

def frequency
  @frequency
end

#sample_rateObject

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