Using AudioBufferList with Swift

前端 未结 4 1403
野的像风
野的像风 2020-12-05 07:51

I have a bridging function in Swift, one of whose arguments in C is AudioBufferList *. In Swift this generates an UnsafePointer

4条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-05 08:23

    I found this by accident. Oddly the type ahead was actually working with Swift when it suggested UnsafeMutableAudioBufferListPointer. Which you can initialize with an UnsafeMutablePointer argument. This type is a MutableCollectionType and provides subscript and generator access to the contained Audio Buffers.

    For example you can set an ABL to silence with the following code

    func renderCallback(ioData: UnsafeMutablePointer) -> OSStatus {
    
        let abl = UnsafeMutableAudioBufferListPointer(ioData)
    
        for buffer in abl {
    
            memset(buffer.mData, 0, Int(buffer.mDataByteSize))
        }
    
        return noErr
    }
    

提交回复
热议问题