diff --git a/android/app-android.cpp b/android/app-android.cpp index d2e6fdd31d..5e7920d5fc 100644 --- a/android/app-android.cpp +++ b/android/app-android.cpp @@ -20,6 +20,7 @@ #include "file/zip_read.h" #include "input/input_state.h" #include "audio/mixer.h" +#include "math/math_util.h" #define coord_xres 800 #define coord_yres 480 @@ -189,6 +190,9 @@ extern "C" void Java_com_turboviking_libnative_NativeRenderer_displayRender } extern "C" void Java_com_turboviking_libnative_NativeApp_audioRender(JNIEnv* env, jclass clazz, jshortArray array) { + // The audio thread can pretty safely enable Flush-to-Zero mode on the FPU. + EnableFZ(); + int buf_size = env->GetArrayLength(array); if (buf_size) { short *data = env->GetShortArrayElements(array, 0); diff --git a/math/math_util.cc b/math/math_util.cc deleted file mode 100644 index 9454df7750..0000000000 --- a/math/math_util.cc +++ /dev/null @@ -1,19 +0,0 @@ -#include "math/math_util.h" -#include -#include - -/* -static unsigned int randSeed = 22222; // Change this for different random sequences. - -void SetSeed(unsigned int seed) { - randSeed = seed * 382792592; -} - -unsigned int GenerateRandomNumber() { - randSeed = (randSeed * 196314165) + 907633515; - randSeed ^= _rotl(randSeed, 13); - return randSeed; -}*/ - -#include - diff --git a/math/math_util.cpp b/math/math_util.cpp new file mode 100644 index 0000000000..29fe6a902e --- /dev/null +++ b/math/math_util.cpp @@ -0,0 +1,53 @@ +#include "math/math_util.h" +#include +#include + +/* +static unsigned int randSeed = 22222; // Change this for different random sequences. + +void SetSeed(unsigned int seed) { + randSeed = seed * 382792592; +} + +unsigned int GenerateRandomNumber() { + randSeed = (randSeed * 196314165) + 907633515; + randSeed ^= _rotl(randSeed, 13); + return randSeed; +}*/ + +#include + +#ifdef ANDROID + +void EnableFZ() +{ + int x; + asm( + "fmrx %[result],FPSCR \r\n" + "orr %[result],%[result],#16777216 \r\n" + "fmxr FPSCR,%[result]" + :[result] "=r" (x) : : + ); + //printf("ARM FPSCR: %08x\n",x); +} + +void DisableFZ( ) +{ + __asm__ volatile( + "fmrx r0, fpscr\n" + "bic r0, $(1 << 24)\n" + "fmxr fpscr, r0" : : : "r0"); +} +#else + +void EnableFZ() +{ + + +} +void DisableFZ() +{ + +} + +#endif \ No newline at end of file diff --git a/math/math_util.h b/math/math_util.h index 67847ce78b..9ee89d6e99 100644 --- a/math/math_util.h +++ b/math/math_util.h @@ -27,24 +27,6 @@ inline float Float16ToFloat(float16 ix) { // The stuff in this file is from all over the web, esp. dspmusic.org. I think it's all public domain. // In any case, very little of it is used anywhere at the moment. -// PM modulated sine -inline float sine(float t,float f,float ph,float fm) { - return sinf((t*f+ph)*2*PI + 0.5f*PI*fm*(1 - sqrt(f*2))); -} - -//fb := feedback (0 to 1) (1 max saw) - -inline float saw(float t,float f,float ph, float fm, float fb = 1.0f) -{ - return sine(t,f,ph,fb*sine(t-1.0f,f,ph,fm)); -} - -// pm := pulse mod (0 to 1) (1 max pulse) -// pw := pulse width (0 to 1) (1 square) -inline float pulse(float t,float f,float ph,float fm,float fb,float pm,float pw) { - return saw(t,f,ph,fm,fb) - saw(t,f,ph+0.5f*pw,fm,fb) * pm; -} - // Calculate pseudo-random 32 bit number based on linear congruential method. void SetSeed(unsigned int seed); unsigned int GenerateRandomNumber(); @@ -61,7 +43,7 @@ inline float GaussRand() float R1 = GenerateRandomFloat01(); float R2 = GenerateRandomFloat01(); - float X = sqrtf( -2.0f * logf(R1)) * cosf(2.0f * PI * R2); + float X = sqrtf(-2.0f * logf(R1)) * cosf(2.0f * PI * R2); if (X > 4.0f) X = 4.0f; if (X < -4.0f) X = -4.0f; return X; @@ -76,13 +58,18 @@ inline double atan_fast(double x) { // linear -> dB conversion inline float lin2dB(float lin) { const float LOG_2_DB = 8.6858896380650365530225783783321f; // 20 / ln( 10 ) - return log(lin) * LOG_2_DB; + return logf(lin) * LOG_2_DB; } // dB -> linear conversion inline float dB2lin(float dB) { const float DB_2_LOG = 0.11512925464970228420089957273422f; // ln( 10 ) / 20 - return exp(dB * DB_2_LOG); + return expf(dB * DB_2_LOG); } + +// FPU control. +void EnableFZ(); +void DisableFZ(); + #endif diff --git a/native.vcxproj b/native.vcxproj index da95fada22..bb1c322ab3 100644 --- a/native.vcxproj +++ b/native.vcxproj @@ -182,7 +182,7 @@ - + diff --git a/native.vcxproj.filters b/native.vcxproj.filters index 912d7a7eef..99a6e411eb 100644 --- a/native.vcxproj.filters +++ b/native.vcxproj.filters @@ -220,9 +220,6 @@ gfx - - math - ext @@ -286,6 +283,9 @@ util + + math +