Skip to content

Commit

Permalink
Fixed effects application marking changed multiple times.
Browse files Browse the repository at this point in the history
  • Loading branch information
RubisetCie committed Jan 2, 2025
1 parent 3b28b41 commit 770781a
Show file tree
Hide file tree
Showing 12 changed files with 49 additions and 40 deletions.
2 changes: 1 addition & 1 deletion libraries/lib-builtin-effects/AutoDuckBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,7 @@ bool AutoDuckBase::ApplyDuckFade(
buf[(i - pos).as_size_t()] *= DB_TO_LINEAR(gain);
}

if (!track.SetFloats(buf.get(), pos, len))
if (!track.SetFloats(buf.get(), pos, len, widestSampleFormat, pos + len >= end))
{
cancel = true;
break;
Expand Down
2 changes: 1 addition & 1 deletion libraries/lib-builtin-effects/ClickRemovalBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ bool ClickRemovalBase::ProcessOne(
if (mbDidSomething)
{
// RemoveClicks() actually did something.
if (!track.SetFloats(buffer.get(), start + s, block))
if (!track.SetFloats(buffer.get(), start + s, block, widestSampleFormat, (len - (s + block)) <= windowSize / 2))
{
bResult = false;
break;
Expand Down
2 changes: 1 addition & 1 deletion libraries/lib-builtin-effects/NormalizeBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ bool NormalizeBase::ProcessOne(
ProcessData(buffer.get(), block, offset);

// Copy the newly-changed samples back onto the track.
if (!track.SetFloats(buffer.get(), s, block))
if (!track.SetFloats(buffer.get(), s, block, widestSampleFormat, s >= end))
{
rc = false;
break;
Expand Down
4 changes: 2 additions & 2 deletions libraries/lib-builtin-effects/TwoPassSimpleMono.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ bool EffectTwoPassSimpleMono::ProcessOne(WaveChannel &track,
// onto the track.
if (mSecondPassDisabled || mPass != 0) {
if (!outTrack.SetFloats(buffer1.get(), s - samples1,
samples1))
samples1, widestSampleFormat, s + samples2 >= end))
return false;
}
else
Expand Down Expand Up @@ -218,7 +218,7 @@ bool EffectTwoPassSimpleMono::ProcessOne(WaveChannel &track,
// onto the track.
if (mSecondPassDisabled || mPass != 0) {
if (!outTrack.SetFloats(buffer1.get(), s - samples1,
samples1))
samples1, widestSampleFormat, s >= end))
return false;
}
else
Expand Down
28 changes: 18 additions & 10 deletions libraries/lib-wave-track/Sequence.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -458,7 +458,9 @@ std::unique_ptr<Sequence> Sequence::Copy( const SampleBlockFactoryPtr &pFactory,
// Increase ref count or duplicate file
}

#if defined(_DEBUG)
dest->ConsistencyCheck(wxT("Sequence::Copy()"));
#endif

return dest;
}
Expand Down Expand Up @@ -600,7 +602,9 @@ void Sequence::Paste(sampleCount s, const Sequence *src)

// This consistency check won't throw, it asserts.
// Proof that we kept consistency is not hard.
ConsistencyCheck(wxT("Paste branch two"), false);
#if defined(_DEBUG)
ConsistencyCheck(wxT("Paste branch two"));
#endif
mSampleFormats.UpdateEffective(src->mSampleFormats.Effective());
return;
}
Expand Down Expand Up @@ -1635,9 +1639,11 @@ void Sequence::Delete(sampleCount start, sampleCount len)

mNumSamples -= len;

#if defined(_DEBUG)
// This consistency check won't throw, it asserts.
// Proof that we kept consistency is not hard.
ConsistencyCheck(wxT("Delete - branch one"), false);
ConsistencyCheck(wxT("Delete - branch one"));
#endif
return;
}

Expand Down Expand Up @@ -1745,15 +1751,15 @@ void Sequence::Delete(sampleCount start, sampleCount len)
(newBlock, mNumSamples - len, wxT("Delete - branch two"));
}

void Sequence::ConsistencyCheck(const wxChar *whereStr, bool mayThrow) const
#if defined(_DEBUG)
void Sequence::ConsistencyCheck(const wxChar *whereStr) const
{
ConsistencyCheck(mBlock, mMaxSamples, 0, mNumSamples, whereStr, mayThrow);
ConsistencyCheck(mBlock, mMaxSamples, 0, mNumSamples, whereStr);
}

void Sequence::ConsistencyCheck
(const BlockArray &mBlock, size_t maxSamples, size_t from,
sampleCount mNumSamples, const wxChar *whereStr,
bool WXUNUSED(mayThrow))
sampleCount mNumSamples, const wxChar *whereStr)
{
// Construction of the exception at the appropriate line of the function
// gives a little more discrimination
Expand Down Expand Up @@ -1794,17 +1800,17 @@ void Sequence::ConsistencyCheck
wxT("Recommended course of action:\n")
wxT("Undo the failed operation(s), then export or save your work and quit."));

//if (mayThrow)
//throw *ex;
//else
wxASSERT(false);
wxASSERT(false);
}
}
#endif

void Sequence::CommitChangesIfConsistent
(BlockArray &newBlock, sampleCount numSamples, const wxChar *whereStr)
{
#if defined(_DEBUG)
ConsistencyCheck( newBlock, mMaxSamples, 0, numSamples, whereStr ); // may throw
#endif

// now commit
// use No-fail-guarantee
Expand Down Expand Up @@ -1848,9 +1854,11 @@ void Sequence::AppendBlocksIfConsistent
std::copy( additionalBlocks.begin(), additionalBlocks.end(),
std::back_inserter( mBlock ) );

#if defined(_DEBUG)
// Check consistency only of the blocks that were added,
// avoiding quadratic time for repeated checking of repeating appends
ConsistencyCheck( mBlock, mMaxSamples, prevSize, numSamples, whereStr ); // may throw
#endif

// now commit
// use No-fail-guarantee
Expand Down
11 changes: 7 additions & 4 deletions libraries/lib-wave-track/Sequence.h
Original file line number Diff line number Diff line change
Expand Up @@ -308,21 +308,24 @@ class WAVE_TRACK_API Sequence final : public XMLTagHandler{
static bool Read(samplePtr buffer, sampleFormat format,
const SeqBlock &b,
size_t blockRelativeStart, size_t len, bool mayThrow);


#if defined(_DEBUG)
// This function throws if the track is messed up
// because of inconsistent block starts & lengths
void ConsistencyCheck (const wxChar *whereStr, bool mayThrow = true) const;
void ConsistencyCheck (const wxChar *whereStr) const;
#endif

// This function prints information to stdout about the blocks in the
// tracks and indicates if there are inconsistencies.
static void DebugPrintf
(const BlockArray &block, sampleCount numSamples, wxString *dest);

private:
#if defined(_DEBUG)
static void ConsistencyCheck
(const BlockArray &block, size_t maxSamples, size_t from,
sampleCount numSamples, const wxChar *whereStr,
bool mayThrow = true);
sampleCount numSamples, const wxChar *whereStr);
#endif

// The next two are used in methods that give a strong guarantee.
// They either throw because final consistency check fails, or swap the
Expand Down
8 changes: 0 additions & 8 deletions libraries/lib-wave-track/WaveChannelUtilities.h
Original file line number Diff line number Diff line change
Expand Up @@ -163,14 +163,6 @@ WAVE_TRACK_API void SetFloatsFromTime(WaveChannel &channel,
double t, const float* buffer, size_t numSamples,
sampleFormat effectiveFormat, PlaybackDirection direction);

/*!
@copydoc SetFloatsFromTime(WaveChannel &, double, const float *, size_t,
sampleFormat, PlaybackDirection)
*/
WAVE_TRACK_API void SetFloatsFromTime(Clip &channel,
double t, const float* buffer, size_t numSamples,
sampleFormat effectiveFormat, PlaybackDirection direction);

/*!
@brief Similar to GetNextClip, but returns `nullptr` if the neighbour
clip is not adjacent.
Expand Down
9 changes: 5 additions & 4 deletions libraries/lib-wave-track/WaveClip.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -169,10 +169,10 @@ sampleCount WaveClipChannel::GetPlayEndSample() const
}

void WaveClipChannel::SetSamples(constSamplePtr buffer, sampleFormat format,
sampleCount start, size_t len, sampleFormat effectiveFormat)
sampleCount start, size_t len, sampleFormat effectiveFormat, bool end)
{
return GetClip().SetSamples(miChannel,
buffer, format, start, len, effectiveFormat);
buffer, format, start, len, effectiveFormat, end);
}

void WaveClipChannel::WriteXML(XMLWriter &xmlFile) const
Expand Down Expand Up @@ -395,15 +395,16 @@ bool WaveClip::GetSamples(samplePtr buffers[], sampleFormat format,

void WaveClip::SetSamples(size_t ii,
constSamplePtr buffer, sampleFormat format,
sampleCount start, size_t len, sampleFormat effectiveFormat)
sampleCount start, size_t len, sampleFormat effectiveFormat, bool end)
{
assert(ii < NChannels());
// use Strong-guarantee
mSequences[ii]->SetSamples(buffer, format,
start + TimeToSamples(mTrimLeft), len, effectiveFormat);

// use No-fail-guarantee
MarkChanged();
if (end)
MarkChanged();
}

void WaveClip::SetEnvelope(std::unique_ptr<Envelope> p)
Expand Down
2 changes: 2 additions & 0 deletions libraries/lib-wave-track/WaveClip.h
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ class WAVE_TRACK_API WaveClipChannel
If the data are later narrowed from stored format, but not narrower
than the effective, then no dithering will occur.
*/
, bool end = true
);

void WriteXML(XMLWriter &xmlFile) const;
Expand Down Expand Up @@ -553,6 +554,7 @@ class WAVE_TRACK_API WaveClip final :
If the data are later narrowed from stored format, but not narrower
than the effective, then no dithering will occur.
*/
, bool end = true
);

//! @}
Expand Down
10 changes: 5 additions & 5 deletions libraries/lib-wave-track/WaveTrack.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1551,7 +1551,7 @@ bool WaveTrack::ReplaceTrackData(
{
const auto len = limitSampleBufferSize(GetMaxBlockSize(), end - pos);
src.DoGet(0, channels, buffersCast, floatSample, seek, len, false);
if (!track.SetFloats(buffers, pos, len))
if (!track.SetFloats(buffers, pos, len, widestSampleFormat, pos + len >= end))
retval = false;
seek += len;
pos += len;
Expand Down Expand Up @@ -2852,7 +2852,7 @@ WaveChannel::GetSampleView(double t0, double t1, bool mayThrow) const

/*! @excsafety{Weak} */
bool WaveChannel::Set(constSamplePtr buffer, sampleFormat format,
sampleCount start, size_t len, sampleFormat effectiveFormat)
sampleCount start, size_t len, sampleFormat effectiveFormat, bool end)
{
for (const auto &clip: Intervals())
{
Expand Down Expand Up @@ -2889,7 +2889,7 @@ bool WaveChannel::Set(constSamplePtr buffer, sampleFormat format,

clip->SetSamples(
buffer + startDelta.as_size_t() * SAMPLE_SIZE(format),
format, inclipDelta, samplesToCopy.as_size_t(), effectiveFormat );
format, inclipDelta, samplesToCopy.as_size_t(), effectiveFormat, end );
}
}
return true;
Expand Down Expand Up @@ -3341,14 +3341,14 @@ void WaveTrack::Resample(int rate, BasicUI::ProgressDialog *progress)
}

bool WaveTrack::SetFloats(const float *const *buffers,
sampleCount start, size_t len, sampleFormat effectiveFormat)
sampleCount start, size_t len, sampleFormat effectiveFormat, bool end)
{
bool result = true;
size_t ii = 0;
for (const auto &pChannel : Channels()) {
const auto buffer = buffers[ii++];
assert(buffer); // precondition
result = pChannel->SetFloats(buffer, start, len, effectiveFormat)
result = pChannel->SetFloats(buffer, start, len, effectiveFormat, end)
&& result;
}
return result;
Expand Down
5 changes: 4 additions & 1 deletion libraries/lib-wave-track/WaveTrack.h
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ class WAVE_TRACK_API WaveChannel final
If the data are later narrowed from stored format, but not narrower
than the effective, then no dithering will occur.
*/
, bool end = true
);

//! Random-access assignment of a range of samples
Expand All @@ -167,10 +168,11 @@ class WAVE_TRACK_API WaveChannel final
If the data are later narrowed from stored format, but not narrower
than the effective, then no dithering will occur.
*/
, bool end = true
)
{
return Set(reinterpret_cast<constSamplePtr>(buffer), floatSample,
start, len, effectiveFormat);
start, len, effectiveFormat, end);
}

bool AppendBuffer(constSamplePtr buffer, sampleFormat format, size_t len, unsigned stride, sampleFormat effectiveFormat);
Expand Down Expand Up @@ -659,6 +661,7 @@ class WAVE_TRACK_API WaveTrack final
If the data are later narrowed from stored format, but not narrower
than the effective, then no dithering will occur.
*/
, bool end = true
);

const TypeInfo &GetTypeInfo() const override;
Expand Down
6 changes: 3 additions & 3 deletions libraries/lib-wave-track/WaveTrackUtilities.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,14 +101,14 @@ bool ReverseOneClip(WaveTrack &track,
track.GetFloats(0, width, pointers1, second, block);
reverseBuffers(pointers1, block);
// Don't dither on later rendering if only reversing samples
len -= 2 * block;
const bool success =
track.SetFloats(pointers1, first, block, narrowestSampleFormat)
track.SetFloats(pointers1, first, block, narrowestSampleFormat, len <= 1)
&&
track.SetFloats(pointers0, second, block, narrowestSampleFormat);
track.SetFloats(pointers0, second, block, narrowestSampleFormat, len <= 1);
if (!success)
return false;

len -= 2 * block;
first += block;

if (!report(
Expand Down

0 comments on commit 770781a

Please sign in to comment.