Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 65d3132

Browse files
Fix for delay compensation when rendering clip effects
1 parent fc7ff23 commit 65d3132

File tree

1 file changed

+34
-7
lines changed

1 file changed

+34
-7
lines changed

‎modules/tracktion_engine/model/clips/tracktion_ClipEffects.cpp‎

Lines changed: 34 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -502,6 +502,9 @@ struct AudioNodeRenderJob : public ClipEffect::ClipEffectRenderJob
502502
nodePlayer->setNumThreads (0);
503503
nodePlayer->prepareToPlay (sampleRate, (int) blockSize);
504504

505+
numLatencySamplesToDrop = nodePlayer->getNode()->getNodeProperties().latencyNumSamples;
506+
totalSamples += numLatencySamplesToDrop;
507+
505508
audioBuffer = choc::buffer::ChannelArrayBuffer<float> ((choc::buffer::ChannelCount) numDestChannels, (choc::buffer::FrameCount) blockSize);
506509
}
507510

@@ -538,15 +541,38 @@ struct AudioNodeRenderJob : public ClipEffect::ClipEffectRenderJob
538541

539542
progressToUpdate = juce::jlimit (0.0f, 0.9f, (float) (0.9 * samplesDone / (double) totalSamples));
540543

541-
// NB buffer gets trashed by this call
542-
if (samplesToDo <= 0 || ! writeChocBufferToAudioFormatWriter (pc.buffers.audio))
543-
{
544-
// complete render
545-
writer->closeForWriting();
544+
bool streamEnded = false;
546545

547-
if (samplesToDo <= 0)
548-
progressToUpdate = 1.0f;
546+
if (samplesToDo <= 0)
547+
{
548+
progressToUpdate = 1.0f;
549+
streamEnded = true;
550+
}
551+
else
552+
{
553+
if (numLatencySamplesToDrop > 0)
554+
{
555+
// Unless we're dropping the whole buffer, write the last bit of it
556+
if (samplesToDo > (uint32_t) numLatencySamplesToDrop)
557+
{
558+
streamEnded = ! writeChocBufferToAudioFormatWriter (pc.buffers.audio.fromFrame ((uint32_t) numLatencySamplesToDrop));
559+
numLatencySamplesToDrop = 0;
560+
}
561+
else
562+
{
563+
numLatencySamplesToDrop -= samplesToDo;
564+
}
565+
}
566+
else
567+
{
568+
// NB buffer gets trashed by this call
569+
streamEnded = ! writeChocBufferToAudioFormatWriter (pc.buffers.audio);
570+
}
571+
}
549572

573+
if (streamEnded)
574+
{
575+
writer->closeForWriting();
550576
return juce::ThreadPoolJob::jobHasFinished;
551577
}
552578

@@ -568,6 +594,7 @@ struct AudioNodeRenderJob : public ClipEffect::ClipEffectRenderJob
568594
double sampleRate = 0;
569595
TimeRange streamRange;
570596
int numPreBlocks = 0;
597+
int numLatencySamplesToDrop = 0;
571598
int64_t samplesDone = 0, totalSamples = 0;
572599
choc::buffer::ChannelArrayBuffer<float> audioBuffer;
573600
MidiMessageArray midiBuffer;

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /