2012-12-04 73 views
2

您可以告訴我如何做到這一點嗎?在一臺設備上錄製音頻&在其他(VoIP)上播放?使用音頻隊列或音頻單元的VoIP功能

我米困在這裏:我m到處在這個函數

void AQRecorder::MyInputBufferHandler( void *        inUserData, 
             AudioQueueRef      inAQ, 
             AudioQueueBufferRef     inBuffer, 
             const AudioTimeStamp *    inStartTime, 
             UInt32        inNumPackets, 
             const AudioStreamPacketDescription* inPacketDesc) 
{ 
    AQRecorder *aqr = (AQRecorder *)inUserData; 
    try { 
     if (inNumPackets > 0) { 
      // write packets to file 
      XThrowIfError(AudioFileWritePackets(aqr->mRecordFile, FALSE, inBuffer->mAudioDataByteSize, 
              inPacketDesc, aqr->mRecordPacket, &inNumPackets, inBuffer->mAudioData), 
         "AudioFileWritePackets failed"); 
      //inData = inBuffer->mAudioData; 
      aqr->mRecordPacket += inNumPackets; 
      aqr->updateIndata(inBuffer); 
     } 

     // if we're not stopping, re-enqueue the buffe so that it gets filled again 
     if (aqr->IsRunning()) 
      XThrowIfError(AudioQueueEnqueueBuffer(inAQ, inBuffer, 0, NULL), "AudioQueueEnqueueBuffer failed"); 
    } catch (CAXException e) { 
     char buf[256]; 
     fprintf(stderr, "Error: %s (%s)\n", e.mOperation, e.FormatError(buf)); 
    } 
} 

一臺設備上輸入語音數據和我米將報文的UDP:

void AQRecorder::updateIndata(AudioQueueBufferRef inBuffer) 
{ 
    SpeakHereAppDelegate *appDelegate = [[UIApplication sharedApplication] delegate]; 
    NSData *audioBytes = [NSData dataWithBytes:inBuffer->mAudioData 
             length:inBuffer->mAudioDataByteSize]; 
    NSLog(@"bytes: %d", [audioBytes length]); 
    [appDelegate.udpSocket sendData:audioBytes 
          toHost:appDelegate.host 
           port:appDelegate.port 
         withTimeout:-1 
           tag:1]; 
} 

&我receving在另一端的數據爲NSData,但不知道如何播放,請你幫忙

回答

0

你需要一個像CARingBuffer一樣的環形緩衝區來存儲接收到的音頻數據,並讀取數據f從類似Audio Unit Render Callback方法的緩衝區中rom。由於寫入操作是異步的且速度不同,因此很難確定環形緩衝區應該存在多長時間。 因此,您還可以使用臨時文件來存儲接收到的數據,始終將日期寫入文件末尾,並從頭讀取。