GUI: prevent resampling under 100Hz

This commit is contained in:
tildearrow 2025-08-19 04:15:20 -05:00
parent cfb47d8b06
commit 7d9df63a39
2 changed files with 9 additions and 4 deletions

View file

@ -1189,6 +1189,7 @@ bool DivSample::resampleSinc(double sRate, double tRate) {
bool DivSample::resample(double sRate, double tRate, int filter) { bool DivSample::resample(double sRate, double tRate, int filter) {
if (depth!=DIV_SAMPLE_DEPTH_8BIT && depth!=DIV_SAMPLE_DEPTH_16BIT) return false; if (depth!=DIV_SAMPLE_DEPTH_8BIT && depth!=DIV_SAMPLE_DEPTH_16BIT) return false;
if (tRate<100) return false;
switch (filter) { switch (filter) {
case DIV_RESAMPLE_NONE: case DIV_RESAMPLE_NONE:
return resampleNone(sRate,tRate); return resampleNone(sRate,tRate);

View file

@ -1110,7 +1110,7 @@ void FurnaceGUI::drawSampleEdit() {
} }
if (ImGui::BeginPopupContextItem("SResampleOpt",ImGuiPopupFlags_MouseButtonLeft)) { if (ImGui::BeginPopupContextItem("SResampleOpt",ImGuiPopupFlags_MouseButtonLeft)) {
if (ImGui::InputDouble("Rate##SRRate",&resampleTarget,1.0,50.0,"%g")) { if (ImGui::InputDouble("Rate##SRRate",&resampleTarget,1.0,50.0,"%g")) {
if (resampleTarget<1) resampleTarget=1; if (resampleTarget<100) resampleTarget=100;
if (resampleTarget>96000) resampleTarget=96000; if (resampleTarget>96000) resampleTarget=96000;
} }
double factor=resampleTarget/(double)targetRate; double factor=resampleTarget/(double)targetRate;
@ -1118,16 +1118,18 @@ void FurnaceGUI::drawSampleEdit() {
if (ImGui::InputScalar("Length##SRLen",ImGuiDataType_U32,&targetLength, &_ONE, &_SIXTEEN)) { if (ImGui::InputScalar("Length##SRLen",ImGuiDataType_U32,&targetLength, &_ONE, &_SIXTEEN)) {
if (targetLength<1) targetLength=1; if (targetLength<1) targetLength=1;
resampleTarget=targetRate*targetLength/(double)sample->samples; resampleTarget=targetRate*targetLength/(double)sample->samples;
if (resampleTarget<1) resampleTarget=1; if (resampleTarget<100) resampleTarget=100;
if (resampleTarget>96000) resampleTarget=96000; if (resampleTarget>96000) resampleTarget=96000;
} }
if (ImGui::InputDouble(_("Factor"),&factor,0.125,0.5,"%g")) { if (ImGui::InputDouble(_("Factor"),&factor,0.125,0.5,"%g")) {
resampleTarget=(double)targetRate*factor; resampleTarget=(double)targetRate*factor;
if (resampleTarget<1) resampleTarget=1; if (resampleTarget<100) resampleTarget=100;
if (resampleTarget>96000) resampleTarget=96000; if (resampleTarget>96000) resampleTarget=96000;
} }
if (ImGui::Button("0.5x")) { if (ImGui::Button("0.5x")) {
resampleTarget*=0.5; resampleTarget*=0.5;
if (resampleTarget<100) resampleTarget=100;
if (resampleTarget>96000) resampleTarget=96000;
} }
ImGui::SameLine(); ImGui::SameLine();
if (ImGui::Button("==")) { if (ImGui::Button("==")) {
@ -1136,13 +1138,15 @@ void FurnaceGUI::drawSampleEdit() {
ImGui::SameLine(); ImGui::SameLine();
if (ImGui::Button("2.0x")) { if (ImGui::Button("2.0x")) {
resampleTarget*=2.0; resampleTarget*=2.0;
if (resampleTarget<100) resampleTarget=100;
if (resampleTarget>96000) resampleTarget=96000;
} }
ImGui::Combo(_("Filter"),&resampleStrat,LocalizedComboGetter,resampleStrats,6); ImGui::Combo(_("Filter"),&resampleStrat,LocalizedComboGetter,resampleStrats,6);
if (ImGui::Button(_("Resample"))) { if (ImGui::Button(_("Resample"))) {
sample->prepareUndo(true); sample->prepareUndo(true);
e->lockEngine([this,sample,targetRate]() { e->lockEngine([this,sample,targetRate]() {
if (!sample->resample(targetRate,resampleTarget,resampleStrat)) { if (!sample->resample(targetRate,resampleTarget,resampleStrat)) {
showError(_("couldn't resample! make sure your sample is 8 or 16-bit.")); showError(_("couldn't resample! make sure your sample is 8 or 16-bit and that the target rate is at least 100Hz."));
} }
e->renderSamples(curSample); e->renderSamples(curSample);
}); });