ardour/libs
Mads Kiilerich c1c95f538f evoral: fix ControlList::_x_scale to avoid ratio overflow when adjusting fade length
Region fades would sometimes get in a mode with weird behaviour. They
would be drawn in 2d with crossing lines, mainly moving back and forth
horizontally - not as a function of time. It would sound as it looked.
The fade would sometimes jump around when resizing. It could be worked
around by resetting the fade shape. It turned out the problem could be
reproduced by making minute long fades.

This change fixes or works around the problem.

Back story:

timepos_t (in temporal/timeline.h) uses 62 bit for integer value and the
max value is thus 4611686018427387904 ~ 5e18. timepos_t counts
superclocks, where superclock_ticks_per_second is 56448000 ~ 6e7. It can
thus store up to 8e10 seconds - thousands of years.

ratio_t (in temporal/types.h) can represent fractions as 64 bit (signed)
numerator and denominator. timepos_t avoids floating point operations,
but has operator* with ratio_t. To avoid crazy loss of precision it will
multiply the superclock count with the numerator before dividing with
the denominator.

Audio region fade in and out uses a number of increasing timepos_t
values (in a ControlList) up to the length of fade. When dragging to
resize, these values are (in_x_scale) multiplied with the ratio_t of the
new and old fade length. The problem is that the 62 bits will overflow
if using fades more than sqrt(5e18) ~ 2e9 superclock ticks ~ 38 seconds.
It will overflow into the "beat" flag and (at 58 seconds) into the sign
bit. The timepos_t values in the fade will thus jump and can be negative
or change to count beats.

To work around that problem, this changeset just use floating point
values for scaling the timepos_t values. All scaled values are stored as
integer anyway, so it should not make any actual difference for this use
case. There might however be other uses of ControlList where it matters.

As an implementation detail of this "workaround" of using double, it
could perhaps also be nice to implement timepos_t operator* (or
operator*=) for double. But I'm not sure we want floating point support
in timepos_t.

An alternative (and better) solution would be to convince the fraction
multiplication to use 128 bits. It is essential to avoid overflow -
mainly in static analysis, alternatively as runtime checks or asserts.
2022-05-24 17:15:37 -06:00
..
appleutility wscript: drop unnecessary trailing ";" 2022-04-09 12:16:41 +02:00
ardour temporal: remove the concept of a time domain for the tempo map 2022-05-24 17:10:25 -06:00
ardouralsautil wscript: consistently have at most one empty separator line 2022-04-09 12:16:40 +02:00
audiographer wscript: consistently have at most one empty separator line 2022-04-09 12:16:40 +02:00
auscan wscript: drop configure statements already present in the top level wscript 2022-01-22 22:19:03 +01:00
backends Further reduce DSP load of debug builds 2022-05-06 02:04:55 +02:00
canvas canvas: change Item::bb_clean() to better named Item::set_bbox_clean() 2022-04-26 22:04:08 -06:00
clearlooks-newer wscript: drop configure statements already present in the top level wscript 2022-01-22 22:19:03 +01:00
evoral evoral: fix ControlList::_x_scale to avoid ratio overflow when adjusting fade length 2022-05-24 17:15:37 -06:00
fluidsynth wscript: drop configure statements already present in the top level wscript 2022-01-22 22:19:03 +01:00
fst wscript: drop configure statements already present in the top level wscript 2022-01-22 22:19:03 +01:00
gtkmm2ext handle an action named "Escape" specially when blocking activation during drags 2022-04-18 12:22:30 -06:00
hidapi wscript: drop configure statements already present in the top level wscript 2022-01-22 22:19:03 +01:00
libltc wscript: drop configure statements already present in the top level wscript 2022-01-22 22:19:03 +01:00
lua Fix memory leak in ctorNilPtrPlacementProxy 2022-04-08 18:21:55 +02:00
midi++2 wscript: consistently have at most one empty separator line 2022-04-09 12:16:40 +02:00
panners wscript: consistently have at most one empty separator line 2022-04-09 12:16:40 +02:00
pbd libpbd: change GlibEventLoopCallback to use C API not C++ 2022-05-19 22:24:43 -06:00
plugins wscript: remove trailing whitespace 2022-04-09 12:16:37 +02:00
ptformat wscript: remove trailing whitespace 2022-04-09 12:16:37 +02:00
qm-dsp wscript: consistently have at most one empty separator line 2022-04-09 12:16:40 +02:00
surfaces use new event loop callback to ensure that all surface/control protocol threads have tempo map ptr set 2022-05-16 15:24:52 -06:00
temporal libs/temporal: clarify superclocks-per-second usage comment 2022-05-24 17:15:37 -06:00
vamp-plugins Do not use ABU suffix for vamp plugin shared object 2022-04-01 18:40:46 +02:00
vamp-pyin wscript: drop configure statements already present in the top level wscript 2022-01-22 22:19:03 +01:00
vfork wscript: drop configure statements already present in the top level wscript 2022-01-22 22:19:03 +01:00
vst3 Backport VST3 diagnostic pragma 2021-03-01 22:14:38 +01:00
waveview apply new Item method name to various other usage sites 2022-04-26 22:04:08 -06:00
widgets wscript: remove trailing whitespace 2022-04-09 12:16:37 +02:00
zita-convolver wscript: drop configure statements already present in the top level wscript 2022-01-22 22:19:03 +01:00
zita-resampler zita-resampler: pass-through data if not configured 2022-05-24 20:41:59 +02:00