2

Can u please tell me how this can be done ? recording the audio on one device & playing on other (VoIP) ?

I m stuck here: I m getting the input voice data on one device in this function

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

and I m sending the packets to 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];
}

& I'm receving the data on other end as NSData but don't know how to play, Can u please help

Asif Ali
  • 21
  • 1

1 Answers1

0

You need a ring buffer like CARingBuffer to store the received audio data , and read data from the buffer in like Audio Unit Render Callback method. Because the write&read operations are asynchronous and with different speed,it's hard to decide how long the ring buffer should be. So you can also use temp file to store the received data, always write the date to the end of the file , and read from the head.

Joe Qian
  • 493
  • 6
  • 13