summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorBent Bisballe Nyeng <deva@aasimon.org>2015-04-23 15:13:07 +0200
committerBent Bisballe Nyeng <deva@aasimon.org>2016-01-20 13:23:14 +0100
commiteaa2062ea50fea853fa1852b152354ba50d44985 (patch)
tree67800491fe0252c188a3d55ef5e55acbc0bc9af8 /src
parentfac1074163dc31f7aea8857d261811a241f19925 (diff)
Added 'preloadedsize' to AudioFile to reflect how much data was loaded and not just how big the entire file is.
Diffstat (limited to 'src')
-rw-r--r--src/audiofile.cc18
-rw-r--r--src/audiofile.h3
2 files changed, 12 insertions, 9 deletions
diff --git a/src/audiofile.cc b/src/audiofile.cc
index f6a2c1d..7ab21a9 100644
--- a/src/audiofile.cc
+++ b/src/audiofile.cc
@@ -115,20 +115,20 @@ void AudioFile::load(int num_samples)
}
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)size > num_samples) size = num_samples;
+ if((int)preloadedsize > num_samples) preloadedsize = num_samples;
}
- sample_t* data = new sample_t[size];
+ sample_t* data = new sample_t[preloadedsize];
if(sf_info.channels == 1) {
- size = sf_read_float(fh, data, size);
- }
- else {
+ preloadedsize = sf_read_float(fh, data, preloadedsize);
+ } else {
// check filechannel exists
if(filechannel >= sf_info.channels) {
filechannel = sf_info.channels - 1;
@@ -142,12 +142,14 @@ void AudioFile::load(int num_samples)
for (int i = 0; i < read && totalread < num_samples; i++) {
data[totalread++] = buffer[i * sf_info.channels + filechannel];
}
- } while(read > 0 && totalread < (int)size && totalread < num_samples);
+ } while( (read > 0) &&
+ (totalread < (int)preloadedsize) &&
+ (totalread < num_samples) );
// set data size to total bytes read
- size = totalread;
+ preloadedsize = totalread;
}
- DEBUG(audiofile,"Loaded %d samples %p\n", (int)size, this);
+ DEBUG(audiofile,"Loaded %d samples %p\n", (int)preloadedsize, this);
sf_close(fh);
diff --git a/src/audiofile.h b/src/audiofile.h
index 5b57db8..5f93584 100644
--- a/src/audiofile.h
+++ b/src/audiofile.h
@@ -79,7 +79,8 @@ public:
bool isLoaded();
- volatile size_t size;
+ volatile size_t size; // Full size of the file
+ volatile size_t preloadedsize; // Number of samples preloaded (in data)
sample_t *data;
std::string filename;