我有一个AURenderCallbackStruct设置了一个音频单元。在回调中,我以ioData: UnsafeMutablePointer<AudioBufferList>的形式获取音频数据。检查下面的代码。
func renderCallback(inRefCon: UnsafeMutablePointer<Void>, ioActionFlag: UnsafeMutablePointer<AudioUnitRenderActionFlags>, inTimeStamp: UnsafePointer<AudioTimeStamp>, inBufferNumber: UInt32, inNumberFrames: UInt32, ioData: UnsafeMutablePointer<AudioBufferList>) -> OSStatus {
// How can i get AudioBuffer from iodate here ?
return noErr
}我怎样才能从AudioBuffer这里得到ioDate?请建议..。
注:我使用的是迅捷2.2。
发布于 2016-05-06 17:39:07
只需使用任何memory属性的UnsafeMutablePointer<>来访问它的原始内存。所以你的代码应该是这样的。
var audioBufferListPtr = UnsafeMutableAudioBufferListPointer(ioData).unsafeMutablePointer.memory
for i in 0 ..< Int(inBufferNumber) {
var buffer: AudioBuffer = audioBufferListPtr.mBuffers
}注: Swift是一种发展迅速的语言。所以这段代码将来可能会变。
https://stackoverflow.com/questions/37078336
复制相似问题