i am trying to capture raw buffer data into an audio file. Like this:
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)
I am hooked into a function with the following parameters:
AudioUnit inUnit, AudioUnitRenderActionFlags * ioActionFlags, const AudioTimeStamp *inTimeStamp, UInt32 inOutputBusNumber, UInt32 inNumberFrames, AudioBufferList * ioData
Inside it I am trying to write the data into file, but a bad parameter -50 error occurs. result = ExtAudioFileWrite(audioFileRef, inNumberFrames, ioData);
If I replace ioData parameter with my own:
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;
}
.. i get file around 260MB for the first second. What is wrong here?