简体   繁体   English

在音频回调中录制音频

[英]Recording audio in an audio callback

I have an audio callback that I use to access a bufferList and analyse the audio. 我有一个音频回调,可用于访问bufferList并分析音频。

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); 例如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? 无论哪种方式,此memcpy是执行此操作的正确方法,我将如何将此音频写入文件?

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? 一旦音频输入完成并将数据传递给文件编写器,totalByteCount是否应该与void * dest上的指针算法一起使用?

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,效果很好。 Portaudio also provide a lock free circular buffer which can be used inside callback without need for thread locking mechanism. Portaudio还提供了无锁循环缓冲区,可在回调内部使用,而无需线程锁定机制。 Following links might help you. 以下链接可能会对您有所帮助。

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

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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