2012-09-05 57 views
2

我有AudioBuffer及其void *mData充滿了使用Apple CoreAudio Audio Unit API的新鮮渲染的音頻樣本,但我有問題以正確格式獲取樣本。該ASBD的所述緩衝如下:爲特定的ASBD緩衝區獲取正確的數字數據類型

Float64 mSampleRate  44100 
UInt32 mFormatID   1819304813 
UInt32 mFormatFlags  41 
UInt32 mBytesPerPacket 4 
UInt32 mFramesPerPacket 1 
UInt32 mBytesPerFrame  4 
UInt32 mChannelsPerFrame 2 
UInt32 mBitsPerChannel 32 
UInt32 mReserved   0 

我通過調試應用程序以及執行AudioUnitGetProperty(rioUnit, kAudioUnitProperty_StreamFormat, ...)電話得到這個。該mFormatFlags場意味着以下標誌(我不知道任何正式的解碼方法,我剛剛纔通過嘗試的kAudioUnitFlags不同組合,直到我得到41):

kAudioFormatFlagIsNonInterleaved | kAudioFormatFlagIsPacked | kAudioFormatFlagIsFloat 

我應該投哪些類型的數據緩衝區?我已經嘗試過Float32,SInt32,但他們不是。

之後我打算做一個轉換爲SInt16,但是如果我沒有首先獲得正確的樣本格式,我不能這樣做。

在此先感謝。

回答

1

基礎上ASBD,該數據是立體聲的非交叉32位浮點,這是在Mac OS X音頻單元

你應該能夠在mData場轉換爲float *規範格式和獲得一個音頻數據通道。全立體聲音頻應包含在AudioBufferList中,每個包含一個通道的兩個緩衝區。

爲什麼鑄造到Float32不工作?

3

根據我的經驗,iOS不會直接向您提供浮點數據。相反,你應該問SInt16(因此,設置mBitsPerChannel至16爲好),然後手動整數數據彩車通過將每個數由32767

0

檢查這個代碼轉換:

- (void)captureOutput:(AVCaptureOutput *)captureOutput didOutputSampleBuffer:(CMSampleBufferRef)sampleBuffer 
    fromConnection:(AVCaptureConnection *)connection 

     //calback function 

     const AudioStreamBasicDescription *audioDescription = CMAudioFormatDescriptionGetStreamBasicDescription(CMSampleBufferGetFormatDescription(sampleBuffer)); 

     int sampleRate  = (int)audioDescription ->mSampleRate; 
     int channelsPerFrame = (int)audioDescription ->mChannelsPerFrame; 
     UInt32 formatFlag  = audioDescription ->mFormatFlags; 

     if (formatFlag & kAudioFormatFlagIsFloat) { 
      NSLog(@"IS FLOAT"); 

     } else if (formatFlag & kAudioFormatFlagIsSignedInteger) { 
      NSLog(@"IS Signed Integer"); 
     } 

}

相關問題