diff --git a/packages/math/include/math/MathTween.h b/packages/math/include/math/MathTween.h index 1f6fca37..381e5da8 100644 --- a/packages/math/include/math/MathTween.h +++ b/packages/math/include/math/MathTween.h @@ -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; diff --git a/packages/math/source/common/MathTween.cpp b/packages/math/source/common/MathTween.cpp index d13c658c..626e341b 100644 --- a/packages/math/source/common/MathTween.cpp +++ b/packages/math/source/common/MathTween.cpp @@ -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(mUpdateRate), mDynamicSmoothAccuracy); - } + mDynamicSmooth = GetRWAFactor(static_cast(updateRate), mDynamicSmoothAccuracy); mTarget = mTargetValue; if (mCounter < mUpdateCount) { - float t = (mCounter + 0.5f * mUpdateRate) / static_cast(mUpdateCount - 0.5f * mUpdateRate); + float t = (mCounter + 0.5f) / static_cast(mUpdateCount - 0.5f); t = l::math::functions::clamp(t, 0.0f, 1.0f); mTarget = mTargetValuePrev + l::math::smooth::smoothPolyh3(t) * (mTargetValue - mTargetValuePrev); } @@ -95,4 +92,5 @@ namespace l::math::tween { float DynamicTween::Value() { return mValue; } + } diff --git a/packages/math/tests/common/MathTweenTest.cpp b/packages/math/tests/common/MathTweenTest.cpp index d42ec505..2286281b 100644 --- a/packages/math/tests/common/MathTweenTest.cpp +++ b/packages/math/tests/common/MathTweenTest.cpp @@ -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, ""); @@ -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, ""); @@ -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); @@ -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; } diff --git a/packages/nodegraph/include/nodegraph/operations/NodeGraphOpFilter.h b/packages/nodegraph/include/nodegraph/operations/NodeGraphOpFilter.h index db6c5db1..82bff617 100644 --- a/packages/nodegraph/include/nodegraph/operations/NodeGraphOpFilter.h +++ b/packages/nodegraph/include/nodegraph/operations/NodeGraphOpFilter.h @@ -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; diff --git a/packages/nodegraph/source/common/operations/NodeGraphOpFilter.cpp b/packages/nodegraph/source/common/operations/NodeGraphOpFilter.cpp index a900be4f..e2d00d73 100644 --- a/packages/nodegraph/source/common/operations/NodeGraphOpFilter.cpp +++ b/packages/nodegraph/source/common/operations/NodeGraphOpFilter.cpp @@ -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); diff --git a/packages/nodegraph/tests/common/NodeGraphBatchingTest.cpp b/packages/nodegraph/tests/common/NodeGraphBatchingTest.cpp index b676245d..f29c9e97 100644 --- a/packages/nodegraph/tests/common/NodeGraphBatchingTest.cpp +++ b/packages/nodegraph/tests/common/NodeGraphBatchingTest.cpp @@ -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; } diff --git a/packages/nodegraph/tests/common/NodeGraphSchemaTest.cpp b/packages/nodegraph/tests/common/NodeGraphSchemaTest.cpp index 0ce45b9d..d1829b4d 100644 --- a/packages/nodegraph/tests/common/NodeGraphSchemaTest.cpp +++ b/packages/nodegraph/tests/common/NodeGraphSchemaTest.cpp @@ -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; } @@ -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; }