AudioObject

public class AudioObject : CustomDebugStringConvertible
extension AudioObject: Hashable

A HAL audio object

  • The underlying audio object ID

    Declaration

    Swift

    public let objectID: AudioObjectID
  • Returns true if self has property

    Declaration

    Swift

    public final func hasProperty(_ property: PropertyAddress) -> Bool

    Parameters

    property

    The property to query

  • Returns true if property is settable

    Throws

    An error if self does not have property

    Declaration

    Swift

    public final func isPropertySettable(_ property: PropertyAddress) throws -> Bool

    Parameters

    property

    The property to query

  • A block called with one or more changed audio object properties

    Declaration

    Swift

    public typealias PropertyChangeNotificationBlock = (_ changes: [PropertyAddress]) -> Void

    Parameters

    changes

    An array of changed property addresses

  • Registers block to be performed when property changes

    Throws

    An error if the property listener could not be registered

    Declaration

    Swift

    public final func whenPropertyChanges(_ property: PropertyAddress, perform block: PropertyChangeNotificationBlock?) throws

    Parameters

    property

    The property to observe

    block

    A closure to invoke when property changes or nil to remove the previous value

  • Declaration

    Swift

    public var debugDescription: String { get }
  • Declaration

    Swift

    public static func == (lhs: AudioObject, rhs: AudioObject) -> Bool
  • Declaration

    Swift

    public func hash(into hasher: inout Hasher)

Scalar Properties

  • Returns the numeric value of property

    Note

    The underlying audio object property must be backed by an equivalent native C type of T

    Throws

    An error if self does not have property or the property value could not be retrieved

    Declaration

    Swift

    public func getProperty<T>(_ property: PropertyAddress, type: T.Type, qualifier: PropertyQualifier? = nil, initialValue: T = 0) throws -> T where T : Numeric

    Parameters

    property

    The address of the desired property

    type

    The underlying numeric type

    qualifier

    An optional property qualifier

    initialValue

    An optional initial value for outData when calling AudioObjectGetPropertyData

  • Returns the Core Foundation object value of property

    Note

    The underlying audio object property must be backed by a Core Foundation object and return a CFType with a +1 retain count

    Throws

    An error if self does not have property or the property value could not be retrieved

    Declaration

    Swift

    public func getProperty<T>(_ property: PropertyAddress, type: T.Type, qualifier: PropertyQualifier? = nil) throws -> T where T : AnyObject

    Parameters

    property

    The address of the desired property

    type

    The underlying CFType

    qualifier

    An optional property qualifier

  • Returns the AudioValueRange value of property

    Note

    The underlying audio object property must be backed by AudioValueRange

    Throws

    An error if self does not have property or the property value could not be retrieved

    Declaration

    Swift

    public func getProperty(_ property: PropertyAddress) throws -> AudioValueRange

    Parameters

    property

    The address of the desired property

  • Returns the AudioStreamBasicDescription value of property

    Note

    The underlying audio object property must be backed by AudioStreamBasicDescription

    Throws

    An error if self does not have property or the property value could not be retrieved

    Declaration

    Swift

    public func getProperty(_ property: PropertyAddress) throws -> AudioStreamBasicDescription

    Parameters

    property

    The address of the desired property

  • Sets the value of property to value

    Note

    The underlying audio object property must be backed by T

    Throws

    An error if self does not have property, property is not settable, or the property value could not be set

    Declaration

    Swift

    public func setProperty<T>(_ property: PropertyAddress, to value: T) throws

    Parameters

    property

    The address of the desired property

    value

    The desired value

Array Properties

  • Returns the array value of property

    Note

    The underlying audio object property must be backed by a C array of T

    Throws

    An error if self does not have property or the property value could not be retrieved

    Declaration

    Swift

    public func getProperty<T>(_ property: PropertyAddress, elementType type: T.Type, qualifier: PropertyQualifier? = nil) throws -> [T]

    Parameters

    property

    The address of the desired property

    type

    The underlying array element type

    qualifier

    An optional property qualifier

  • Sets the value of property to value

    Note

    The underlying audio object property must be backed by a C array of T

    Throws

    An error if self does not have property, property is not settable, or the property value could not be set

    Declaration

    Swift

    public func setProperty<T>(_ property: PropertyAddress, to value: [T]) throws

    Parameters

    property

    The address of the desired property

    value

    The desired value

Base Audio Object Properties

  • Returns the base class of the underlying HAL audio object

    Remark

    This corresponds to the property kAudioObjectPropertyBaseClass

    Declaration

    Swift

    public func baseClass() throws -> AudioClassID
  • Returns the class of the underlying HAL audio object

    Remark

    This corresponds to the property kAudioObjectPropertyClass

    Declaration

    Swift

    public func `class`() throws -> AudioClassID
  • Returns the audio object’s owning object

    Remark

    This corresponds to the property kAudioObjectPropertyOwner

    Note

    The system audio object does not have an owner

    Declaration

    Swift

    public func owner() throws -> AudioObject
  • Returns the audio object’s name

    Remark

    This corresponds to the property kAudioObjectPropertyName

    Declaration

    Swift

    public func name() throws -> String
  • Returns the audio object’s model name

    Remark

    This corresponds to the property kAudioObjectPropertyModelName

    Declaration

    Swift

    public func modelName() throws -> String
  • Returns the audio object’s manufacturer

    Remark

    This corresponds to the property kAudioObjectPropertyManufacturer

    Declaration

    Swift

    public func manufacturer() throws -> String
  • Returns the name of element

    Remark

    This corresponds to the property kAudioObjectPropertyElementName

    Declaration

    Swift

    public func nameOfElement(_ element: PropertyElement, inScope scope: PropertyScope = .global) throws -> String

    Parameters

    element

    The desired element

    scope

    The desired scope

  • Returns the category name of element in scope

    Remark

    This corresponds to the property kAudioObjectPropertyElementCategoryName

    Declaration

    Swift

    public func categoryNameOfElement(_ element: PropertyElement, inScope scope: PropertyScope = .global) throws -> String

    Parameters

    element

    The desired element

    scope

    The desired scope

  • Returns the number name of element

    Remark

    This corresponds to the property kAudioObjectPropertyElementNumberName

    Declaration

    Swift

    public func numberNameOfElement(_ element: PropertyElement, inScope scope: PropertyScope = .global) throws -> String
  • Returns the audio objects owned by self

    Remark

    This corresponds to the property kAudioObjectPropertyOwnedObjects

    Declaration

    Swift

    public func ownedObjects(ofType type: [AudioClassID]? = nil) throws -> [AudioObject]

    Parameters

    type

    An optional array of AudioClassIDs to which the returned objects will be restricted

  • Returns true if the audio object’s hardware is drawing attention to itself

    Remark

    This corresponds to the property kAudioObjectPropertyIdentify

    Declaration

    Swift

    public func identify() throws -> Bool
  • Sets whether the audio object’s hardware should draw attention to itself

    Remark

    This corresponds to the property kAudioObjectPropertyIdentify

    Declaration

    Swift

    public func setIdentify(_ value: Bool) throws

    Parameters

    value

    Whether the audio hardware should draw attention to itself

  • Returns the audio object’s serial number

    Remark

    This corresponds to the property kAudioObjectPropertySerialNumber

    Declaration

    Swift

    public func serialNumber() throws -> String
  • Returns the audio object’s firmware version

    Remark

    This corresponds to the property kAudioObjectPropertyFirmwareVersion

    Declaration

    Swift

    public func firmwareVersion() throws -> String

AudioObject Creation

  • Creates and returns an initialized AudioObject

    Whenever possible this will return a specialized subclass exposing additional functionality

    Precondition

    objectID != kAudioObjectUnknown

    Declaration

    Swift

    public class func make(_ objectID: AudioObjectID) -> AudioObject

    Parameters

    objectID

    The audio object ID