new chan osc, part 2

why is it jerky?
This commit is contained in:
tildearrow 2025-03-01 17:22:34 -05:00
parent 6dc4f16689
commit 10e60ec8c1
3 changed files with 16 additions and 10 deletions

View file

@ -439,7 +439,6 @@ struct DivDispatchOscBuffer {
bool follow;
short data[65536];
// TODO: all of this
inline void putSample(uintmax_t pos, short val) {
unsigned short realPos=needle+((needleSub+pos*rateMul)>>OSCBUF_PREC);
if (val==-1) {
@ -454,8 +453,10 @@ struct DivDispatchOscBuffer {
unsigned short start=needle;
unsigned short end=needle+calc;
//logD("C %d %d %d",len,calc,rate);
if (end<start) {
logE("ELS %d %d %d",end,start,calc);
//logE("ELS %d %d %d",end,start,calc);
memset(&data[start],-1,(0x10000-start)*sizeof(short));
memset(data,-1,end*sizeof(short));
data[needle]=lastSample;
@ -466,8 +467,8 @@ struct DivDispatchOscBuffer {
}
inline void end(unsigned short len) {
uintmax_t calc=len*rateMul;
if (((calc&OSCBUF_MASK)+needleSub)>=(OSCBUF_MASK+1UL)) {
needle++;
if (((calc&OSCBUF_MASK)+needleSub)>OSCBUF_MASK) {
calc+=1UL<<OSCBUF_PREC;
}
needleSub=(needleSub+calc)&OSCBUF_MASK;
needle+=calc>>OSCBUF_PREC;

View file

@ -211,7 +211,7 @@ void DivPlatformPCSpeaker::acquire_unfilt(blip_buffer_t** bb, size_t off, size_t
}
out=(posToggle && !isMuted[0])?32767:0;
blip_add_delta(bb[0],off,out-oldOut);
oscBuf->data[oscBuf->needle++]=out;
oscBuf->putSample(0,out);
oldOut=out;
if (freq>=1) {
size_t boff=off;

View file

@ -474,9 +474,10 @@ void FurnaceGUI::drawChanOsc() {
short lastSample=0;
memset(fft->inBuf,0,FURNACE_FFT_SIZE*sizeof(double));
if (displaySize2<FURNACE_FFT_SIZE) {
for (int j=0; j<FURNACE_FFT_SIZE; j++) {
for (int j=-FURNACE_FFT_SIZE; j<FURNACE_FFT_SIZE; j++) {
const short newData=buf->data[(unsigned short)(fft->needle-displaySize2+((j*displaySize2)/(FURNACE_FFT_SIZE)))];
if (newData!=-1) lastSample=newData;
if (j<0) continue;
fft->inBuf[j]=(double)lastSample/32768.0;
if (fft->inBuf[j]>0.001 || fft->inBuf[j]<-0.001) fft->loudEnough=true;
fft->inBuf[j]*=0.55-0.45*cos(M_PI*(double)j/(double)(FURNACE_FFT_SIZE>>1));
@ -693,17 +694,19 @@ void FurnaceGUI::drawChanOsc() {
}
}
} else {
String dStr=fmt::sprintf("DS: %d P: %d",displaySize,precision);
String dStr=fmt::sprintf("DS: %d P: %d\nMAX: %d",displaySize,precision,(short)((fft->needle+displaySize)-fft->relatedBuf->needle));
dl->AddText(inRect.Min,0xffffffff,dStr.c_str());
if (displaySize<precision) {
float y=0;
for (unsigned short j=0; j<precision; j++) {
for (int j=-2048; j<precision; j++) {
const short y_s=buf->data[(unsigned short)(fft->needle+(j*displaySize/precision))];
if (y_s!=-1) {
y=(float)y_s/32768.0f;
if (j<0) continue;
if (minLevel>y) minLevel=y;
if (maxLevel<y) maxLevel=y;
}
if (j<0) continue;
float yOut=y-dcOff;
if (yOut<-0.5f) yOut=-0.5f;
if (yOut>0.5f) yOut=0.5f;
@ -712,16 +715,18 @@ void FurnaceGUI::drawChanOsc() {
}
} else {
float y=0;
int k=0;
for (unsigned short j=fft->needle; j!=fft->needle+displaySize; j++, k++) {
int k=-2048;
for (unsigned short j=fft->needle-2048; j!=fft->needle+displaySize; j++, k++) {
const short y_s=buf->data[j];
const int kTex=(k*precision)/displaySize;
if (kTex>=precision) break;
if (y_s!=-1) {
y=(float)y_s/32768.0f;
if (k<0) continue;
if (minLevel>y) minLevel=y;
if (maxLevel<y) maxLevel=y;
}
if (kTex<0) continue;
float yOut=y-dcOff;
if (yOut<-0.5f) yOut=-0.5f;
if (yOut>0.5f) yOut=0.5f;