Class: AudioPlayback::Playback::StreamData

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

Overview

Playback data for the Device::Stream

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(playback) ⇒ StreamData

Returns a new instance of StreamData.

Parameters:



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

def initialize(playback)
  @playback = playback
  populate
end

Class Method Details

.to_pointer(playback) ⇒ FFI::Pointer

A C pointer version of the audio data

Parameters:

Returns:

  • (FFI::Pointer)


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

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

Instance Method Details

#resetObject

Reset the stream metadata

Parameters:

  • (Boolean)


24
25
26
27
28
29
30
31
# File 'lib/audio-playback/playback/stream_data.rb', line 24

def reset
  indexes = [
    Playback::.index(:pointer),
    Playback::.index(:is_eof)
  ]
  indexes.each { |index| @data[index] = 0.0 }
  true
end

#to_pointerFFI::Pointer

A C pointer version of the audio data

Returns:

  • (FFI::Pointer)


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

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