简体   繁体   English

从麦克风到整数数组的音频采样(C ++ / Qt)

[英]Sample audio from microphone to array of integers (C++/Qt)

I am developing an app that records audio from microphone to integer array. 我正在开发一个应用程序,可将音频从麦克风录制到整数数组。 Array is then passed to FFT and MFCC. 然后将数组传递给FFT和MFCC。 I need to make frames about n samples and I need to 50% overlaps them (they cannot be side by side). 我需要制作大约n个样本的框架,并且需要将它们重叠50%(它们不能并排放置)。 So I need 3 buffers - when the first is full is passed to FFT. 所以我需要3个缓冲区-当第一个缓冲区已满时传递给FFT。 I this moment app should record second half of second buffer and first half of third buffer. 我此刻应用程序应该记录第二个缓冲区的下半部分和第三个缓冲区的上半部分。 FFT will be separate thread (my idea). FFT将是单独的线程(我的想法)。

So I tried to sample audio using QAudioRecorder and QAudioProbe . 因此,我尝试使用QAudioRecorderQAudioProbe采样音频。 I connected audioBufferProbed signal with processBuffer and there i use buffer.constData<int>() . 我将audioBufferProbed信号与processBuffer连接audioBufferProbed ,在这里我使用了buffer.constData<int>() I seems it works. 我似乎行得通。 I understood audioBufferProbed is emitted when buffer is full. 我了解到缓冲区已满时会发出audioBufferProbed

I don't know how to associate more buffers with one recorder. 我不知道如何将更多缓冲区与一个记录器关联。 Or start writing to second buffer too at half of first buffer. 或者也从第一缓冲区的一半开始写入第二缓冲区。

The easiest way here (since 50% is a nice round number) is to ask Qt for frames half the size of the ones you need for your FFT. 这里最简单的方法(因为50%是一个很好的整数)是向Qt请求帧,其大小是FFT所需帧的一半 You now run your FFT over frames 0&1, 1&2, 2&3, etc. 现在,您可以在帧0-1、1&2、2&3等上运行FFT。

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

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