Rename math_util.cc to cpp, cleanup.

This commit is contained in:
Henrik Rydgard 2012-05-09 00:33:43 +02:00
parent 17f1e71da2
commit ba8e5be264
6 changed files with 69 additions and 44 deletions

View File

@ -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);

View File

@ -1,19 +0,0 @@
#include "math/math_util.h"
#include <math.h>
#include <stdlib.h>
/*
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 <math.h>

53
math/math_util.cpp Normal file
View File

@ -0,0 +1,53 @@
#include "math/math_util.h"
#include <math.h>
#include <stdlib.h>
/*
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 <math.h>
#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

View File

@ -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

View File

@ -182,7 +182,7 @@
<ClCompile Include="math\lin\matrix4x4.cpp" />
<ClCompile Include="math\lin\quat.cpp" />
<ClCompile Include="math\lin\vec3.cpp" />
<ClCompile Include="math\math_util.cc" />
<ClCompile Include="math\math_util.cpp" />
<ClCompile Include="midi\midi_input.cpp" />
<ClCompile Include="profiler\profiler.cpp" />
<ClCompile Include="ui\ui.cpp" />

View File

@ -220,9 +220,6 @@
<ClCompile Include="gfx\texture_atlas.cpp">
<Filter>gfx</Filter>
</ClCompile>
<ClCompile Include="math\math_util.cc">
<Filter>math</Filter>
</ClCompile>
<ClCompile Include="ext\etcpack\etcpack.cpp">
<Filter>ext</Filter>
</ClCompile>
@ -286,6 +283,9 @@
<ClCompile Include="util\bits\bits.cpp">
<Filter>util</Filter>
</ClCompile>
<ClCompile Include="math\math_util.cpp">
<Filter>math</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<Filter Include="gfx">