Class: AudioPlayback::Device::Output

Inherits:
Object
  • Object
show all
Defined in:
lib/audio-playback/device/output.rb

Overview

An output device

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id, options = {}) ⇒ Output

Returns a new instance of Output.

Parameters:

  • id (Integer)
  • options (Hash) (defaults to: {})

Options Hash (options):

  • :latency (Float)

    Device latency in seconds



61
62
63
64
65
# File 'lib/audio-playback/device/output.rb', line 61

def initialize(id, options = {})
  # Init audio output resource
  AudioPlayback.ensure_initialized
  populate(id, options)
end

Instance Attribute Details

#idInteger (readonly)

ID of the device

Returns:

  • (Integer)


81
82
83
# File 'lib/audio-playback/device/output.rb', line 81

def id
  @id
end

#nameObject (readonly)

Returns the value of attribute name.



7
8
9
# File 'lib/audio-playback/device/output.rb', line 7

def name
  @name
end

#resourceObject (readonly)

Returns the value of attribute resource.



7
8
9
# File 'lib/audio-playback/device/output.rb', line 7

def resource
  @resource
end

Class Method Details

.allArray<Output>

All output devices

Returns:



11
12
13
# File 'lib/audio-playback/device/output.rb', line 11

def self.all
  Device.outputs
end

.by_id(id) ⇒ Output

Select an output device by ID

Parameters:

  • id (Integer)

Returns:



47
48
49
# File 'lib/audio-playback/device/output.rb', line 47

def self.by_id(id)
  Device.by_id(id)
end

.by_name(name) ⇒ Output

Select an output device by name

Parameters:

  • name (String)

Returns:



54
55
56
# File 'lib/audio-playback/device/output.rb', line 54

def self.by_name(name)
  Device.by_name(name)
end

.getsOutput

Streamlined console prompt that asks the user (via standard in) to select a device When their input is received, the device is selected and enabled

Returns:



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/audio-playback/device/output.rb', line 28

def self.gets
  device = nil
  puts ""
  puts "Select an audio output..."
  while device.nil?
    list
    print "> "
    selection = $stdin.gets.chomp
    if selection != ""
      selection = Integer(selection) rescue nil
      device = all.find { |d| d.id == selection } unless selection.nil?
    end
  end
  device
end

.listArray<String>

Prints ids and names of each device to standard out

Returns:

  • (Array<String>)


17
18
19
20
21
22
23
# File 'lib/audio-playback/device/output.rb', line 17

def self.list
  all.map do |device|
    name = "#{device.id}. #{device.name}"
    $>.puts(name)
    name
  end
end

Instance Method Details

#latencyFloat

Device latency in seconds

Returns:

  • (Float)


69
70
71
# File 'lib/audio-playback/device/output.rb', line 69

def latency
  @resource[:suggestedLatency]
end

#num_channelsInteger

Number of channels the device supports

Returns:

  • (Integer)


75
76
77
# File 'lib/audio-playback/device/output.rb', line 75

def num_channels
  @resource[:channelCount]
end