better blip_buf excess strategy

fixes #133
This commit is contained in:
tildearrow 2022-02-07 21:31:58 -05:00
parent e6201b8390
commit 632f17862e
3 changed files with 24 additions and 8 deletions

View file

@ -31,7 +31,15 @@ void DivDispatchContainer::acquire(size_t offset, size_t count) {
dispatch->acquire(bbIn[0],bbIn[1],offset,count); dispatch->acquire(bbIn[0],bbIn[1],offset,count);
} }
void DivDispatchContainer::fillBuf(size_t runtotal, size_t size) { void DivDispatchContainer::flush(size_t count) {
blip_read_samples(bb[0],bbOut[0],count,0);
if (dispatch->isStereo()) {
blip_read_samples(bb[1],bbOut[1],count,0);
}
}
void DivDispatchContainer::fillBuf(size_t runtotal, size_t offset, size_t size) {
if (lowQuality) { if (lowQuality) {
for (size_t i=0; i<runtotal; i++) { for (size_t i=0; i<runtotal; i++) {
temp[0]=bbIn[0][i]; temp[0]=bbIn[0][i];
@ -59,16 +67,16 @@ void DivDispatchContainer::fillBuf(size_t runtotal, size_t size) {
} }
blip_end_frame(bb[0],runtotal); blip_end_frame(bb[0],runtotal);
int totalRead=blip_read_samples(bb[0],bbOut[0],size,0); blip_read_samples(bb[0],bbOut[0]+offset,size,0);
if (totalRead<(int)size && totalRead>0) { /*if (totalRead<(int)size && totalRead>0) {
for (size_t i=totalRead; i<size; i++) { for (size_t i=totalRead; i<size; i++) {
bbOut[0][i]=bbOut[0][totalRead-1];//bbOut[0][totalRead]; bbOut[0][i]=bbOut[0][totalRead-1];//bbOut[0][totalRead];
} }
} }*/
if (dispatch->isStereo()) { if (dispatch->isStereo()) {
blip_end_frame(bb[1],runtotal); blip_end_frame(bb[1],runtotal);
blip_read_samples(bb[1],bbOut[1],size,0); blip_read_samples(bb[1],bbOut[1]+offset,size,0);
} }
} }

View file

@ -114,7 +114,8 @@ struct DivDispatchContainer {
void setRates(double gotRate); void setRates(double gotRate);
void setQuality(bool lowQual); void setQuality(bool lowQual);
void acquire(size_t offset, size_t count); void acquire(size_t offset, size_t count);
void fillBuf(size_t runtotal, size_t size); void flush(size_t count);
void fillBuf(size_t runtotal, size_t offset, size_t size);
void clear(); void clear();
void init(DivSystem sys, DivEngine* eng, int chanCount, double gotRate, unsigned int flags); void init(DivSystem sys, DivEngine* eng, int chanCount, double gotRate, unsigned int flags);
void quit(); void quit();

View file

@ -988,6 +988,8 @@ void DivEngine::nextBuf(float** in, float** out, int inChans, int outChans, unsi
} }
isBusy.lock(); isBusy.lock();
got.bufsize=size;
if (out!=NULL && ((sPreview.sample>=0 && sPreview.sample<(int)song.sample.size()) || (sPreview.wave>=0 && sPreview.wave<(int)song.wave.size()))) { if (out!=NULL && ((sPreview.sample>=0 && sPreview.sample<(int)song.sample.size()) || (sPreview.wave>=0 && sPreview.wave<(int)song.wave.size()))) {
unsigned int samp_bbOff=0; unsigned int samp_bbOff=0;
unsigned int prevAvail=blip_samples_avail(samp_bb); unsigned int prevAvail=blip_samples_avail(samp_bb);
@ -1063,8 +1065,13 @@ void DivEngine::nextBuf(float** in, float** out, int inChans, int outChans, unsi
size_t runtotal[32]; size_t runtotal[32];
size_t runLeft[32]; size_t runLeft[32];
size_t runPos[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++) {
runtotal[i]=blip_clocks_needed(disCont[i].bb[0],size)-blip_samples_avail(disCont[i].bb[0]); lastAvail[i]=blip_samples_avail(disCont[i].bb[0]);
if (lastAvail[i]>0) {
disCont[i].flush(lastAvail[i]);
}
runtotal[i]=blip_clocks_needed(disCont[i].bb[0],size-lastAvail[i]);
if (runtotal[i]>disCont[i].bbInLen) { if (runtotal[i]>disCont[i].bbInLen) {
delete disCont[i].bbIn[0]; delete disCont[i].bbIn[0];
delete disCont[i].bbIn[1]; delete disCont[i].bbIn[1];
@ -1153,7 +1160,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],size); disCont[i].fillBuf(runtotal[i],lastAvail[i],size-lastAvail[i]);
} }
for (int i=0; i<song.systemLen; i++) { for (int i=0; i<song.systemLen; i++) {