new dispatch, part 4

This commit is contained in:
tildearrow 2023-01-04 17:01:14 -05:00
parent 9436e2ab55
commit 6c834524aa
3 changed files with 42 additions and 6 deletions

View file

@ -83,6 +83,7 @@ void DivDispatchContainer::setRates(double gotRate) {
int outs=dispatch->getOutputCount();
for (int i=0; i<outs; i++) {
if (bb[i]==NULL) continue;
blip_set_rates(bb[i],dispatch->rate,gotRate);
}
rateMemory=gotRate;
@ -92,6 +93,16 @@ void DivDispatchContainer::setQuality(bool lowQual) {
lowQuality=lowQual;
}
void DivDispatchContainer::grow(size_t size) {
bbInLen=size;
for (int i=0; i<DIV_MAX_OUTPUTS; i++) {
if (bbIn[i]!=NULL) {
delete[] bbIn[i];
bbIn[i]=new short[bbInLen];
}
}
}
void DivDispatchContainer::acquire(size_t offset, size_t count) {
int outs=dispatch->getOutputCount();
for (int i=0; i<DIV_MAX_OUTPUTS; i++) {
@ -108,20 +119,44 @@ void DivDispatchContainer::flush(size_t count) {
int outs=dispatch->getOutputCount();
for (int i=0; i<outs; i++) {
if (bb[i]==NULL) continue;
blip_read_samples(bb[i],bbOut[i],count,0);
}
}
void DivDispatchContainer::fillBuf(size_t runtotal, size_t offset, size_t size) {
int outs=dispatch->getOutputCount();
// create missing buffers if any
bool mustClear=false;
for (int i=0; i<outs; i++) {
if (bb[i]==NULL) {
bb[i]=blip_new(bbInLen);
if (bb[i]==NULL) {
logE("not enough memory!");
return;
}
blip_set_rates(bb[i],dispatch->rate,rateMemory);
if (bbIn[i]==NULL) bbIn[i]=new short[bbInLen];
if (bbOut[i]==NULL) bbOut[i]=new short[bbInLen];
memset(bbIn[i],0,bbInLen*sizeof(short));
memset(bbOut[i],0,bbInLen*sizeof(short));
}
}
if (mustClear) clear();
if (dcOffCompensation && runtotal>0) {
dcOffCompensation=false;
for (int i=0; i<outs; i++) {
if (bbIn[i]==NULL) continue;
prevSample[i]=bbIn[i][0];
}
}
if (lowQuality) {
for (int i=0; i<outs; i++) {
if (bbIn[i]==NULL) continue;
if (bb[i]==NULL) continue;
for (size_t j=0; j<runtotal; j++) {
temp[i]=bbIn[i][j];
blip_add_delta_fast(bb[i],j,temp[i]-prevSample[i]);
@ -130,6 +165,8 @@ void DivDispatchContainer::fillBuf(size_t runtotal, size_t offset, size_t size)
}
} else {
for (int i=0; i<outs; i++) {
if (bbIn[i]==NULL) continue;
if (bb[i]==NULL) continue;
for (size_t j=0; j<runtotal; j++) {
temp[i]=bbIn[i][j];
blip_add_delta(bb[i],j,temp[i]-prevSample[i]);
@ -139,6 +176,8 @@ void DivDispatchContainer::fillBuf(size_t runtotal, size_t offset, size_t size)
}
for (int i=0; i<outs; i++) {
if (bbOut[i]==NULL) continue;
if (bb[i]==NULL) continue;
blip_end_frame(bb[i],runtotal);
blip_read_samples(bb[i],bbOut[i]+offset,size,0);
}

View file

@ -181,6 +181,7 @@ struct DivDispatchContainer {
void setRates(double gotRate);
void setQuality(bool lowQual);
void grow(size_t size);
void acquire(size_t offset, size_t count);
void flush(size_t count);
void fillBuf(size_t runtotal, size_t offset, size_t size);

View file

@ -1601,12 +1601,8 @@ void DivEngine::nextBuf(float** in, float** out, int inChans, int outChans, unsi
disCont[i].runtotal=blip_clocks_needed(disCont[i].bb[0],size-disCont[i].lastAvail);
}
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[1];
disCont[i].bbIn[0]=new short[disCont[i].runtotal+256];
disCont[i].bbIn[1]=new short[disCont[i].runtotal+256];
disCont[i].bbInLen=disCont[i].runtotal+256;
logD("growing dispatch %d bbIn to %d",i,disCont[i].runtotal+256);
disCont[i].grow(disCont[i].runtotal+256);
}
disCont[i].runLeft=disCont[i].runtotal;
disCont[i].runPos=0;