Skip to content

Commit

Permalink
Further reduce input meta data size keeping it at or below 32 bytes f…
Browse files Browse the repository at this point in the history
…or all options. Overhaul filters and fix some issues.
  • Loading branch information
linuscu committed Sep 24, 2024
1 parent f282b4a commit 6ad9b3f
Show file tree
Hide file tree
Showing 7 changed files with 14 additions and 16 deletions.
1 change: 0 additions & 1 deletion packages/math/include/math/MathTween.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ namespace l::math::tween {
float Value();

protected:
float mUpdateRate = 0.0f;
int32_t mUpdateCount = 1;
float mDynamicSmoothAccuracy = 0.1f;
float mDynamicSmooth = 0.25f;
Expand Down
8 changes: 3 additions & 5 deletions packages/math/source/common/MathTween.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,14 +73,11 @@ namespace l::math::tween {
// update rate in audio processing, the number of samples between calls
// we can use this to update expensive interpolation here
void DynamicTween::Update(float updateRate) {
if (updateRate != mUpdateRate) {
mUpdateRate = l::math::functions::max(updateRate, 2.0f);
mDynamicSmooth = GetRWAFactor(static_cast<int32_t>(mUpdateRate), mDynamicSmoothAccuracy);
}
mDynamicSmooth = GetRWAFactor(static_cast<int32_t>(updateRate), mDynamicSmoothAccuracy);

mTarget = mTargetValue;
if (mCounter < mUpdateCount) {
float t = (mCounter + 0.5f * mUpdateRate) / static_cast<float>(mUpdateCount - 0.5f * mUpdateRate);
float t = (mCounter + 0.5f) / static_cast<float>(mUpdateCount - 0.5f);
t = l::math::functions::clamp(t, 0.0f, 1.0f);
mTarget = mTargetValuePrev + l::math::smooth::smoothPolyh3(t) * (mTargetValue - mTargetValuePrev);
}
Expand All @@ -95,4 +92,5 @@ namespace l::math::tween {
float DynamicTween::Value() {
return mValue;
}

}
8 changes: 4 additions & 4 deletions packages/math/tests/common/MathTweenTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ TEST(MathTween, DynamicTween) {
}

TEST(MathTween, DynamicTweenVeryShortBatch) {
DynamicTween tween(0.1f);
DynamicTween tween(0.01f);
tween.SetValue(1.0f);
tween.SetTarget(0.0, 22);
TEST_FUZZY(tween.Value(), 1.0f, 0.01f, "");
Expand All @@ -55,7 +55,7 @@ TEST(MathTween, DynamicTweenVeryShortBatch) {
}

TEST(MathTween, DynamicTweenShortBatch) {
DynamicTween tween(0.35f);
DynamicTween tween(0.135f);
tween.SetValue(1.0f);
tween.SetTarget(0.0, 102);
TEST_FUZZY(tween.Value(), 1.0f, 0.01f, "");
Expand All @@ -72,7 +72,7 @@ TEST(MathTween, DynamicTweenShortBatch) {
}

TEST(MathTween, DynamicTweenLongBatch) {
int32_t updateRate = 100;
float updateRate = 100.0f;
DynamicTween tween(0.35f);
tween.SetValue(1.0f);
tween.SetTarget(0.0, 1020);
Expand All @@ -84,7 +84,7 @@ TEST(MathTween, DynamicTweenLongBatch) {
auto value = tween.Next();
LOG(LogInfo) << "Tween (" << i << "): " << value;
}
TEST_FUZZY(tween.Value(), 0.0f, 0.01f, "");
TEST_FUZZY(tween.Value(), 0.0f, 0.02f, "");

return 0;
}
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ namespace l::nodegraph {
GraphFilterChamberlain2pole(NodeGraphBase* node) :
GraphFilterBase(node, "Chamberlin two-pole")
{
AddInput("Mode");
mNodeInputManager.AddInput(InputTypeBase::SAMPLED, AddInput("Mode"));
mState.resize(4);
}
virtual ~GraphFilterChamberlain2pole() = default;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,9 @@ namespace l::nodegraph {
float GraphFilterChamberlain2pole::ProcessSignal(float input, float cutoff, float resonance) {
float inputValueInbetween = (mInputValuePrev + input) * 0.5f;
float scale = mScaleFilter.Next();
resonance *= 0.99f * (cutoff * 0.15f + 0.85f); // adjust resonance slightly down at low frequencies to avoid oscillation
cutoff *= 0.5f;
resonance = 1.0f - resonance;
resonance = (1.0f - resonance);
for (int32_t oversample = 0; oversample < 2; oversample++) {
mState.at(0) = mState.at(0) + cutoff * mState.at(2);
mState.at(1) = scale * (oversample == 0 ? inputValueInbetween : input) - mState.at(0) - resonance * mState.at(2);
Expand Down
2 changes: 1 addition & 1 deletion packages/nodegraph/tests/common/NodeGraphBatchingTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ TEST(NodeGraphBatching, Simple) {

auto output = &group.GetOutput(0, 8);

TEST_FUZZY(0.034771f, output[7], 0.0001f, "");
TEST_FUZZY(0.012347f, output[7], 0.0001f, "");

return 0;
}
Expand Down
6 changes: 3 additions & 3 deletions packages/nodegraph/tests/common/NodeGraphSchemaTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ TEST(NodeGraph, FilterLowpass) {
//LOG(LogInfo) << nodeLowpass.GetOutput(0);
}

TEST_FUZZY(nodeLowpass.GetOutput(0), -0.201134, 0.0001f, "");
TEST_FUZZY(nodeLowpass.GetOutput(0), -0.287209, 0.0001f, "");

return 0;
}
Expand Down Expand Up @@ -173,8 +173,8 @@ TEST(NodeGraph, GraphGroups) {
float output1 = group2.GetOutput(0);
float output2 = group2.GetOutput(1);

TEST_FUZZY(output1, 0.149999559f, 0.00001, "");
TEST_FUZZY(output2, 0.0999997109f, 0.00001, "");
TEST_FUZZY(output1, 0.130579203f, 0.00001, "");
TEST_FUZZY(output2, 0.0870528072f, 0.00001, "");

return 0;
}
Expand Down

0 comments on commit 6ad9b3f

Please sign in to comment.