Class: AudioPlayback::Device::Stream

Inherits:
FFI::PortAudio::Stream
  • Object
show all
Defined in:
lib/audio-playback/device/stream.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(output, options = {}) ⇒ Stream

Returns a new instance of Stream.

Parameters:

  • output (Output)
  • options (Hash) (defaults to: {})

Options Hash (options):

  • logger (IO)


16
17
18
19
20
21
22
23
# File 'lib/audio-playback/device/stream.rb', line 16

def initialize(output, options = {})
  @is_muted = false
  @gain = 1.0
  @input = nil
  @output = output.resource
  initialize_exit_callback(:logger => options[:logger])
  Stream.streams << self
end

Class Method Details

.streamsArray<Stream>

Keep track of all streams

Returns:



9
10
11
# File 'lib/audio-playback/device/stream.rb', line 9

def self.streams
  @streams ||= []
end

Instance Method Details

#active?Boolean

Is the stream active?

Returns:

  • (Boolean)


39
40
41
# File 'lib/audio-playback/device/stream.rb', line 39

def active?
  FFI::PortAudio::API.Pa_IsStreamActive(@stream.read_pointer) == 1
end

#blockBoolean

Block process until the current playback finishes

Returns:

  • (Boolean)


45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/audio-playback/device/stream.rb', line 45

def block
  begin
    while active?
      sleep(0.0001)
    end
    while FFI::PortAudio::API.Pa_IsStreamActive(@stream.read_pointer) != :paNoError
      sleep(1)
    end
  rescue SystemExit, Interrupt
    # Control-C
  ensure
    true
  end
end

#play(playback, options = {}) ⇒ Stream

Perform the given playback

Parameters:

  • playback (Playback)
  • options (Hash) (defaults to: {})

Options Hash (options):

  • logger (IO)

Returns:



30
31
32
33
34
35
# File 'lib/audio-playback/device/stream.rb', line 30

def play(playback, options = {})
  report(playback, options[:logger]) if options[:logger]
  open_playback(playback)
  start
  self
end