From 85bb081f3bd9099d5833996e4bc7de4e1633918a Mon Sep 17 00:00:00 2001 From: tildearrow Date: Wed, 19 Jan 2022 23:23:47 -0500 Subject: [PATCH] prevent clock drift when previewing samples --- src/engine/playback.cpp | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/engine/playback.cpp b/src/engine/playback.cpp index 8b681076b..2b26a98fa 100644 --- a/src/engine/playback.cpp +++ b/src/engine/playback.cpp @@ -1,3 +1,4 @@ +#include "blip_buf.h" #define _USE_MATH_DEFINES #include "dispatch.h" #include "engine.h" @@ -938,8 +939,16 @@ void DivEngine::nextBuf(float** in, float** out, int inChans, int outChans, unsi isBusy.lock(); if (out!=NULL && sPreview.sample>=0 && sPreview.sample<(int)song.sample.size()) { + unsigned int samp_bbOff=0; + unsigned int prevAvail=blip_samples_avail(samp_bb); + if (prevAvail>size) prevAvail=size; + if (prevAvail>0) { + blip_read_samples(samp_bb,samp_bbOut,prevAvail,0); + samp_bbOff=prevAvail; + } + DivSample* s=song.sample[sPreview.sample]; - size_t prevtotal=blip_clocks_needed(samp_bb,size); + size_t prevtotal=blip_clocks_needed(samp_bb,size-prevAvail); for (size_t i=0; i=s->rendLength) { @@ -955,7 +964,7 @@ void DivEngine::nextBuf(float** in, float** out, int inChans, int outChans, unsi if (sPreview.pos>=s->rendLength) sPreview.sample=-1; blip_end_frame(samp_bb,prevtotal); - blip_read_samples(samp_bb,samp_bbOut,size,0); + blip_read_samples(samp_bb,samp_bbOut+samp_bbOff,size-samp_bbOff,0); for (size_t i=0; i