GUI: add non-mono mode to osc

This commit is contained in:
tildearrow 2023-08-05 03:26:36 -05:00
parent bf77b95ec9
commit 1983529bdb
5 changed files with 162 additions and 56 deletions

View file

@ -47,56 +47,47 @@ void FurnaceGUI::readOsc() {
if (total>avail) total=avail;
//printf("total: %d. avail: %d bias: %d\n",total,avail,bias);
memset(oscValues,0,1024*sizeof(float));
int winSize=e->getAudioDescGot().rate*(oscWindowSize/1000.0);
int oscReadPos=(writePos-winSize)&0x7fff;
float* sincITable=DivFilterTables::getSincIntegralTable();
float posFrac=0.0;
int posInt=oscReadPos;
float factor=(float)oscWidth/(float)winSize;
for (int i=0; i<oscWidth; i++) {
float avg=0.0f;
float prevAvg=0.0f;
for (int j=0; j<e->getAudioDescGot().outChans; j++) {
avg+=e->oscBuf[j][posInt&0x7fff];
for (int ch=0; ch<e->getAudioDescGot().outChans; ch++) {
if (oscValues[ch]==NULL) {
oscValues[ch]=new float[1024];
}
avg/=e->getAudioDescGot().outChans;
oscValues[i]+=avg;
memset(oscValues[ch],0,1024*sizeof(float));
float* sincITable=DivFilterTables::getSincIntegralTable();
posFrac+=1.0;
while (posFrac>=1.0) {
unsigned int n=((unsigned int)(posFrac*8192.0))&8191;
posFrac-=factor;
posInt++;
float posFrac=0.0;
int posInt=oscReadPos;
float factor=(float)oscWidth/(float)winSize;
for (int i=0; i<oscWidth; i++) {
oscValues[ch][i]+=e->oscBuf[ch][posInt&0x7fff];
prevAvg=avg;
avg=0.0f;
for (int j=0; j<e->getAudioDescGot().outChans; j++) {
avg+=e->oscBuf[j][posInt&0x7fff];
}
avg/=e->getAudioDescGot().outChans;
posFrac+=1.0;
while (posFrac>=1.0) {
unsigned int n=((unsigned int)(posFrac*8192.0))&8191;
posFrac-=factor;
posInt++;
float* t1=&sincITable[(8191-n)<<3];
float* t2=&sincITable[n<<3];
float delta=avg-prevAvg;
float* t1=&sincITable[(8191-n)<<3];
float* t2=&sincITable[n<<3];
float delta=e->oscBuf[ch][posInt&0x7fff]-e->oscBuf[ch][(posInt-1)&0x7fff];
for (int j=0; j<8; j++) {
if (i-j>0) {
oscValues[i-j]+=t1[j]*-delta;
}
if (i+j+1<oscWidth) {
oscValues[i+j+1]+=t2[j]*delta;
for (int j=0; j<8; j++) {
if (i-j>0) {
oscValues[ch][i-j]+=t1[j]*-delta;
}
if (i+j+1<oscWidth) {
oscValues[ch][i+j+1]+=t2[j]*delta;
}
}
}
}
}
for (int i=0; i<oscWidth; i++) {
if (oscValues[i]>0.001f || oscValues[i]<-0.001f) {
WAKE_UP;
for (int i=0; i<oscWidth; i++) {
if (oscValues[ch][i]>0.001f || oscValues[ch][i]<-0.001f) {
WAKE_UP;
}
}
}
@ -259,25 +250,63 @@ void FurnaceGUI::drawOsc() {
if (oscWidth<1) oscWidth=1;
if (oscWidth>1024) oscWidth=1024;
for (int i=0; i<oscWidth; i++) {
float x=(float)i/(float)oscWidth;
float y=oscValues[i]*oscZoom;
if (!settings.oscEscapesBoundary) {
if (y<-0.5f) y=-0.5f;
if (y>0.5f) y=0.5f;
ImDrawListFlags prevFlags=dl->Flags;
if (!settings.oscAntiAlias) {
dl->Flags&=~(ImDrawListFlags_AntiAliasedLines|ImDrawListFlags_AntiAliasedLinesUseTex);
}
if (settings.oscMono) {
for (int i=0; i<oscWidth; i++) {
float x=(float)i/(float)oscWidth;
float avg=0;
for (int j=0; j<e->getAudioDescGot().outChans; j++) {
avg+=oscValues[j][i];
}
avg/=e->getAudioDescGot().outChans;
float y=avg*oscZoom;
if (!settings.oscEscapesBoundary) {
if (y<-0.5f) y=-0.5f;
if (y>0.5f) y=0.5f;
}
waveform[i]=ImLerp(inRect.Min,inRect.Max,ImVec2(x,0.5f-y));
}
if (settings.oscEscapesBoundary) {
dl->PushClipRectFullScreen();
dl->AddPolyline(waveform,oscWidth,color,ImDrawFlags_None,dpiScale);
dl->PopClipRect();
} else {
dl->AddPolyline(waveform,oscWidth,color,ImDrawFlags_None,dpiScale);
}
waveform[i]=ImLerp(inRect.Min,inRect.Max,ImVec2(x,0.5f-y));
}
//ImDrawListFlags prevFlags=dl->Flags;
//dl->Flags&=~(ImDrawListFlags_AntiAliasedLines|ImDrawListFlags_AntiAliasedLinesUseTex);
if (settings.oscEscapesBoundary) {
dl->PushClipRectFullScreen();
dl->AddPolyline(waveform,oscWidth,color,ImDrawFlags_None,dpiScale);
dl->PopClipRect();
} else {
dl->AddPolyline(waveform,oscWidth,color,ImDrawFlags_None,dpiScale);
for (int ch=0; ch<e->getAudioDescGot().outChans; ch++) {
for (int i=0; i<oscWidth; i++) {
float x=(float)i/(float)oscWidth;
float y=oscValues[ch][i]*oscZoom;
if (!settings.oscEscapesBoundary) {
if (y<-0.5f) y=-0.5f;
if (y>0.5f) y=0.5f;
}
waveform[i]=ImLerp(inRect.Min,inRect.Max,ImVec2(x,0.5f-y));
}
if (!isClipping) {
color=ImGui::GetColorU32(uiColors[GUI_COLOR_OSC_WAVE_CH0+ch]);
}
if (settings.oscEscapesBoundary) {
dl->PushClipRectFullScreen();
dl->AddPolyline(waveform,oscWidth,color,ImDrawFlags_None,dpiScale);
dl->PopClipRect();
} else {
dl->AddPolyline(waveform,oscWidth,color,ImDrawFlags_None,dpiScale);
}
}
}
//dl->Flags=prevFlags;
dl->Flags=prevFlags;
if (settings.oscBorder) {
dl->AddRect(inRect.Min,inRect.Max,borderColor,settings.oscRoundedCorners?(8.0f*dpiScale):0.0f,0,1.5f*dpiScale);
}