Skip to content

Commit

Permalink
Sas: Make ADSR fields private.
Browse files Browse the repository at this point in the history
  • Loading branch information
unknownbrackets committed Jan 15, 2023
1 parent b118ffa commit 9258540
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 19 deletions.
12 changes: 3 additions & 9 deletions Core/HLE/sceSas.cpp
Expand Up @@ -536,7 +536,7 @@ static u32 sceSasSetSL(u32 core, int voiceNum, int level) {
DEBUG_LOG(SCESAS, "sceSasSetSL(%08x, %i, %08x)", core, voiceNum, level);
__SasDrain();
SasVoice &v = sas->voices[voiceNum];
v.envelope.sustainLevel = level;
v.envelope.SetSustainLevel(level);
return 0;
}

Expand All @@ -556,10 +556,7 @@ static u32 sceSasSetADSR(u32 core, int voiceNum, int flag, int a, int d, int s,

__SasDrain();
SasVoice &v = sas->voices[voiceNum];
if ((flag & 0x1) != 0) v.envelope.attackRate = a;
if ((flag & 0x2) != 0) v.envelope.decayRate = d;
if ((flag & 0x4) != 0) v.envelope.sustainRate = s;
if ((flag & 0x8) != 0) v.envelope.releaseRate = r;
v.envelope.SetRate(flag, a, d, s, r);
return 0;
}

Expand Down Expand Up @@ -602,10 +599,7 @@ static u32 sceSasSetADSRMode(u32 core, int voiceNum, int flag, int a, int d, int
DEBUG_LOG(SCESAS, "sceSasSetADSRMode(%08x, %i, %i, %08x, %08x, %08x, %08x)", core, voiceNum, flag, a, d, s, r);
__SasDrain();
SasVoice &v = sas->voices[voiceNum];
if ((flag & 0x1) != 0) v.envelope.attackType = a;
if ((flag & 0x2) != 0) v.envelope.decayType = d;
if ((flag & 0x4) != 0) v.envelope.sustainType = s;
if ((flag & 0x8) != 0) v.envelope.releaseType = r;
v.envelope.SetEnvelope(flag, a, d, s, r);
return 0;
}

Expand Down
22 changes: 22 additions & 0 deletions Core/HW/SasAudio.cpp
Expand Up @@ -318,6 +318,28 @@ static int getSustainLevel(int bitfield1) {
return ((bitfield1 & 0x000F) + 1) << 26;
}

void ADSREnvelope::SetEnvelope(int flag, int a, int d, int s, int r) {
if ((flag & 0x1) != 0)
attackType = a;
if ((flag & 0x2) != 0)
decayType = d;
if ((flag & 0x4) != 0)
sustainType = s;
if ((flag & 0x8) != 0)
releaseType = r;
}

void ADSREnvelope::SetRate(int flag, int a, int d, int s, int r) {
if ((flag & 0x1) != 0)
attackRate = a;
if ((flag & 0x2) != 0)
decayRate = d;
if ((flag & 0x4) != 0)
sustainRate = s;
if ((flag & 0x8) != 0)
releaseRate = r;
}

void ADSREnvelope::SetSimpleEnvelope(u32 ADSREnv1, u32 ADSREnv2) {
attackRate = getAttackRate(ADSREnv1);
attackType = getAttackType(ADSREnv1);
Expand Down
25 changes: 15 additions & 10 deletions Core/HW/SasAudio.h
Expand Up @@ -151,6 +151,11 @@ class ADSREnvelope {
public:
ADSREnvelope();
void SetSimpleEnvelope(u32 ADSREnv1, u32 ADSREnv2);
void SetEnvelope(int flag, int a, int d, int s, int r);
void SetRate(int flag, int a, int d, int s, int r);
void SetSustainLevel(int sl) {
sustainLevel = sl;
}

void WalkCurve(int type, int rate);

Expand All @@ -170,16 +175,6 @@ class ADSREnvelope {
return state_ == STATE_OFF;
}

int attackRate;
int decayRate;
int sustainRate;
int releaseRate;
int attackType;
int decayType;
int sustainType;
int sustainLevel;
int releaseType;

void DoState(PointerWrap &p);

private:
Expand All @@ -197,6 +192,16 @@ class ADSREnvelope {
};
void SetState(ADSRState state);

int attackRate;
int decayRate;
int sustainRate;
int releaseRate;
int attackType;
int decayType;
int sustainType;
int sustainLevel;
int releaseType;

ADSRState state_;
s64 height_; // s64 to avoid having to care about overflow when calculating. TODO: this should be fine as s32
};
Expand Down

0 comments on commit 9258540

Please sign in to comment.