giuliomoro I am currently working on autocorrelation using FFT and trying to emulate the code (https://github.com/yoyololicon/ape-examples/blob/main/yin.hpp) below using Bela
std::copy(cyclic_begin(history, history_counter),
cyclic_end(history, history_counter, history.size()),
fft_buf1.begin());
std::fill(fft_buf1.begin() + 2 * W - 1, fft_buf1.end(), 0);
std::copy(fft_buf1.begin(), fft_buf1.begin() + W, fft_buf2.begin());
std::fill(fft_buf2.begin() + W, fft_buf2.end(), 0);
fft.forward(fft_buf1);
fft.forward(fft_buf2);
for (i = 0; i < N / 2 + 1; i++)
fft_buf1[i] *= std::conj(fft_buf2[i]);
for (; i < N; i++)
fft_buf1[i] = std::conj(fft_buf1[N - i]);
fft.inverse(fft_buf1);
where basically fft_buf1 and fft_buf2 respectively load up with 2W and W samples (roughly) of audio and perform FFT with same number of size 2W. fft_buf2 is zero-padded.
The code then realises and rearranges the obtained coefficients followed by IFFT fft.inverse() to obtain autocorrelation.
Currently I am having
static std::vector<float> unwrapBuffer1(gFftSize, 0.0);
static std::vector<float> unwrapBuffer2(gFftSize, 0.0);
for (int k = 0; k < gFftSize; k++) {
int index_circular = (k + gWritePointer - gFftSize + gBufferSize) % gBufferSize;
unwrapBuffer1[k] = gCircularBuffer[index_circular];
}
for (int k = 0; k < gInputSize; k++) {
unwrapBuffer2[k] = unwrapBuffer1[k];
}
gFft1.fft(unwrapBuffer1);
gFft2.fft(unwrapBuffer2);
std::vector<float> spectrum(gFftSize / 2 + 1);
for (int i = 0; i < gFftSize / 2 + 1; i++) {
spectrum[i] = gFft1.fda(i) * gFft2.fda(i) + gFft1.fdi(i) * gFft2.fdi(i);
}
for (int i = gFftSize / 2; i < gFftSize; i++) {
spectrum[i] = spectrum[gFftSize - i];
}
gFft1.ifft(spectrum); // this line won't work
Because I can't call ifft() this way, I am wondering how to translate the part of IFFT to Bela properly.