用ExtAudioFileRead循环AAC文件 - bug?

Gre*_*gzo 4 audio objective-c ios extaudiofileread

使用ExtAudioFileRead读取iOS上的音频文件,似乎达到eof完全冻结了读者......例如,假设_abl AudioBufferList和_eaf ExtendedAudioFileRef已分配并正确配置:

- ( void )testRead
{
    UInt32 requestedFrames = 1024;
    UInt32 numFrames = requestedFrames;
    OSStatus error = 0;

    error = ExtAudioFileRead( _eaf, &numFrames, _abl );

    if( numFrames < requestedFrames ) //eof, want to read enough frames from the beginning of the file to reach requestedFrames and loop gaplessly
    {
         requestedFrames = requestedFrames - numFrames;
         numFrames = requestedFrames;
         // move some pointers in _abl's buffers to write at the correct offset
         error = ExtAudioFileSeek( _eaf, 0 );
         error = ExtAudioFileRead( _eaf, &numFrames, _abl );
         if( numFrames != requestedFrames ) //Now this call always sets numFrames to the same value as the previous read call...
         {
             NSLog( @"Oh no!" );
         }
    }
}
Run Code Online (Sandbox Code Playgroud)

没有错误,总是相同的行为,就像读者卡在文件的末尾一样.ExtAudioFileTell确认请求的搜索,顺便说一句.还尝试跟踪文件中的位置以仅请求eof可用的帧数,结果相同:一旦读取最后一个数据包,搜索似乎没有任何效果.

在其他情况下愉快地寻求.

错误?特征?即将面掌?我非常感谢你解决这个问题的任何帮助!

我正在iPad 3(iOS7.1)上测试它.

干杯,

Gregzo

Gre*_*gzo 5

Woozah!

陷阱,邪恶的AudioBufferList修补匠.

因此,除了通知客户端实际读取的帧数外,ExtAudioFileRead还将AudioBufferList的AudioBuffers mDataByteSize设置为读取的字节数.由于它将读数限制在该值,因此不会将其重置为eof会导致帧数不断增加而不是询问.

因此,一旦达到eof,只需重置abl的缓冲区大小.

-( void )resetABLBuffersSize: ( AudioBufferList * )alb size: ( UInt32 )size
{
     AudioBuffer * buffer;
     UInt32 i;

     for( i = 0; i < abl->mNumberBuffers; i++ )
     {
         buffer = &( abl->mBuffers[ i ] );
         buffer->mDataByteSize = size;
     }
}
Run Code Online (Sandbox Code Playgroud)

这不应该记录在案吗?官方文档仅描述AudioBufferList参数:一个或多个缓冲区,其中读取音频数据.

干杯,

Gregzo