ExtAudioFileWrite inNumberFrames 参数的适当值是多少?
我正在开发 FLAC 到 ALAC 转码器,并尝试使用 ExtAudioFile 写入 ALAC。我正在使用 FLAC 库的基于回调的系统读取 FLAC 文件,这意味着 FLAC 文件中的每一帧都会导致函数调用。在该调用中,我设置了缓冲区并调用 ExtAudioFileWrite 代码,如下所示:
AudioBufferList * fillBufList;
fillBufList = malloc(sizeof *fillBufList + (frame->header.channels - 1) * sizeof fillBufList->mBuffers[0]);
fillBufList->mNumberBuffers = frame->header.channels;
for (int i = 0; i < fillBufList->mNumberBuffers; i++) {
fillBufList->mBuffers[i].mNumberChannels = 1; // non-interleaved
fillBufList->mBuffers[i].mDataByteSize = frame->header.blocksize * frame->header.bits_per_sample / 8;
fillBufList->mBuffers[i].mData = (void *)(buffer[i]);
NSLog(@"%i", fillBufList->mBuffers[i].mDataByteSize);
}
OSStatus err = ExtAudioFileWrite (outFile, 1, fillBufList);
现在,最后一行中的数字 1 是我选择的一个神奇数字,因为我认为 FLAC 文件中的一帧可能对应到相应 ALAC 文件中的一帧,但情况似乎并非如此。每次调用 ExtAudioFileWrite 都会返回错误值 -50(用户参数列表中的错误)。明显的罪魁祸首是我为框架参数提供的值。
那么我问,我应该提供什么价值?
还是我找错了树?
(旁注:我怀疑,尽管存在与参数相关的错误值,但真正的问题可能是缓冲区设置,因此我尝试分配一个清零的虚拟缓冲区只是为了看看会发生什么。同样的错误。)
I'm working on a FLAC-to-ALAC transcoder and trying to use ExtAudioFile to write to ALAC. I am using the FLAC library's callback-based system to read in the FLAC file, which means that every frame in the FLAC file results in a function call. Within that call, I set up my buffers and call the ExtAudioFileWrite code as follows:
AudioBufferList * fillBufList;
fillBufList = malloc(sizeof *fillBufList + (frame->header.channels - 1) * sizeof fillBufList->mBuffers[0]);
fillBufList->mNumberBuffers = frame->header.channels;
for (int i = 0; i < fillBufList->mNumberBuffers; i++) {
fillBufList->mBuffers[i].mNumberChannels = 1; // non-interleaved
fillBufList->mBuffers[i].mDataByteSize = frame->header.blocksize * frame->header.bits_per_sample / 8;
fillBufList->mBuffers[i].mData = (void *)(buffer[i]);
NSLog(@"%i", fillBufList->mBuffers[i].mDataByteSize);
}
OSStatus err = ExtAudioFileWrite (outFile, 1, fillBufList);
Now, the number 1 in the final line is something of a magic number that I've chosen because I figured that one frame in the FLAC file would probably correspond to one frame in the corresponding ALAC file, but this seems not to be the case. Every call to ExtAudioFileWrite returns an error value of -50 (error in user parameter list). The obvious culprit is the value I'm providing for the frame parameter.
So I ask, then, what value should I be providing?
Or am I barking up the wrong tree?
(Side note: I suspected that, despite the param-related error value, the true problem could be the buffer setup, so I tried mallocing a zeroed-out dummy buffer just to see what would happen. Same error.)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
对于 ExtAudioFileWrite,帧数等于要写入的样本数。如果您使用 32 位浮点交错数据,则它将是 mDataByteSize / (sizeof(Float32) / mNumberChannels)。它不应该是 1,除非您只想编写一个示例,并且如果您正在编写压缩格式,我认为它需要一定数量的示例。 -50 错误也可能是另一个问题。
要检查的一件事是 ExtAudioFile 只需要一个缓冲区。所以你的fillBufList->mNumberBuffers应该总是等于1,如果你需要做立体声,你需要交错音频数据,这样mBuffers[0].mNumberChannels对于立体声来说等于2。
For ExtAudioFileWrite, the number of frames is equal to the number of samples you want to write. If you're working with 32-bit float interleaved data, it would be the mDataByteSize / (sizeof(Float32) / mNumberChannels). It shouldn't be 1 unless you meant to write only one sample, and if you're writing a compressed format, it expects a certain number of samples, I think. It's also possible that the -50 error is another issue.
One thing to check is that ExtAudioFile expects only one buffer. So your fillBufList->mNumberBuffers should always equal 1, and if you need to do stereo, you need to interleave the audio data, so that mBuffers[0].mNumberChannels is equal to 2 for stereo.