2010-11-23 63 views
1

我正在研究DSP相關的iOS應用程序。部分工作是將音頻數據從outBuffer - > mAudioData複製到用戶指定的數組進行數據處理。讀取方法如下:AudioQueue:無法讀取AudioFileReadPackets中的原始數據

OSStatus result = AudioFileReadPackets(myInfo->mAudioFile,  // The audio file from which packets of audio data are to be read. 
             false,     // Set to true to cache the data. Otherwise, set to false. 
             &numBytes,    // On output, a pointer to the number of bytes actually returned. 
             myInfo->mPacketDescs, // A pointer to an array of packet descriptions that have been allocated. 
             myInfo->mCurrentPacket, // The packet index of the first packet you want to be returned. 
             &nPackets,    // On input, a pointer to the number of packets to read. On output, the number of packets actually read.           
             outBuffer->mAudioData); // A pointer to user-allocated memory. 

該過程是成功的。但是,當我試圖讀取outBuffer-> mAudioData數據,總有一個錯誤,從「無效* const的」無效轉換到「SInt16 *」:

outBuffer->mAudioDataByteSize = numBytes;  
SInt16 *testBuffer = outBuffer->mAudioData; //Read data from buffer... Error! 

for (int i=0; i<numBytes; i++) 
{ 
    UInt16 currentData = testBuffer[i]; 
    printf("Current data in testbuffer is %d", currentData); 
} 

我已經通過像幾個相關的問題了THISTHIS,似乎他們的工作... 我也嘗試將AudioBuffer-> mAudioData替換爲AudioFileReadPackets()中的testBuffer,但testBuffer原來是一個空數組。

那麼這是正確的做法嗎?有沒有其他的方法來讀取原始數據到一個int/float數組?

或者更一般地說,如何訪問一個void常量指針並對其執行讀/寫操作? (是我的C++是不是強...)

任何幫助將不勝感激:-)

乾杯, 曼卡

回答

2

我只是把前面的演員和它似乎工作:

SInt16* frames = (SInt16*)inBuffer->mAudioData;