summaryrefslogtreecommitdiff
path: root/src/audiofile.cc
diff options
context:
space:
mode:
authorBent Bisballe Nyeng <deva@aasimon.org>2015-07-19 13:55:22 +0200
committerBent Bisballe Nyeng <deva@aasimon.org>2016-01-20 13:31:08 +0100
commitec281ca43fc368f87789ff52c911d5d6457a288c (patch)
tree02e8ea83e4e33bb143bcc704466803bd4594cc32 /src/audiofile.cc
parentfec796b8c5e6c933585d75f6405adf1b222c491e (diff)
Fix loading with num_samples==ALL_SAMPLES (-1).
Diffstat (limited to 'src/audiofile.cc')
-rw-r--r--src/audiofile.cc16
1 files changed, 8 insertions, 8 deletions
diff --git a/src/audiofile.cc b/src/audiofile.cc
index 7ab21a9..5ceff59 100644
--- a/src/audiofile.cc
+++ b/src/audiofile.cc
@@ -114,15 +114,15 @@ void AudioFile::load(int num_samples)
return;
}
+ if(num_samples == ALL_SAMPLES) {
+ num_samples = sf_info.frames;
+ }
+
size = sf_info.frames;
preloadedsize = sf_info.frames;
- double ratio = (double)Conf::samplerate / (double)sf_info.samplerate;
-
- if(num_samples != ALL_SAMPLES) {
- // Make sure we read enough samples, even after conversion.
- num_samples /= ratio;
- if((int)preloadedsize > num_samples) preloadedsize = num_samples;
+ if(preloadedsize > (size_t)num_samples) {
+ preloadedsize = num_samples;
}
sample_t* data = new sample_t[preloadedsize];
@@ -139,7 +139,7 @@ void AudioFile::load(int num_samples)
int read;
do {
read = sf_readf_float(fh, buffer, readsize);
- for (int i = 0; i < read && totalread < num_samples; i++) {
+ for (int i = 0; (i < read) && (totalread < num_samples); i++) {
data[totalread++] = buffer[i * sf_info.channels + filechannel];
}
} while( (read > 0) &&
@@ -148,7 +148,7 @@ void AudioFile::load(int num_samples)
// set data size to total bytes read
preloadedsize = totalread;
}
-
+
DEBUG(audiofile,"Loaded %d samples %p\n", (int)preloadedsize, this);
sf_close(fh);