From 751db481a699d80a1aeec014920f6c972b25b9bd Mon Sep 17 00:00:00 2001 From: Robin Gareus Date: Fri, 25 Sep 2020 17:08:21 +0200 Subject: [PATCH] Use linear fades for loop-range cross-fades The cross-over point of an exponential fade occurs further towards start of the fade. This increases consistency of cross-fades moving the cross-over point to the center of the fade. Also looped material is likely correlated in which a linear fade is more appropriate. --- libs/ardour/ardour/disk_reader.h | 2 +- libs/ardour/disk_reader.cc | 22 +++++++++++++++++++--- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/libs/ardour/ardour/disk_reader.h b/libs/ardour/ardour/disk_reader.h index d9773bbeba..14ca54a07c 100644 --- a/libs/ardour/ardour/disk_reader.h +++ b/libs/ardour/ardour/disk_reader.h @@ -181,7 +181,7 @@ protected: Declicker (); ~Declicker (); - void alloc (samplecnt_t sr, bool fadein); + void alloc (samplecnt_t sr, bool fadein, bool linear); void run (Sample* buf, samplepos_t start, samplepos_t end); void reset (samplepos_t start, samplepos_t end, bool fadein, samplecnt_t sr); diff --git a/libs/ardour/disk_reader.cc b/libs/ardour/disk_reader.cc index 95904fa171..607f5fdefc 100644 --- a/libs/ardour/disk_reader.cc +++ b/libs/ardour/disk_reader.cc @@ -1643,11 +1643,27 @@ DiskReader::Declicker::~Declicker () } void -DiskReader::Declicker::alloc (samplecnt_t sr, bool fadein) +DiskReader::Declicker::alloc (samplecnt_t sr, bool fadein, bool linear) { delete[] vec; vec = new Sample[loop_fade_length]; + if (linear) { + if (fadein) { + for (samplecnt_t n = 0; n < loop_fade_length; ++n) { + vec[n] = n / (float) loop_fade_length; + } + } else { + for (samplecnt_t n = 0; n < loop_fade_length; ++n) { + vec[n] = 1.f - n / (float) loop_fade_length; + } + } + fade_length = loop_fade_length - 1; + return; + } + + /* Exponential fade */ + const float a = 390.f / sr; // ~ 1/100Hz for 40dB /* build a psuedo-exponential (linear-volume) shape for the fade */ @@ -1884,8 +1900,8 @@ void DiskReader::alloc_loop_declick (samplecnt_t sr) { loop_fade_length = lrintf (ceil (-log (GAIN_COEFF_DELTA / 2.) / (390. / sr))); - loop_declick_in.alloc (sr, true); - loop_declick_out.alloc (sr, false); + loop_declick_in.alloc (sr, true, Config->get_loop_fade_choice () == XFadeLoop); + loop_declick_out.alloc (sr, false, Config->get_loop_fade_choice () == XFadeLoop); } #undef GAIN_COEFF_DELTA