(ffmpeg FFT) No longer needs GLM

This commit is contained in:
twinaphex 2017-04-22 12:25:54 +02:00
parent d674d2102e
commit 21f7f6059a
2 changed files with 91 additions and 7 deletions

View File

@ -10,10 +10,7 @@
#include <filters.h>
#include <math/complex.h>
#include <gfx/math/matrix_4x4.h>
#define GLM_SWIZZLE
#define GLM_FORCE_RADIANS
#include <glm/packing.hpp>
#include <gfx/math/vector_2.h>
#if GL_DEBUG
#define GL_CHECK_ERROR() do { \
@ -373,6 +370,7 @@ void fft_build_params(glfft_t *fft, GLuint *buffer,
{
for (j = i; j < i + step_size; j++)
{
vec2_t tmp;
int s = j - i;
float phase = -1.0f * (float)s / step_size;
unsigned a = j;
@ -381,12 +379,14 @@ void fft_build_params(glfft_t *fft, GLuint *buffer,
unsigned read_a = (step == 0) ? bitinverse(a, size) : a;
unsigned read_b = (step == 0) ? bitinverse(b, size) : b;
glm::vec2 tmp = glm::vec2(twiddle.real, twiddle.imag);
tmp[0] = twiddle.real;
tmp[1] = twiddle.imag;
buffer[2 * a + 0] = (read_a << 16) | read_b;
buffer[2 * a + 1] = glm::packHalf2x16(tmp);
buffer[2 * a + 1] = vec2_packHalf2x16(tmp[0], tmp[1]);
buffer[2 * b + 0] = (read_a << 16) | read_b;
buffer[2 * b + 1] = glm::packHalf2x16(-tmp);
buffer[2 * b + 1] = vec2_packHalf2x16(-tmp[0], -tmp[1]);
}
}
}

View File

@ -27,6 +27,7 @@
#include <math.h>
#include <retro_common_api.h>
#include <retro_inline.h>
RETRO_BEGIN_DECLS
@ -48,6 +49,89 @@ typedef float vec2_t[2];
dst[0] = src[0]; \
dst[1] = src[1]
static INLINE float overflow(void)
{
volatile float f = 1e10;
for(int i = 0; i < 10; ++i)
f *= f;
return f;
}
static INLINE int16_t tofloat16(float f)
{
union uif32
{
float f;
uint32_t i;
};
int i, s, e, m;
uif32 Entry;
Entry.f = f;
i = (int)Entry.i;
s = (i >> 16) & 0x00008000;
e = ((i >> 23) & 0x000000ff) - (127 - 15);
m = i & 0x007fffff;
if(e <= 0)
{
if(e < -10)
return (int16_t)(s);
m = (m | 0x00800000) >> (1 - e);
if(m & 0x00001000)
m += 0x00002000;
return (int16_t)(s | (m >> 13));
}
if(e == 0xff - (127 - 15))
{
if(m == 0)
return (int16_t)(s | 0x7c00);
m >>= 13;
return (int16_t)(s | 0x7c00 | m | (m == 0));
}
if(m & 0x00001000)
{
m += 0x00002000;
if(m & 0x00800000)
{
m = 0;
e += 1;
}
}
if (e > 30)
{
overflow();
return (int16_t)(s | 0x7c00);
}
return (int16_t)(s | (e << 10) | (m >> 13));
}
static INLINE unsigned int vec2_packHalf2x16(float vec0, float vec1)
{
union
{
int16_t in[2];
unsigned int out;
} u;
u.in[0] = tofloat16(vec0);
u.in[1] = tofloat16(vec1);
return u.out;
}
RETRO_END_DECLS
#endif