this won't build

This commit is contained in:
tildearrow 2023-09-04 18:35:18 -05:00
parent ad7b4f61b5
commit 55eeb241cf
2 changed files with 202 additions and 186 deletions

View File

@ -363,10 +363,11 @@ void FurnaceGUI::drawChanOsc() {
std::vector<int> oscChans;
int chans=e->getTotalChannelCount();
ImGuiWindow* window=ImGui::GetCurrentWindow();
ImVec2 waveform[512];
ImGuiStyle& style=ImGui::GetStyle();
ImVec2 waveform[1024];
// fill buffers
for (int i=0; i<chans; i++) {
DivDispatchOscBuffer* buf=e->getOscBuffer(i);
if (buf!=NULL && e->curSubSong->chanShow[i]) {
@ -376,45 +377,15 @@ void FurnaceGUI::drawChanOsc() {
}
}
// 0: none
// 1: sqrt(chans)
// 2: sqrt(chans+1)
// 3: sqrt(chans)+1
switch (chanOscAutoColsType) {
case 1:
chanOscCols=sqrt(oscChans.size());
break;
case 2:
chanOscCols=sqrt(oscChans.size()+1);
break;
case 3:
chanOscCols=sqrt(oscChans.size())+1;
break;
}
if (chanOscCols<1) chanOscCols=1;
if (chanOscCols>64) chanOscCols=64;
int rows=(oscBufs.size()+(chanOscCols-1))/chanOscCols;
// process
for (size_t i=0; i<oscBufs.size(); i++) {
if (i%chanOscCols==0) ImGui::TableNextRow();
ImGui::TableNextColumn();
DivDispatchOscBuffer* buf=oscBufs[i];
ChanOscStatus* fft=oscFFTs[i];
int ch=oscChans[i];
if (buf==NULL) {
ImGui::Text("Error!");
} else {
ImVec2 size=ImGui::GetContentRegionAvail();
size.y=availY/rows;
if (centerSettingReset) {
buf->readNeedle=buf->needle;
}
if (buf!=NULL) {
// check FFT status existence
if (fft->plan==NULL) {
if (!fft->ready) {
logD("creating FFT plan for channel %d",ch);
fft->inBuf=(double*)fftw_malloc(FURNACE_FFT_SIZE*sizeof(double));
fft->outBuf=(fftw_complex*)fftw_malloc(FURNACE_FFT_SIZE*sizeof(fftw_complex));
@ -423,41 +394,16 @@ void FurnaceGUI::drawChanOsc() {
fft->planI=fftw_plan_dft_c2r_1d(FURNACE_FFT_SIZE,fft->outBuf,fft->corrBuf,FFTW_ESTIMATE);
if (fft->plan==NULL) {
logE("failed to create plan!");
}
if (fft->planI==NULL) {
} else if (fft->planI==NULL) {
logE("failed to create inverse plan!");
}
if (fft->inBuf==NULL || fft->outBuf==NULL || fft->corrBuf==NULL) {
} else if (fft->inBuf==NULL || fft->outBuf==NULL || fft->corrBuf==NULL) {
logE("failed to create FFT buffers");
}
}
int displaySize=(float)(buf->rate)*(chanOscWindowSize/1000.0f);
ImVec2 minArea=window->DC.CursorPos;
ImVec2 maxArea=ImVec2(
minArea.x+size.x,
minArea.y+size.y
);
ImRect rect=ImRect(minArea,maxArea);
ImRect inRect=rect;
inRect.Min.x+=dpiScale;
inRect.Min.y+=2.0*dpiScale;
inRect.Max.x-=dpiScale;
inRect.Max.y-=2.0*dpiScale;
int precision=inRect.Max.x-inRect.Min.x;
if (precision<1) precision=1;
if (precision>512) precision=512;
ImGui::ItemSize(size,style.FramePadding.y);
if (ImGui::ItemAdd(rect,ImGui::GetID("chOscDisplay"))) {
if (!e->isRunning()) {
for (unsigned short j=0; j<precision; j++) {
float x=(float)j/(float)precision;
waveform[j]=ImLerp(inRect.Min,inRect.Max,ImVec2(x,0.5f));
}
} else {
fft->ready=true;
}
}
if (fft->ready && e->isRunning()) {
// the STRATEGY
// 1. FFT of windowed signal
// 2. inverse FFT of auto-correlation
@ -473,12 +419,13 @@ void FurnaceGUI::drawChanOsc() {
float minLevel=1.0f;
float maxLevel=-1.0f;
float dcOff=0.0f;
unsigned short needlePos=buf->needle;
bool loudEnough=false;
fft->needle=buf->needle;
// first FFT
for (int j=0; j<FURNACE_FFT_SIZE; j++) {
fft->inBuf[j]=(double)buf->data[(unsigned short)(needlePos-displaySize*2+((j*displaySize*2)/(FURNACE_FFT_SIZE)))]/32768.0;
fft->inBuf[j]=(double)buf->data[(unsigned short)(fft->needle-displaySize*2+((j*displaySize*2)/(FURNACE_FFT_SIZE)))]/32768.0;
if (fft->inBuf[j]>0.001 || fft->inBuf[j]<-0.001) loudEnough=true;
fft->inBuf[j]*=0.55-0.45*cos(M_PI*(double)j/(double)(FURNACE_FFT_SIZE>>1));
}
@ -540,7 +487,7 @@ void FurnaceGUI::drawChanOsc() {
double dft[2];
dft[0]=0.0;
dft[1]=0.0;
for (int j=needlePos-1-(displaySize>>1)-(int)waveLen, k=0; k<waveLen; j++, k++) {
for (int j=fft->needle-1-(displaySize>>1)-(int)waveLen, k=0; k<waveLen; j++, k++) {
double one=((double)buf->data[j&0xffff]/32768.0);
double two=(double)k*(-2.0*M_PI)/waveLen;
dft[0]+=one*cos(two);
@ -551,8 +498,7 @@ void FurnaceGUI::drawChanOsc() {
phase=(0.5+(atan2(dft[1],dft[0])/(2.0*M_PI)));
if (chanOscWaveCorr) {
needlePos-=phase*waveLen;
//needlePos-=(2*waveLen-fmod(displaySize,waveLen*2))*0.5;
fft->needle-=phase*waveLen;
}
}
@ -596,16 +542,16 @@ void FurnaceGUI::drawChanOsc() {
}
if (!debugFFT || !loudEnough) {
needlePos-=displaySize;
fft->needle-=displaySize;
for (unsigned short j=0; j<precision; j++) {
float y=(float)buf->data[(unsigned short)(needlePos+(j*displaySize/precision))]/32768.0f;
float y=(float)buf->data[(unsigned short)(fft->needle+(j*displaySize/precision))]/32768.0f;
if (minLevel>y) minLevel=y;
if (maxLevel<y) maxLevel=y;
}
dcOff=(minLevel+maxLevel)*0.5f;
for (unsigned short j=0; j<precision; j++) {
float x=(float)j/(float)precision;
float y=(float)buf->data[(unsigned short)(needlePos+(j*displaySize/precision))]/32768.0f;
float y=(float)buf->data[(unsigned short)(fft->needle+(j*displaySize/precision))]/32768.0f;
y-=dcOff;
if (y<-0.5f) y=-0.5f;
if (y>0.5f) y=0.5f;
@ -614,6 +560,74 @@ void FurnaceGUI::drawChanOsc() {
}
}
}
}
}
// 0: none
// 1: sqrt(chans)
// 2: sqrt(chans+1)
// 3: sqrt(chans)+1
switch (chanOscAutoColsType) {
case 1:
chanOscCols=sqrt(oscChans.size());
break;
case 2:
chanOscCols=sqrt(oscChans.size()+1);
break;
case 3:
chanOscCols=sqrt(oscChans.size())+1;
break;
}
if (chanOscCols<1) chanOscCols=1;
if (chanOscCols>64) chanOscCols=64;
int rows=(oscBufs.size()+(chanOscCols-1))/chanOscCols;
// render
for (size_t i=0; i<oscBufs.size(); i++) {
if (i%chanOscCols==0) ImGui::TableNextRow();
ImGui::TableNextColumn();
DivDispatchOscBuffer* buf=oscBufs[i];
ChanOscStatus* fft=oscFFTs[i];
int ch=oscChans[i];
if (buf==NULL) {
ImGui::Text("Error!");
} else {
ImVec2 size=ImGui::GetContentRegionAvail();
size.y=availY/rows;
ImVec2 minArea=window->DC.CursorPos;
ImVec2 maxArea=ImVec2(
minArea.x+size.x,
minArea.y+size.y
);
ImRect rect=ImRect(minArea,maxArea);
ImRect inRect=rect;
inRect.Min.x+=dpiScale;
inRect.Min.y+=2.0*dpiScale;
inRect.Max.x-=dpiScale;
inRect.Max.y-=2.0*dpiScale;
int precision=inRect.Max.x-inRect.Min.x;
if (precision<1) precision=1;
if (precision>1024) precision=1024;
if (centerSettingReset) {
buf->readNeedle=buf->needle;
}
int displaySize=(float)(buf->rate)*(chanOscWindowSize/1000.0f);
ImGui::ItemSize(size,style.FramePadding.y);
if (ImGui::ItemAdd(rect,ImGui::GetID("chOscDisplay"))) {
if (!e->isRunning()) {
for (unsigned short j=0; j<precision; j++) {
float x=(float)j/(float)precision;
waveform[j]=ImLerp(inRect.Min,inRect.Max,ImVec2(x,0.5f));
}
} else {
}
ImU32 color=ImGui::GetColorU32(chanOscColor);
if (chanOscUseGrad) {
float xVal=computeGradPos(chanOscColorX,ch);

View File

@ -2056,20 +2056,22 @@ class FurnaceGUI {
unsigned short lastCorrPos[DIV_MAX_CHANS];
struct ChanOscStatus {
double* inBuf;
fftw_complex* outBuf;
double* corrBuf;
size_t inBufPos;
double inBufPosFrac;
unsigned short needle;
fftw_complex* outBuf;
double* corrBuf;
bool ready;
fftw_plan plan;
fftw_plan planI;
ChanOscStatus():
inBuf(NULL),
outBuf(NULL),
corrBuf(NULL),
inBufPos(0),
inBufPosFrac(0.0f),
needle(0),
outBuf(NULL),
corrBuf(NULL),
ready(false),
plan(NULL),
planI(NULL) {}
} chanOscChan[DIV_MAX_CHANS];