class AudioStream::AudioInputFile

Attributes

path[R]

Public Class Methods

new(path, soundinfo:) click to toggle source
# File lib/audio_stream/audio_input_file.rb, line 7
def initialize(path, soundinfo:)
  @path = path
  @soundinfo = soundinfo
end

Public Instance Methods

connect() click to toggle source
# File lib/audio_stream/audio_input_file.rb, line 12
def connect
  if !connected?
    @sound = RubyAudio::Sound.open(@path)
  end
  self
end
connected?() click to toggle source
# File lib/audio_stream/audio_input_file.rb, line 26
def connected?
  @sound && !@sound.closed?
end
disconnect() click to toggle source
Calls superclass method AudioStream::AudioInput#disconnect
# File lib/audio_stream/audio_input_file.rb, line 19
def disconnect
  if connected?
    @sound.close
  end
  super
end
each(&block) click to toggle source
# File lib/audio_stream/audio_input_file.rb, line 39
def each(&block)
  Enumerator.new do |y|
    if !connected?
      raise Error, "File is not opened. You need to exec #{self.class.name}.connect: #{@path}"
    end

    rabuf = RubyAudio::Buffer.float(@soundinfo.window_size, @soundinfo.channels)
    while @sound.read(rabuf)!=0
      y << Buffer.from_rabuffer(rabuf)
    end
  end.each(&block)
end
seek(frames, whence=IO::SEEK_SET) click to toggle source
# File lib/audio_stream/audio_input_file.rb, line 30
def seek(frames, whence=IO::SEEK_SET)
  if !connected?
    raise Error, "File is not opened. You need to exec #{self.class.name}.connect: #{@path}"
  end

  @sound.seek(frames, whence)
  self
end