请你告诉我这是怎么做到的?在一台设备上录制音频&在其他(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,但不知道怎么玩,请你帮忙
答案 0 :(得分:0)
您需要一个像CARingBuffer这样的环形缓冲区来存储接收到的音频数据,并像Audio Unit Render Callback方法一样从缓冲区读取数据。由于写入和读取操作是异步的并且速度不同,因此很难确定环形缓冲区应该有多长。 因此,您还可以使用临时文件存储接收的数据,始终将日期写入文件的末尾,并从头部读取。