mirror of
https://github.com/azahar-emu/soundtouch
synced 2025-11-07 07:30:02 +01:00
bugfix: flush() didn't properly flush final samples from the pipeline on 2nd time, in case that soundtouch object instance were recycled and used for processing a 2nd audio stream.
This commit is contained in:
parent
9287800b65
commit
882f248a0c
@ -110,8 +110,8 @@ SoundTouch::SoundTouch()
|
|||||||
|
|
||||||
calcEffectiveRateAndTempo();
|
calcEffectiveRateAndTempo();
|
||||||
|
|
||||||
samplesExpectedOut = 0;
|
samplesExpectedOut = 0;
|
||||||
samplesOutput = 0;
|
samplesOutput = 0;
|
||||||
|
|
||||||
channels = 0;
|
channels = 0;
|
||||||
bSrateSet = false;
|
bSrateSet = false;
|
||||||
@ -149,7 +149,7 @@ void SoundTouch::setChannels(uint numChannels)
|
|||||||
/*if (numChannels != 1 && numChannels != 2)
|
/*if (numChannels != 1 && numChannels != 2)
|
||||||
{
|
{
|
||||||
//ST_THROW_RT_ERROR("Illegal number of channels");
|
//ST_THROW_RT_ERROR("Illegal number of channels");
|
||||||
return;
|
return;
|
||||||
}*/
|
}*/
|
||||||
channels = numChannels;
|
channels = numChannels;
|
||||||
pRateTransposer->setChannels((int)numChannels);
|
pRateTransposer->setChannels((int)numChannels);
|
||||||
@ -240,11 +240,11 @@ void SoundTouch::calcEffectiveRateAndTempo()
|
|||||||
double oldTempo = tempo;
|
double oldTempo = tempo;
|
||||||
double oldRate = rate;
|
double oldRate = rate;
|
||||||
|
|
||||||
tempo = virtualTempo / virtualPitch;
|
tempo = virtualTempo / virtualPitch;
|
||||||
rate = virtualPitch * virtualRate;
|
rate = virtualPitch * virtualRate;
|
||||||
|
|
||||||
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);
|
||||||
|
|
||||||
#ifndef SOUNDTOUCH_PREVENT_CLICK_AT_RATE_CROSSOVER
|
#ifndef SOUNDTOUCH_PREVENT_CLICK_AT_RATE_CROSSOVER
|
||||||
if (rate <= 1.0f)
|
if (rate <= 1.0f)
|
||||||
@ -321,9 +321,9 @@ void SoundTouch::putSamples(const SAMPLETYPE *samples, uint nSamples)
|
|||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// accumulate how many samples are expected out from processing, given the current
|
// accumulate how many samples are expected out from processing, given the current
|
||||||
// processing setting
|
// processing setting
|
||||||
samplesExpectedOut += (double)nSamples / ((double)rate * (double)tempo);
|
samplesExpectedOut += (double)nSamples / ((double)rate * (double)tempo);
|
||||||
|
|
||||||
#ifndef SOUNDTOUCH_PREVENT_CLICK_AT_RATE_CROSSOVER
|
#ifndef SOUNDTOUCH_PREVENT_CLICK_AT_RATE_CROSSOVER
|
||||||
if (rate <= 1.0f)
|
if (rate <= 1.0f)
|
||||||
@ -354,23 +354,24 @@ void SoundTouch::putSamples(const SAMPLETYPE *samples, uint nSamples)
|
|||||||
void SoundTouch::flush()
|
void SoundTouch::flush()
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
int numStillExpected;
|
int numStillExpected;
|
||||||
SAMPLETYPE *buff = new SAMPLETYPE[128 * channels];
|
SAMPLETYPE *buff = new SAMPLETYPE[128 * channels];
|
||||||
|
|
||||||
// how many samples are still expected to output
|
// how many samples are still expected to output
|
||||||
numStillExpected = (int)((long)(samplesExpectedOut + 0.5) - samplesOutput);
|
numStillExpected = (int)((long)(samplesExpectedOut + 0.5) - samplesOutput);
|
||||||
|
if (numStillExpected < 0) numStillExpected = 0;
|
||||||
|
|
||||||
memset(buff, 0, 128 * channels * sizeof(SAMPLETYPE));
|
memset(buff, 0, 128 * channels * sizeof(SAMPLETYPE));
|
||||||
// "Push" the last active samples out from the processing pipeline by
|
// "Push" the last active samples out from the processing pipeline by
|
||||||
// feeding blank samples into the processing pipeline until new,
|
// feeding blank samples into the processing pipeline until new,
|
||||||
// processed samples appear in the output (not however, more than
|
// processed samples appear in the output (not however, more than
|
||||||
// 24ksamples in any case)
|
// 24ksamples in any case)
|
||||||
for (i = 0; (numStillExpected > (int)numSamples()) && (i < 200); i ++)
|
for (i = 0; (numStillExpected > (int)numSamples()) && (i < 200); i ++)
|
||||||
{
|
{
|
||||||
putSamples(buff, 128);
|
putSamples(buff, 128);
|
||||||
}
|
}
|
||||||
|
|
||||||
adjustAmountOfSamples(numStillExpected);
|
adjustAmountOfSamples(numStillExpected);
|
||||||
|
|
||||||
delete[] buff;
|
delete[] buff;
|
||||||
|
|
||||||
@ -460,13 +461,13 @@ int SoundTouch::getSetting(int settingId) const
|
|||||||
pTDStretch->getParameters(NULL, NULL, NULL, &temp);
|
pTDStretch->getParameters(NULL, NULL, NULL, &temp);
|
||||||
return temp;
|
return temp;
|
||||||
|
|
||||||
case SETTING_NOMINAL_INPUT_SEQUENCE :
|
case SETTING_NOMINAL_INPUT_SEQUENCE :
|
||||||
return pTDStretch->getInputSampleReq();
|
return pTDStretch->getInputSampleReq();
|
||||||
|
|
||||||
case SETTING_NOMINAL_OUTPUT_SEQUENCE :
|
case SETTING_NOMINAL_OUTPUT_SEQUENCE :
|
||||||
return pTDStretch->getOutputBatchSize();
|
return pTDStretch->getOutputBatchSize();
|
||||||
|
|
||||||
default :
|
default :
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -476,7 +477,8 @@ int SoundTouch::getSetting(int settingId) const
|
|||||||
// buffers.
|
// buffers.
|
||||||
void SoundTouch::clear()
|
void SoundTouch::clear()
|
||||||
{
|
{
|
||||||
samplesExpectedOut = 0;
|
samplesExpectedOut = 0;
|
||||||
|
samplesOutput = 0;
|
||||||
pRateTransposer->clear();
|
pRateTransposer->clear();
|
||||||
pTDStretch->clear();
|
pTDStretch->clear();
|
||||||
}
|
}
|
||||||
@ -507,9 +509,9 @@ uint SoundTouch::numUnprocessedSamples() const
|
|||||||
/// \return Number of samples returned.
|
/// \return Number of samples returned.
|
||||||
uint SoundTouch::receiveSamples(SAMPLETYPE *output, uint maxSamples)
|
uint SoundTouch::receiveSamples(SAMPLETYPE *output, uint maxSamples)
|
||||||
{
|
{
|
||||||
uint ret = FIFOProcessor::receiveSamples(output, maxSamples);
|
uint ret = FIFOProcessor::receiveSamples(output, maxSamples);
|
||||||
samplesOutput += (long)ret;
|
samplesOutput += (long)ret;
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -520,7 +522,7 @@ uint SoundTouch::receiveSamples(SAMPLETYPE *output, uint maxSamples)
|
|||||||
/// with 'ptrBegin' function.
|
/// with 'ptrBegin' function.
|
||||||
uint SoundTouch::receiveSamples(uint maxSamples)
|
uint SoundTouch::receiveSamples(uint maxSamples)
|
||||||
{
|
{
|
||||||
uint ret = FIFOProcessor::receiveSamples(maxSamples);
|
uint ret = FIFOProcessor::receiveSamples(maxSamples);
|
||||||
samplesOutput += (long)ret;
|
samplesOutput += (long)ret;
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user