0

I'm investigating aurioTouch2 sample code.

I wanna change smth to record audio from microphone and to write these data to .caff or .wav file. So later I will be able to play this audio with AVAudioPlayer.

My idea is to use AVAudioRecorder in applicationDidFinishLaunching, but may be it's not the best solution or may be even it's not possible by this way (I've not tried to use AVAudioRecorder, because I think that most likely it's not the best idea). I've tried to write byte data in

void FFTBufferManager::GrabAudioData(AudioBufferList *inBL)
{
     memcpy(mAudioBuffer+mAudioBufferCurrentIndex, inBL->mBuffers[0].mData, bytesToCopy);
     // after this I copy to my own buffer and collect all the data during 30 seconds
}

So as you see, I copy to my own buffer and collect all the data during 30 seconds. Than I write data to .caff file. That doesn't work.

Update:

Or may be the way of playing binary data of audio (not encoded to .waf or .caff audio) exist?

Paul T.
  • 4,938
  • 7
  • 45
  • 93

2 Answers2

1

There's a few different ways to do this. One approach is to use ExtAudioFileWriteAsync.

Apple provide a sample project that demonstrates how to do this. It's RecordAudioToFile.

Have a look at some other posts as well, e.g. Can anybody help me in recording iPhone output sound through Audio Unit

Community
  • 1
  • 1
Max MacLeod
  • 26,115
  • 13
  • 104
  • 132
  • About "There's a few different ways to do this. One approach is to use ExtAudioFileWriteAsync.": to use it, you should use AudioBufferList. But in this case you will have the other issue: AudioBufferList have only data for 0.1 second of audio data, and the issue: is how to combine this AudioBufferList to get all the data. – Paul T. Jul 17 '12 at 09:55
  • RecordAudioToFile is for MacOS, not for iOS – Paul T. Jul 17 '12 at 09:57
  • yes but the AudioToolbox API that it uses, and you will use is available for iOS – Max MacLeod Jul 17 '12 at 10:33
  • memcpy each AudioBufferList buffer's frames to a different buffer then write out those frames as done in the example using err = ExtAudioFileWriteAsync(afr->fOutputAudioFile, inNumberFrames, afr->fAudioBuffer); – Max MacLeod Jul 17 '12 at 10:43
0

I am not sure if I got you correctly but you can't just write the buffer to disk. CAF and WAV files need their own headers and encoding of the audio data. The AVRecorder class does this for you. There are plenty of questions on this topic. See for example this question.

Community
  • 1
  • 1
Krumelur
  • 31,081
  • 7
  • 77
  • 119
  • I know about AVRecorder, but aurioTouch uses low-level programming, such as AudioUnit and AudioBufferList. I think, it should be the way to implement this , using this low-level instruments. – Paul T. Jul 17 '12 at 08:46
  • Or may be, there is a way, how I can play the set of data, that I wrote to binary file? – Paul T. Jul 17 '12 at 08:49