Switch to ldexp in Vorbis float32_unpack

This commit is contained in:
UnknownShadow200 2023-06-10 17:37:22 +10:00
parent 896b6bf8f0
commit 5f7526e732
5 changed files with 7 additions and 5 deletions

View File

@ -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/ I am assuming you used the installer from https://sourceforge.net/projects/mingw-w64/
1. Install MinGW-W64 1. Install MinGW-W64
2. Use either *Run Terminal* from Start Menu or run *mingw-w64.bat* in the installation folder 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` 4. Enter `gcc *.c -o ClassiCube.exe -mwindows -lwinmm -limagehlp`
##### Using MinGW ##### Using MinGW

View File

@ -21,6 +21,7 @@ double Math_Cos(double x) { return cos(x); }
float Math_SinF(float x) { return (float)Math_Sin(x); } float Math_SinF(float x) { return (float)Math_Sin(x); }
float Math_CosF(float x) { return (float)Math_Cos(x); } float Math_CosF(float x) { return (float)Math_Cos(x); }
double Math_Atan2(double x, double y) { return atan2(y, 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 Math_Floor(float value) {
int valueI = (int)value; int valueI = (int)value;

View File

@ -33,6 +33,8 @@ CC_API double Math_Cos(double x);
float Math_SinF(float x); float Math_SinF(float x);
float Math_CosF(float x); float Math_CosF(float x);
double Math_Atan2(double x, double y); 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). */ /* Computes loge(x). Can also be used to approximate logy(x). */
/* e.g. for log3(x), use: Math_Log(x)/log(3) */ /* e.g. for log3(x), use: Math_Log(x)/log(3) */

View File

@ -347,6 +347,7 @@ void Gfx_UnlockDynamicVb(GfxResourceID vb) {
// Current size of vertices // Current size of vertices
static int gfx_stride; // TODO move down to Drawing area ?? static int gfx_stride; // TODO move down to Drawing area ??
void Gfx_SetDynamicVbData(GfxResourceID vb, void* vertices, int vCount) { void Gfx_SetDynamicVbData(GfxResourceID vb, void* vertices, int vCount) {
gfx_vertices = vb;
Mem_Copy(vb, vertices, vCount * gfx_stride); Mem_Copy(vb, vertices, vCount * gfx_stride);
DCFlushRange(vertices, vCount * gfx_stride); DCFlushRange(vertices, vCount * gfx_stride);
} }

View File

@ -204,9 +204,7 @@ static float float32_unpack(struct VorbisState* ctx) {
cc_uint32 exponent = (x & 0x7fe00000) >> 21; cc_uint32 exponent = (x & 0x7fe00000) >> 21;
if (x & 0x80000000UL) mantissa = -mantissa; if (x & 0x80000000UL) mantissa = -mantissa;
#define LOG_2 0.693147180559945 return (float)Math_ldexp(mantissa, (int)exponent - 788);
/* TODO: Can we make this more accurate? maybe ldexp ?? */
return (float)(mantissa * Math_Exp(LOG_2 * ((int)exponent - 788))); /* pow(2, x) */
} }