mirror of
https://github.com/juce-framework/JUCE.git
synced 2026-01-10 23:44:24 +00:00
GenericInterpolator: Fix discontinuity when changing the speedRatio
This commit is contained in:
parent
d15e152da5
commit
7aa3bfdc93
1 changed files with 25 additions and 38 deletions
|
|
@ -293,7 +293,6 @@ private:
|
|||
Process process)
|
||||
{
|
||||
auto originalIn = input;
|
||||
auto pos = subSamplePos;
|
||||
bool exceeded = false;
|
||||
|
||||
const auto pushSample = [&]
|
||||
|
|
@ -321,38 +320,11 @@ private:
|
|||
}
|
||||
};
|
||||
|
||||
if (speedRatio < 1.0)
|
||||
{
|
||||
for (int i = numOutputSamplesToProduce; --i >= 0;)
|
||||
{
|
||||
if (pos >= 1.0)
|
||||
{
|
||||
pushSample();
|
||||
pos -= 1.0;
|
||||
}
|
||||
|
||||
*output = process (*output, InterpolatorTraits::valueAtOffset (lastInputSamples, (float) pos, indexBuffer));
|
||||
++output;
|
||||
pos += speedRatio;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for (int i = numOutputSamplesToProduce; --i >= 0;)
|
||||
{
|
||||
while (pos < speedRatio)
|
||||
{
|
||||
pushSample();
|
||||
pos += 1.0;
|
||||
}
|
||||
|
||||
pos -= speedRatio;
|
||||
*output = process (*output, InterpolatorTraits::valueAtOffset (lastInputSamples, jmax (0.0f, 1.0f - (float) pos), indexBuffer));
|
||||
++output;
|
||||
}
|
||||
}
|
||||
|
||||
subSamplePos = pos;
|
||||
interpolateImpl (speedRatio,
|
||||
output,
|
||||
numOutputSamplesToProduce,
|
||||
process,
|
||||
pushSample);
|
||||
|
||||
if (wrap == 0)
|
||||
return (int) (input - originalIn);
|
||||
|
|
@ -367,25 +339,40 @@ private:
|
|||
int numOutputSamplesToProduce,
|
||||
Process process)
|
||||
{
|
||||
auto pos = subSamplePos;
|
||||
int numUsed = 0;
|
||||
|
||||
while (numOutputSamplesToProduce > 0)
|
||||
interpolateImpl (speedRatio,
|
||||
output,
|
||||
numOutputSamplesToProduce,
|
||||
process,
|
||||
[this, input, &numUsed] { pushInterpolationSample (input[numUsed++]); });
|
||||
|
||||
return numUsed;
|
||||
}
|
||||
|
||||
template <typename Process, typename PushSample>
|
||||
void interpolateImpl (double speedRatio,
|
||||
float* output,
|
||||
int numOutputSamplesToProduce,
|
||||
Process process,
|
||||
PushSample pushSample)
|
||||
{
|
||||
auto pos = subSamplePos;
|
||||
|
||||
for (auto i = 0; i < numOutputSamplesToProduce; ++i)
|
||||
{
|
||||
while (pos >= 1.0)
|
||||
{
|
||||
pushInterpolationSample (input[numUsed++]);
|
||||
pushSample();
|
||||
pos -= 1.0;
|
||||
}
|
||||
|
||||
*output = process (*output, InterpolatorTraits::valueAtOffset (lastInputSamples, (float) pos, indexBuffer));
|
||||
++output;
|
||||
pos += speedRatio;
|
||||
--numOutputSamplesToProduce;
|
||||
}
|
||||
|
||||
subSamplePos = pos;
|
||||
return numUsed;
|
||||
}
|
||||
|
||||
//==============================================================================
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue