Added switch PREVENT_CLICK_AT_RATE_CROSSOVER to prevent click artifact at crossing the nominal pitch from either side

This commit is contained in:
oparviai 2009-05-17 11:30:57 +00:00
parent 02483980a5
commit dc4004e0c3
2 changed files with 28 additions and 19 deletions

View File

@ -139,4 +139,11 @@ namespace soundtouch
#endif // INTEGER_SAMPLES #endif // INTEGER_SAMPLES
}; };
// When this #define is active, eliminates a clicking sound when the "rate" or "pitch"
// parameter setting crosses from value <1 to >=1 or vice versa during processing.
// Default is off as such crossover is untypical case and involves a slight sound
// quality compromise.
//#define PREVENT_CLICK_AT_RATE_CROSSOVER 1
#endif #endif

View File

@ -243,23 +243,8 @@ void SoundTouch::calcEffectiveRateAndTempo()
if (!TEST_FLOAT_EQUAL(rate,oldRate)) pRateTransposer->setRate(rate); if (!TEST_FLOAT_EQUAL(rate,oldRate)) pRateTransposer->setRate(rate);
if (!TEST_FLOAT_EQUAL(tempo, oldTempo)) pTDStretch->setTempo(tempo); if (!TEST_FLOAT_EQUAL(tempo, oldTempo)) pTDStretch->setTempo(tempo);
if (rate > 1.0f) #ifndef PREVENT_CLICK_AT_RATE_CROSSOVER
{ if (rate <= 1.0f)
if (output != pRateTransposer)
{
FIFOSamplePipe *transOut;
assert(output == pTDStretch);
// move samples in the current output buffer to the output of pRateTransposer
transOut = pRateTransposer->getOutput();
transOut->moveSamples(*output);
// move samples in tempo changer's input to pitch transposer's input
pRateTransposer->moveSamples(*pTDStretch->getInput());
output = pRateTransposer;
}
}
else
{ {
if (output != pTDStretch) if (output != pTDStretch)
{ {
@ -273,7 +258,23 @@ void SoundTouch::calcEffectiveRateAndTempo()
pTDStretch->moveSamples(*pRateTransposer->getStore()); pTDStretch->moveSamples(*pRateTransposer->getStore());
output = pTDStretch; output = pTDStretch;
}
}
else
#endif
{
if (output != pRateTransposer)
{
FIFOSamplePipe *transOut;
assert(output == pTDStretch);
// move samples in the current output buffer to the output of pRateTransposer
transOut = pRateTransposer->getOutput();
transOut->moveSamples(*output);
// move samples in tempo changer's input to pitch transposer's input
pRateTransposer->moveSamples(*pTDStretch->getInput());
output = pRateTransposer;
} }
} }
} }
@ -316,6 +317,7 @@ void SoundTouch::putSamples(const SAMPLETYPE *samples, uint nSamples)
pTDStretch->putSamples(samples, nSamples); pTDStretch->putSamples(samples, nSamples);
} }
*/ */
#ifndef _PREVENT_CLICK_AT_RATE_CROSSOVER
else if (rate <= 1.0f) else if (rate <= 1.0f)
{ {
// transpose the rate down, output the transposed sound to tempo changer buffer // transpose the rate down, output the transposed sound to tempo changer buffer
@ -324,8 +326,8 @@ void SoundTouch::putSamples(const SAMPLETYPE *samples, uint nSamples)
pTDStretch->moveSamples(*pRateTransposer); pTDStretch->moveSamples(*pRateTransposer);
} }
else else
#endif
{ {
assert(rate > 1.0f);
// evaluate the tempo changer, then transpose the rate up, // evaluate the tempo changer, then transpose the rate up,
assert(output == pRateTransposer); assert(output == pRateTransposer);
pTDStretch->putSamples(samples, nSamples); pTDStretch->putSamples(samples, nSamples);