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>2015-07-19 13:55:22 +0200
commite35b527e8bc261bb1f4ecbff474d1ff6fcd1db60 (patch)
treeff319865f9e173b466b32eb66d1c093086711aff /src/audiofile.cc
parentea2d9e8ee5db8ae5ec1aaa15eebda3296a027baf (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);