0

我正在尝试通过QAudioProbe创建一个简单的频谱,但我的频谱没有“感觉节拍”。频谱中的每个 bin 都会变得高低。 这是我来自 QAudioProbe 的代码处理缓冲区:

void Waveform::bufferReady(QAudioBuffer buffer){  

int n = buffer.frameCount();
cfg = kiss_fft_alloc(n, 0/*is_inverse_fft*/, NULL, NULL);
QAudioBuffer::S16U *frames = buffer.data<QAudioBuffer::S16U>();
qDeleteAll(m_finalData);
m_finalData.clear();

kiss_fft_cpx output[n],input[n];
for (int i=0; i < n; i++)
{
    // frames[i].right contains the i-th sample from the right channel
    // frames[i].left contains the i-th sample from the left channel
    // if the signal is mono and not stereo, then only one of the channels will have data
    qreal hanawindow = 0.5 * (1 - qCos((2 * M_PI * i) / (n - 1)));
    input[i].r = frames[i].right * hanawindow; // WindowFunction
    input[i].i = 0;
}

kiss_fft(cfg, input, output);  // DO FFT
int step = n/(2*60); // distance to take value for bin from list. Here is 60bins

for(int i=0; i< n/2;i+=step){
    qreal magnitude = qSqrt(output[i].i*output[i].i + output[i].r*output[i].r);
    qreal amplitude = 0.15 * log10(magnitude);
    amplitude = qMax(qreal(0.0), amplitude);
    amplitude = qMin(qreal(1.0), amplitude);
    m_finalData.append(new Sample(amplitude));
}

qDebug() << "Number of Bins : " << m_finalData.count();
emit dataReady();
}

我不知道上面的代码有什么问题。我一直在尝试很多其他方法,但光谱仍然很奇怪。

4

0 回答 0