Module: Radio::Signal

Defined in:
lib/radio/signal.rb,
lib/radio/signals/wav.rb,
lib/radio/signals/alsa.rb,
lib/radio/signals/file.rb,
lib/radio/signals/coreaudio.rb

Defined Under Namespace

Classes: ALSA, CoreAudio, File

Class Method Summary collapse

Class Method Details

.devicesObject

Consolidate all sources from all inputs and add the class name to the keys.



33
34
35
36
37
38
39
40
41
# File 'lib/radio/signal.rb', line 33

def self.devices
  s = {}
  constants.each do |type|
    eval(type.to_s).devices.each do |id, source|
      s[[type, id]] = source
    end
  end
  s
end

.new(options) ⇒ Object

You can’t new a module so this switches into the specific class.



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/radio/signal.rb', line 44

def self.new options
  type = options.delete :type
  options[:output] = [options[:output]].flatten if options[:output]
  options[:input] = [options[:input]].flatten if options[:input]
  unless constants.include? type.to_sym
    raise NameError, "uninitialized constant Radio::Input::#{type}"
  end
  device = eval(type.to_s).new options
  # Ask for and discard the first sample to report errors here
  begin
    device.out NArray.scomplex(1) if device.output_channels == 2
    device.out NArray.sfloat(1) if device.output_channels == 1
    device.in 1 if device.input_channels > 0
  rescue Exception => e
    device.stop
    raise e
  end
  device
end

.statusObject

Drivers are supposed to fail silently if they can’t find dependencies. This allows us to present a basic debug screen.



24
25
26
27
28
29
30
# File 'lib/radio/signal.rb', line 24

def self.status
  s = {}
  constants.collect do |input_name|
    s[input_name] = eval(input_name.to_s).status
  end
  s
end