Class: AudioPlayback::Device::Stream
- Inherits:
-
FFI::PortAudio::Stream
- Object
- FFI::PortAudio::Stream
- AudioPlayback::Device::Stream
- Defined in:
- lib/audio-playback/device/stream.rb
Instance Attribute Summary collapse
-
#is_playing ⇒ Object
(also: #playing?)
readonly
Returns the value of attribute is_playing.
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.
19 20 21 22 23 24 25 26 27 |
# File 'lib/audio-playback/device/stream.rb', line 19 def initialize(output, = {}) @is_playing = false @is_muted = false @gain = 1.0 @input = nil @output = output.resource initialize_exit_callback(:logger => [:logger]) Stream.streams << self end |
Instance Attribute Details
#is_playing ⇒ Object (readonly) Also known as: playing?
Returns the value of attribute is_playing.
7 8 9 |
# File 'lib/audio-playback/device/stream.rb', line 7 def @is_playing end |
Class Method Details
.streams ⇒ Array<Stream>
Keep track of all streams
12 13 14 |
# File 'lib/audio-playback/device/stream.rb', line 12 def self.streams @streams ||= [] end |
Instance Method Details
#active? ⇒ Boolean
Is the stream active?
48 49 50 |
# File 'lib/audio-playback/device/stream.rb', line 48 def active? FFI::PortAudio::API.Pa_IsStreamActive(@stream.read_pointer) == 1 end |
#block ⇒ Boolean
Block process until the current playback finishes
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/audio-playback/device/stream.rb', line 54 def block begin while active? sleep(0.001) end while FFI::PortAudio::API.Pa_IsStreamActive(@stream.read_pointer) != :paNoError sleep(0.1) end rescue SystemExit, Interrupt # Control-C @is_playing = false exit end @is_playing = false true end |
#play(playback, options = {}) ⇒ Stream
Perform the given playback
34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/audio-playback/device/stream.rb', line 34 def play(playback, = {}) @is_playing = true report(playback, [:logger]) if [:logger] if @stream.nil? open_playback(playback) else continue(playback) end start self end |