summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/audiofile.cc4
1 files 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;
}