Skip to content

Commit

Permalink
update filter.d
Browse files Browse the repository at this point in the history
  • Loading branch information
ZILtoid1991 committed Jun 11, 2024
1 parent 77355cb commit cfcdc34
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions pixelperfectengine/src/pixelperfectengine/audio/base/filter.d
Original file line number Diff line number Diff line change
Expand Up @@ -85,4 +85,45 @@ public struct CtrlValFilter {
filterCoeff[3] = filterCoeff[1];
return filterCoeff;
}
}
/**
* Implements a bak of linear interpolation-like filter algorithm.
* Formula:
* output = target * (1.0 - (cntr / steps)) + output_n1 * (cntr / steps)
* This is optimized for:
* output = target * (1.0 - cntrf) + output_n1 * cntrf
* Where:
* cntrf = cntr / steps
* Or:
* cntrf = cntr * factor
* `factor` is the reciprocal of steps (1 / steps).
*/
struct LinearFilter {
__m128i cntr;
__m128 out_0 = __m128(0.0);
__m128 out_1 = __m128(0.0);
/**
* Sets the next target values for the filter.
* Params:
* nextT = The next target value for the filter.
* nextC = The next counter amount (should be less or equal than 65535)
* factor = The filter factor for this turn.
*/
void setNextTarget(__m128 nextT, __m128i nextC, __m128 factor) pure @nogc nothrow @safe {
out_1 = output(factor);
out_0 = nextT;
cntr =nextC;
}
/**
* Returns the output and subtracts one from the counter.
* Params:
* factor = the filter factor for this turn.
*/
pragma(inline, true)
__m128 output(__m128 factor) pure @nogc nothrow @safe {
__m128 cntrf = _mm_cvtpi32x2_ps(cntr) * factor;
__m128 result = (out_0 * (__m128(1.0) - cntrf)) + (out_1 * cntrf);
cntr = _mm_subs_epu16(cntr, __m128i(1));
return result;
}
}

0 comments on commit cfcdc34

Please sign in to comment.