From 5f7526e7326e198d1c64ee02fdabe567df2b361c Mon Sep 17 00:00:00 2001 From: UnknownShadow200 Date: Sat, 10 Jun 2023 17:37:22 +1000 Subject: [PATCH] Switch to ldexp in Vorbis float32_unpack --- readme.md | 2 +- src/ExtMath.c | 1 + src/ExtMath.h | 2 ++ src/Graphics_GCWii.c | 3 ++- src/Vorbis.c | 4 +--- 5 files changed, 7 insertions(+), 5 deletions(-) diff --git a/readme.md b/readme.md index 8a7e36960..d5531f36f 100644 --- a/readme.md +++ b/readme.md @@ -71,7 +71,7 @@ If you get a ```The Windows SDK version 5.1 was not found``` compilation error, I am assuming you used the installer from https://sourceforge.net/projects/mingw-w64/ 1. Install MinGW-W64 2. Use either *Run Terminal* from Start Menu or run *mingw-w64.bat* in the installation folder -2. Navigate to the directory with ClassiCube's source code +3. Navigate to the directory with ClassiCube's source code 4. Enter `gcc *.c -o ClassiCube.exe -mwindows -lwinmm -limagehlp` ##### Using MinGW diff --git a/src/ExtMath.c b/src/ExtMath.c index f4e94a5e9..dec7d7bad 100644 --- a/src/ExtMath.c +++ b/src/ExtMath.c @@ -21,6 +21,7 @@ double Math_Cos(double x) { return cos(x); } float Math_SinF(float x) { return (float)Math_Sin(x); } float Math_CosF(float x) { return (float)Math_Cos(x); } double Math_Atan2(double x, double y) { return atan2(y, x); } +double Math_ldexp(double m, int exp) { return ldexp(m, exp); } int Math_Floor(float value) { int valueI = (int)value; diff --git a/src/ExtMath.h b/src/ExtMath.h index 5535ebe8a..bc5bb8308 100644 --- a/src/ExtMath.h +++ b/src/ExtMath.h @@ -33,6 +33,8 @@ CC_API double Math_Cos(double x); float Math_SinF(float x); float Math_CosF(float x); double Math_Atan2(double x, double y); +/* Returns m * 2^exp */ +double Math_ldexp(double m, int exp); /* Computes loge(x). Can also be used to approximate logy(x). */ /* e.g. for log3(x), use: Math_Log(x)/log(3) */ diff --git a/src/Graphics_GCWii.c b/src/Graphics_GCWii.c index da2f13443..1a673ba13 100644 --- a/src/Graphics_GCWii.c +++ b/src/Graphics_GCWii.c @@ -340,13 +340,14 @@ void* Gfx_LockDynamicVb(GfxResourceID vb, VertexFormat fmt, int count) { } void Gfx_UnlockDynamicVb(GfxResourceID vb) { - gfx_vertices = vb; + gfx_vertices = vb; DCFlushRange(vb, vb_size); } // Current size of vertices static int gfx_stride; // TODO move down to Drawing area ?? void Gfx_SetDynamicVbData(GfxResourceID vb, void* vertices, int vCount) { + gfx_vertices = vb; Mem_Copy(vb, vertices, vCount * gfx_stride); DCFlushRange(vertices, vCount * gfx_stride); } diff --git a/src/Vorbis.c b/src/Vorbis.c index 453995d9b..6781c70ed 100644 --- a/src/Vorbis.c +++ b/src/Vorbis.c @@ -204,9 +204,7 @@ static float float32_unpack(struct VorbisState* ctx) { cc_uint32 exponent = (x & 0x7fe00000) >> 21; if (x & 0x80000000UL) mantissa = -mantissa; - #define LOG_2 0.693147180559945 - /* TODO: Can we make this more accurate? maybe ldexp ?? */ - return (float)(mantissa * Math_Exp(LOG_2 * ((int)exponent - 788))); /* pow(2, x) */ + return (float)Math_ldexp(mantissa, (int)exponent - 788); }