如何使用 AudioQueueEnqueueBuffer... 和 kAudioFormatMPEG4AAC_HE(VBR) 播放静音

发布于 2024-12-27 03:11:15 字数 1547 浏览 0 评论 0原文

我正在使用网络应用程序,因此有时我会丢失数据包,或者在我开始播放的地方没有可播放的数据。 这是我的源代码:

struct AQPlayerState *pAqData = (struct AQPlayerState *) m_aqData ;
UInt32 numBytesReadFromFile = 0 ;
UInt32 numPackets = 0 ;
char * pdata = (char *)inBuffer->mAudioData ;
for ( int i = 0 ; i < pAqData->mNumPacketsToRead ; ++i )
{
    unsigned int uiRead =GetOneFrame(pdata, pAqData->bufferByteSize - numBytesReadFromFile) ;
    if ( uiRead == 0 )
        break ;

    AudioStreamPacketDescription * packetDescs = pAqData->mPacketDescs + i ;
    packetDescs->mDataByteSize = uiRead ;
    packetDescs->mStartOffset = numBytesReadFromFile ;
    packetDescs->mVariableFramesInPacket = 0 ;
    numBytesReadFromFile += uiRead ;
    pdata += uiRead ;
    ++numPackets ;
}
if (numPackets > 0) 
{
    inBuffer->mAudioDataByteSize = numBytesReadFromFile ;
    OSStatus state = AudioQueueEnqueueBuffer (pAqData->mQueue, inBuffer, (pAqData->mPacketDescs ? numPackets : 0), pAqData->mPacketDescs) ;
    NSLog(@"HandleOutputBuffer packet count:%lu, res:%lu", numPackets, state) ;
}
else 
{
    inBuffer->mAudioDataByteSize = 0 ;
    (*(pAqData->mPacketDescs)).mDataByteSize = 0 ;
    (*(pAqData->mPacketDescs)).mStartOffset = 0 ;
    (*(pAqData->mPacketDescs)).mVariableFramesInPacket = 0 ;
    OSStatus state = AudioQueueEnqueueBuffer (pAqData->mQueue, inBuffer, 0, nil) ;
    NSLog(@"no packet: enqueuebuffer res:%ld", state) ;
}

但如果这些不是数据包,我会收到错误 kAudioQueueErr_BufferEmpty,所以我只想知道如何使用 aac_he type(vbr) 播放静音帧

I am working with a network application, so someting i will lose packet or where i have start play , there is no data for playing.
this is my source code:

struct AQPlayerState *pAqData = (struct AQPlayerState *) m_aqData ;
UInt32 numBytesReadFromFile = 0 ;
UInt32 numPackets = 0 ;
char * pdata = (char *)inBuffer->mAudioData ;
for ( int i = 0 ; i < pAqData->mNumPacketsToRead ; ++i )
{
    unsigned int uiRead =GetOneFrame(pdata, pAqData->bufferByteSize - numBytesReadFromFile) ;
    if ( uiRead == 0 )
        break ;

    AudioStreamPacketDescription * packetDescs = pAqData->mPacketDescs + i ;
    packetDescs->mDataByteSize = uiRead ;
    packetDescs->mStartOffset = numBytesReadFromFile ;
    packetDescs->mVariableFramesInPacket = 0 ;
    numBytesReadFromFile += uiRead ;
    pdata += uiRead ;
    ++numPackets ;
}
if (numPackets > 0) 
{
    inBuffer->mAudioDataByteSize = numBytesReadFromFile ;
    OSStatus state = AudioQueueEnqueueBuffer (pAqData->mQueue, inBuffer, (pAqData->mPacketDescs ? numPackets : 0), pAqData->mPacketDescs) ;
    NSLog(@"HandleOutputBuffer packet count:%lu, res:%lu", numPackets, state) ;
}
else 
{
    inBuffer->mAudioDataByteSize = 0 ;
    (*(pAqData->mPacketDescs)).mDataByteSize = 0 ;
    (*(pAqData->mPacketDescs)).mStartOffset = 0 ;
    (*(pAqData->mPacketDescs)).mVariableFramesInPacket = 0 ;
    OSStatus state = AudioQueueEnqueueBuffer (pAqData->mQueue, inBuffer, 0, nil) ;
    NSLog(@"no packet: enqueuebuffer res:%ld", state) ;
}

but if these is no packet, i get a error kAudioQueueErr_BufferEmpty,so i just want to know how to play a silence frame with aac_he type(vbr)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

若水微香 2025-01-03 03:11:15

这个问题是我两年前提出的,我实际上已经得到了解决方案。

解决方案是使用录音工具记录静默数据包。

首先找到一个录音工具,将录音参数设置为AAC_HE。然后开始录音并保持安静。保存文件。

当您的应用程序启动时,将文件加载到内存中并在没有数据可播放时使用它。

由于音频队列是一个pull模式的api,如果我们通过网络获取数据是不合适的。 Open AL 是推送模式 api,但它只支持未压缩格式,因此也许我们应该使用 core-audio 解码压缩数据,然后使用 Open AL 播放。

The question is asked by me 2 years ago, I have get a solution actually.

The solution is that recording a silence packet using recording tools.

First find a recording tool and set the record parameters to AAC_HE. Then start recording and keep quiet. Save the file.

When your app launches, load the file in memory and use it when no data to playback.

As audio queue is a pull-mode api, it is not appropriate if we get data through network. Open AL is a push-mode api but it only supports uncompressed format, so maybe we should decode the compressed data using core-audio then playback using Open AL.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文