mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-07-24 14:49:42 -06:00
Updated SoundTouch library to 1.9.2
This commit is contained in:
120
Externals/soundtouch/SoundTouch.cpp
vendored
120
Externals/soundtouch/SoundTouch.cpp
vendored
@ -41,10 +41,10 @@
|
||||
///
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Last changed : $Date: 2014-04-07 01:57:21 +1000 (Mon, 07 Apr 2014) $
|
||||
// Last changed : $Date: 2015-07-26 17:45:48 +0300 (Sun, 26 Jul 2015) $
|
||||
// File revision : $Revision: 4 $
|
||||
//
|
||||
// $Id: SoundTouch.cpp 195 2014-04-06 15:57:21Z oparviai $
|
||||
// $Id: SoundTouch.cpp 225 2015-07-26 14:45:48Z oparviai $
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
@ -110,6 +110,9 @@ SoundTouch::SoundTouch()
|
||||
|
||||
calcEffectiveRateAndTempo();
|
||||
|
||||
samplesExpectedOut = 0;
|
||||
samplesOutput = 0;
|
||||
|
||||
channels = 0;
|
||||
bSrateSet = false;
|
||||
}
|
||||
@ -157,7 +160,7 @@ void SoundTouch::setChannels(uint numChannels)
|
||||
|
||||
// Sets new rate control value. Normal rate = 1.0, smaller values
|
||||
// represent slower rate, larger faster rates.
|
||||
void SoundTouch::setRate(float newRate)
|
||||
void SoundTouch::setRate(double newRate)
|
||||
{
|
||||
virtualRate = newRate;
|
||||
calcEffectiveRateAndTempo();
|
||||
@ -167,9 +170,9 @@ void SoundTouch::setRate(float newRate)
|
||||
|
||||
// Sets new rate control value as a difference in percents compared
|
||||
// to the original rate (-50 .. +100 %)
|
||||
void SoundTouch::setRateChange(float newRate)
|
||||
void SoundTouch::setRateChange(double newRate)
|
||||
{
|
||||
virtualRate = 1.0f + 0.01f * newRate;
|
||||
virtualRate = 1.0 + 0.01 * newRate;
|
||||
calcEffectiveRateAndTempo();
|
||||
}
|
||||
|
||||
@ -177,7 +180,7 @@ void SoundTouch::setRateChange(float newRate)
|
||||
|
||||
// Sets new tempo control value. Normal tempo = 1.0, smaller values
|
||||
// represent slower tempo, larger faster tempo.
|
||||
void SoundTouch::setTempo(float newTempo)
|
||||
void SoundTouch::setTempo(double newTempo)
|
||||
{
|
||||
virtualTempo = newTempo;
|
||||
calcEffectiveRateAndTempo();
|
||||
@ -187,9 +190,9 @@ void SoundTouch::setTempo(float newTempo)
|
||||
|
||||
// Sets new tempo control value as a difference in percents compared
|
||||
// to the original tempo (-50 .. +100 %)
|
||||
void SoundTouch::setTempoChange(float newTempo)
|
||||
void SoundTouch::setTempoChange(double newTempo)
|
||||
{
|
||||
virtualTempo = 1.0f + 0.01f * newTempo;
|
||||
virtualTempo = 1.0 + 0.01 * newTempo;
|
||||
calcEffectiveRateAndTempo();
|
||||
}
|
||||
|
||||
@ -197,7 +200,7 @@ void SoundTouch::setTempoChange(float newTempo)
|
||||
|
||||
// Sets new pitch control value. Original pitch = 1.0, smaller values
|
||||
// represent lower pitches, larger values higher pitch.
|
||||
void SoundTouch::setPitch(float newPitch)
|
||||
void SoundTouch::setPitch(double newPitch)
|
||||
{
|
||||
virtualPitch = newPitch;
|
||||
calcEffectiveRateAndTempo();
|
||||
@ -207,9 +210,9 @@ void SoundTouch::setPitch(float newPitch)
|
||||
|
||||
// Sets pitch change in octaves compared to the original pitch
|
||||
// (-1.00 .. +1.00)
|
||||
void SoundTouch::setPitchOctaves(float newPitch)
|
||||
void SoundTouch::setPitchOctaves(double newPitch)
|
||||
{
|
||||
virtualPitch = (float)exp(0.69314718056f * newPitch);
|
||||
virtualPitch = exp(0.69314718056 * newPitch);
|
||||
calcEffectiveRateAndTempo();
|
||||
}
|
||||
|
||||
@ -219,14 +222,14 @@ void SoundTouch::setPitchOctaves(float newPitch)
|
||||
// (-12 .. +12)
|
||||
void SoundTouch::setPitchSemiTones(int newPitch)
|
||||
{
|
||||
setPitchOctaves((float)newPitch / 12.0f);
|
||||
setPitchOctaves((double)newPitch / 12.0);
|
||||
}
|
||||
|
||||
|
||||
|
||||
void SoundTouch::setPitchSemiTones(float newPitch)
|
||||
void SoundTouch::setPitchSemiTones(double newPitch)
|
||||
{
|
||||
setPitchOctaves(newPitch / 12.0f);
|
||||
setPitchOctaves(newPitch / 12.0);
|
||||
}
|
||||
|
||||
|
||||
@ -234,14 +237,14 @@ void SoundTouch::setPitchSemiTones(float newPitch)
|
||||
// nominal control values.
|
||||
void SoundTouch::calcEffectiveRateAndTempo()
|
||||
{
|
||||
float oldTempo = tempo;
|
||||
float oldRate = rate;
|
||||
double oldTempo = tempo;
|
||||
double oldRate = rate;
|
||||
|
||||
tempo = virtualTempo / virtualPitch;
|
||||
rate = virtualPitch * virtualRate;
|
||||
tempo = virtualTempo / virtualPitch;
|
||||
rate = virtualPitch * virtualRate;
|
||||
|
||||
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
|
||||
if (rate <= 1.0f)
|
||||
@ -317,8 +320,13 @@ void SoundTouch::putSamples(const SAMPLETYPE *samples, uint nSamples)
|
||||
pTDStretch->putSamples(samples, nSamples);
|
||||
}
|
||||
*/
|
||||
|
||||
// accumulate how many samples are expected out from processing, given the current
|
||||
// processing setting
|
||||
samplesExpectedOut += (double)nSamples / ((double)rate * (double)tempo);
|
||||
|
||||
#ifndef SOUNDTOUCH_PREVENT_CLICK_AT_RATE_CROSSOVER
|
||||
else if (rate <= 1.0f)
|
||||
if (rate <= 1.0f)
|
||||
{
|
||||
// transpose the rate down, output the transposed sound to tempo changer buffer
|
||||
assert(output == pTDStretch);
|
||||
@ -346,42 +354,30 @@ void SoundTouch::putSamples(const SAMPLETYPE *samples, uint nSamples)
|
||||
void SoundTouch::flush()
|
||||
{
|
||||
int i;
|
||||
int nUnprocessed;
|
||||
int nOut;
|
||||
SAMPLETYPE *buff=(SAMPLETYPE*)malloc(64*channels*sizeof(SAMPLETYPE));
|
||||
int numStillExpected;
|
||||
SAMPLETYPE *buff = new SAMPLETYPE[128 * channels];
|
||||
|
||||
// check how many samples still await processing, and scale
|
||||
// that by tempo & rate to get expected output sample count
|
||||
nUnprocessed = numUnprocessedSamples();
|
||||
nUnprocessed = (int)((double)nUnprocessed / (tempo * rate) + 0.5);
|
||||
// how many samples are still expected to output
|
||||
numStillExpected = (int)((long)(samplesExpectedOut + 0.5) - samplesOutput);
|
||||
|
||||
nOut = numSamples(); // ready samples currently in buffer ...
|
||||
nOut += nUnprocessed; // ... and how many we expect there to be in the end
|
||||
|
||||
memset(buff, 0, 64 * channels * sizeof(SAMPLETYPE));
|
||||
memset(buff, 0, 128 * channels * sizeof(SAMPLETYPE));
|
||||
// "Push" the last active samples out from the processing pipeline by
|
||||
// feeding blank samples into the processing pipeline until new,
|
||||
// processed samples appear in the output (not however, more than
|
||||
// 8ksamples in any case)
|
||||
for (i = 0; i < 128; i ++)
|
||||
{
|
||||
putSamples(buff, 64);
|
||||
if ((int)numSamples() >= nOut)
|
||||
{
|
||||
// Enough new samples have appeared into the output!
|
||||
// As samples come from processing with bigger chunks, now truncate it
|
||||
// back to maximum "nOut" samples to improve duration accuracy
|
||||
adjustAmountOfSamples(nOut);
|
||||
// 24ksamples in any case)
|
||||
for (i = 0; (numStillExpected > (int)numSamples()) && (i < 200); i ++)
|
||||
{
|
||||
putSamples(buff, 128);
|
||||
}
|
||||
|
||||
// finish
|
||||
break;
|
||||
}
|
||||
}
|
||||
adjustAmountOfSamples(numStillExpected);
|
||||
|
||||
// Clear working buffers
|
||||
pRateTransposer->clear();
|
||||
delete[] buff;
|
||||
|
||||
// Clear input buffers
|
||||
// pRateTransposer->clearInput();
|
||||
pTDStretch->clearInput();
|
||||
// yet leave the 'tempoChanger' output intouched as that's where the
|
||||
// yet leave the output intouched as that's where the
|
||||
// flushed samples are!
|
||||
}
|
||||
|
||||
@ -480,6 +476,7 @@ int SoundTouch::getSetting(int settingId) const
|
||||
// buffers.
|
||||
void SoundTouch::clear()
|
||||
{
|
||||
samplesExpectedOut = 0;
|
||||
pRateTransposer->clear();
|
||||
pTDStretch->clear();
|
||||
}
|
||||
@ -500,3 +497,30 @@ uint SoundTouch::numUnprocessedSamples() const
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// Output samples from beginning of the sample buffer. Copies requested samples to
|
||||
/// output buffer and removes them from the sample buffer. If there are less than
|
||||
/// 'numsample' samples in the buffer, returns all that available.
|
||||
///
|
||||
/// \return Number of samples returned.
|
||||
uint SoundTouch::receiveSamples(SAMPLETYPE *output, uint maxSamples)
|
||||
{
|
||||
uint ret = FIFOProcessor::receiveSamples(output, maxSamples);
|
||||
samplesOutput += (long)ret;
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
/// Adjusts book-keeping so that given number of samples are removed from beginning of the
|
||||
/// sample buffer without copying them anywhere.
|
||||
///
|
||||
/// Used to reduce the number of samples in the buffer when accessing the sample buffer directly
|
||||
/// with 'ptrBegin' function.
|
||||
uint SoundTouch::receiveSamples(uint maxSamples)
|
||||
{
|
||||
uint ret = FIFOProcessor::receiveSamples(maxSamples);
|
||||
samplesOutput += (long)ret;
|
||||
return ret;
|
||||
}
|
||||
|
Reference in New Issue
Block a user