I have been struggling with this yesterday and would really appreciate the help.
I have a multi channel mixer audio unit and the callback assigned to each channel fills the needed audio buffer when called. I am trying to record within the same callback by writing the data to a file.
At the moment the audio records as noise if I dont call AudioUnitRender and if I do call it I get two errors. Error 10877 and error 50.
the recording code in the callback looks like this
if (recordingOn)
{
AudioBufferList *bufferList = (AudioBufferList *)malloc(sizeof(AudioBuffer));
SInt16 samples[inNumberFrames];
memset (&samples, 0, sizeof (samples));
bufferList->mNumberBuffers = 1;
bufferList->mBuffers[0].mData = samples;
bufferList->mBuffers[0].mNumberChannels = 2;
bufferList->mBuffers[0].mDataByteSize = inNumberFrames*sizeof(SInt16);
OSStatus status;
status = AudioUnitRender(audioObject.mixerUnit,
ioActionFlags,
inTimeStamp,
inBusNumber,
inNumberFrames,
bufferList);
if (noErr != status) {
printf("AudioUnitRender error: %ld", status);
return noErr;
}
ExtAudioFileWriteAsync(audioObject.recordingFile, inNumberFrames, bufferList);
}
Is it correct to write the data in each channels callback or should I connect it to the remote I/O unit?
I am using LPCM and the ASBD for the recording file (caf) is
recordingFormat.mFormatID = kAudioFormatLinearPCM;
recordingFormat.mFormatFlags = kAudioFormatFlagIsSignedInteger |
kAudioFormatFlagIsBigEndian | kAudioFormatFlagIsPacked;
recordingFormat.mSampleRate = 44100;
recordingFormat.mChannelsPerFrame = 2;
recordingFormat.mFramesPerPacket = 1;
recordingFormat.mBytesPerPacket = recordingFormat.mChannelsPerFrame * sizeof (SInt16);
recordingFormat.mBytesPerFrame = recordingFormat.mChannelsPerFrame * sizeof (SInt16);
recordingFormat.mBitsPerChannel = 16;
I am not really sure what I am doing wrong.
How does stereo effect the way the recorded data must be handled before writing to the file?