forked from kcat/openal-soft
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use an interpolated FIR filter for cubic resampling
Similar to how the bsinc filters work, but optimized for 4-point filtering. At least the SSE version is notably faster than calculating the coefficients in real time.
- Loading branch information
Showing
9 changed files
with
227 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
#ifndef CORE_CUBIC_DEFS_H | ||
#define CORE_CUBIC_DEFS_H | ||
|
||
/* The number of distinct phase intervals within the cubic filter tables. */ | ||
constexpr unsigned int CubicPhaseBits{5}; | ||
constexpr unsigned int CubicPhaseCount{1 << CubicPhaseBits}; | ||
|
||
struct CubicCoefficients { | ||
float mCoeffs[4]; | ||
float mDeltas[4]; | ||
}; | ||
|
||
#endif /* CORE_CUBIC_DEFS_H */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
|
||
#include "cubic_tables.h" | ||
|
||
#include <algorithm> | ||
#include <array> | ||
#include <cassert> | ||
#include <cmath> | ||
#include <limits> | ||
#include <memory> | ||
#include <stdexcept> | ||
|
||
#include "alnumbers.h" | ||
#include "core/mixer/defs.h" | ||
|
||
|
||
namespace { | ||
|
||
using uint = unsigned int; | ||
|
||
struct SplineFilterArray { | ||
alignas(16) CubicCoefficients mTable[CubicPhaseCount]{}; | ||
|
||
constexpr SplineFilterArray() | ||
{ | ||
/* Fill in the main coefficients. */ | ||
for(size_t pi{0};pi < CubicPhaseCount;++pi) | ||
{ | ||
const double mu{pi / double{CubicPhaseCount}}; | ||
const double mu2{mu*mu}, mu3{mu2*mu}; | ||
mTable[pi].mCoeffs[0] = static_cast<float>(-0.5*mu3 + mu2 + -0.5*mu); | ||
mTable[pi].mCoeffs[1] = static_cast<float>( 1.5*mu3 + -2.5*mu2 + 1.0); | ||
mTable[pi].mCoeffs[2] = static_cast<float>(-1.5*mu3 + 2.0*mu2 + 0.5*mu); | ||
mTable[pi].mCoeffs[3] = static_cast<float>( 0.5*mu3 + -0.5*mu2); | ||
} | ||
|
||
/* Fill in the coefficient deltas. */ | ||
for(size_t pi{0};pi < CubicPhaseCount-1;++pi) | ||
{ | ||
mTable[pi].mDeltas[0] = mTable[pi+1].mCoeffs[0] - mTable[pi].mCoeffs[0]; | ||
mTable[pi].mDeltas[1] = mTable[pi+1].mCoeffs[1] - mTable[pi].mCoeffs[1]; | ||
mTable[pi].mDeltas[2] = mTable[pi+1].mCoeffs[2] - mTable[pi].mCoeffs[2]; | ||
mTable[pi].mDeltas[3] = mTable[pi+1].mCoeffs[3] - mTable[pi].mCoeffs[3]; | ||
} | ||
|
||
const size_t pi{CubicPhaseCount - 1}; | ||
mTable[pi].mDeltas[0] = -mTable[pi].mCoeffs[0]; | ||
mTable[pi].mDeltas[1] = -mTable[pi].mCoeffs[1]; | ||
mTable[pi].mDeltas[2] = 1.0f - mTable[pi].mCoeffs[2]; | ||
mTable[pi].mDeltas[3] = -mTable[pi].mCoeffs[3]; | ||
} | ||
|
||
constexpr const CubicCoefficients *getTable() const noexcept { return mTable; } | ||
}; | ||
|
||
constexpr SplineFilterArray SplineFilter{}; | ||
|
||
} // namespace | ||
|
||
const CubicTable gCubicSpline{SplineFilter.getTable()}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
#ifndef CORE_CUBIC_TABLES_H | ||
#define CORE_CUBIC_TABLES_H | ||
|
||
#include "cubic_defs.h" | ||
|
||
|
||
struct CubicTable { | ||
const CubicCoefficients *Tab; | ||
}; | ||
|
||
/* A Catmull-Rom spline. The spline passes through the center two samples, | ||
* ensuring no discontinuity while moving through a series of samples. | ||
*/ | ||
extern const CubicTable gCubicSpline; | ||
|
||
#endif /* CORE_CUBIC_TABLES_H */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.