diff options
author | Bent Bisballe Nyeng <deva@aasimon.org> | 2015-04-23 15:13:07 +0200 |
---|---|---|
committer | Bent Bisballe Nyeng <deva@aasimon.org> | 2016-01-20 13:23:14 +0100 |
commit | eaa2062ea50fea853fa1852b152354ba50d44985 (patch) | |
tree | 67800491fe0252c188a3d55ef5e55acbc0bc9af8 /src/audiofile.cc | |
parent | fac1074163dc31f7aea8857d261811a241f19925 (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/audiofile.cc')
-rw-r--r-- | src/audiofile.cc | 18 |
1 files changed, 10 insertions, 8 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); |