Class: AudioPlayback::Playback::Frame

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

Overview

A single frame of audio data in the FrameSet

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(frame) ⇒ Frame

Returns a new instance of Frame.

Parameters:

  • frame (Array<Float>, Frame)


14
15
16
17
# File 'lib/audio-playback/playback/frame.rb', line 14

def initialize(frame)
  @frame = frame.frame if frame.kind_of?(Frame)
  @frame ||= frame
end

Instance Attribute Details

#frameObject (readonly)

Returns the value of attribute frame.



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

def frame
  @frame
end

Instance Method Details

#fill(num, options = {}) ⇒ Boolean

Fill up the given number of channels at the end of the frame with duplicate data from the last

existing channel

Parameters:

  • num (Integer)
  • options (Hash) (defaults to: {})

Options Hash (options):

  • :channels (Array<Integer>) — default: required if :num_channels is provided
  • :num_channels (Integer) — default: required if :channels is provided

Returns:

  • (Boolean)


34
35
36
37
38
39
40
41
# File 'lib/audio-playback/playback/frame.rb', line 34

def fill(num, options = {})
  if (channels = options[:channels]).nil?
    @frame.fill(@frame.last, @frame.size, num)
  else
    fill_for_channels(options[:num_channels], channels)
  end
  true
end

#truncate(num) ⇒ Frame

Truncate the frame to the given size

Parameters:

  • num (Integer)

Returns:



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

def truncate(num)
  @frame.slice!(num..-1)
  self
end