Module: AudioStream::AudioInput

Includes:
AudioObservable, Enumerable
Included in:
AudioInputBuffer, AudioInputDevice, AudioInputFile
Defined in:
lib/audio_stream/audio_input.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from AudioObservable

#fx, #mono, #notify_complete, #notify_next, #send_to, #stereo, #subscribe, #subscribe_on_next

Instance Attribute Details

#connectionObject (readonly)

Returns the value of attribute connection.



7
8
9
# File 'lib/audio_stream/audio_input.rb', line 7

def connection
  @connection
end

Class Method Details

.buffer(buf) ⇒ Object



52
53
54
# File 'lib/audio_stream/audio_input.rb', line 52

def self.buffer(buf)
  AudioInputBuffer.new(buf)
end

.device(soundinfo:) ⇒ Object



56
57
58
# File 'lib/audio_stream/audio_input.rb', line 56

def self.device(soundinfo:)
  AudioInputDevice.default_device(soundinfo: soundinfo)
end

.file(fname, soundinfo:) ⇒ Object



48
49
50
# File 'lib/audio_stream/audio_input.rb', line 48

def self.file(fname, soundinfo:)
  AudioInputFile.new(fname, soundinfo: soundinfo)
end

Instance Method Details

#connectObject



27
28
29
# File 'lib/audio_stream/audio_input.rb', line 27

def connect
  nil
end

#connected?Boolean

Returns:

  • (Boolean)


39
40
41
# File 'lib/audio_stream/audio_input.rb', line 39

def connected?
  nil
end

#disconnectObject



31
32
33
34
35
36
37
# File 'lib/audio_stream/audio_input.rb', line 31

def disconnect
  if @connection
    @connection.kill
    @connection = nil
  end
  self
end

#publishObject



13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/audio_stream/audio_input.rb', line 13

def publish
  @connection = Thread.start {
    each {|input|
      sync.resume_wait
      notify_next(input)
      sync.yield
    }
    sync.resume_wait
    notify_complete
    sync.finish
  }
  self
end

#published?Boolean

Returns:

  • (Boolean)


43
44
45
# File 'lib/audio_stream/audio_input.rb', line 43

def published?
  !!@connection
end

#syncObject



9
10
11
# File 'lib/audio_stream/audio_input.rb', line 9

def sync
  @sync ||= Sync.new
end