我一直在研究一些 vDSP 代码,但遇到了一个恼人的问题。我的代码是跨平台的,因此使用 std::complex 来存储其复杂值。
现在我假设我能够按如下方式设置 FFT:
DSPSplitComplex dspsc;
dspsc.realp = &complexVector.front().real();
dspsc.imagp = &complexVector.front().imag();
然后在适当的 vDSP_fft_* 调用中使用步长 2。
然而这似乎不起作用。我可以通过执行 vDSP_ztoc 来解决这个问题,但这需要临时缓冲区,我真的不想闲逛。有没有办法直接在交错的复杂数据上使用 vDSP_fft_* 函数?还有谁能解释一下为什么我不能像上面那样步幅为 2?
谢谢
编辑: 正如 Bo Persson 所指出的, real 和 imag 函数实际上并不返回引用。
但是,如果我执行以下操作,它仍然不起作用
DSPSplitComplex dspsc;
dspsc.realp = ((float*)&complexVector.front()) + 0;
dspsc.imagp = ((float*)&complexVector.front()) + 1;
所以我原来的问题仍然有效:(
I've been working on some vDSP code and I have come up against an annoying problem. My code is cross platform and hence uses std::complex to store its complex values.
Now I assumed that I would be able to set up an FFT as follows:
DSPSplitComplex dspsc;
dspsc.realp = &complexVector.front().real();
dspsc.imagp = &complexVector.front().imag();
And then use a stride of 2 in the appropriate vDSP_fft_* call.
However this just doesn't seem to work. I can solve the issue by doing a vDSP_ztoc but this requires temporary buffers that I really don't want hanging around. Is there any way to use the vDSP_fft_* functions directly on interleaved complex data? Also can anyone explain why I can't do as I do above with a stride of 2?
Thanks
Edit: As pointed out by Bo Persson the real and imag functions don't actually return a reference.
However it still doesn't work if I do the following instead
DSPSplitComplex dspsc;
dspsc.realp = ((float*)&complexVector.front()) + 0;
dspsc.imagp = ((float*)&complexVector.front()) + 1;
So my original question still does stand :(
发布评论
评论(2)
std::complex 函数
real()
和imag()
按值返回,它们不返回对complex 成员的引用。这意味着您无法通过这种方式获取他们的地址。
The std::complex functions
real()
andimag()
return by value, they do not return a reference to the members of complex.This means that you cannot get their addresses this way.
这就是你的做法。
const COMPLEX *in = reinterpret_cast(std::complex);
来源:http://www.fftw.org/doc/Complex-numbers.html
编辑:
澄清来源; COMPLEX 和 fftw_complex 使用相同的数据布局(尽管 fftw_complex 使用
double
和 COMPLEXfloat
)This is how you do it.
const COMPLEX *in = reinterpret_cast<const COMPLEX*>(std::complex);
Source: http://www.fftw.org/doc/Complex-numbers.html
EDIT:
To clarify the source; COMPLEX and fftw_complex use the same data layout (although fftw_complex uses
double
and COMPLEXfloat
)