Class: CoreAudio::AudioObject

Inherits:
Object
  • Object
show all
Defined in:
lib/core_audio/audio_object.rb

Direct Known Subclasses

AudioDevice

Defined Under Namespace

Classes: PropertyAddress

Constant Summary collapse

ObjectID =
FFI::Type::UINT32
PropertyElement =
FFI::Type::UINT32
PropertyScope =
FFI::Type::UINT32
PropertySelector =
FFI::Type::UINT32
PropertyScopeGlobal =

AudioHardwareBase.h: Basic Constants

'glob'
PropertyScopeInput =
'inpt'
PropertyScopeOutput =
'outp'
PropertyScopePlayThrough =
'ptru'
PropertyElementMaster =
0
PropertyBaseClass =

AudioHardwareBase.h: AudioObject Properties

'bcls'
PropertyClass =
'clas'
PropertyOwner =
'stdv'
PropertyName =
'lnam'
PropertyModelName =
'lmod'
PropertyManufacturer =
'lmak'
PropertyElementName =
'lchn'
PropertyElementCategoryName =
'lccn'
PropertyElementNumberName =
'lcnn'
PropertyOwnedObjects =
'ownd'
PropertyIdentify =
'iden'
PropertySerialNumber =
'snum'
PropertyFirmwareVersion =
'fwvn'
SystemObject =

AudioHardware.h: Basic Constants

1

Instance Attribute Summary collapse

Convenience Attributes collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id) ⇒ AudioObject

Returns a new instance of AudioObject.



108
109
110
# File 'lib/core_audio/audio_object.rb', line 108

def initialize(id)
    @id = id
end

Instance Attribute Details

#idObject (readonly)

Returns the value of attribute id.



72
73
74
# File 'lib/core_audio/audio_object.rb', line 72

def id
  @id
end

Class Method Details

.systemObject



104
105
106
# File 'lib/core_audio/audio_object.rb', line 104

def self.system
    new(SystemObject)
end

Instance Method Details

#device_nameString

Returns the name of the device.

Returns:

  • (String)

    the name of the device



137
138
139
140
# File 'lib/core_audio/audio_object.rb', line 137

def device_name
    address = PropertyAddress.global_master(PropertyName)
    get_string(address)
end

#device_uidObject



142
143
144
145
# File 'lib/core_audio/audio_object.rb', line 142

def device_uid
    address = PropertyAddress.global_master(AudioHardwareBase::AudioDevicePropertyDeviceUID)
    get_string(address)
end

#external?Boolean

Returns:

  • (Boolean)


127
128
129
# File 'lib/core_audio/audio_object.rb', line 127

def external?
    not internal?
end

#get_property(address) ⇒ FFI::MemoryPointer

Returns:

  • (FFI::MemoryPointer)


113
114
115
116
117
118
119
120
121
122
123
124
# File 'lib/core_audio/audio_object.rb', line 113

def get_property(address)
    buffer_size = FFI::MemoryPointer.new(:uint32)
    status = CoreAudio.AudioObjectGetPropertyDataSize(id, address, 0, nil, buffer_size)
    raise('Could not get audio property size') unless 0 == status

    # buffer_size is now the size of the buffer to be passed to AudioObjectGetPropertyData()
    buffer = FFI::MemoryPointer.new(1, buffer_size.get_int32(0))
    status = CoreAudio.AudioObjectGetPropertyData(id, address, 0, nil, buffer_size, buffer)
    raise('Could not get the audio property data') unless 0 == status

    buffer
end

#internal?Boolean

Returns:

  • (Boolean)


131
132
133
# File 'lib/core_audio/audio_object.rb', line 131

def internal?
    transport_type == 'bltn'
end

#model_uidString

Returns a persistent identifier for the model of an AudioDevice.

Returns:

  • (String)

    a persistent identifier for the model of an AudioDevice



148
149
150
151
# File 'lib/core_audio/audio_object.rb', line 148

def model_uid
    address = PropertyAddress.global_master(AudioHardwareBase::AudioDevicePropertyModelUID)
    get_string(address)
end

#transport_typeString

Returns the 4-character transport type identifier.

Returns:

  • (String)

    the 4-character transport type identifier



154
155
156
157
158
# File 'lib/core_audio/audio_object.rb', line 154

def transport_type
    address = PropertyAddress.global_master(AudioHardwareBase::AudioDevicePropertyTransportType)
    buffer = get_property(address)
    buffer.get_bytes(0, buffer.size).reverse
end