diff options
author | Bent Bisballe Nyeng <deva@aasimon.org> | 2015-04-23 15:13:07 +0200 |
---|---|---|
committer | Bent Bisballe Nyeng <deva@aasimon.org> | 2015-04-23 15:13:07 +0200 |
commit | 83316b2cc7cba508c9f9a7dfcc4c82026507badf (patch) | |
tree | 40c4229f01874aca7fa6c9323b1080b9d5e7a537 /src | |
parent | d4b217d3c2902bab3daf438714bcb7cb3ccbca51 (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.cc | 18 | ||||
-rw-r--r-- | src/audiofile.h | 3 |
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; |