How to access multiple buffers in UnsafePointerAudioBufferList (non-mutable)
To access each AudioBuffer
in an AudioBufferList
in Swift, you may choose two ways:
- Do some pointer operations yourself and calculate each address of
AudioBuffer
. - Use
UnsafeMutableAudioBufferListPointer
forcefully.
If you could find a right sample code before UnsafeMutableAudioBufferListPointer
was introduced in Swift, the first way might be your option, but as for now, it's hard to find one.
To use UnsafeMutableAudioBufferListPointer
forcefully, you may need to convert UnsafePointer<AudioBufferList>
to UnsafeMutablePointer<AudioBufferList>
, which is not too difficult:
let audioBufferListPtr = UnsafeMutableAudioBufferListPointer(UnsafeMutablePointer(mutating: audioBufferList))
I believe you know how to access buffers once you get UnsafeMutableAudioBufferListPointer
.
Caution: Even if type conversion from UnsafePointer<AudioBufferList>
to UnsafeMutablePointer<AudioBufferList>
is easily made, the actual region passed through audioBufferList
is not mutable. You may need extra care not to mutate such region.
AudioObjectAddPropertyListener for kAudioDevicePropertyNominalSampleRate
The combination of kAudioDevicePropertyNominalSampleRate
and kAudioObjectPropertyScopeGlobal
will get the callback to work correctly. The documentation of this selector (CoreAudio/AudioHardware.h) doesn't tell me what scope to use, though. If anyone finds a source of proof/reason for this, feel free to edit.
The situation is also confusing because calling AudioObjectSetPropertyData()
with kAudioDevicePropertyNominalSampleRate
and either kAudioObjectPropertyScopeInput
or kAudioObjectPropertyScopeOutput
will also result in a successful sample rate switch (one could argue this to be erroneous behaviour).
Using RtAudio with Core-Audio, the probeDeviceOpen function fails
Are you on Lion (10.7)? I am seeing the same problem, on older systems (10.6.x) RtAudio work fine for me.
Perhaps you can downgrade to RtAudio 4.0.6, this worked for me on Lion, but there's still a bug lurking around with device names which got fixed in 4.0.8.
Related Topics
Xcode Playgrounds Shared Directory Not Working
Nsinvocationoperation' Is Unavailable in Xcode 6.1
Set Custom Uiview Frame in Uiviewrepresentable Swiftui
Swift Use Unicode Character in Localization.Strings
Swift Combine: What Are Those Multicast Functions for and How to Use Them
Best Way to Avoid Capturing a Copy of the Value in Closure
How to Respond with an Image Using Vapor
Class with Non-Optional Property Conforming to Protocol with Optional Property
Rotate a Text View and Its Frame in Swiftui
Nonfailable Enum Initializer with Default Value
Ios15 Uttype Deprecations for Url-Extension
Google Sign-In via Firebase: Gidsignindelegate Does Not Conform to Viewcontroller
Saving a Codable Struct to Userdefaults with Swift
Alamofire Returns Wrong Encoding
Suppress Warnings from Dependencies with Swift Package Manager
Maccatalyst App: How to Close a Window Without Terminating The App