Simplify fft_build_params

This commit is contained in:
twinaphex 2016-06-16 16:55:36 +02:00
parent 72355683a3
commit 8e454f7127

View File

@ -8,6 +8,7 @@
#include <retro_miscellaneous.h>
#include <filters.h>
#include <math/complex.h>
#define GLM_SWIZZLE
#define GLM_FORCE_RADIANS
@ -347,6 +348,12 @@ static inline unsigned bitinverse(unsigned x, unsigned size)
return ret;
}
static fft_complex_t exp_imag(float phase)
{
fft_complex_t out = { cosf(phase), sinf(phase) };
return out;
}
void fft_build_params(glfft_t *fft, GLuint *buffer,
unsigned step, unsigned size)
{
@ -357,23 +364,20 @@ void fft_build_params(glfft_t *fft, GLuint *buffer,
{
for (j = i; j < i + step_size; j++)
{
int s = j - i;
float phase = -1.0f * (float)s / step_size;
int s = j - i;
float phase = -1.0f * (float)s / step_size;
unsigned a = j;
unsigned b = j + step_size;
fft_complex_t twiddle = exp_imag(M_PI * phase);
float twiddle_real = cos(M_PI * phase);
float twiddle_imag = sin(M_PI * phase);
unsigned read_a = (step == 0) ? bitinverse(a, size) : a;
unsigned read_b = (step == 0) ? bitinverse(b, size) : b;
vec2 tmp = vec2(twiddle.real, twiddle.imag);
unsigned a = j;
unsigned b = j + step_size;
unsigned read_a = (step == 0) ? bitinverse(a, size) : a;
unsigned read_b = (step == 0) ? bitinverse(b, size) : b;
vec2 tmp = vec2(twiddle_real, twiddle_imag);
buffer[2 * a + 0] = (read_a << 16) | read_b;
buffer[2 * a + 1] = packHalf2x16(tmp);
buffer[2 * b + 0] = (read_a << 16) | read_b;
buffer[2 * b + 1] = packHalf2x16(-tmp);
buffer[2 * a + 0] = (read_a << 16) | read_b;
buffer[2 * a + 1] = packHalf2x16(tmp);
buffer[2 * b + 0] = (read_a << 16) | read_b;
buffer[2 * b + 1] = packHalf2x16(-tmp);
}
}
}