1
0
mirror of https://github.com/cookiengineer/audacity synced 2025-10-15 15:11:12 +02:00

Rewrite WaveTrack::GetEnvelopeValues, taking one less argument...

... In practice this argument was always 1 / rate so it was superfluous.

Also make the buffer size argument unsigned.
This commit is contained in:
Paul Licameli
2016-08-20 17:56:41 -04:00
parent 0c4c835b27
commit 5cf331ae8c
3 changed files with 21 additions and 23 deletions

View File

@@ -460,8 +460,7 @@ sampleCount Mixer::MixVariableRates(int *channelFlags, WaveTrackCache &cache,
track->GetEnvelopeValues(mEnvValues,
getLen,
(*pos - (getLen- 1)) / trackRate,
tstep);
(*pos - (getLen- 1)) / trackRate);
*pos -= getLen;
}
@@ -471,8 +470,7 @@ sampleCount Mixer::MixVariableRates(int *channelFlags, WaveTrackCache &cache,
track->GetEnvelopeValues(mEnvValues,
getLen,
(*pos) / trackRate,
tstep);
(*pos) / trackRate);
*pos += getLen;
}
@@ -584,10 +582,12 @@ sampleCount Mixer::MixSameRate(int *channelFlags, WaveTrackCache &cache,
if (slen > mMaxOut)
slen = mMaxOut;
wxASSERT(slen >= 0);
if (backwards) {
auto results = cache.Get(floatSample, *pos - (slen - 1), slen);
memcpy(mFloatBuffer, results, sizeof(float) * slen);
track->GetEnvelopeValues(mEnvValues, slen, t - (slen - 1) / mRate, 1.0 / mRate);
track->GetEnvelopeValues(mEnvValues, slen, t - (slen - 1) / mRate);
for(int i=0; i<slen; i++)
mFloatBuffer[i] *= mEnvValues[i]; // Track gain control will go here?
ReverseSamples((samplePtr)mFloatBuffer, floatSample, 0, slen);
@@ -597,7 +597,7 @@ sampleCount Mixer::MixSameRate(int *channelFlags, WaveTrackCache &cache,
else {
auto results = cache.Get(floatSample, *pos, slen);
memcpy(mFloatBuffer, results, sizeof(float) * slen);
track->GetEnvelopeValues(mEnvValues, slen, t, 1.0 / mRate);
track->GetEnvelopeValues(mEnvValues, slen, t);
for(int i=0; i<slen; i++)
mFloatBuffer[i] *= mEnvValues[i]; // Track gain control will go here?

View File

@@ -2096,13 +2096,9 @@ bool WaveTrack::Set(samplePtr buffer, sampleFormat format,
return result;
}
void WaveTrack::GetEnvelopeValues(double *buffer, int bufferLen,
double t0, double tstep) const
void WaveTrack::GetEnvelopeValues(double *buffer, size_t bufferLen,
double t0) const
{
// Possibly nothing to do.
if( bufferLen <= 0 )
return;
// The output buffer corresponds to an unbroken span of time which the callers expect
// to be fully valid. As clips are processed below, the output buffer is updated with
// envelope values from any portion of a clip, start, end, middle, or none at all.
@@ -2119,29 +2115,31 @@ void WaveTrack::GetEnvelopeValues(double *buffer, int bufferLen,
}
double startTime = t0;
double endTime = t0+tstep*bufferLen;
auto tstep = 1.0 / mRate;
double endTime = t0 + tstep * bufferLen;
for (const auto &clip: mClips)
{
// IF clip intersects startTime..endTime THEN...
double dClipStartTime = clip->GetStartTime();
double dClipEndTime = clip->GetEndTime();
auto dClipStartTime = clip->GetStartTime();
auto dClipEndTime = clip->GetEndTime();
if ((dClipStartTime < endTime) && (dClipEndTime > startTime))
{
double* rbuf = buffer;
int rlen = bufferLen;
double rt0 = t0;
auto rbuf = buffer;
auto rlen = bufferLen;
auto rt0 = t0;
if (rt0 < dClipStartTime)
{
sampleCount nDiff = (sampleCount)floor((dClipStartTime - rt0) * mRate + 0.5);
rbuf += nDiff;
wxASSERT(nDiff <= rlen);
rlen -= nDiff;
rt0 = dClipStartTime;
}
if (rt0 + rlen*tstep > dClipEndTime)
{
int nClipLen = clip->GetEndSample() - clip->GetStartSample();
auto nClipLen = clip->GetEndSample() - clip->GetStartSample();
if (nClipLen <= 0) // Testing for bug 641, this problem is consistently '== 0', but doesn't hurt to check <.
return;
@@ -2151,8 +2149,8 @@ void WaveTrack::GetEnvelopeValues(double *buffer, int bufferLen,
// This conditional prevents the previous write past the buffer end, in clip->GetEnvelope() call.
// Never increase rlen here.
// PRL bug 827: rewrote it again
rlen = std::min(rlen, nClipLen);
rlen = std::min(rlen, int(floor(0.5 + (dClipEndTime - rt0) / tstep)));
rlen = static_cast<size_t>( std::min(sampleCount( rlen ), nClipLen) );
rlen = std::min(rlen, size_t(floor(0.5 + (dClipEndTime - rt0) / tstep)));
}
clip->GetEnvelope()->GetValues(rbuf, rlen, rt0, tstep);
}

View File

@@ -239,8 +239,8 @@ class AUDACITY_DLL_API WaveTrack final : public Track {
sampleCount start, sampleCount len, fillFormat fill=fillZero) const;
bool Set(samplePtr buffer, sampleFormat format,
sampleCount start, sampleCount len);
void GetEnvelopeValues(double *buffer, int bufferLen,
double t0, double tstep) const;
void GetEnvelopeValues(double *buffer, size_t bufferLen,
double t0) const;
bool GetMinMax(float *min, float *max,
double t0, double t1) const;
bool GetRMS(float *rms, double t0, double t1);