2012-12-04 2 views
2

어떻게 수행 할 수 있습니까? 하나의 기기에 오디오 녹음하기 & (VoIP)에서 재생 중입니까?오디오 대기열 또는 오디오 장치를 사용하는 VoIP 기능

여기 붙어 M : I이 함수

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)); 
    } 
} 

한 장치에 입력 된 음성 데이터를 얻고, m 및 I는 UDP로 패킷을 전송 M : I가 왔는지있어

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]; 
} 

& 다른 쪽 끝의 데이터는 NSData로 재생할 수는 없지만 도움을 청할 수 있습니까?

답변

0

수신 된 오디오 데이터를 저장하고 데이터 f를 읽으려면 CARingBuffer와 같은 링 버퍼가 필요합니다 같은 오디오 유닛 렌더링 콜백 방법으로 버퍼를 rom. & 쓰기 작업은 비동기 적이며 속도가 다르기 때문에 링 버퍼의 길이를 결정하기가 어렵습니다. 임시 파일을 사용하여 수신 된 데이터를 저장하고 항상 파일의 끝에 날짜를 쓰고 헤드에서 읽을 수도 있습니다.