Class: CoreAudio::AudioDevice

Inherits:
AudioObject show all
Defined in:
lib/core_audio/audio_device.rb

AudioHardware.h: AudioDevice Properties collapse

PropertyPlugIn =
'plug'
PropertyDeviceHasChanged =
'diff'
PropertyDeviceIsRunningSomewhere =
'gone'
ProcessorOverload =
'over'
PropertyIOStoppedAbnormally =
'stpd'
PropertyHogMode =
'oink'
PropertyBufferFrameSize =
'fsiz'
PropertyBufferFrameSizeRange =
'fsz#'
PropertyUsesVariableBufferFrameSizes =
'vfsz'
PropertyIOCycleUsage =
'ncyc'
PropertyStreamConfiguration =
'slay'
PropertyIOProcStreamUsage =
'suse'
PropertyActualSampleRate =
'asrt'

Constants inherited from AudioObject

CoreAudio::AudioObject::ObjectID, CoreAudio::AudioObject::PropertyBaseClass, CoreAudio::AudioObject::PropertyClass, CoreAudio::AudioObject::PropertyElement, CoreAudio::AudioObject::PropertyElementCategoryName, CoreAudio::AudioObject::PropertyElementMaster, CoreAudio::AudioObject::PropertyElementName, CoreAudio::AudioObject::PropertyElementNumberName, CoreAudio::AudioObject::PropertyFirmwareVersion, CoreAudio::AudioObject::PropertyIdentify, CoreAudio::AudioObject::PropertyManufacturer, CoreAudio::AudioObject::PropertyModelName, CoreAudio::AudioObject::PropertyName, CoreAudio::AudioObject::PropertyOwnedObjects, CoreAudio::AudioObject::PropertyOwner, CoreAudio::AudioObject::PropertyScope, CoreAudio::AudioObject::PropertyScopeGlobal, CoreAudio::AudioObject::PropertyScopeInput, CoreAudio::AudioObject::PropertyScopeOutput, CoreAudio::AudioObject::PropertyScopePlayThrough, CoreAudio::AudioObject::PropertySelector, CoreAudio::AudioObject::PropertySerialNumber, CoreAudio::AudioObject::SystemObject

Instance Attribute Summary

Attributes inherited from AudioObject

#id

Properties collapse

Instance Method Summary collapse

Methods inherited from AudioObject

#device_name, #device_uid, #external?, #get_property, #initialize, #internal?, #model_uid, system, #transport_type

Constructor Details

This class inherits a constructor from CoreAudio::AudioObject

Instance Method Details

#actual_sample_rateObject



57
58
59
60
# File 'lib/core_audio/audio_device.rb', line 57

def actual_sample_rate
    address = PropertyAddress.global_master(PropertyActualSampleRate)
    get_property(address).get_float64(0)
end

#buffer_frame_sizeObject



62
63
64
65
# File 'lib/core_audio/audio_device.rb', line 62

def buffer_frame_size
    address = PropertyAddress.global_master(PropertyBufferFrameSize)
    get_property(address).get_uint32(0)
end

#running_somewhere?Boolean

Returns:

  • (Boolean)


67
68
69
70
# File 'lib/core_audio/audio_device.rb', line 67

def running_somewhere?
    address = PropertyAddress.global_master(PropertyDeviceIsRunningSomewhere)
    0 != get_property(address).get_uint32(0)
end

#start(&block) ⇒ Object

Start the AudioDevice

If a block is provided, register it as a callback before starting the device
@note The device will continue to run until `stop` is called


76
77
78
79
80
81
82
83
84
85
86
87
88
89
# File 'lib/core_audio/audio_device.rb', line 76

def start(&block)
    if block_given?
	io_proc_id = FFI::MemoryPointer.new(:pointer)
	status = CoreAudio.AudioDeviceCreateIOProcID(id, block, nil, io_proc_id)

	raise "Couldn't create an IO Proc #{status} => '#{[status].pack('L').reverse}'" unless status.zero? # && !@proc_id.nil?

	@proc_id = io_proc_id.get_pointer(0)
    end

    Thread.start do
	CoreAudio.AudioDeviceStart(id, @proc_id)
    end
end

#stopObject

Stop the AudioDevice and delete any registered callbacks



92
93
94
95
# File 'lib/core_audio/audio_device.rb', line 92

def stop
    CoreAudio.AudioDeviceStop(id, @proc_id)
    CoreAudio.AudioDeviceDestroyIOProcID(id, @proc_id)
end