Skip to content

Commit

Permalink
optimize
Browse files Browse the repository at this point in the history
  • Loading branch information
CrSjimo committed Sep 20, 2024
1 parent 433eb5a commit a2de405
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 6 deletions.
10 changes: 7 additions & 3 deletions src/core/base/IMixer_p.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
13 changes: 10 additions & 3 deletions src/dspx/DspxNoteContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 2 additions & 0 deletions src/dspx/DspxNoteContext_p.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ namespace talcs {

QMap<int, QVariant> pitchAnchors;
QMap<int, QVariant> energyAnchors;

bool isBeingReadByClip() const;
};
}

Expand Down
2 changes: 2 additions & 0 deletions src/dspx/DspxSingingClipContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ namespace talcs {
class PositionableMixerAudioSource;
class DspxPseudoSingerContext;
class DspxNoteContext;
class DspxNoteContextPrivate;

class DspxSingingClipContextPrivate;

Expand All @@ -37,6 +38,7 @@ namespace talcs {
Q_DECLARE_PRIVATE(DspxSingingClipContext)
friend class DspxPseudoSingerContext;
friend class DspxNoteContext;
friend class DspxNoteContextPrivate;
public:
~DspxSingingClipContext() override;

Expand Down

0 comments on commit a2de405

Please sign in to comment.