2013-02-25 73 views

回答

0

是,其可能的,你需要設置配置AudioQueue因此,

基本上AudioQueue緩衝區大小,具有40ms的進行設置,因此這將是左右,

int AQRecorder::ComputeRecordBufferSize(const AudioStreamBasicDescription *format, float seconds) 
{ 
    int packets, frames, bytes = 0; 
    try { 
     frames = (int)ceil(seconds * format->mSampleRate); 

     if (format->mBytesPerFrame > 0) 
      bytes = frames * format->mBytesPerFrame; 
     else { 
      UInt32 maxPacketSize; 
      if (format->mBytesPerPacket > 0) 
       maxPacketSize = format->mBytesPerPacket; // constant packet size 
      else { 
       UInt32 propertySize = sizeof(maxPacketSize); 
       XThrowIfError(AudioQueueGetProperty(mQueue, kAudioQueueProperty_MaximumOutputPacketSize, &maxPacketSize, 
                &propertySize), "couldn't get queue's maximum output packet size"); 
      } 
      if (format->mFramesPerPacket > 0) 
       packets = frames/format->mFramesPerPacket; 
      else 
       packets = frames; // worst-case scenario: 1 frame in a packet 
      if (packets == 0)  // sanity check 
       packets = 1; 
      bytes = packets * maxPacketSize; 
     } 
    } catch (CAXException e) { 
     char buf[256]; 
     return 0; 
    } 
    return bytes; 
} 

,並設置格式,

void AQRecorder::SetupAudioFormat(UInt32 inFormatID) 
{ 
    AudioStreamBasicDescription sRecordFormat; 
    FillOutASBDForLPCM (sRecordFormat, 
         SAMPLING_RATE, 
         1, 
         8*BYTES_PER_PACKET, 
         8*BYTES_PER_PACKET, 
         false, 
         false 
         ); 
    memset(&mRecordFormat, 0, sizeof(mRecordFormat)); 

    mRecordFormat.SetFrom(sRecordFormat); 
} 

我的情況,這些宏的值,

#define SAMPLING_RATE 16000 
#define kNumberRecordBuffers 3 
#define BYTES_PER_PACKET 2 
+0

嗨羅漢, 感謝您的答覆, 我已經相應改變的項目,它的工作在我結束。由於我是這個領域的新手,我如何確保它在每個數據包40毫秒音頻幀的工作? 感謝,Pravin – Pravin 2013-02-28 10:01:03

+0

AudioQueue框架,當入列的緩衝區被填滿時拋出一個回調,所以最小的間隔時間肯定是40ms ... – Amitg2k12 2013-03-01 16:03:54

+0

感謝Rohan,你能給我一個想法(公式)每個數據包40ms音頻幀計算關於宏/定義即SAMPLING_RATE,kNumberRecordBuffers,BYTES_PER_PACKET – Pravin 2013-03-13 11:30:12