Class: AudioPlayback::Device::Stream
- Inherits:
-
FFI::PortAudio::Stream
- Object
- FFI::PortAudio::Stream
- AudioPlayback::Device::Stream
- Defined in:
- lib/audio-playback/device/stream.rb
Class Method Summary collapse
-
.streams ⇒ Array<Stream>
Keep track of all streams.
Instance Method Summary collapse
-
#active? ⇒ Boolean
Is the stream active?.
-
#block ⇒ Boolean
Block process until the current playback finishes.
-
#initialize(output, options = {}) ⇒ Stream
constructor
A new instance of Stream.
-
#play(playback, options = {}) ⇒ Stream
Perform the given playback.
Constructor Details
#initialize(output, options = {}) ⇒ Stream
Returns a new instance of Stream.
16 17 18 19 20 21 22 23 |
# File 'lib/audio-playback/device/stream.rb', line 16 def initialize(output, = {}) @is_muted = false @gain = 1.0 @input = nil @output = output.resource initialize_exit_callback(:logger => [:logger]) Stream.streams << self end |
Class Method Details
.streams ⇒ Array<Stream>
Keep track of all streams
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?
39 40 41 |
# File 'lib/audio-playback/device/stream.rb', line 39 def active? FFI::PortAudio::API.Pa_IsStreamActive(@stream.read_pointer) == 1 end |
#block ⇒ Boolean
Block process until the current playback finishes
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
30 31 32 33 34 35 |
# File 'lib/audio-playback/device/stream.rb', line 30 def play(playback, = {}) report(playback, [:logger]) if [:logger] open_playback(playback) start self end |