你能告诉我这是怎么做到的吗?在一台设备上录制音频并在另一台设备上播放(VoIP)?
我被困在这里:我在此功能中的一台设备上获取输入语音数据
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];
}
&我正在以 NSData 的形式接收另一端的数据,但不知道如何玩,你能帮忙吗