mirror of
https://github.com/tildearrow/furnace.git
synced 2024-11-16 09:45:06 +00:00
minimize allocations in nextBuf
This commit is contained in:
parent
829db187df
commit
f80488d9b0
2 changed files with 23 additions and 22 deletions
|
@ -164,7 +164,7 @@ struct DivNoteEvent {
|
||||||
struct DivDispatchContainer {
|
struct DivDispatchContainer {
|
||||||
DivDispatch* dispatch;
|
DivDispatch* dispatch;
|
||||||
blip_buffer_t* bb[2];
|
blip_buffer_t* bb[2];
|
||||||
size_t bbInLen;
|
size_t bbInLen, runtotal, runLeft, runPos, lastAvail;
|
||||||
int temp[2], prevSample[2];
|
int temp[2], prevSample[2];
|
||||||
short* bbIn[2];
|
short* bbIn[2];
|
||||||
short* bbOut[2];
|
short* bbOut[2];
|
||||||
|
@ -182,6 +182,10 @@ struct DivDispatchContainer {
|
||||||
dispatch(NULL),
|
dispatch(NULL),
|
||||||
bb{NULL,NULL},
|
bb{NULL,NULL},
|
||||||
bbInLen(0),
|
bbInLen(0),
|
||||||
|
runtotal(0),
|
||||||
|
runLeft(0),
|
||||||
|
runPos(0),
|
||||||
|
lastAvail(0),
|
||||||
temp{0,0},
|
temp{0,0},
|
||||||
prevSample{0,0},
|
prevSample{0,0},
|
||||||
bbIn{NULL,NULL},
|
bbIn{NULL,NULL},
|
||||||
|
|
|
@ -1308,25 +1308,22 @@ void DivEngine::nextBuf(float** in, float** out, int inChans, int outChans, unsi
|
||||||
}
|
}
|
||||||
|
|
||||||
// logic starts here
|
// logic starts here
|
||||||
size_t runtotal[32];
|
|
||||||
size_t runLeft[32];
|
|
||||||
size_t runPos[32];
|
|
||||||
size_t lastAvail[32];
|
|
||||||
for (int i=0; i<song.systemLen; i++) {
|
for (int i=0; i<song.systemLen; i++) {
|
||||||
lastAvail[i]=blip_samples_avail(disCont[i].bb[0]);
|
disCont[i].lastAvail=blip_samples_avail(disCont[i].bb[0]);
|
||||||
if (lastAvail[i]>0) {
|
if (disCont[i].lastAvail>0) {
|
||||||
disCont[i].flush(lastAvail[i]);
|
disCont[i].flush(disCont[i].lastAvail);
|
||||||
}
|
}
|
||||||
runtotal[i]=blip_clocks_needed(disCont[i].bb[0],size-lastAvail[i]);
|
disCont[i].runtotal=blip_clocks_needed(disCont[i].bb[0],size-disCont[i].lastAvail);
|
||||||
if (runtotal[i]>disCont[i].bbInLen) {
|
if (disCont[i].runtotal>disCont[i].bbInLen) {
|
||||||
|
logV("growing dispatch %d bbIn to %d",i,disCont[i].runtotal+256);
|
||||||
delete[] disCont[i].bbIn[0];
|
delete[] disCont[i].bbIn[0];
|
||||||
delete[] disCont[i].bbIn[1];
|
delete[] disCont[i].bbIn[1];
|
||||||
disCont[i].bbIn[0]=new short[runtotal[i]+256];
|
disCont[i].bbIn[0]=new short[disCont[i].runtotal+256];
|
||||||
disCont[i].bbIn[1]=new short[runtotal[i]+256];
|
disCont[i].bbIn[1]=new short[disCont[i].runtotal+256];
|
||||||
disCont[i].bbInLen=runtotal[i]+256;
|
disCont[i].bbInLen=disCont[i].runtotal+256;
|
||||||
}
|
}
|
||||||
runLeft[i]=runtotal[i];
|
disCont[i].runLeft=disCont[i].runtotal;
|
||||||
runPos[i]=0;
|
disCont[i].runPos=0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (metroTickLen<size) {
|
if (metroTickLen<size) {
|
||||||
|
@ -1378,10 +1375,10 @@ void DivEngine::nextBuf(float** in, float** out, int inChans, int outChans, unsi
|
||||||
// 3. tick the clock and fill buffers as needed
|
// 3. tick the clock and fill buffers as needed
|
||||||
if (cycles<runLeftG) {
|
if (cycles<runLeftG) {
|
||||||
for (int i=0; i<song.systemLen; i++) {
|
for (int i=0; i<song.systemLen; i++) {
|
||||||
int total=(cycles*runtotal[i])/(size<<MASTER_CLOCK_PREC);
|
int total=(cycles*disCont[i].runtotal)/(size<<MASTER_CLOCK_PREC);
|
||||||
disCont[i].acquire(runPos[i],total);
|
disCont[i].acquire(disCont[i].runPos,total);
|
||||||
runLeft[i]-=total;
|
disCont[i].runLeft-=total;
|
||||||
runPos[i]+=total;
|
disCont[i].runPos+=total;
|
||||||
}
|
}
|
||||||
runLeftG-=cycles;
|
runLeftG-=cycles;
|
||||||
cycles=0;
|
cycles=0;
|
||||||
|
@ -1389,8 +1386,8 @@ void DivEngine::nextBuf(float** in, float** out, int inChans, int outChans, unsi
|
||||||
cycles-=runLeftG;
|
cycles-=runLeftG;
|
||||||
runLeftG=0;
|
runLeftG=0;
|
||||||
for (int i=0; i<song.systemLen; i++) {
|
for (int i=0; i<song.systemLen; i++) {
|
||||||
disCont[i].acquire(runPos[i],runLeft[i]);
|
disCont[i].acquire(disCont[i].runPos,disCont[i].runLeft);
|
||||||
runLeft[i]=0;
|
disCont[i].runLeft=0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1411,7 +1408,7 @@ void DivEngine::nextBuf(float** in, float** out, int inChans, int outChans, unsi
|
||||||
totalProcessed=size-(runLeftG>>MASTER_CLOCK_PREC);
|
totalProcessed=size-(runLeftG>>MASTER_CLOCK_PREC);
|
||||||
|
|
||||||
for (int i=0; i<song.systemLen; i++) {
|
for (int i=0; i<song.systemLen; i++) {
|
||||||
disCont[i].fillBuf(runtotal[i],lastAvail[i],size-lastAvail[i]);
|
disCont[i].fillBuf(disCont[i].runtotal,disCont[i].lastAvail,size-disCont[i].lastAvail);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int i=0; i<song.systemLen; i++) {
|
for (int i=0; i<song.systemLen; i++) {
|
||||||
|
|
Loading…
Reference in a new issue