class AudioPlayback::Playback::Frame

A single frame of audio data in the FrameSet

Attributes

frame[R]

Public Class Methods

new(frame) click to toggle source

@param [Array<Float>, Frame] frame

# File lib/audio-playback/playback/frame.rb, line 14
def initialize(frame)
  @frame = frame.frame if frame.kind_of?(Frame)
  @frame ||= frame
end

Public Instance Methods

fill(num, options = {}) click to toggle source

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

existing channel

@param [Integer] num @param [Hash] options @option options [Array<Integer>] :channels (required if :num_channels is provided) @option options [Integer] :num_channels (required if :channels is provided) @return [Boolean]

# 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) click to toggle source

Truncate the frame to the given size @param [Integer] num @return [Frame]

# File lib/audio-playback/playback/frame.rb, line 22
def truncate(num)
  @frame.slice!(num..-1)
  self
end

Private Instance Methods

fill_for_channels(num_channels, channels) click to toggle source

Fill the entire frame for the given channels @param [Integer] num_channels @param [Array<Integer>] channels @return [Boolean]

# File lib/audio-playback/playback/frame.rb, line 58
def fill_for_channels(num_channels, channels)
  values = @frame.dup
  silence_channels(0, num_channels)
  channels.each do |channel|
    value = values[channel] || values.first
    @frame[channel] = value
  end
  true
end
silence_channels(index, num_channels) click to toggle source

Zero out the given number of channels in the frame starting with the given index @param [Integer] index @param [Integer] num_channels @return [Frame]

# File lib/audio-playback/playback/frame.rb, line 49
def silence_channels(index, num_channels)
  @frame.fill(0, index, num_channels)
  self
end