GUI: add chan osc DC off correction strat options

off: no DC offset correction
normal: the old algorithm
high-pass: a new algorithm

also fix a hang!
This commit is contained in:
tildearrow 2025-03-17 04:07:22 -05:00
parent 30ef81779d
commit 0f4d70a34e
4 changed files with 82 additions and 53 deletions

View file

@ -183,6 +183,21 @@ void FurnaceGUI::drawChanOsc() {
if (ImGui::Checkbox(_("Randomize phase on note"),&chanOscRandomPhase)) {
}
ImGui::TableNextColumn();
ImGui::Text("DC offset correction");
ImGui::SameLine();
if (ImGui::RadioButton("Off###_cocs0",chanOscCenterStrat==0)) {
chanOscCenterStrat=0;
}
ImGui::SameLine();
if (ImGui::RadioButton("Normal###_cocs1",chanOscCenterStrat==1)) {
chanOscCenterStrat=1;
}
ImGui::SameLine();
if (ImGui::RadioButton("High-pass###_cocs2",chanOscCenterStrat==2)) {
chanOscCenterStrat=2;
}
ImGui::TableNextRow();
ImGui::TableNextColumn();
ImGui::AlignTextToFramePadding();
@ -710,6 +725,21 @@ void FurnaceGUI::drawChanOsc() {
break;
}
}
if (chanOscCenterStrat==0) { // DC correction off
fft->dcOff=0;
} else if (chanOscCenterStrat==1) { // normal DC correction
if (minLevel>y) minLevel=y;
if (maxLevel<y) maxLevel=y;
for (unsigned short j=fft->needle; j!=((fft->needle+displaySize)&0xffff); j++) {
const short y_s=buf->data[j];
if (y_s!=-1) {
y=(float)y_s/32768.0f;
if (minLevel>y) minLevel=y;
if (maxLevel<y) maxLevel=y;
}
}
fft->dcOff=(minLevel+maxLevel)*0.5f;
}
// render chan osc
if (displaySize<precision) {
for (int j=0; j<precision; j++) {
@ -722,9 +752,7 @@ void FurnaceGUI::drawChanOsc() {
}
if (j<0) continue;
float yOut=y-fft->dcOff;
if (!settings.audioHiPass) {
fft->dcOff=0;
} else {
if (chanOscCenterStrat==2) {
fft->dcOff+=(y-fft->dcOff)*0.001;
}
if (yOut<-0.5f) yOut=-0.5f;
@ -734,7 +762,7 @@ void FurnaceGUI::drawChanOsc() {
}
} else {
int k=0;
for (unsigned short j=fft->needle; j!=fft->needle+displaySize; j++, k++) {
for (unsigned short j=fft->needle; j!=((fft->needle+displaySize)&0xffff); j++, k++) {
const short y_s=buf->data[j];
const int kTex=(k*precision)/displaySize;
if (kTex>=precision) break;
@ -746,9 +774,7 @@ void FurnaceGUI::drawChanOsc() {
}
if (kTex<0) continue;
float yOut=y-fft->dcOff;
if (!settings.audioHiPass) {
fft->dcOff=0;
} else {
if (chanOscCenterStrat==2) {
fft->dcOff+=(y-fft->dcOff)*0.001;
}
if (yOut<-0.5f) yOut=-0.5f;
@ -757,7 +783,6 @@ void FurnaceGUI::drawChanOsc() {
fft->oscTex[kTex]=yOut;
}
}
//dcOff=(minLevel+maxLevel)*0.5f;
if (!(rend->supportsDrawOsc() && settings.shaderOsc)) {
for (unsigned short j=0; j<precision; j++) {