Class: FrameReader

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/terminal_player/spotiphy.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(channels, sample_type, frames_count, frames_ptr) ⇒ FrameReader

Returns a new instance of FrameReader.



17
18
19
20
21
22
# File 'lib/terminal_player/spotiphy.rb', line 17

def initialize(channels, sample_type, frames_count, frames_ptr)
  @channels = channels
  @sample_type = sample_type
  @size = frames_count * @channels
  @pointer = FFI::Pointer.new(@sample_type, frames_ptr)
end

Instance Attribute Details

#sizeObject (readonly)

Returns the value of attribute size.



24
25
26
# File 'lib/terminal_player/spotiphy.rb', line 24

def size
  @size
end

Instance Method Details

#eachObject



26
27
28
29
30
31
32
33
34
# File 'lib/terminal_player/spotiphy.rb', line 26

def each
  return enum_for(__method__) unless block_given?

  ffi_read = :"read_#{@sample_type}"

  (0...size).each do |index|
    yield @pointer[index].public_send(ffi_read)
  end
end