Aquila音频谱

时间:2016-05-07 08:01:51

标签: qt audio histogram spectrum

这是我的代码:

const std::size_t SIZE = 16;
const Aquila::FrequencyType sampleFreq = 44100;
const Aquila::FrequencyType f1 = //left audio data, f2 = //right audio data;

Aquila::SineGenerator sineGenerator1 = Aquila::SineGenerator(sampleFreq);
sineGenerator1.setAmplitude(SIZE).setFrequency(f1).generate(SIZE);
Aquila::SineGenerator sineGenerator2 = Aquila::SineGenerator(sampleFreq);
sineGenerator2.setAmplitude(SIZE).setFrequency(f2).generate(SIZE);
auto sum = sineGenerator1 + sineGenerator2;
// calculate the FFT
auto fft = Aquila::FftFactory::getFft(SIZE);
Aquila::SpectrumType spectrum = fft->fft(sum.toArray());//create complex

int halfLength = spectrum.size() / 2;
std::vector<double> absSpectrum(halfLength);
     for (int i = 0; i < absSpectrum.size(); ++i)
         {
             absSpectrum[i] = std::abs(spectrum[i]);//returns the magnitude of a complex number
         }

我想创建简单的音频可视化工具,我不知道这段代码是否正确。我可以通过absSectrum直方图吗?也许有任何建议我能做些什么。

0 个答案:

没有答案