summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBent Bisballe Nyeng <deva@aasimon.org>2016-03-12 14:33:27 +0100
committerBent Bisballe Nyeng <deva@aasimon.org>2016-03-12 14:33:27 +0100
commit53271c82f9cdcc2fec0da348c7c93cee80a6bb0f (patch)
tree30eb5905576bdbda9d4d5dea143e0d8dda3ff2d9
parentb9773f6eecea38e6a5aa28745cc6fe79aa2d441f (diff)
Only open file if we actually need to read from it.
-rw-r--r--src/audiocache.cc13
1 files changed, 11 insertions, 2 deletions
diff --git a/src/audiocache.cc b/src/audiocache.cc
index 346c93b..1aa0320 100644
--- a/src/audiocache.cc
+++ b/src/audiocache.cc
@@ -86,7 +86,7 @@ sample_t* AudioCache::open(const AudioFile& file, size_t initial_samples_needed,
// Get the cache_t connected with the registered id.
cache_t& c = id_manager.getCache(id);
- c.afile = &event_handler.openFile(file.filename);
+ c.afile = nullptr; // File is opened when needed.
c.channel = channel;
// Next call to 'next()' will read from this point.
@@ -112,7 +112,7 @@ sample_t* AudioCache::open(const AudioFile& file, size_t initial_samples_needed,
// \ /
// \----------------------v-------------------/
// cropped_size
-
+
cropped_size = file.preloadedsize - c.localpos;
cropped_size -= cropped_size % framesize;
cropped_size += initial_samples_needed;
@@ -127,6 +127,8 @@ sample_t* AudioCache::open(const AudioFile& file, size_t initial_samples_needed,
// Only load next buffer if there is more data in the file to be loaded...
if(c.pos < file.size)
{
+ c.afile = &event_handler.openFile(file.filename);
+
if(c.back == nullptr)
{
c.back = new sample_t[CHUNKSIZE(framesize)];
@@ -230,6 +232,13 @@ void AudioCache::close(cacheid_t id)
return;
}
+ cache_t& cache = id_manager.getCache(id);
+ if(cache.afile == nullptr)
+ {
+ // The file was never opened. It was played entirely from preloaded data.
+ return;
+ }
+
event_handler.pushCloseEvent(id);
}