summaryrefslogtreecommitdiff
path: root/libs/ardour/disk_reader.cc
diff options
context:
space:
mode:
authorRobin Gareus <robin@gareus.org>2020-02-12 17:19:57 +0100
committerRobin Gareus <robin@gareus.org>2020-02-12 17:28:53 +0100
commit6f755c3c029c5f1e7a2e81cd3ed5b5493d19af8a (patch)
treefff99fd21e3833132b6aa3514ba08192c655caa4 /libs/ardour/disk_reader.cc
parentf477dd088c02f22bc4c4b197bfec87026c0ac462 (diff)
Fix loop-fade and de-click buffersize calculation
Exponential approach to zero: 1 / exp(t) == exp (-t) we "stretch" it by a time-constant "c": gain(t) = exp (-t * c) To find the time t, at which the exponential approach reaches gain "g": exp (-c * t) = g take the log of both sides: log (exp (-c * t) = log (g) since log (exp (x)) == x : -c t = log (g) divide by -c : t = -log (g) / c set g = 1e-5 and c = _a/sr and we get: t = -log (1e-5) / (_a/sr) The iterative approach using g += c * (target_gain - g); converges faster than the exact exp() calculation. Except with 32-bit float, if target-gain is 1.0f and "c" is small. With 32bit float (1.0 - 1e-5) = .9999900 is represented as sign: +1 | mantissa: 0x7fff58 | exponent: 126 there are only 126 "steps" to 1.0. Rounding of the lowest mantissa bit does matter. We have to assume worst-case, and increase the required loop_fade_length buffersize. vs. approaching 0, where there are over 2^110 steps between zero and 1e-5.
Diffstat (limited to 'libs/ardour/disk_reader.cc')
-rw-r--r--libs/ardour/disk_reader.cc4
1 files changed, 3 insertions, 1 deletions
diff --git a/libs/ardour/disk_reader.cc b/libs/ardour/disk_reader.cc
index e668626195..b7d74bdfc5 100644
--- a/libs/ardour/disk_reader.cc
+++ b/libs/ardour/disk_reader.cc
@@ -1528,6 +1528,8 @@ DiskReader::Declicker::alloc (samplecnt_t sr, bool fadein)
}
}
+ assert (n < loop_fade_length);
+
fade_length = n;
/* zero out the rest just to be safe */
@@ -1733,7 +1735,7 @@ DiskReader::rt_midibuffer ()
void
DiskReader::alloc_loop_declick (samplecnt_t sr)
{
- loop_fade_length = lrintf (ceil (-log (GAIN_COEFF_DELTA) / (1024. / sr)));
+ loop_fade_length = lrintf (ceil (-log (GAIN_COEFF_DELTA / 2.) / (1024. / sr)));
loop_declick_in.alloc (sr, true);
loop_declick_out.alloc (sr, false);
}