Skip to content

Commit

Permalink
JASOscillator code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
DanTGL committed Aug 17, 2024
1 parent 69b626f commit 4169b87
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 29 deletions.
10 changes: 5 additions & 5 deletions include/JSystem/JAudio/JASOscillator.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ namespace JASystem {
bool release();
f32 calc(s16*);

const Osc_* getOsc() const { return field_0x0; }
void setOsc(const Osc_* osc) { field_0x0 = osc; }
BOOL isOsc() { return field_0x0 != NULL ? TRUE : FALSE; }
const Osc_* getOsc() const { return mOsc; }
void setOsc(const Osc_* osc) { mOsc = osc; }
BOOL isOsc() { return mOsc != NULL ? TRUE : FALSE; }
void releaseDirect(u16 param_0) { mDirectRelease = param_0; }
void bankOscToOfs() {}
void getEffectorKind() const {}
Expand All @@ -37,7 +37,7 @@ namespace JASystem {
static const f32 relTableSqRoot[17];
static const f32 relTableSquare[17];

/* 0x00 */ const Osc_* field_0x0;
/* 0x00 */ const Osc_* mOsc;
/* 0x04 */ u8 mState;
/* 0x05 */ u8 field_0x5;
/* 0x06 */ u16 field_0x6;
Expand All @@ -46,7 +46,7 @@ namespace JASystem {
/* 0x10 */ f32 mTargetPhase;
/* 0x14 */ f32 mPhaseChangeRate;
/* 0x18 */ u16 mDirectRelease;
/* 0x1C */ f32 field_0x1c;
/* 0x1C */ f32 mInitialReleaseRate;
};
}

Expand Down
4 changes: 2 additions & 2 deletions src/JSystem/JAudio/JASChannel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ void JASystem::TChannel::init() {
}
for (u32 i = 0; i < 4; i++) {
JUT_ASSERT(155, osc[i]);
osc[i]->field_0x0 = NULL;
osc[i]->setOsc(NULL);
osc[i]->init();
}
mPauseFlag = 0;
Expand All @@ -67,7 +67,7 @@ void JASystem::TChannel::setOscillator(u32 oscnum, TOscillator* param_2) {
/* 8028B620-8028B6A8 .text setOscInit__Q28JASystem8TChannelFUlPCQ38JASystem11TOscillator4Osc_ */
void JASystem::TChannel::setOscInit(u32 oscnum, const TOscillator::Osc_* param_2) {
JUT_ASSERT(183, oscnum < (4));
osc[oscnum]->field_0x0 = param_2;
osc[oscnum]->setOsc(param_2);
osc[oscnum]->initStart();
}

Expand Down
44 changes: 22 additions & 22 deletions src/JSystem/JAudio/JASOscillator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
#include "math.h"

s16 JASystem::TOscillator::oscTableForceStop[] = {
0x0000, 0x000F, 0x0000,
0x000F, 0x0000, 0x0000
0, 15, 0,
15, 0, 0
};

const f32 JASystem::TOscillator::relTableSampleCell[] = {
Expand All @@ -39,7 +39,7 @@ const f32 JASystem::TOscillator::relTableSquare[] = {

/* 8028DE94-8028DECC .text init__Q28JASystem11TOscillatorFv */
void JASystem::TOscillator::init() {
field_0x0 = NULL;
mOsc = NULL;
mState = 1;
field_0x5 = 0;
field_0x6 = 0;
Expand All @@ -48,27 +48,27 @@ void JASystem::TOscillator::init() {
mTargetPhase = 0.0f;
mPhaseChangeRate = 0.0f;
mDirectRelease = 0;
field_0x1c = 0.0f;
mInitialReleaseRate = 0.0f;
}

/* 8028DECC-8028DF2C .text initStart__Q28JASystem11TOscillatorFv */
void JASystem::TOscillator::initStart() {
mState = 2;
mDirectRelease = 0;
if (!field_0x0 || !field_0x0->table) {
if (mOsc == NULL || !mOsc->table) {
mPhase = 0.0f;
return;
}
field_0x6 = 0;
mReleaseRate = 0.0f;
mTargetPhase = 0.0f;
mDirectRelease = 0;
mReleaseRate -= field_0x0->field_0x4;
mReleaseRate -= mOsc->field_0x4;
}

/* 8028DF2C-8028E070 .text getOffset__Q28JASystem11TOscillatorFv */
f32 JASystem::TOscillator::getOffset() {
if (field_0x0 == NULL) {
if (mOsc == NULL) {
OSReport("----- Oscillator is NULL\n");
mPhase = 1.0f;
return 1.0f;
Expand All @@ -78,7 +78,7 @@ f32 JASystem::TOscillator::getOffset() {
case 0:
return 1.0f;
case 3:
return field_0x0->field_0x14 + (mPhase * field_0x0->field_0x10);
return mOsc->field_0x14 + (mPhase * mOsc->field_0x10);

case 1:
mState = 2;
Expand All @@ -87,11 +87,11 @@ f32 JASystem::TOscillator::getOffset() {
default:
s16* var_r4;
if (mState == 4) {
var_r4 = (s16*)field_0x0->rel_table;
var_r4 = (s16*)mOsc->rel_table;
} else if (mState == 5) {
var_r4 = oscTableForceStop;
} else {
var_r4 = (s16*)field_0x0->table;
var_r4 = (s16*)mOsc->table;
}

if (var_r4 == NULL && mState != 6) {
Expand All @@ -102,7 +102,7 @@ f32 JASystem::TOscillator::getOffset() {
if (mState == 5) {
mReleaseRate -= 1.0f;
} else {
mReleaseRate -= field_0x0->field_0x4;
mReleaseRate -= mOsc->field_0x4;
}

return calc(var_r4);
Expand All @@ -128,13 +128,13 @@ bool JASystem::TOscillator::release() {
return false;
}

if (field_0x0->table != field_0x0->rel_table) {
if (mOsc->table != mOsc->rel_table) {
field_0x6 = 0;
mReleaseRate = 0.0f;
mTargetPhase = mPhase;
}

if (field_0x0->rel_table == NULL && mDirectRelease == 0) {
if (mOsc->rel_table == NULL && mDirectRelease == 0) {
mDirectRelease = 0x10;
}

Expand All @@ -151,7 +151,7 @@ bool JASystem::TOscillator::release() {
mReleaseRate = 1.0f;
}

field_0x1c = mReleaseRate;
mInitialReleaseRate = mReleaseRate;
mTargetPhase = 0.0f;
if (field_0x5 == 0) {
mPhaseChangeRate = (mTargetPhase - mPhase) / mReleaseRate;
Expand Down Expand Up @@ -191,7 +191,7 @@ f32 JASystem::TOscillator::calc(s16* i_table) {

if (envMode == 14) {
mState = 3;
return field_0x0->field_0x14 + mPhase * field_0x0->field_0x10;
return mOsc->field_0x14 + mPhase * mOsc->field_0x10;
}

field_0x5 = envMode;
Expand All @@ -203,7 +203,7 @@ f32 JASystem::TOscillator::calc(s16* i_table) {
}

mReleaseRate = envTime * ((Kernel::getDacRate() / 80.0f) / 600.0f) / Driver::getUpdateInterval();
field_0x1c = mReleaseRate;
mInitialReleaseRate = mReleaseRate;
mTargetPhase = envValue / 32768.0f;

if (field_0x5 == 0) {
Expand All @@ -215,14 +215,14 @@ f32 JASystem::TOscillator::calc(s16* i_table) {
field_0x6 += 1;
}

if (field_0x0->field_0x10 == 0.0f) {
return field_0x0->field_0x14;
if (mOsc->field_0x10 == 0.0f) {
return mOsc->field_0x14;
}


f32 temp_f31 = 0.0f;
f32 newPhase;
if (field_0x1c == 0.0) { // Developer probably forgot the f suffix
if (mInitialReleaseRate == 0.0) { // Developer probably forgot the f suffix
newPhase = mTargetPhase;
mPhase = mTargetPhase;
} else {
Expand All @@ -247,9 +247,9 @@ f32 JASystem::TOscillator::calc(s16* i_table) {
f32 fIdx;

if (temp_f31 < 0.0f) {
fIdx = 16.0f * (1.0f - (mReleaseRate / field_0x1c));
fIdx = 16.0f * (1.0f - (mReleaseRate / mInitialReleaseRate));
} else {
fIdx = 16.0f * (mReleaseRate / field_0x1c);
fIdx = 16.0f * (mReleaseRate / mInitialReleaseRate);
}

u32 idx = fIdx;
Expand All @@ -274,5 +274,5 @@ f32 JASystem::TOscillator::calc(s16* i_table) {
}
}

return newPhase * field_0x0->field_0x10 + field_0x0->field_0x14;
return newPhase * mOsc->field_0x10 + mOsc->field_0x14;
}

0 comments on commit 4169b87

Please sign in to comment.