Adjustments to crossfade algo/slider and renaming

This commit is contained in:
LeviathaninWaves 2023-12-02 19:02:43 -06:00
parent 249ce83662
commit d59dfa30f0
4 changed files with 40 additions and 40 deletions

View file

@ -1338,7 +1338,7 @@ void FurnaceGUI::doAction(int what) {
} }
case GUI_ACTION_SAMPLE_XFADE_LOOP: case GUI_ACTION_SAMPLE_XFADE_LOOP:
if (curSample<0 || curSample>=(int)e->song.sample.size()) break; if (curSample<0 || curSample>=(int)e->song.sample.size()) break;
openSampleXFadeOpt=true; openSampleCrossFadeOpt=true;
break; break;
case GUI_ACTION_SAMPLE_FILTER: case GUI_ACTION_SAMPLE_FILTER:
if (curSample<0 || curSample>=(int)e->song.sample.size()) break; if (curSample<0 || curSample>=(int)e->song.sample.size()) break;

View file

@ -7529,8 +7529,8 @@ FurnaceGUI::FurnaceGUI():
sampleFilterRes(0.25f), sampleFilterRes(0.25f),
sampleFilterCutStart(16000.0f), sampleFilterCutStart(16000.0f),
sampleFilterCutEnd(100.0f), sampleFilterCutEnd(100.0f),
sampleXFadeLoopLength(0), sampleCrossFadeLoopLength(0),
sampleXFadeLoopLaw(50000), sampleCrossFadeLoopLaw(50),
sampleFilterPower(1), sampleFilterPower(1),
sampleClipboard(NULL), sampleClipboard(NULL),
sampleClipboardLen(0), sampleClipboardLen(0),
@ -7539,7 +7539,7 @@ FurnaceGUI::FurnaceGUI():
openSampleAmplifyOpt(false), openSampleAmplifyOpt(false),
openSampleSilenceOpt(false), openSampleSilenceOpt(false),
openSampleFilterOpt(false), openSampleFilterOpt(false),
openSampleXFadeOpt(false), openSampleCrossFadeOpt(false),
selectedPortSet(0x1fff), selectedPortSet(0x1fff),
selectedSubPort(-1), selectedSubPort(-1),
hoveredPortSet(0x1fff), hoveredPortSet(0x1fff),

View file

@ -2104,11 +2104,11 @@ class FurnaceGUI {
ImVec2 sampleDragAreaSize; ImVec2 sampleDragAreaSize;
unsigned int sampleDragLen; unsigned int sampleDragLen;
float sampleFilterL, sampleFilterB, sampleFilterH, sampleFilterRes, sampleFilterCutStart, sampleFilterCutEnd; float sampleFilterL, sampleFilterB, sampleFilterH, sampleFilterRes, sampleFilterCutStart, sampleFilterCutEnd;
int sampleXFadeLoopLength, sampleXFadeLoopLaw; int sampleCrossFadeLoopLength, sampleCrossFadeLoopLaw;
unsigned char sampleFilterPower; unsigned char sampleFilterPower;
short* sampleClipboard; short* sampleClipboard;
size_t sampleClipboardLen; size_t sampleClipboardLen;
bool openSampleResizeOpt, openSampleResampleOpt, openSampleAmplifyOpt, openSampleSilenceOpt, openSampleFilterOpt, openSampleXFadeOpt; bool openSampleResizeOpt, openSampleResampleOpt, openSampleAmplifyOpt, openSampleSilenceOpt, openSampleFilterOpt, openSampleCrossFadeOpt;
// mixer // mixer
// 0xxx: output // 0xxx: output

View file

@ -1230,58 +1230,58 @@ void FurnaceGUI::drawSampleEdit() {
if (ImGui::IsItemHovered()) { if (ImGui::IsItemHovered()) {
ImGui::SetTooltip("Crossfade loop points."); ImGui::SetTooltip("Crossfade loop points.");
} }
if (openSampleXFadeOpt) { if (openSampleCrossFadeOpt) {
openSampleXFadeOpt=false; openSampleCrossFadeOpt=false;
ImGui::OpenPopup("SXFadeOpt"); ImGui::OpenPopup("SCrossFadeOpt");
} }
if (ImGui::BeginPopupContextItem("SXFadeÓpt",ImGuiPopupFlags_MouseButtonLeft)) { if (ImGui::BeginPopupContextItem("SCrossFadeÓpt",ImGuiPopupFlags_MouseButtonLeft)) {
if (sampleXFadeLoopLength>sample->loopStart) sampleXFadeLoopLength=sample->loopStart; if (sampleCrossFadeLoopLength>sample->loopStart) sampleCrossFadeLoopLength=sample->loopStart;
if (sampleXFadeLoopLength>(sample->loopEnd-sample->loopStart)) sampleXFadeLoopLength=sample->loopEnd-sample->loopStart; if (sampleCrossFadeLoopLength>(sample->loopEnd-sample->loopStart)) sampleCrossFadeLoopLength=sample->loopEnd-sample->loopStart;
if (ImGui::SliderInt("Number of samples", &sampleXFadeLoopLength, 0, 100000)) { if (ImGui::SliderInt("Number of samples", &sampleCrossFadeLoopLength, 0, 100000)) {
if (sampleXFadeLoopLength<0) sampleXFadeLoopLength=0; if (sampleCrossFadeLoopLength<0) sampleCrossFadeLoopLength=0;
if (sampleXFadeLoopLength>sample->loopStart) sampleXFadeLoopLength=sample->loopStart; if (sampleCrossFadeLoopLength>sample->loopStart) sampleCrossFadeLoopLength=sample->loopStart;
if (sampleXFadeLoopLength>(sample->loopEnd-sample->loopStart)) sampleXFadeLoopLength=sample->loopEnd-sample->loopStart; if (sampleCrossFadeLoopLength>(sample->loopEnd-sample->loopStart)) sampleCrossFadeLoopLength=sample->loopEnd-sample->loopStart;
if (sampleXFadeLoopLength>100000) sampleXFadeLoopLength=100000; if (sampleCrossFadeLoopLength>100000) sampleCrossFadeLoopLength=100000;
} }
if (ImGui::SliderInt("Linear <-> Equal power", &sampleXFadeLoopLaw, 0, 100000)) { if (ImGui::SliderInt("Linear <-> Equal power", &sampleCrossFadeLoopLaw, 0, 100)) {
if (sampleXFadeLoopLaw<0) sampleXFadeLoopLaw=0; if (sampleCrossFadeLoopLaw<0) sampleCrossFadeLoopLaw=0;
if (sampleXFadeLoopLaw>100000) sampleXFadeLoopLaw=100000; if (sampleCrossFadeLoopLaw>100) sampleCrossFadeLoopLaw=100;
} }
if (ImGui::Button("Apply")) { if (ImGui::Button("Apply")) {
if (sampleXFadeLoopLength>sample->loopStart){ if (sampleCrossFadeLoopLength>sample->loopStart){
SAMPLE_WARN(warnLoop,"Crossfade: length would go out of bounds. Aborted..."); SAMPLE_WARN(warnLoop,"Crossfade: length would go out of bounds. Aborted...");
goto done; 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."); SAMPLE_WARN(warnLoop,"Crossfade: length would overflow loopStart. Try a smaller random value.");
goto done; goto done;
} }
sample->prepareUndo(true); sample->prepareUndo(true);
e->lockEngine([this,sample]{ e->lockEngine([this,sample]{
SAMPLE_OP_BEGIN; SAMPLE_OP_BEGIN;
double l=1.0/(double)sampleXFadeLoopLength; double l=1.0/(double)sampleCrossFadeLoopLength;
double evar=1.0-sampleXFadeLoopLaw/200000.0; double evar=1.0-sampleCrossFadeLoopLaw/200.0;
if (sample->depth==DIV_SAMPLE_DEPTH_8BIT) { if (sample->depth==DIV_SAMPLE_DEPTH_8BIT) {
unsigned int xfadeInput=sample->loopStart-sampleXFadeLoopLength; unsigned int crossFadeInput=sample->loopStart-sampleCrossFadeLoopLength;
unsigned int xfadeOutput=sample->loopEnd-sampleXFadeLoopLength; unsigned int crossFadeOutput=sample->loopEnd-sampleCrossFadeLoopLength;
for (int i=0;i<sampleXFadeLoopLength;i++) { for (int i=0;i<sampleCrossFadeLoopLength;i++) {
double f1=std::pow(i*l,evar); double f1=std::pow(i*l,evar);
double f2=std::pow((sampleXFadeLoopLength-i)*l, evar); double f2=std::pow((sampleCrossFadeLoopLength-i)*l, evar);
signed char out=(signed char)(((double)sample->data8[xfadeInput])*f1+((double)sample->data8[xfadeOutput])*f2); signed char out=(signed char)(((double)sample->data8[crossFadeInput])*f1+((double)sample->data8[crossFadeOutput])*f2);
sample->data8[xfadeOutput]=out; sample->data8[crossFadeOutput]=out;
xfadeInput++; crossFadeInput++;
xfadeOutput++; crossFadeOutput++;
} }
} else if (sample->depth==DIV_SAMPLE_DEPTH_16BIT) { } else if (sample->depth==DIV_SAMPLE_DEPTH_16BIT) {
unsigned int xfadeInput=sample->loopStart-sampleXFadeLoopLength; unsigned int crossFadeInput=sample->loopStart-sampleCrossFadeLoopLength;
unsigned int xfadeOutput=sample->loopEnd-sampleXFadeLoopLength; unsigned int crossFadeOutput=sample->loopEnd-sampleCrossFadeLoopLength;
for (int i=0;i<sampleXFadeLoopLength;i++) { for (int i=0;i<sampleCrossFadeLoopLength;i++) {
double f1=std::pow(i*l,evar); double f1=std::pow(i*l,evar);
double f2=std::pow((sampleXFadeLoopLength-i)*l,evar); double f2=std::pow((sampleCrossFadeLoopLength-i)*l,evar);
short out = (short)(((double)sample->data16[xfadeInput])*f1+((double)sample->data16[xfadeOutput])*f2); short out = (short)(((double)sample->data16[crossFadeInput])*f1+((double)sample->data16[crossFadeOutput])*f2);
sample->data16[xfadeOutput]=out; sample->data16[crossFadeOutput]=out;
xfadeInput++; crossFadeInput++;
xfadeOutput++; crossFadeOutput++;
} }
} }
updateSampleTex=true; updateSampleTex=true;