From d59dfa30f066092ab6d8faf487e4d9ebd3c8a83f Mon Sep 17 00:00:00 2001 From: LeviathaninWaves Date: Sat, 2 Dec 2023 19:02:43 -0600 Subject: [PATCH] Adjustments to crossfade algo/slider and renaming --- src/gui/doAction.cpp | 2 +- src/gui/gui.cpp | 6 ++-- src/gui/gui.h | 4 +-- src/gui/sampleEdit.cpp | 68 +++++++++++++++++++++--------------------- 4 files changed, 40 insertions(+), 40 deletions(-) diff --git a/src/gui/doAction.cpp b/src/gui/doAction.cpp index afd6de957..7e998af91 100644 --- a/src/gui/doAction.cpp +++ b/src/gui/doAction.cpp @@ -1338,7 +1338,7 @@ void FurnaceGUI::doAction(int what) { } case GUI_ACTION_SAMPLE_XFADE_LOOP: if (curSample<0 || curSample>=(int)e->song.sample.size()) break; - openSampleXFadeOpt=true; + openSampleCrossFadeOpt=true; break; case GUI_ACTION_SAMPLE_FILTER: if (curSample<0 || curSample>=(int)e->song.sample.size()) break; diff --git a/src/gui/gui.cpp b/src/gui/gui.cpp index 50808e689..d032cc805 100644 --- a/src/gui/gui.cpp +++ b/src/gui/gui.cpp @@ -7529,8 +7529,8 @@ FurnaceGUI::FurnaceGUI(): sampleFilterRes(0.25f), sampleFilterCutStart(16000.0f), sampleFilterCutEnd(100.0f), - sampleXFadeLoopLength(0), - sampleXFadeLoopLaw(50000), + sampleCrossFadeLoopLength(0), + sampleCrossFadeLoopLaw(50), sampleFilterPower(1), sampleClipboard(NULL), sampleClipboardLen(0), @@ -7539,7 +7539,7 @@ FurnaceGUI::FurnaceGUI(): openSampleAmplifyOpt(false), openSampleSilenceOpt(false), openSampleFilterOpt(false), - openSampleXFadeOpt(false), + openSampleCrossFadeOpt(false), selectedPortSet(0x1fff), selectedSubPort(-1), hoveredPortSet(0x1fff), diff --git a/src/gui/gui.h b/src/gui/gui.h index 686f9b966..704e3475b 100644 --- a/src/gui/gui.h +++ b/src/gui/gui.h @@ -2104,11 +2104,11 @@ class FurnaceGUI { ImVec2 sampleDragAreaSize; unsigned int sampleDragLen; float sampleFilterL, sampleFilterB, sampleFilterH, sampleFilterRes, sampleFilterCutStart, sampleFilterCutEnd; - int sampleXFadeLoopLength, sampleXFadeLoopLaw; + int sampleCrossFadeLoopLength, sampleCrossFadeLoopLaw; unsigned char sampleFilterPower; short* sampleClipboard; size_t sampleClipboardLen; - bool openSampleResizeOpt, openSampleResampleOpt, openSampleAmplifyOpt, openSampleSilenceOpt, openSampleFilterOpt, openSampleXFadeOpt; + bool openSampleResizeOpt, openSampleResampleOpt, openSampleAmplifyOpt, openSampleSilenceOpt, openSampleFilterOpt, openSampleCrossFadeOpt; // mixer // 0xxx: output diff --git a/src/gui/sampleEdit.cpp b/src/gui/sampleEdit.cpp index 53ff39c3e..78a8aa9e5 100644 --- a/src/gui/sampleEdit.cpp +++ b/src/gui/sampleEdit.cpp @@ -1230,58 +1230,58 @@ void FurnaceGUI::drawSampleEdit() { if (ImGui::IsItemHovered()) { ImGui::SetTooltip("Crossfade loop points."); } - if (openSampleXFadeOpt) { - openSampleXFadeOpt=false; - ImGui::OpenPopup("SXFadeOpt"); + if (openSampleCrossFadeOpt) { + openSampleCrossFadeOpt=false; + ImGui::OpenPopup("SCrossFadeOpt"); } - if (ImGui::BeginPopupContextItem("SXFadeÓpt",ImGuiPopupFlags_MouseButtonLeft)) { - if (sampleXFadeLoopLength>sample->loopStart) sampleXFadeLoopLength=sample->loopStart; - if (sampleXFadeLoopLength>(sample->loopEnd-sample->loopStart)) sampleXFadeLoopLength=sample->loopEnd-sample->loopStart; - if (ImGui::SliderInt("Number of samples", &sampleXFadeLoopLength, 0, 100000)) { - if (sampleXFadeLoopLength<0) sampleXFadeLoopLength=0; - if (sampleXFadeLoopLength>sample->loopStart) sampleXFadeLoopLength=sample->loopStart; - if (sampleXFadeLoopLength>(sample->loopEnd-sample->loopStart)) sampleXFadeLoopLength=sample->loopEnd-sample->loopStart; - if (sampleXFadeLoopLength>100000) sampleXFadeLoopLength=100000; + if (ImGui::BeginPopupContextItem("SCrossFadeÓpt",ImGuiPopupFlags_MouseButtonLeft)) { + if (sampleCrossFadeLoopLength>sample->loopStart) sampleCrossFadeLoopLength=sample->loopStart; + if (sampleCrossFadeLoopLength>(sample->loopEnd-sample->loopStart)) sampleCrossFadeLoopLength=sample->loopEnd-sample->loopStart; + if (ImGui::SliderInt("Number of samples", &sampleCrossFadeLoopLength, 0, 100000)) { + if (sampleCrossFadeLoopLength<0) sampleCrossFadeLoopLength=0; + if (sampleCrossFadeLoopLength>sample->loopStart) sampleCrossFadeLoopLength=sample->loopStart; + if (sampleCrossFadeLoopLength>(sample->loopEnd-sample->loopStart)) sampleCrossFadeLoopLength=sample->loopEnd-sample->loopStart; + if (sampleCrossFadeLoopLength>100000) sampleCrossFadeLoopLength=100000; } - if (ImGui::SliderInt("Linear <-> Equal power", &sampleXFadeLoopLaw, 0, 100000)) { - if (sampleXFadeLoopLaw<0) sampleXFadeLoopLaw=0; - if (sampleXFadeLoopLaw>100000) sampleXFadeLoopLaw=100000; + if (ImGui::SliderInt("Linear <-> Equal power", &sampleCrossFadeLoopLaw, 0, 100)) { + if (sampleCrossFadeLoopLaw<0) sampleCrossFadeLoopLaw=0; + if (sampleCrossFadeLoopLaw>100) sampleCrossFadeLoopLaw=100; } if (ImGui::Button("Apply")) { - if (sampleXFadeLoopLength>sample->loopStart){ + if (sampleCrossFadeLoopLength>sample->loopStart){ SAMPLE_WARN(warnLoop,"Crossfade: length would go out of bounds. Aborted..."); goto done; } - if (sampleXFadeLoopLength>(sample->loopEnd-sample->loopStart)) { + if (sampleCrossFadeLoopLength>(sample->loopEnd-sample->loopStart)) { SAMPLE_WARN(warnLoop,"Crossfade: length would overflow loopStart. Try a smaller random value."); goto done; } sample->prepareUndo(true); e->lockEngine([this,sample]{ SAMPLE_OP_BEGIN; - double l=1.0/(double)sampleXFadeLoopLength; - double evar=1.0-sampleXFadeLoopLaw/200000.0; + double l=1.0/(double)sampleCrossFadeLoopLength; + double evar=1.0-sampleCrossFadeLoopLaw/200.0; if (sample->depth==DIV_SAMPLE_DEPTH_8BIT) { - unsigned int xfadeInput=sample->loopStart-sampleXFadeLoopLength; - unsigned int xfadeOutput=sample->loopEnd-sampleXFadeLoopLength; - for (int i=0;iloopStart-sampleCrossFadeLoopLength; + unsigned int crossFadeOutput=sample->loopEnd-sampleCrossFadeLoopLength; + for (int i=0;idata8[xfadeInput])*f1+((double)sample->data8[xfadeOutput])*f2); - sample->data8[xfadeOutput]=out; - xfadeInput++; - xfadeOutput++; + double f2=std::pow((sampleCrossFadeLoopLength-i)*l, evar); + signed char out=(signed char)(((double)sample->data8[crossFadeInput])*f1+((double)sample->data8[crossFadeOutput])*f2); + sample->data8[crossFadeOutput]=out; + crossFadeInput++; + crossFadeOutput++; } } else if (sample->depth==DIV_SAMPLE_DEPTH_16BIT) { - unsigned int xfadeInput=sample->loopStart-sampleXFadeLoopLength; - unsigned int xfadeOutput=sample->loopEnd-sampleXFadeLoopLength; - for (int i=0;iloopStart-sampleCrossFadeLoopLength; + unsigned int crossFadeOutput=sample->loopEnd-sampleCrossFadeLoopLength; + for (int i=0;idata16[xfadeInput])*f1+((double)sample->data16[xfadeOutput])*f2); - sample->data16[xfadeOutput]=out; - xfadeInput++; - xfadeOutput++; + double f2=std::pow((sampleCrossFadeLoopLength-i)*l,evar); + short out = (short)(((double)sample->data16[crossFadeInput])*f1+((double)sample->data16[crossFadeOutput])*f2); + sample->data16[crossFadeOutput]=out; + crossFadeInput++; + crossFadeOutput++; } } updateSampleTex=true;