diff --git a/src/engine/dispatchContainer.cpp b/src/engine/dispatchContainer.cpp index 81db5d728..dff2019bd 100644 --- a/src/engine/dispatchContainer.cpp +++ b/src/engine/dispatchContainer.cpp @@ -17,6 +17,32 @@ void DivDispatchContainer::setRates(double gotRate) { blip_set_rates(bb[1],dispatch->rate,gotRate); } +void DivDispatchContainer::acquire(size_t offset, size_t count) { + dispatch->acquire(bbIn[0],bbIn[1],offset,count); +} + +void DivDispatchContainer::fillBuf(size_t runtotal, size_t size) { + for (size_t i=0; iisStereo()) for (size_t i=0; iisStereo()) { + blip_end_frame(bb[1],runtotal); + blip_read_samples(bb[1],bbOut[1],size,0); + } +} + void DivDispatchContainer::clear() { blip_clear(bb[0]); blip_clear(bb[1]); diff --git a/src/engine/engine.cpp b/src/engine/engine.cpp index f52549a3c..9c0372644 100644 --- a/src/engine/engine.cpp +++ b/src/engine/engine.cpp @@ -1940,7 +1940,7 @@ void DivEngine::addOrder(bool duplicate, bool where) { if (song.ordersLen>=0x7e) return; isBusy.lock(); if (duplicate) { - for (int i=0; i<32; i++) { + for (int i=0; icurOrder; j--) { song.orders.ord[i][j]=song.orders.ord[i][j-1]; } @@ -1983,7 +1983,7 @@ void DivEngine::addOrder(bool duplicate, bool where) { void DivEngine::deleteOrder() { if (song.ordersLen<=1) return; isBusy.lock(); - for (int i=0; i<32; i++) { + for (int i=0; iisStereo()) { - for (size_t i=0; iisStereo()) { + for (size_t i=0; irate/divider; dc.clockDrift+=dc.dispatch->rate%divider; if (dc.clockDrift>=divider) { @@ -858,26 +858,26 @@ 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()) { DivSample* s=song.sample[sPreview.sample]; - size_t prevtotal=blip_clocks_needed(bb[2],size); + size_t prevtotal=blip_clocks_needed(samp_bb,size); for (size_t i=0; i=s->rendLength) { - temp[2]=0; + samp_temp=0; } else { - temp[2]=s->rendData[sPreview.pos++]; + samp_temp=s->rendData[sPreview.pos++]; } - if (s->depth==8) temp[2]<<=8; - blip_add_delta(bb[2],i,temp[2]-prevSample[2]); - prevSample[2]=temp[2]; + if (s->depth==8) samp_temp<<=8; + blip_add_delta(samp_bb,i,samp_temp-samp_prevSample); + samp_prevSample=samp_temp; } if (sPreview.pos>=s->rendLength) sPreview.sample=-1; - blip_end_frame(bb[2],prevtotal); - blip_read_samples(bb[2],bbOut[2],size,0); + blip_end_frame(samp_bb,prevtotal); + blip_read_samples(samp_bb,samp_bbOut,size,0); for (size_t i=0; ibbInLen) { - delete bbIn[0]; - delete bbIn[1]; - bbIn[0]=new short[runtotal+256]; - bbIn[1]=new short[runtotal+256]; - bbInLen=runtotal+256; + size_t runtotal[32]; + size_t runLeft[32]; + size_t runPos[32]; + for (int i=0; idisCont[i].bbInLen) { + delete disCont[i].bbIn[0]; + delete disCont[i].bbIn[1]; + disCont[i].bbIn[0]=new short[runtotal[i]+256]; + disCont[i].bbIn[1]=new short[runtotal[i]+256]; + disCont[i].bbInLen=runtotal[i]+256; + } + runLeft[i]=runtotal[i]; + runPos[i]=0; } if (metroTickLen=cycles) { - runLeft-=cycles; - dispatch->acquire(bbIn[0],bbIn[1],runPos,cycles); - runPos+=cycles; - unsigned int realPos=(runPos*size)/runtotal; - if (realPos>=size) realPos=size-1; - if (song.hilightA>0) { - if ((curRow%song.hilightA)==0 && ticks==1) metroTick[realPos]=1; - } - if (song.hilightB>0) { - if ((curRow%song.hilightB)==0 && ticks==1) metroTick[realPos]=2; - } - if (nextTick()) { - if (remainingLoops>0) { - remainingLoops--; - if (!remainingLoops) logI("end of song!\n"); - } - } - } else { - dispatch->acquire(bbIn[0],bbIn[1],runPos,runLeft); - cycles-=runLeft; - runPos=runtotal; + while (true) { + bool allDone=true; + bool getOut=true; + // 1. check whether we are done with all buffers + for (int i=0; i0) { + getOut=false; break; } } + if (getOut) break; + + // 2. check whether we gonna tick + for (int i=0; i0) { + allDone=false; + break; + } + } + if (allDone) { + // we have to tick + unsigned int realPos=(runPos[0]*size)/runtotal[0]; + if (realPos>=size) realPos=size-1; + if (song.hilightA>0) { + if ((curRow%song.hilightA)==0 && ticks==1) metroTick[realPos]=1; + } + if (song.hilightB>0) { + if ((curRow%song.hilightB)==0 && ticks==1) metroTick[realPos]=2; + } + if (nextTick()) { + if (remainingLoops>0) { + remainingLoops--; + if (!remainingLoops) logI("end of song!\n"); + } + } + } + + // 3. fill buffers as needed + for (int i=0; idisCont[i].cycles) total=disCont[i].cycles; + runLeft[i]-=total; + disCont[i].cycles-=total; + disCont[i].acquire(runPos[i],total); + runPos[i]+=total; + } } - totalProcessed=(1+runPos)*got.rate/dispatch->rate; + totalProcessed=(1+runPos[0])*got.rate/disCont[0].dispatch->rate; - for (size_t i=0; iisStereo()) for (size_t i=0; iisStereo()) { - blip_end_frame(bb[1],runtotal); - blip_read_samples(bb[1],bbOut[1],size,0); + for (int i=0; iisStereo()) { - for (size_t i=0; iisStereo()) { + for (size_t j=0; jsong.orders.ord[i][j]) { s.ord.push_back(UndoOrderData(i,j,oldOrders.ord[i][j],e->song.orders.ord[i][j])); @@ -3076,7 +3076,6 @@ FurnaceGUI::FurnaceGUI(): macroDragActive(false), nextScroll(-1.0f), nextAddScroll(0.0f), - oldSystem(DIV_SYSTEM_NULL), oldOrdersLen(0) { uiColors[GUI_COLOR_BACKGROUND]=ImVec4(0.1f,0.1f,0.1f,1.0f); uiColors[GUI_COLOR_FRAME_BACKGROUND]=ImVec4(0.0f,0.0f,0.0f,0.85f); diff --git a/src/gui/gui.h b/src/gui/gui.h index 90b45687a..93fba3c2a 100644 --- a/src/gui/gui.h +++ b/src/gui/gui.h @@ -123,7 +123,6 @@ struct UndoStep { SelectionPoint cursor, selStart, selEnd; int order; bool nibble; - DivSystem oldSystem, newSystem; int oldOrdersLen, newOrdersLen; int oldPatLen, newPatLen; std::vector ord; @@ -202,7 +201,6 @@ class FurnaceGUI { ImVec2 patWindowPos, patWindowSize; - DivSystem oldSystem; int oldOrdersLen; DivOrders oldOrders; DivPattern* oldPat[128];