2

I've searched around but haven't found any good examples or tutorials of saving audio out of a RemoteIO Audio Unit.

My setup: Using the MusicPlayer API, I have several AUSamplers -> MixerUnit -> RemoteIO

Audio playback works great. I would like to add functionality to save the audio output to a file. Would I do this in a render callback on the RemoteIO?

Any tips or pointers to example code much appreciated!

spring
  • 18,009
  • 15
  • 80
  • 160

1 Answers1

1

Due to the tight latency requirements of Audio Unit callbacks, one should not to do any synchronous file access (or any other calls that could potentially block, involve memory management or OS locking actions) inside the RemoteIO callback. Instead, just copy the audio data out to another buffer (a larger circular buffer for example), and set some state indicating how much data has been copied. Then, in another thread, when the amount of data is sufficient, write the contents of that buffer out to a file. This could be a raw PCM file, which can later be converted by AVAssetReader/Writer into another audio file type.

hotpaw2
  • 70,107
  • 14
  • 90
  • 153
  • 3
    ExtAudioFileWriteAsync(outFile,numberFrames,&bufferList); will do this for you, so you can call it from the RemoteIO callback. That is really all there is to it. – hooleyhoop Apr 06 '12 at 17:32
  • I've got recording working but the sound is distorted - maybe something wrong with the format I specify? I posted a question @ it here: http://stackoverflow.com/questions/10067117/recording-from-remoteio-resulting-caf-is-pitch-shifted-slower-distorted - any tips greatly appreciated! – spring Apr 09 '12 at 13:42
  • Have posted the solution here: http://stackoverflow.com/questions/10067117/recording-from-remoteio-resulting-caf-is-pitch-shifted-slower-distorted – spring Apr 09 '12 at 15:44