Class: AudioPlayback::Playback::StreamData

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/audio-playback/playback/stream_data.rb

Overview

Playback data for the Device::Stream

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(playback) ⇒ StreamData

Returns a new instance of StreamData.

Parameters:



22
23
24
25
# File 'lib/audio-playback/playback/stream_data.rb', line 22

def initialize(playback)
  @playback = playback
  populate
end

Instance Attribute Details

#num_framesObject (readonly)

Returns the value of attribute num_frames.



10
11
12
# File 'lib/audio-playback/playback/stream_data.rb', line 10

def num_frames
  @num_frames
end

Class Method Details

.to_pointer(playback) ⇒ FFI::Pointer

A C pointer version of the audio data

Parameters:

Returns:

  • (FFI::Pointer)


16
17
18
19
# File 'lib/audio-playback/playback/stream_data.rb', line 16

def self.to_pointer(playback)
  stream_data = new(playback)
  stream_data.to_pointer
end

Instance Method Details

#resetObject

Reset the stream metadata

Parameters:

  • (Boolean)


29
30
31
32
# File 'lib/audio-playback/playback/stream_data.rb', line 29

def reset
  [:is_eof, :pointer].each { |key| (key, 0.0) }
  true
end

#to_pointerFFI::Pointer

A C pointer version of the audio data

Returns:

  • (FFI::Pointer)


36
37
38
39
40
41
42
# File 'lib/audio-playback/playback/stream_data.rb', line 36

def to_pointer
  if @pointer.nil?
    @pointer = FFI::LibC.malloc(@playback.data_size)
    @pointer.write_array_of_float(@data.flatten)
  end
  @pointer
end