From fcfa4676a2be89fff6ea55ff13c5e3e73ba59a74 Mon Sep 17 00:00:00 2001 From: Bent Bisballe Nyeng Date: Sun, 12 Apr 2015 20:23:19 +0200 Subject: Fix partial loading of multichannel files. --- src/audiofile.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/audiofile.cc b/src/audiofile.cc index 59e0c14..f6a2c1d 100644 --- a/src/audiofile.cc +++ b/src/audiofile.cc @@ -139,10 +139,10 @@ void AudioFile::load(int num_samples) int read; do { read = sf_readf_float(fh, buffer, readsize); - for (int i = 0; i < read; i++) { + for (int i = 0; i < read && totalread < num_samples; i++) { data[totalread++] = buffer[i * sf_info.channels + filechannel]; } - } while(read > 0 && totalread < (int)size); + } while(read > 0 && totalread < (int)size && totalread < num_samples); // set data size to total bytes read size = totalread; } -- cgit v1.2.3