4
Core Audio的C API可以将一些数据复制到您提供的内存中。在一种情况下,我需要一个指针传递到一个AudioBufferList,其被定义为:快速访问可变长度数组
struct AudioBufferList {
var mNumberBuffers: UInt32
var mBuffers: (AudioBuffer) // this is a variable length array of mNumberBuffers elements
}
的UInt32的标识缓冲区的数目,实际的缓冲器紧随。
我可以成功地得到这样的:
let bufferList = UnsafeMutablePointer<AudioBufferList>.alloc(Int(propsize));
AudioObjectGetPropertyData(self.audioDeviceID, &address, 0, nil, &propsize, bufferList);
我不认识(AudioBuffer)语法,但我不认为这是显著 - 我认为括号被忽略,mBuffers只是一个AudioBuffer和它的直到我做指针数学找到第二个。
我尝试这样做:
let buffer = UnsafeMutablePointer<AudioBuffer>(&bufferList.memory.mBuffers);
// and index via buffer += index;
// Cannot invoke 'init' with an argument of type 'inout (AudioBuffer)'
也试过:
let buffer = UnsafeMutablePointer<Array<AudioBuffer>>(&bufferList.memory.mBuffers);
// and index via buffer[index];
// error: Cannot invoke 'init' with an argument of type '@lvalue (AudioBuffer)'
措辞更一般地:在夫特,我怎样才能采取UnsafeMutablePointer到一结构,并将其视为那些结构的阵列?