From 21f7f6059a2da4a1a21c544ea2ee958c9f1af78e Mon Sep 17 00:00:00 2001 From: twinaphex Date: Sat, 22 Apr 2017 12:25:54 +0200 Subject: [PATCH] (ffmpeg FFT) No longer needs GLM --- cores/libretro-ffmpeg/fft/fft.cpp | 14 ++-- libretro-common/include/gfx/math/vector_2.h | 84 +++++++++++++++++++++ 2 files changed, 91 insertions(+), 7 deletions(-) diff --git a/cores/libretro-ffmpeg/fft/fft.cpp b/cores/libretro-ffmpeg/fft/fft.cpp index c5320b7300..0ebde3f4af 100644 --- a/cores/libretro-ffmpeg/fft/fft.cpp +++ b/cores/libretro-ffmpeg/fft/fft.cpp @@ -10,10 +10,7 @@ #include #include #include - -#define GLM_SWIZZLE -#define GLM_FORCE_RADIANS -#include +#include #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]); } } } diff --git a/libretro-common/include/gfx/math/vector_2.h b/libretro-common/include/gfx/math/vector_2.h index 5248693b06..bf6b20ae86 100644 --- a/libretro-common/include/gfx/math/vector_2.h +++ b/libretro-common/include/gfx/math/vector_2.h @@ -27,6 +27,7 @@ #include #include +#include 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