Avaudiosinknode with Non-Default, But Still Device-Native Sample Rates

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



Leave a reply



Submit