From a2de40594a98a62f2b77a36ba0ea5b5d8d919c80 Mon Sep 17 00:00:00 2001 From: CrSjimo Date: Fri, 20 Sep 2024 17:01:39 +0800 Subject: [PATCH] optimize --- src/core/base/IMixer_p.h | 10 +++++++--- src/dspx/DspxNoteContext.cpp | 13 ++++++++++--- src/dspx/DspxNoteContext_p.h | 2 ++ src/dspx/DspxSingingClipContext.h | 2 ++ 4 files changed, 21 insertions(+), 6 deletions(-) diff --git a/src/core/base/IMixer_p.h b/src/core/base/IMixer_p.h index 1bd7f85..0b429f3 100644 --- a/src/core/base/IMixer_p.h +++ b/src/core/base/IMixer_p.h @@ -198,13 +198,17 @@ namespace talcs { bool isMutedBySoloSetting = (soloCounter && !srcInfo.isSolo); if (sourceList.size() == 1) { // fast-read - actualReadLength = src->read(AudioSourceReadData(readData.buffer, readData.startPos, readLength, isMutedBySoloSetting ? -1 : silentFlags)); + IAudioSampleContainer *adoptedBuffer = readData.buffer->isContinuous() ? readData.buffer : &tmpBuf; + actualReadLength = src->read(AudioSourceReadData(adoptedBuffer, adoptedBuffer == readData.buffer ? readData.startPos : 0, readLength, isMutedBySoloSetting ? -1 : silentFlags)); for (int i = 0; i < channelCount; i++) { if (((1 << i) & silentFlags) != 0) { - readData.buffer->clear(i, readData.startPos, readLength); + adoptedBuffer->clear(i, readData.startPos, readLength); } else { auto gainCh = i == 0 ? gainLeftRight.first : i == 1 ? gainLeftRight.second : gain; - readData.buffer->gainSampleRange(i, readData.startPos, readLength, gainCh); + adoptedBuffer->gainSampleRange(i, readData.startPos, readLength, gainCh); + if (adoptedBuffer != readData.buffer) { + readData.buffer->setSampleRange(i, readData.startPos, readLength, tmpBuf, i, 0); + } } } break; diff --git a/src/dspx/DspxNoteContext.cpp b/src/dspx/DspxNoteContext.cpp index 2ee3edd..3e9a01a 100644 --- a/src/dspx/DspxNoteContext.cpp +++ b/src/dspx/DspxNoteContext.cpp @@ -93,17 +93,24 @@ namespace talcs { auto pos = PositionableAudioSource::nextReadPosition(); PositionableAudioSource::setNextReadPosition(0); d->noteSynthesizer->flush(true); - d->noteSynthesizer->read({&dummyBuffer, 0, pos, -1}); - PositionableAudioSource::setNextReadPosition(pos); + if (d->isBeingReadByClip()) { + d->noteSynthesizer->read({&dummyBuffer, 0, pos, -1}); + PositionableAudioSource::setNextReadPosition(pos); + } } qint64 DspxNoteContextSynthesizer::processReading(const AudioSourceReadData &readData) { QMutexLocker locker(&mutex); d->noteSynthesizer->read(readData); - PositionableAudioSource::setNextReadPosition(PositionableAudioSource::nextReadPosition() + readData.length); + PositionableAudioSource::setNextReadPosition(PositionableAudioSource::nextReadPosition() + + readData.length); return readData.length; } + bool DspxNoteContextPrivate::isBeingReadByClip() const { + auto pos = singingClipContext->d_func()->noteClipSeries->nextReadPosition(); + return pos >= clipView.position() && pos < clipView.position() + clipView.length(); + } DspxNoteContext::DspxNoteContext(DspxSingingClipContext *singingClipContext) : QObject(singingClipContext), d_ptr(new DspxNoteContextPrivate) { Q_D(DspxNoteContext); diff --git a/src/dspx/DspxNoteContext_p.h b/src/dspx/DspxNoteContext_p.h index 32ad78f..aeec31f 100644 --- a/src/dspx/DspxNoteContext_p.h +++ b/src/dspx/DspxNoteContext_p.h @@ -77,6 +77,8 @@ namespace talcs { QMap pitchAnchors; QMap energyAnchors; + + bool isBeingReadByClip() const; }; } diff --git a/src/dspx/DspxSingingClipContext.h b/src/dspx/DspxSingingClipContext.h index c39a0d0..064072a 100644 --- a/src/dspx/DspxSingingClipContext.h +++ b/src/dspx/DspxSingingClipContext.h @@ -29,6 +29,7 @@ namespace talcs { class PositionableMixerAudioSource; class DspxPseudoSingerContext; class DspxNoteContext; + class DspxNoteContextPrivate; class DspxSingingClipContextPrivate; @@ -37,6 +38,7 @@ namespace talcs { Q_DECLARE_PRIVATE(DspxSingingClipContext) friend class DspxPseudoSingerContext; friend class DspxNoteContext; + friend class DspxNoteContextPrivate; public: ~DspxSingingClipContext() override;