mirror of
https://github.com/cookiengineer/audacity
synced 2025-10-10 16:43:33 +02:00
Fix for bug 955 from Clayton Otey
This commit is contained in:
@@ -51,6 +51,7 @@ class SBSMSInterface {
|
||||
virtual ~SBSMSInterface() {}
|
||||
virtual long samples(audio *buf, long n) { return 0; }
|
||||
virtual float getStretch(float t)=0;
|
||||
virtual float getMeanStretch(float t0, float t1)=0;
|
||||
virtual float getPitch(float t)=0;
|
||||
virtual long getPresamples()=0;
|
||||
virtual SampleCountType getSamplesToInput()=0;
|
||||
@@ -127,8 +128,10 @@ class Slide {
|
||||
~Slide();
|
||||
float getTotalStretch();
|
||||
float getStretchedTime(float t);
|
||||
float getInverseStretchedTime(float t);
|
||||
float getRate(float t);
|
||||
float getStretch(float t);
|
||||
float getMeanStretch(float t0, float t1);
|
||||
float getRate();
|
||||
float getStretch();
|
||||
void step();
|
||||
@@ -148,6 +151,7 @@ public:
|
||||
SBSMSQuality *quality);
|
||||
virtual ~SBSMSInterfaceSliding();
|
||||
virtual float getStretch(float t);
|
||||
virtual float getMeanStretch(float t0, float t1);
|
||||
virtual float getPitch(float t);
|
||||
virtual long getPresamples();
|
||||
virtual SampleCountType getSamplesToInput();
|
||||
|
@@ -663,7 +663,8 @@ long SBSMSImp :: write(SBSMSInterface *iface)
|
||||
long nWrite = 0;
|
||||
|
||||
float t = getInputTime(iface);
|
||||
float stretch = iface->getStretch(t);
|
||||
float t1 = (float)(nSamplesInputed + quality->getFrameSize()) / (float)iface->getSamplesToInput();
|
||||
float stretch = iface->getMeanStretch(t,t1);
|
||||
float pitch = iface->getPitch(t);
|
||||
|
||||
long nPresamples = iface->getPresamples();
|
||||
|
@@ -11,8 +11,10 @@ public:
|
||||
virtual ~SlideImp() {}
|
||||
virtual float getTotalStretch()=0;
|
||||
virtual float getStretchedTime(float t)=0;
|
||||
virtual float getInverseStretchedTime(float t)=0;
|
||||
virtual float getRate(float t)=0;
|
||||
virtual float getStretch(float t)=0;
|
||||
virtual float getMeanStretch(float t0, float t1)=0;
|
||||
virtual float getRate()=0;
|
||||
virtual float getStretch()=0;
|
||||
virtual void step()=0;
|
||||
@@ -28,12 +30,18 @@ public:
|
||||
float getStretchedTime(float t) {
|
||||
return t;
|
||||
}
|
||||
float getInverseStretchedTime(float t) {
|
||||
return t;
|
||||
}
|
||||
float getRate(float t) {
|
||||
return 1.0f;
|
||||
}
|
||||
float getStretch(float t) {
|
||||
return 1.0f;
|
||||
}
|
||||
float getMeanStretch(float t0, float t1) {
|
||||
return 1.0f;
|
||||
}
|
||||
float getRate() {
|
||||
return 1.0f;
|
||||
}
|
||||
@@ -55,12 +63,18 @@ public:
|
||||
float getStretchedTime(float t) {
|
||||
return t / rate;
|
||||
}
|
||||
float getInverseStretchedTime(float t) {
|
||||
return rate * t;
|
||||
}
|
||||
float getRate(float t) {
|
||||
return rate;
|
||||
}
|
||||
float getStretch(float t) {
|
||||
return 1.0f / rate;
|
||||
}
|
||||
float getMeanStretch(float t0, float t1) {
|
||||
return 1.0f / rate;
|
||||
}
|
||||
float getRate() {
|
||||
return rate;
|
||||
}
|
||||
@@ -90,12 +104,18 @@ public:
|
||||
float ratet = getRate(t);
|
||||
return log(ratet / rate0) / (rate1 - rate0);
|
||||
}
|
||||
float getInverseStretchedTime(float t) {
|
||||
return (exp((rate1-rate0)*t)-1.0f)*rate0/(rate1-rate0);
|
||||
}
|
||||
float getRate(float t) {
|
||||
return rate0 + (rate1 - rate0) * t;
|
||||
}
|
||||
float getStretch(float t) {
|
||||
return 1.0f / getRate(t);
|
||||
}
|
||||
float getMeanStretch(float t0, float t1) {
|
||||
return log(getRate(t1)/getRate(t0))/((rate1-rate0)*(t1-t0));
|
||||
}
|
||||
float getRate() {
|
||||
return (float)val;
|
||||
}
|
||||
@@ -126,12 +146,22 @@ public:
|
||||
float getStretchedTime(float t) {
|
||||
return (sqrt(rate0 * rate0 + (rate1 * rate1 - rate0 * rate0) * t) - rate0) * 2.0f / (rate1 * rate1 - rate0 * rate0);
|
||||
}
|
||||
float getInverseStretchedTime(float t) {
|
||||
float r12 = rate1 * rate1 - rate0 * rate0;
|
||||
float s = 0.5f * r12 * t + rate0;
|
||||
return (s * s - rate0 * rate0) / r12;
|
||||
}
|
||||
float getRate(float t) {
|
||||
return rate0 + (sqrt(rate0 * rate0 + (rate1 * rate1 - rate0 * rate0) * t) - rate0);
|
||||
return sqrt(rate0 * rate0 + (rate1 * rate1 - rate0 * rate0) * t);
|
||||
}
|
||||
float getStretch(float t) {
|
||||
return 1.0f / getRate(t);
|
||||
}
|
||||
float getMeanStretch(float t0, float t1) {
|
||||
float r02 = rate0 * rate0;
|
||||
float r102 = rate1 * rate1 - r02;
|
||||
return 2.0f * (sqrt(r02 + r102*t1) - sqrt(r02 + r102 * t0)) / (r102 * (t1 - t0));
|
||||
}
|
||||
float getRate() {
|
||||
return getRate((float)val);
|
||||
}
|
||||
@@ -162,12 +192,19 @@ public:
|
||||
float getStretchedTime(float t) {
|
||||
return t / rate0 * (1.0f + 0.5f * t * (rate0 / rate1 - 1.0f));
|
||||
}
|
||||
float getInverseStretchedTime(float t) {
|
||||
float s = 1.0f / rate1 - 1.0f / rate0;
|
||||
return (-1.0f / rate0 + sqrt(1/(rate0*rate0)-2.0f*t*s)) / s;
|
||||
}
|
||||
float getRate(float t) {
|
||||
return 1.0f / getStretch(t);
|
||||
}
|
||||
float getStretch(float t) {
|
||||
return (1.0f / rate0 + (1.0f / rate1 - 1.0f / rate0) * t);
|
||||
}
|
||||
float getMeanStretch(float t0, float t1) {
|
||||
return ((t1 + t0) * (rate0 - rate1) - 2.0f * rate1) / (2.0f * rate0 * rate1);
|
||||
}
|
||||
float getRate() {
|
||||
return (float)(1.0 / val);
|
||||
}
|
||||
@@ -200,12 +237,18 @@ public:
|
||||
float getStretchedTime(float t) {
|
||||
return c1 * (pow(c0, t) - 1.0f);
|
||||
}
|
||||
float getInverseStretchedTime(float t) {
|
||||
return log(t/c1 + 1.0f) * c1 * rate0;
|
||||
}
|
||||
float getRate(float t) {
|
||||
return rate0 * pow(c0, -t);
|
||||
}
|
||||
float getStretch(float t) {
|
||||
return pow(c0, t) / rate0;
|
||||
}
|
||||
float getMeanStretch(float t0, float t1) {
|
||||
return (pow(c0,t1) - pow(c0,t0)) / (c1 * (t1 - t0));
|
||||
}
|
||||
float getRate() {
|
||||
return getRate((float)val);
|
||||
}
|
||||
@@ -226,16 +269,21 @@ public:
|
||||
GeometricInputSlide(float rate0, float rate1, const SampleCountType &n) {
|
||||
this->rate0 = rate0;
|
||||
this->rate1 = rate1;
|
||||
this->c0 = rate0 / rate1;
|
||||
this->log01 = log(c0);
|
||||
if(n) {
|
||||
val = rate0;
|
||||
inc = pow((double)rate1 / rate0, 1.0 / (double)n);
|
||||
}
|
||||
}
|
||||
float getTotalStretch() {
|
||||
return (rate1 - rate0) / (log(rate1 / rate0) * (rate0 * rate1));
|
||||
return (rate0 - rate1) / (log01 * (rate0 * rate1));
|
||||
}
|
||||
float getStretchedTime(float t) {
|
||||
return (float)(pow(rate0 / rate1, t) - 1.0) / (rate0 * log(rate0 / rate1));
|
||||
return (float)(pow(rate0 / rate1, t) - 1.0) / (rate0 * log01);
|
||||
}
|
||||
float getInverseStretchedTime(float t) {
|
||||
return log(t * rate0 * log01 + 1.0f) / log01;
|
||||
}
|
||||
float getRate(float t) {
|
||||
return rate0 * pow(rate1 / rate0, t);
|
||||
@@ -243,6 +291,9 @@ public:
|
||||
float getStretch(float t) {
|
||||
return 1.0f / getRate(t);
|
||||
}
|
||||
float getMeanStretch(float t0, float t1) {
|
||||
return (pow(c0,t1) - pow(c0,t0)) / (rate0 * log01 * (t1 - t0));
|
||||
}
|
||||
float getRate() {
|
||||
return (float)val;
|
||||
}
|
||||
@@ -253,7 +304,7 @@ public:
|
||||
val *= inc;
|
||||
}
|
||||
protected:
|
||||
float rate0, rate1;
|
||||
float rate0, rate1, c0, log01;
|
||||
double val, inc;
|
||||
};
|
||||
|
||||
@@ -276,6 +327,9 @@ public:
|
||||
float getStretchedTime(float t) {
|
||||
return log(r10 / rate0 * t + 1.0f) / r10;
|
||||
}
|
||||
float getInverseStretchedTime(float t) {
|
||||
return rate0 / r10 * (exp(t * r10) - 1.0f);
|
||||
}
|
||||
float getRate(float t) {
|
||||
float t1 = getStretchedTime(t) / totalStretch;
|
||||
return rate0 * pow(rate1 / rate0, t1);
|
||||
@@ -283,6 +337,9 @@ public:
|
||||
float getStretch(float t) {
|
||||
return 1.0f / getRate(t);
|
||||
}
|
||||
float getMeanStretch(float t0, float t1) {
|
||||
return log((rate0 + r10 * t1)/(rate0 + r10 * t0)) /(r10 * (t1 - t0));
|
||||
}
|
||||
float getRate() {
|
||||
return getRate((float)val);
|
||||
}
|
||||
@@ -347,6 +404,16 @@ float Slide :: getStretchedTime(float t)
|
||||
if(t > 1.0f) t = 1.0f;
|
||||
return imp->getStretchedTime(t);
|
||||
}
|
||||
|
||||
float Slide :: getMeanStretch(float t0, float t1) {
|
||||
if(t0 < 0.0f) t0 = 0.0f;
|
||||
return imp->getMeanStretch(t0,t1);
|
||||
}
|
||||
|
||||
float Slide :: getInverseStretchedTime(float t)
|
||||
{
|
||||
return imp->getInverseStretchedTime(t);
|
||||
}
|
||||
|
||||
float Slide :: getRate()
|
||||
{
|
||||
@@ -374,6 +441,7 @@ public:
|
||||
SBSMSQuality *quality);
|
||||
~SBSMSInterfaceSlidingImp() {}
|
||||
inline float getStretch(float t);
|
||||
inline float getMeanStretch(float t0, float t1);
|
||||
inline float getPitch(float t);
|
||||
inline long getPresamples();
|
||||
SampleCountType getSamplesToInput();
|
||||
@@ -388,8 +456,7 @@ protected:
|
||||
SampleCountType samplesToInput;
|
||||
SampleCountType samplesToOutput;
|
||||
};
|
||||
|
||||
|
||||
|
||||
SBSMSInterfaceSlidingImp :: SBSMSInterfaceSlidingImp(Slide *stretchSlide,
|
||||
Slide *pitchSlide,
|
||||
bool bPitchReferenceInput,
|
||||
@@ -414,7 +481,8 @@ SBSMSInterfaceSlidingImp :: SBSMSInterfaceSlidingImp(Slide *stretchSlide,
|
||||
int inFrameSize = quality->getFrameSize();
|
||||
while(samplesIn < samplesToInput) {
|
||||
float t = (float)samplesIn / (float)samplesToInput;
|
||||
stretch = stretchSlide->getStretch(t);
|
||||
float t1 =(float)(samplesIn + inFrameSize) / (float)samplesToInput;
|
||||
stretch = stretchSlide->getMeanStretch(t,t1);
|
||||
outFrameSizefloat += stretch * inFrameSize;
|
||||
int outFrameSize = (int) outFrameSizefloat;
|
||||
outFrameSizefloat -= (float) outFrameSize;
|
||||
@@ -432,6 +500,12 @@ float SBSMSInterfaceSlidingImp :: getStretch(float t)
|
||||
return stretchScale * stretchSlide->getStretch(t);
|
||||
}
|
||||
|
||||
float SBSMSInterfaceSliding :: getMeanStretch(float t0, float t1) { return imp->getMeanStretch(t0, t1); }
|
||||
float SBSMSInterfaceSlidingImp :: getMeanStretch(float t0, float t1)
|
||||
{
|
||||
return stretchSlide->getMeanStretch(t0, t1);
|
||||
}
|
||||
|
||||
float SBSMSInterfaceSliding :: getPitch(float t) { return imp->getPitch(t); }
|
||||
float SBSMSInterfaceSlidingImp :: getPitch(float t)
|
||||
{
|
||||
|
Reference in New Issue
Block a user