From e1846c79a9292d4e58527aa1d2a33119ea966902 Mon Sep 17 00:00:00 2001 From: Robin Gareus Date: Wed, 28 Dec 2016 22:18:41 +0100 Subject: [PATCH] Fix AudioRegion RMS calc for multi-channel --- libs/ardour/audioregion.cc | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/libs/ardour/audioregion.cc b/libs/ardour/audioregion.cc index 873d4119d4..bf4c5c6910 100644 --- a/libs/ardour/audioregion.cc +++ b/libs/ardour/audioregion.cc @@ -1454,13 +1454,12 @@ AudioRegion::rms (Progress* p) const framecnt_t total = 0; - if (n_chan == 0) { + if (n_chan == 0 || fend == fpos) { return 0; } while (fpos < fend) { framecnt_t const to_read = min (fend - fpos, blocksize); - total += to_read; for (uint32_t c = 0; c < n_chan; ++c) { if (read_raw_internal (buf, fpos, to_read, c) != to_read) { return 0; @@ -1468,12 +1467,13 @@ AudioRegion::rms (Progress* p) const for (framepos_t i = 0; i < to_read; ++i) { rms += buf[i] * buf[i]; } - fpos += to_read; - if (p) { - p->set_progress (float (fpos - _start) / _length); - if (p->cancelled ()) { - return -1; - } + } + total += to_read; + fpos += to_read; + if (p) { + p->set_progress (float (fpos - _start) / _length); + if (p->cancelled ()) { + return -1; } } }