我正在尝试将原始缓冲区数据捕获到音频文件中。像这样:
dstFormat.mSampleRate = 224000;
dstFormat.mFormatID = kAudioFormatMPEG4AAC;
dstFormat.mChannelsPerFrame = 1;
dstFormat.mBitsPerChannel = 16;
dstFormat.mBytesPerPacket = dstFormat.mBytesPerFrame = 2 * dstFormat.mChannelsPerFrame;
dstFormat.mFramesPerPacket = 1;
dstFormat.mFormatFlags = kLinearPCMFormatFlagIsPacked | kLinearPCMFormatFlagIsSignedInteger;
OSStatus result = ExtAudioFileCreateWithURL((CFURLRef) inURL,
kAudioFileM4AType,
&dstFormat,
0,
kAudioFileFlags_EraseFile,
&audioFileRef)
我被一个具有以下参数的函数所吸引:
AudioUnit inUnit, AudioUnitRenderActionFlags * ioActionFlags, const AudioTimeStamp *inTimeStamp, UInt32 inOutputBusNumber, UInt32 inNumberFrames, AudioBufferList * ioData
在其中我试图将数据写入文件,但出现错误的参数 -50 错误。结果 = ExtAudioFileWrite(audioFileRef, inNumberFrames, ioData);
如果我用自己的替换 ioData 参数:
AudioBufferList *bufferList = (AudioBufferList*) malloc(sizeof(AudioBufferList));
bufferList->mNumberBuffers = 1;// ioData->mNumberBuffers;
for(UInt32 i=0;i<bufferList->mNumberBuffers;i++)
{
bufferList->mBuffers[i].mNumberChannels = 1;
bufferList->mBuffers[i].mDataByteSize = ioData->mBuffers[i].mDataByteSize; //ioData->mBuffers[i].mDataByteSize; // (1024*2) * dstFormat.mBytesPerFrame;
bufferList->mBuffers[i].mData = ioData->mBuffers[i].mData;
}
..我第一秒得到大约 260MB 的文件。这里有什么问题?