Module: AudioPlayback::Device

Extended by:
Device
Included in:
Device
Defined in:
lib/audio-playback/device.rb,
lib/audio-playback/device/output.rb,
lib/audio-playback/device/stream.rb

Overview

Audio IO devices

Defined Under Namespace

Classes: Output, Stream

Instance Method Summary collapse

Instance Method Details

#by_id(id) ⇒ Output

Get a device by its ID

Parameters:

  • id (Integer)

Returns:



26
27
28
# File 'lib/audio-playback/device.rb', line 26

def by_id(id)
  outputs.find { |device| [device, device.id].include?(id) }
end

#by_name(name) ⇒ Output

Get a device by its name

Parameters:

  • name (String)

Returns:



33
34
35
# File 'lib/audio-playback/device.rb', line 33

def by_name(name)
  outputs.find { |device| device.name == name }
end

#default_outputOutput

The system default output

Returns:



39
40
41
# File 'lib/audio-playback/device.rb', line 39

def default_output
  by_id(FFI::PortAudio::API.Pa_GetDefaultOutputDevice)
end

#device_info(id) ⇒ FFI::PortAudio::API::PaDeviceInfo

Get system device info given a device ID

Parameters:

  • id (Integer)

Returns:

  • (FFI::PortAudio::API::PaDeviceInfo)


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

def device_info(id)
  FFI::PortAudio::API.Pa_GetDeviceInfo(id)
end

#outputsArray<Output>

All output devices

Returns:



13
14
15
16
17
18
19
20
21
# File 'lib/audio-playback/device.rb', line 13

def outputs
  AudioPlayback.ensure_initialized
  if @devices.nil?
    count = FFI::PortAudio::API.Pa_GetDeviceCount
    ids = (0..count-1).to_a.select { |id| output?(id) }
    @devices = ids.map { |id| Output.new(id) }
  end
  @devices
end