Readability cleanup
This commit is contained in:
parent
db2f64d3cc
commit
ba4c64adea
2 changed files with 51 additions and 39 deletions
|
|
@ -131,6 +131,25 @@ constexpr T clamp( const T& v, const T& lo, const T& hi )
|
||||||
return (v < lo) ? lo : (hi < v) ? hi : v;
|
return (v < lo) ? lo : (hi < v) ? hi : v;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template<class T>
|
||||||
|
constexpr void incrementAll(T& only)
|
||||||
|
{
|
||||||
|
only++;
|
||||||
|
}
|
||||||
|
|
||||||
|
template<class T, class... Args>
|
||||||
|
constexpr void incrementAll(T& first, Args&... rest)
|
||||||
|
{
|
||||||
|
first++;
|
||||||
|
incrementAll(rest...);
|
||||||
|
}
|
||||||
|
|
||||||
|
template<class ValueType>
|
||||||
|
constexpr ValueType linearInterpolation(ValueType left, ValueType right, ValueType leftCoeff, ValueType rightCoeff)
|
||||||
|
{
|
||||||
|
return left * leftCoeff + right * rightCoeff;
|
||||||
|
}
|
||||||
|
|
||||||
template <class Type>
|
template <class Type>
|
||||||
constexpr Type pi { 3.141592653589793238462643383279502884 };
|
constexpr Type pi { 3.141592653589793238462643383279502884 };
|
||||||
template <class Type>
|
template <class Type>
|
||||||
|
|
|
||||||
|
|
@ -420,23 +420,16 @@ void sfz::Voice::fillWithData(AudioSpan<float> buffer) noexcept
|
||||||
auto leftSource = source.getChannel(0);
|
auto leftSource = source.getChannel(0);
|
||||||
if (source.getNumChannels() == 1) {
|
if (source.getNumChannels() == 1) {
|
||||||
while (ind < indices.end()) {
|
while (ind < indices.end()) {
|
||||||
*left = leftSource[*ind] * (*leftCoeff) + leftSource[*ind + 1] * (*rightCoeff);
|
*left = linearInterpolation(leftSource[*ind], leftSource[*ind + 1], *leftCoeff, *rightCoeff);
|
||||||
left++;
|
incrementAll(ind, left, leftCoeff, rightCoeff);
|
||||||
ind++;
|
|
||||||
leftCoeff++;
|
|
||||||
rightCoeff++;
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
auto right = buffer.getChannel(1);
|
auto right = buffer.getChannel(1);
|
||||||
auto rightSource = source.getChannel(1);
|
auto rightSource = source.getChannel(1);
|
||||||
while (ind < indices.end()) {
|
while (ind < indices.end()) {
|
||||||
*left = leftSource[*ind] * (*leftCoeff) + leftSource[*ind + 1] * (*rightCoeff);
|
*left = linearInterpolation(leftSource[*ind], leftSource[*ind + 1], *leftCoeff, *rightCoeff);
|
||||||
*right = rightSource[*ind] * (*leftCoeff) + rightSource[*ind + 1] * (*rightCoeff);
|
*right = linearInterpolation(rightSource[*ind], rightSource[*ind + 1], *leftCoeff, *rightCoeff);
|
||||||
left++;
|
incrementAll(ind, left, right, leftCoeff, rightCoeff);
|
||||||
right++;
|
|
||||||
ind++;
|
|
||||||
leftCoeff++;
|
|
||||||
rightCoeff++;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue