So I\'ve cobbled together some routines for recording audio based on some posts here. The posts I\'ve referenced are here and here, along with reading the sites they referen
Ok - found some code that solves this - though I don't fully understand why.
I had been setting the mBitsPerChannel
to 16 for both the RemoteIO output stream and the ExtFileRef. The result was slowed down & scratchy audio. Setting the ExtFileRef mBitsPerChannel
to 32 plus adding the kAudioFormatFlagsNativeEndian
flag solves the problem: the .caf audio is perfect (while leaving the RemoteIO output stream settings to what they were).
But then also setting the RemoteIO output stream settings to match my new settings also works. So I'm confused. Shouldn't this work so long as the AudioStreamBasicDescription
settings are symmetrical for the RemoteIO instance and the ExtFileRef?
Anyway... the working setting is below.
size_t bytesPerSample = sizeof (AudioUnitSampleType);
AudioStreamBasicDescription audioFormat;
audioFormat.mSampleRate= graphSampleRate;
audioFormat.mFormatID=kAudioFormatLinearPCM;
audioFormat.mFormatFlags=kAudioFormatFlagsNativeEndian|kAudioFormatFlagIsSignedInteger|kAudioFormatFlagIsPacked;
audioFormat.mBytesPerPacket=bytesPerSample;
audioFormat.mBytesPerFrame=bytesPerSample;
audioFormat.mFramesPerPacket=1;
audioFormat.mChannelsPerFrame=1;
audioFormat.mBitsPerChannel= 8 * bytesPerSample;
audioFormat.mReserved=0;