在iOS上用ExtAudioFileRead读取音频文件,似乎完全冻结了阅读器…。例如,假设分配并正确配置了_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!" );
}
}
}没有错误,总是相同的行为,就像阅读器被卡在文件的末尾一样。ExtAudioFileTell确认了请求的查找,顺便说一句。还试着跟踪文件中的位置,只请求eof中可用的帧数,同样的结果是:一旦读取最后一个数据包,查找似乎没有任何效果。
在其他情况下幸福地寻找。
窃听器?特征?即将来临的脸手掌?我将非常感谢任何帮助解决这一问题!
我正在iPad 3( iOS7.1 )上测试这个。
干杯,
格雷戈佐
发布于 2014-05-10 09:25:09
伍扎!
明白了,邪恶的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;
}
}这不是应该被记录下来吗?官方文档只将AudioBufferList参数描述为:读取音频数据的一个或多个缓冲区。
干杯,
格雷戈佐
https://stackoverflow.com/questions/23570038
复制相似问题