Class: AudioStream::Conductor

Inherits:
Object
  • Object
show all
Defined in:
lib/audio_stream/conductor.rb

Instance Method Summary collapse

Constructor Details

#initialize(input:, output:) ⇒ Conductor

Returns a new instance of Conductor.



3
4
5
6
# File 'lib/audio_stream/conductor.rb', line 3

def initialize(input:, output:)
  @inputs = Set[*[input].flatten.compact]
  @outputs = Set[*[output].flatten.compact]
end

Instance Method Details

#connectObject



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/audio_stream/conductor.rb', line 8

def connect
  @outputs.map(&:connect)
  @inputs.map(&:connect)
  @inputs.map(&:publish)

  @sync_thread = Thread.start {
    catch :break do
      loop {
        @inputs.each {|input|
          input.sync.resume
        }

        @inputs.each {|input|
          stat = input.sync.yield_wait
          if stat==Sync::COMPLETED
            @inputs.delete(input)
            #throw :break
          end
        }

        if @inputs.length==0
          throw :break
        end
      }
    end
  }
end

#joinObject



36
37
38
39
40
# File 'lib/audio_stream/conductor.rb', line 36

def join
  @sync_thread.join
  @inputs.map(&:disconnect)
  @outputs.map(&:disconnect)
end