简体   繁体   中英

Recording audio in an audio callback

I have an audio callback that I use to access a bufferList and analyse the audio.

I need to record this audio too. Firstly would it be wise to do the recording in the same callback?

eg memcpy(void *dest, ioData->mBuffers[0].mData, int byteCount);

Or should the recording have its own callback?

Either way, is this memcpy the correct way to do this and how would I write this audio to a file?

Should the totalByteCount be used with pointer arithmetic on the void * dest once the audio input completes and pass the data to a file writer?

What is the best way to record audio in a core-audio render callback?

I think you can have two different callbacks each for both input and output audio stream. Normally when you open a particular stream it could be input or output you specify the callback too. In the callback you can do all your audio processing provided that you can meeting the callback deadline otherwise there are chances that you may end up missing audio samples. A better way would be to use some kind of circular buffer and it the callback you just fill the buffer. You can do all the other processing in main thread (along with recording). I'm not sure which audio framework you are using. I've used portaudio in my project and it worked fine. Portaudio also provide a lock free circular buffer which can be used inside callback without need for thread locking mechanism. Following links might help you.

http://portaudio.com/docs/v19-doxydocs/paex__record_8c.html.

http://portaudio.com/docs/v19-doxydocs/paex_ ocean _shore_8c.html

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM