From d9c671d14dacf3d7c02305df9b7d5fba67357a55 Mon Sep 17 00:00:00 2001 From: Bent Bisballe Nyeng Date: Sun, 12 Apr 2020 18:16:50 +0200 Subject: Add setting and knob for controlling resampling quality. --- src/drumgizmo.cc | 19 +++++++++++++------ src/drumgizmo.h | 2 +- src/settings.h | 5 +++++ 3 files changed, 19 insertions(+), 7 deletions(-) (limited to 'src') diff --git a/src/drumgizmo.cc b/src/drumgizmo.cc index fcc54ad..3af5cbc 100644 --- a/src/drumgizmo.cc +++ b/src/drumgizmo.cc @@ -53,7 +53,7 @@ DrumGizmo::DrumGizmo(Settings& settings, audio_cache.init(10000); // start thread events.reserve(1000); loader.init(); - setSamplerate(44100.0f); + setSamplerate(44100.0f, settings.resampling_quality.load()); settings_getter.audition_counter.hasChanged(); // Reset audition_counter } @@ -114,10 +114,15 @@ bool DrumGizmo::run(size_t pos, sample_t *samples, size_t nsamples) enable_resampling = settings_getter.enable_resampling.getValue(); } - if(settings_getter.drumkit_samplerate.hasChanged()) { - settings_getter.drumkit_samplerate.getValue(); // stage new value - setSamplerate(settings.samplerate.load()); + auto sample_rate_changed = settings_getter.drumkit_samplerate.hasChanged(); + auto resampling_quality_changed = settings_getter.resampling_quality.hasChanged(); + if(sample_rate_changed || resampling_quality_changed) + { + settings_getter.drumkit_samplerate.getValue(); // stage new value + setSamplerate(settings.samplerate.load(), + settings_getter.resampling_quality.getValue()); + } } setFrameSize(nsamples); @@ -414,7 +419,7 @@ float DrumGizmo::samplerate() return settings.samplerate.load(); } -void DrumGizmo::setSamplerate(float samplerate) +void DrumGizmo::setSamplerate(float samplerate, float resampling_quality) { DEBUG(dgeditor, "%s samplerate: %f\n", __PRETTY_FUNCTION__, samplerate); settings.samplerate.store(samplerate); @@ -438,7 +443,9 @@ void DrumGizmo::setSamplerate(float samplerate) { zita[c].reset(); auto nchan = 1u; // mono - auto hlen = 72u; // 16 ≤ hlen ≤ 96 + // 16 ≤ hlen ≤ 96 - default is 72, q: 0.7f + resampling_quality = std::max(0.0f, std::min(1.0f, resampling_quality)); + std::size_t hlen = 16 + (96 - 16) * resampling_quality; zita[c].setup(input_fs, output_fs, nchan, hlen); // Prefill diff --git a/src/drumgizmo.h b/src/drumgizmo.h index 0aeab07..a075dd6 100644 --- a/src/drumgizmo.h +++ b/src/drumgizmo.h @@ -67,7 +67,7 @@ public: std::size_t getLatency() const; float samplerate(); - void setSamplerate(float samplerate); + void setSamplerate(float samplerate, float resample_quality = 0.7f); void setFrameSize(size_t framesize); diff --git a/src/settings.h b/src/settings.h index a3d21d0..7749adf 100644 --- a/src/settings.h +++ b/src/settings.h @@ -103,6 +103,7 @@ struct Settings Atomic enable_resampling{true}; Atomic resampling_recommended{false}; + Atomic resampling_quality{0.7f}; // [0.0f; 1.0f] Atomic number_of_files{0}; Atomic number_of_files_loaded{0}; @@ -205,6 +206,7 @@ struct SettingsGetter SettingRef enable_resampling; SettingRef resampling_recommended; + SettingRef resampling_quality; SettingRef number_of_files; SettingRef number_of_files_loaded; @@ -270,6 +272,7 @@ struct SettingsGetter , buffer_size(settings.buffer_size) , enable_resampling{settings.enable_resampling} , resampling_recommended{settings.resampling_recommended} + , resampling_quality{settings.resampling_quality} , number_of_files{settings.number_of_files} , number_of_files_loaded{settings.number_of_files_loaded} , current_file{settings.current_file} @@ -339,6 +342,7 @@ public: Notifier enable_resampling; Notifier resampling_recommended; + Notifier resampling_quality; Notifier number_of_files; Notifier number_of_files_loaded; @@ -413,6 +417,7 @@ public: EVAL(enable_resampling); EVAL(resampling_recommended); + EVAL(resampling_quality); EVAL(number_of_files); EVAL(number_of_files_loaded); -- cgit v1.2.3