1

我制作了一个使用 EZAudio 库的应用程序,它必须从麦克风获取数据并将其存储在变量中(我已经这样做了):

    func microphone(microphone: EZMicrophone!, 
                    hasAudioReceived buffer: UnsafeMutablePointer<UnsafeMutablePointer<Float>>, 
                    withBufferSize bufferSize: UInt32, 
                    withNumberOfChannels numberOfChannels: UInt32) 
   {
       let new = (buffer[0].memory)
       audioStack.append(new)
   }

如您所见,我正在使用 EZMicrophoneDelegate 和上面的 func 从麦克风获取缓冲区数据。

未来的想法是通过WebSocket发送值并立即播放。

我想使用 EZOuput 和 EZOuputDataSource 的方法播放该数组:

    func output(output: EZOutput!, 
                shouldFillAudioBufferList audioBufferList: UnsafeMutablePointer<AudioBufferList>, 
                withNumberOfFrames frames: UInt32, 
                timestamp: UnsafePointer<AudioTimeStamp>) -> OSStatus 
    {
         if audioStack.count > 0 {
         let data = audioBufferList.memory.mBuffers.mData
         // "data" = is pointer to mData, that i want to fill with float
         // and I have do it here

         return noErr
    }

但是“mData”的类型是UnsafeMutablePointer,我不知道怎么填,我在objective-C中看到了一些这样的例子,就是 这一行:

Float32 *buffer = (Float32 *)audioBufferList->mBuffers[0].mData;

而且我无法理解如何将 Float 类型从数组快速存储到具有 Void 类型的 mData?

铸造如:

(audioBufferList.memory.mBuffers.mData) as Float = audioStack[0]

失败..

4

1 回答 1

5

看起来我找到了如何将 UnsafeMurtablePointer 转换为 UnsafeMutablePointer :

let data = UnsafeMutablePointer<Float>(audioBufferList.memory.mBuffers.mData)
于 2016-04-20T12:10:49.553 回答