Class: AudioStream::AudioOutputFile

Inherits:
AudioOutput show all
Defined in:
lib/audio_stream/audio_output_file.rb

Instance Method Summary collapse

Methods inherited from AudioOutput

device, file

Methods inherited from AudioBus

#add, #on_complete, #update

Methods included from AudioObservable

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

Methods included from AudioObserver

#update

Constructor Details

#initialize(fname, soundinfo:) ⇒ AudioOutputFile

Returns a new instance of AudioOutputFile.



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

def initialize(fname, soundinfo:)
  super()
  @fname = fname
  @soundinfo = soundinfo
end

Instance Method Details

#connectObject



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

def connect
  @sound = RubyAudio::Sound.open(@fname, "w", @soundinfo)
end

#disconnectObject



13
14
15
16
17
# File 'lib/audio_stream/audio_output_file.rb', line 13

def disconnect
  if @sound && !@sound.closed?
    @sound.close
  end
end

#on_completedObject



35
36
37
# File 'lib/audio_stream/audio_output_file.rb', line 35

def on_completed
  disconnect
end

#on_error(error) ⇒ Object



29
30
31
32
33
# File 'lib/audio_stream/audio_output_file.rb', line 29

def on_error(error)
  puts error
  puts error.backtrace.join("\n")
  @sound.close
end

#on_next(input) ⇒ Object



19
20
21
22
23
24
25
26
27
# File 'lib/audio_stream/audio_output_file.rb', line 19

def on_next(input)
  case @soundinfo.channels
  when 1
    input = input.mono
  when 2
    input = input.stereo
  end
  @sound.write(input.to_rabuffer)
end