Fix AudioRegion RMS calc for multi-channel

This commit is contained in:
Robin Gareus 2016-12-28 22:18:41 +01:00
parent 910e369140
commit e1846c79a9

View file

@ -1454,13 +1454,12 @@ AudioRegion::rms (Progress* p) const
framecnt_t total = 0; framecnt_t total = 0;
if (n_chan == 0) { if (n_chan == 0 || fend == fpos) {
return 0; return 0;
} }
while (fpos < fend) { while (fpos < fend) {
framecnt_t const to_read = min (fend - fpos, blocksize); framecnt_t const to_read = min (fend - fpos, blocksize);
total += to_read;
for (uint32_t c = 0; c < n_chan; ++c) { for (uint32_t c = 0; c < n_chan; ++c) {
if (read_raw_internal (buf, fpos, to_read, c) != to_read) { if (read_raw_internal (buf, fpos, to_read, c) != to_read) {
return 0; return 0;
@ -1468,12 +1467,13 @@ AudioRegion::rms (Progress* p) const
for (framepos_t i = 0; i < to_read; ++i) { for (framepos_t i = 0; i < to_read; ++i) {
rms += buf[i] * buf[i]; rms += buf[i] * buf[i];
} }
fpos += to_read; }
if (p) { total += to_read;
p->set_progress (float (fpos - _start) / _length); fpos += to_read;
if (p->cancelled ()) { if (p) {
return -1; p->set_progress (float (fpos - _start) / _length);
} if (p->cancelled ()) {
return -1;
} }
} }
} }