mirror of https://github.com/zeldaret/tp.git
144 lines
3.9 KiB
C++
144 lines
3.9 KiB
C++
//
|
|
// Generated By: dol2asm
|
|
// Translation Unit: Z2Calc
|
|
//
|
|
|
|
#include "Z2AudioLib/Z2Calc.h"
|
|
#include "JSystem/JMath/random.h"
|
|
#include "dol2asm.h"
|
|
#include "global.h"
|
|
#include "msl_c/math.h"
|
|
|
|
//
|
|
// Declarations:
|
|
//
|
|
|
|
/* 802A968C-802A96F4 2A3FCC 0068+00 1/1 16/16 0/0 .text linearTransform__6Z2CalcFfffffb
|
|
*/
|
|
f32 Z2Calc::linearTransform(f32 param1, f32 param2, f32 param3, f32 param4, f32 param5,
|
|
bool param6) {
|
|
f32 temp;
|
|
|
|
temp = param4 + (param1 - param2) * ((param5 - param4) / (param3 - param2));
|
|
|
|
if (param6) {
|
|
return temp;
|
|
} else if (param4 < param5) {
|
|
if (temp > param5) {
|
|
return param5;
|
|
} else if (temp < param4) {
|
|
return param4;
|
|
} else {
|
|
return temp;
|
|
}
|
|
} else if (temp > param4) {
|
|
return param4;
|
|
} else if (temp < param5) {
|
|
return param5;
|
|
} else {
|
|
return temp;
|
|
}
|
|
}
|
|
|
|
/* ############################################################################################## */
|
|
/* 80455820-80455824 003E20 0004+00 0/0 1/1 0/0 .sdata2 cEqualCSlope__6Z2Calc */
|
|
SECTION_SDATA2 f32 Z2Calc::cEqualCSlope = 1.0f;
|
|
|
|
/* 80455824-80455828 003E24 0004+00 0/0 1/1 0/0 .sdata2 cEqualPSlope__6Z2Calc */
|
|
SECTION_SDATA2 f32 Z2Calc::cEqualPSlope = 0.5f;
|
|
|
|
/* 802A96F4-802A9814 2A4034 0120+00 0/0 29/29 0/0 .text
|
|
* getParamByExp__6Z2CalcFffffffQ26Z2Calc9CurveSign */
|
|
f32 Z2Calc::getParamByExp(f32 f1, f32 f2, f32 f3, f32 f4, f32 f5, f32 f6, Z2Calc::CurveSign sign) {
|
|
f32 out;
|
|
if (sign == Z2Calc::CURVE_SIGN_1) {
|
|
f32 tmp = exp(Z2Calc::linearTransform(f1, f2, f3, 0.0f, f4, true));
|
|
out = Z2Calc::linearTransform(tmp, 1.0f, exp(f4), f5, f6, true);
|
|
} else if (sign == Z2Calc::CURVE_SIGN_0) {
|
|
f32 tmp = exp(Z2Calc::linearTransform(f1, f2, f3, f4, 0.0f, true));
|
|
out = Z2Calc::linearTransform(tmp, exp(f4), 1.0f, f5, f6, true);
|
|
} else {
|
|
out = Z2Calc::linearTransform(f1, f2, f3, f5, f6, false);
|
|
}
|
|
if (out > f6) {
|
|
return f6;
|
|
}
|
|
if (out < f5) {
|
|
return f5;
|
|
}
|
|
return out;
|
|
}
|
|
|
|
/* 802A9814-802A98D4 2A4154 00C0+00 0/0 2/2 0/0 .text getRandom__6Z2CalcFfff */
|
|
f32 Z2Calc::getRandom(f32 f1, f32 f2, f32 f3) {
|
|
f32 tmp = 2.0f * f3;
|
|
f32 tmp2 = (1.0f - f3) * -2.0f;
|
|
f1 *= Z2Calc::getRandom_0_1() < f3 ? tmp : tmp2;
|
|
f32 tmp3 = pow(Z2Calc::getRandom_0_1(), f2);
|
|
return tmp3 * f1;
|
|
}
|
|
|
|
/* 802A98D4-802A9944 2A4214 0070+00 1/1 1/1 0/0 .text getRandom_0_1__6Z2CalcFv */
|
|
f32 Z2Calc::getRandom_0_1(void) {
|
|
static JMath::TRandom_fast_ oRandom(0);
|
|
return oRandom.get_ufloat_1();
|
|
}
|
|
|
|
/* 802A9944-802A9958 2A4284 0014+00 0/0 1/1 0/0 .text setParam__Q26Z2Calc8FNoise1fFfff */
|
|
void Z2Calc::FNoise1f::setParam(f32 param1, f32 param2, f32 param3) {
|
|
this->unk0 = param1;
|
|
this->unk4 = param1;
|
|
this->unk12 = param2;
|
|
this->unk8 = param3;
|
|
}
|
|
|
|
/* 802A9958-802A99A0 2A4298 0048+00 1/1 0/0 0/0 .text tau__Q26Z2Calc8FNoise1fFf */
|
|
f32 Z2Calc::FNoise1f::tau(f32 param1) {
|
|
f32 temp1;
|
|
f32 temp2;
|
|
|
|
temp1 = param1;
|
|
temp2 = temp1 + (temp1 * temp1);
|
|
|
|
if (temp2 > 1.0f) {
|
|
temp2 = temp2 - 1.0f;
|
|
|
|
if (temp1 < this->unk12) {
|
|
temp2 = temp2 + this->unk12;
|
|
}
|
|
|
|
return temp2;
|
|
} else if (temp1 < this->unk12) {
|
|
temp2 = temp2 + this->unk12;
|
|
}
|
|
return temp2;
|
|
}
|
|
|
|
/* 802A99A0-802A9A34 2A42E0 0094+00 0/0 5/5 0/0 .text calcNoise1f__Q26Z2Calc8FNoise1fFv
|
|
*/
|
|
f32 Z2Calc::FNoise1f::calcNoise1f(void) {
|
|
f32 temp1;
|
|
f32 temp2;
|
|
|
|
temp1 = this->unk0;
|
|
|
|
if (this->unk0 < this->unk4) {
|
|
this->unk0 = temp1 + this->unk8;
|
|
|
|
if (this->unk0 < this->unk4) {
|
|
return this->unk0;
|
|
}
|
|
} else {
|
|
this->unk0 = temp1 - this->unk8;
|
|
|
|
if (this->unk0 > this->unk4) {
|
|
return this->unk0;
|
|
}
|
|
}
|
|
this->unk0 = this->unk4;
|
|
temp2 = tau(this->unk0);
|
|
this->unk4 = temp2;
|
|
|
|
return this->unk0;
|
|
}
|