使用音频队列服务将数据记录声音 [英] Audio recorded using Audio Queue Services to data

查看:233
本文介绍了使用音频队列服务将数据记录声音的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要来传输语音从一个iPhone到另一个。我已经建立了使用TCP两台iPhone之间的连接,我已成功地记录在iPhone语音和使用音频队列服务播放。我还设法送两台iPhone间的数据。我通过发送NSData的包做到这一点。

下一步是将音频数据发送到其他iPhone,因为它是被记录。我相信我应该在 AudioInputCallback 做到这一点。我的 AudioQueueBufferRef 被称为 inBuffer ,似乎我要转换的 inBuffer-> mAudioData 来的NSData,然后发送NSData的其他设备,然后解压。

有谁知道这是做它的方式,我怎么能转换我的 inBuffer-> mAudioData 来的NSData?其他的方法也欢迎。

这是我的回调方法,我认为我应该抢的数据并将其发送给其他iPhone:

 无效AudioInputCallback(无效* inUserData,AudioQueueRef inAQ,AudioQueueBufferRef inBuffer,常量AudioTimeStamp * inStartTime,UInt32的inNumberPacketDescriptions,常量AudioStreamPacketDescription * inPacketDescs)
{
    RecordState * recordState =(RecordState *)inUserData;
    如果(recordState->!录音)
        返回;    OSStatus状态= AudioFileWritePackets(recordState->的AudioFile,
                                            假,
                                            inBuffer-> mAudioDataByteSize,
                                            inPacketDescs,
                                            recordState-> currentPacket,
                                            &安培; inNumberPacketDescriptions,
                                            inBuffer-> mAudioData);
    如果(状态== 0)
    {
        recordState-> currentPacket + = inNumberPacketDescriptions;
    }    AudioQueueEnqueueBuffer(recordState->队列,in​​Buffer,0,NULL);
}


解决方案

您可能要考虑保存音频数据(你的例子显示了音频采样指针和字节计数)从音频回调到另一个队列或FIFO,则有一个单独的网络线程从音频字节NSData的创建和发送。

I want to transmit voice from one iPhone to another. I have established connection between two iPhones using TCP and I have managed to record voice on the iPhone and play it using Audio Queue Services. I have also managed to send data between the two iPhones. I do this by sending NSData packages.

My next step is to send the audio data to the other iPhone as it is being recorded. I believe I should do this in the AudioInputCallback. My AudioQueueBufferRef is called inBuffer and it seems that I want to convert the inBuffer->mAudioData to NSData and then send the NSData to the other device and then unpack it.

Does anyone know if this would be the way to do it and how I can convert my inBuffer->mAudioData to NSData? Other approaches are also welcome.

This is my callback method in which I believe I should "grab" the data and send it to the other iPhone:

void AudioInputCallback(void *inUserData, AudioQueueRef inAQ, AudioQueueBufferRef inBuffer, const AudioTimeStamp *inStartTime, UInt32 inNumberPacketDescriptions, const AudioStreamPacketDescription *inPacketDescs)
{
    RecordState *recordState = (RecordState *)inUserData;
    if(!recordState->recording)
        return;

    OSStatus status = AudioFileWritePackets(recordState->audioFile,
                                            false,
                                            inBuffer->mAudioDataByteSize,
                                            inPacketDescs,
                                            recordState->currentPacket,
                                            &inNumberPacketDescriptions,
                                            inBuffer->mAudioData);
    if(status == 0)
    {
        recordState->currentPacket += inNumberPacketDescriptions;
    }

    AudioQueueEnqueueBuffer(recordState->queue, inBuffer, 0, NULL);
}

解决方案

You might want to consider saving the audio data (your example shows the audio sample pointer and the byte count) from the audio callback to another queue or FIFO, then having a separate networking thread create NSData from the audio bytes and sending it.

这篇关于使用音频队列服务将数据记录声音的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆