Library/Bgm: Implement DspValueController (#937)

This commit is contained in:
Naii-the-Baf 2026-03-12 19:04:40 -06:00 committed by GitHub
parent fc33c409ec
commit 33097d8def
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 99 additions and 23 deletions

View file

@ -226971,41 +226971,41 @@ Library/Bgm/DspValueController.o:
label:
- _ZN2al24DspLinearValueControllerC1Ef
- _ZN2al24DspLinearValueControllerC2Ef
status: NotDecompiled
status: Matching
- offset: 0x82e248
size: 12
label: _ZN2al24DspLinearValueController4initEf
status: NotDecompiled
status: Matching
- offset: 0x82e254
size: 88
label: _ZN2al24DspLinearValueController6updateEv
status: NotDecompiled
status: Matching
- offset: 0x82e2ac
size: 48
label: _ZN2al24DspLinearValueController12changeTargetEfi
status: NotDecompiled
status: Matching
- offset: 0x82e2dc
size: 64
label:
- _ZN2al21DspSinValueControllerC1Eff
- _ZN2al21DspSinValueControllerC2Eff
status: NotDecompiled
status: NonMatchingMinor
- offset: 0x82e31c
size: 16
label: _ZN2al21DspSinValueController4initEf
status: NotDecompiled
status: Matching
- offset: 0x82e32c
size: 200
label: _ZN2al21DspSinValueController6updateEv
status: NotDecompiled
status: Matching
- offset: 0x82e3f4
size: 52
label: _ZN2al21DspSinValueController12changeTargetEfi
status: NotDecompiled
status: Matching
- offset: 0x82e428
size: 32
label: _ZN2al21DspSinValueController10changeFreqEf
status: NotDecompiled
status: Matching
Library/Bgm/BgmEventProcInfo.o:
'.text':
- offset: 0x82e448

View file

@ -129,7 +129,7 @@ void BgmParamsChanger::changeDefaultParams(s32 stepCount) {
void BgmParamsChanger::forceDeactivate() {
mVolume->changeTarget(mVolume->getCurrent(), 0);
mPitchShift->changeTarget(mPitchShift->getCurrent(), 0);
mPitchShiftModulation->changeTarget(mPitchShiftModulation->getAmplitude(), 0);
mPitchShiftModulation->changeTarget(mPitchShiftModulation->getCurrent(), 0);
mLpf->changeTarget(mLpf->getCurrent(), 0);
mBiquadFilter->changeTarget(mBiquadFilter->getCurrent(), 0);
mEffectSend->changeTarget(mEffectSend->getCurrent(), 0);
@ -147,7 +147,7 @@ f32 BgmParamsChanger::getCurPitchShift() const {
}
f32 BgmParamsChanger::getCurPitchShiftModulation() const {
return mPitchShiftModulation->getAmplitude();
return mPitchShiftModulation->getCurrent();
}
f32 BgmParamsChanger::getCurLpfCutOff() const {

View file

@ -0,0 +1,76 @@
#include "Library/Bgm/DspValueController.h"
#include <math/seadMathCalcCommon.h>
namespace al {
DspLinearValueController::DspLinearValueController(f32 value) : mCurrent(value), mTarget(value) {}
void DspLinearValueController::init(f32 value) {
mCurrent = value;
mTarget = value;
}
void DspLinearValueController::update() {
if (mStep > 0.0f && mTarget > mCurrent) {
mCurrent += mStep;
if (mTarget < mCurrent)
mCurrent = mTarget;
return;
}
if (mStep < 0.0f && mTarget < mCurrent) {
mCurrent += mStep;
if (mTarget > mCurrent)
mCurrent = mTarget;
}
}
void DspLinearValueController::changeTarget(f32 target, s32 stepCount) {
mTarget = target;
f32 difference = target - mCurrent;
if (stepCount <= 0) {
mCurrent = target;
mStep = difference;
return;
}
mStep = difference / stepCount;
}
// NON_MATCHING: https://decomp.me/scratch/q2k8I
DspSinValueController::DspSinValueController(f32 updateFreq, f32 value)
: mUpdateFreq(updateFreq), mCurrent(value) {
mAmplitude = new DspLinearValueController(0.0f);
}
void DspSinValueController::init(f32 value) {
mCurrent = value;
mAmplitude->init(0.0f);
}
void DspSinValueController::update() {
if (mFreq <= 0.0f)
return;
mAmplitude->update();
mCurrent = sead::Mathf::sin(mAngle) * mAmplitude->getCurrent();
mAngle += mDelta;
while (mAngle >= sead::Mathf::pi2())
mAngle -= sead::Mathf::pi2();
}
void DspSinValueController::changeTarget(f32 target, s32 stepCount) {
mAmplitude->changeTarget(target, stepCount);
}
void DspSinValueController::changeFreq(f32 frequency) {
mFreq = frequency;
mAngle = 0.0f;
mCurrent = 0.0f;
mDelta = sead::Mathf::pi2() / mUpdateFreq * mFreq;
}
} // namespace al

View file

@ -24,23 +24,23 @@ static_assert(sizeof(DspLinearValueController) == 0xc);
class DspSinValueController {
public:
DspSinValueController(f32 shift, f32 amplitude);
void init(f32);
DspSinValueController(f32 updateFreq, f32 value);
void init(f32 value);
void update();
void changeTarget(f32, s32);
void changeFreq(f32);
void changeTarget(f32 target, s32 stepCount);
void changeFreq(f32 frequency);
bool isReachedTarget() const { return mLinearValue->isReachedTarget(); }
bool isReachedTarget() const { return mAmplitude->isReachedTarget(); }
f32 getAmplitude() const { return mAmplitude; }
f32 getCurrent() const { return mCurrent; }
private:
f32 mShift;
f32 mFreq;
f32 mDelta;
f32 mAngle;
f32 mAmplitude;
DspLinearValueController* mLinearValue;
f32 mUpdateFreq = 0.0f;
f32 mFreq = 0.0f;
f32 mDelta = 0.0f;
f32 mAngle = 0.0f;
f32 mCurrent = 0.0f;
DspLinearValueController* mAmplitude;
};
static_assert(sizeof(DspSinValueController) == 0x20);