C++ SDL和Aquila FFT
我正在使用wav文件,并希望对其应用fft。我使用的是AQILA C++库和SDL2.0。 我已经使用SDL的“SDL_LoadWav”函数加载了wav文件。现在我有一个float类型的向量缓冲区。我想对它应用FFT。 我不知道如何将(const SampleType x[])参数赋予fft 这是我在对它应用DCT时所做的,但我觉得我没有正确地使用它,因为它没有提供正确的声音输出C++ SDL和Aquila FFT,c++,audio,sdl,fft,spectrum,C++,Audio,Sdl,Fft,Spectrum,我正在使用wav文件,并希望对其应用fft。我使用的是AQILA C++库和SDL2.0。 我已经使用SDL的“SDL_LoadWav”函数加载了wav文件。现在我有一个float类型的向量缓冲区。我想对它应用FFT。 我不知道如何将(const SampleType x[])参数赋予fft 这是我在对它应用DCT时所做的,但我觉得我没有正确地使用它,因为它没有提供正确的声音输出 struct SignalComponent { float frequency; float ampli
struct SignalComponent {
float frequency;
float amplitude;
};
auto buffer = audio_file->GetWavBuffer(); // float vector
auto buffer_length = audio_file->GetWavLength();
auto sample_rate = audio_file->GetWavFile()->freq;
for (unsigned int i=0; i < buffer_length/sample_rate; i++) {
// Conversion of float vector into Double vector;
std::vector<double> buffer_vector (buffer.begin()+(i*sample_rate),
buffer.begin()+((i+1)*sample_rate));
std::vector<double> dctCoefficients = dct->dct(buffer_vector, 576);
int length = dctCoefficients.size();
auto signal_components = std::vector<SignalComponent>() = {};
for (int i = 0; i<length; i++) {
SignalComponent sComponent;
//sqrt(re*re+im*im) will be the magnitude of the signal at the frequency of the given bin.
sComponent.amplitude = dctCoefficients[i];
sComponent.frequency = (static_cast<float>(i) *
(static_cast<float>(sample_rate) /
static_cast<float>(length)));
signal_components.push_back(sComponent);
}
SignalChunk sChunk = SignalChunk(signal_components);
signal_chunks.push_back(sChunk); // One big signalChunk
auto signal = Signal(signal_chunks);
// Clean up the DCT generator
delete dct;
}
struct-SignalComponent{
浮动频率;
浮动幅度;
};
自动缓冲=音频文件->GetWavBuffer();//浮点向量
自动缓冲区长度=音频文件->GetWavLength();
自动采样率=音频文件->GetWavFile()->频率;
for(无符号整数i=0;idct(缓冲区向量,576);
int length=dct系数.size();
自动信号组件=std::vector()={};
for(int i=0;ifft(buffer_vector1);//由于类型复杂,此行是错误的**
}
这就是我得到的错误:
错误:没有用于调用的匹配函数
'Aquila::Fft::Fft(std::vector&)'
spect=fft->fft(缓冲区向量1);/usr/local/include/aquila/transform/fft.h:70:30:注:候选:
虚拟Aquila::频谱类型Aquila::Fft::Fft(常量采样类型*)
虚谱型fft(常数采样型x[])=0;
^/usr/local/include/aquila/transform/Fft.h:70:30:注:未知
参数1从“std::vector”到“const”的转换
样本类型*{aka const double*}'
有人能帮我吗?我想在应用DCT时实现类似的效果
编辑:
Aquila::SpectrumType spect;
typedef complex<double> ComplexType;
typedef std::vector< ComplexType > SpectrumType
Aquila::SpectrumType spect;
typedef复杂复合型;
typedef std::vectorSpectrumType
<> PF>当我得到FFT工作时,如何提取真值和虚值?< /P> < P>将数据存储在向量中,这是C++编码时的一个好实践。 现在您调用的是一个API,它不知道代码> STD::vector (耻辱),可能是因为C++接口是C库的一个廉价包装。 必须按如下方式在向量的原始数据上传递指针:
fft->fft(&buffer_vector1[0]);
或者更好:使用数据成员方法:
fft->fft(buffer_vector1.data());
因为buffer\u vector1
是std::vector
要编译和链接代码,请链接这两个库:-lAquila-lOoura\u fft
尝试:fft->fft(&buffer\u vector1[0]);
fft->fft(buffer_vector1.data());