mirror of
https://github.com/tildearrow/furnace.git
synced 2024-11-23 21:15:11 +00:00
GUI: much more stable osc view
This commit is contained in:
parent
0895789539
commit
ead4a05348
1 changed files with 35 additions and 9 deletions
|
@ -22,8 +22,9 @@
|
||||||
#include "imgui.h"
|
#include "imgui.h"
|
||||||
#include "imgui_internal.h"
|
#include "imgui_internal.h"
|
||||||
|
|
||||||
#define FURNACE_FFT_SIZE 8192
|
#define FURNACE_FFT_SIZE 4096
|
||||||
#define FURNACE_FFT_RATE 80.0
|
#define FURNACE_FFT_RATE 80.0
|
||||||
|
#define FURNACE_FFT_CUTOFF 0.1
|
||||||
|
|
||||||
void FurnaceGUI::drawChanOsc() {
|
void FurnaceGUI::drawChanOsc() {
|
||||||
if (nextWindow==GUI_WINDOW_CHAN_OSC) {
|
if (nextWindow==GUI_WINDOW_CHAN_OSC) {
|
||||||
|
@ -34,6 +35,7 @@ void FurnaceGUI::drawChanOsc() {
|
||||||
if (!chanOscOpen) return;
|
if (!chanOscOpen) return;
|
||||||
ImGui::SetNextWindowSizeConstraints(ImVec2(64.0f*dpiScale,32.0f*dpiScale),ImVec2(scrW*dpiScale,scrH*dpiScale));
|
ImGui::SetNextWindowSizeConstraints(ImVec2(64.0f*dpiScale,32.0f*dpiScale),ImVec2(scrW*dpiScale,scrH*dpiScale));
|
||||||
if (ImGui::Begin("Oscilloscope (per-channel)",&chanOscOpen,globalWinFlags)) {
|
if (ImGui::Begin("Oscilloscope (per-channel)",&chanOscOpen,globalWinFlags)) {
|
||||||
|
bool centerSettingReset=false;
|
||||||
if (ImGui::BeginTable("ChanOscSettings",3)) {
|
if (ImGui::BeginTable("ChanOscSettings",3)) {
|
||||||
ImGui::TableNextRow();
|
ImGui::TableNextRow();
|
||||||
ImGui::TableNextColumn();
|
ImGui::TableNextColumn();
|
||||||
|
@ -55,7 +57,9 @@ void FurnaceGUI::drawChanOsc() {
|
||||||
}
|
}
|
||||||
|
|
||||||
ImGui::TableNextColumn();
|
ImGui::TableNextColumn();
|
||||||
ImGui::Checkbox("Center waveform",&chanOscWaveCorr);
|
if (ImGui::Checkbox("Center waveform",&chanOscWaveCorr)) {
|
||||||
|
centerSettingReset=true;
|
||||||
|
}
|
||||||
|
|
||||||
ImGui::EndTable();
|
ImGui::EndTable();
|
||||||
}
|
}
|
||||||
|
@ -98,6 +102,10 @@ void FurnaceGUI::drawChanOsc() {
|
||||||
ImVec2 size=ImGui::GetContentRegionAvail();
|
ImVec2 size=ImGui::GetContentRegionAvail();
|
||||||
size.y=availY/rows;
|
size.y=availY/rows;
|
||||||
|
|
||||||
|
if (centerSettingReset) {
|
||||||
|
buf->readNeedle=buf->needle;
|
||||||
|
}
|
||||||
|
|
||||||
// check FFT status existence
|
// check FFT status existence
|
||||||
if (fft->plan==NULL) {
|
if (fft->plan==NULL) {
|
||||||
logD("creating FFT plan for channel %d",ch);
|
logD("creating FFT plan for channel %d",ch);
|
||||||
|
@ -129,11 +137,14 @@ void FurnaceGUI::drawChanOsc() {
|
||||||
} else {
|
} else {
|
||||||
unsigned short needlePos=buf->needle;
|
unsigned short needlePos=buf->needle;
|
||||||
if (chanOscWaveCorr) {
|
if (chanOscWaveCorr) {
|
||||||
|
/*
|
||||||
double fftDataRate=(FURNACE_FFT_SIZE*FURNACE_FFT_RATE)/((double)buf->rate);
|
double fftDataRate=(FURNACE_FFT_SIZE*FURNACE_FFT_RATE)/((double)buf->rate);
|
||||||
while (buf->readNeedle!=needlePos) {
|
while (buf->readNeedle!=needlePos) {
|
||||||
fft->inBufPosFrac+=fftDataRate;
|
fft->inBufPosFrac+=fftDataRate;
|
||||||
while (fft->inBufPosFrac>=1.0) {
|
while (fft->inBufPosFrac>=1.0) {
|
||||||
fft->inBuf[fft->inBufPos]=(double)buf->data[buf->readNeedle]/32768.0;
|
chanOscLP0[ch]+=FURNACE_FFT_CUTOFF*((float)buf->data[buf->readNeedle]-chanOscLP0[ch]);
|
||||||
|
chanOscLP1[ch]+=FURNACE_FFT_CUTOFF*(chanOscLP0[ch]-chanOscLP1[ch]);
|
||||||
|
fft->inBuf[fft->inBufPos]=(double)chanOscLP1[ch]/32768.0;
|
||||||
if (++fft->inBufPos>=FURNACE_FFT_SIZE) {
|
if (++fft->inBufPos>=FURNACE_FFT_SIZE) {
|
||||||
fftw_execute(fft->plan);
|
fftw_execute(fft->plan);
|
||||||
fft->inBufPos=0;
|
fft->inBufPos=0;
|
||||||
|
@ -142,7 +153,12 @@ void FurnaceGUI::drawChanOsc() {
|
||||||
fft->inBufPosFrac-=1.0;
|
fft->inBufPosFrac-=1.0;
|
||||||
}
|
}
|
||||||
buf->readNeedle++;
|
buf->readNeedle++;
|
||||||
|
}*/
|
||||||
|
|
||||||
|
for (int i=0; i<FURNACE_FFT_SIZE; i++) {
|
||||||
|
fft->inBuf[i]=(double)buf->data[(unsigned short)(needlePos-displaySize*2+((i*displaySize*2)/FURNACE_FFT_SIZE))]/32768.0;
|
||||||
}
|
}
|
||||||
|
fftw_execute(fft->plan);
|
||||||
|
|
||||||
// find origin frequency
|
// find origin frequency
|
||||||
int point=1;
|
int point=1;
|
||||||
|
@ -159,14 +175,24 @@ void FurnaceGUI::drawChanOsc() {
|
||||||
|
|
||||||
// PHASE
|
// PHASE
|
||||||
fftw_complex& candPoint=fft->outBuf[point];
|
fftw_complex& candPoint=fft->outBuf[point];
|
||||||
double phase=((double)buf->rate/(FURNACE_FFT_RATE*point))*(0.5+(atan2(candPoint[1],candPoint[0])/(M_PI*2)));
|
double phase=((double)(displaySize*2)/(double)point)*(0.5+(atan2(candPoint[1],candPoint[0])/(M_PI*2)));
|
||||||
|
|
||||||
//printf("%d cphase: %f\n",ch,phase*((double)buf->rate/FURNACE_FFT_RATE));
|
//needlePos=fft->needle;
|
||||||
//String cPhase=fmt::sprintf("%d cphase: %f\n",point,phase);
|
|
||||||
//dl->AddText(inRect.Min,0xffffffff,cPhase.c_str());
|
|
||||||
|
|
||||||
needlePos=fft->needle;
|
|
||||||
needlePos-=phase;
|
needlePos-=phase;
|
||||||
|
|
||||||
|
/*
|
||||||
|
int alignment=0;
|
||||||
|
for (unsigned short i=0; i<displaySize; i++) {
|
||||||
|
if (fabs(buf->data[(unsigned short)(needlePos-i)])>fabs(buf->data[(unsigned short)(needlePos-alignment)])) {
|
||||||
|
alignment=i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
needlePos-=alignment;
|
||||||
|
*/
|
||||||
|
|
||||||
|
String cPhase=fmt::sprintf("%d cphase: %f",point,phase);
|
||||||
|
dl->AddText(inRect.Min,0xffffffff,cPhase.c_str());
|
||||||
|
|
||||||
needlePos-=displaySize;
|
needlePos-=displaySize;
|
||||||
for (unsigned short i=0; i<512; i++) {
|
for (unsigned short i=0; i<512; i++) {
|
||||||
float x=(float)i/512.0f;
|
float x=(float)i/512.0f;
|
||||||
|
|
Loading…
Reference in a new issue