summaryrefslogtreecommitdiff
path: root/src/audiocache.cc
diff options
context:
space:
mode:
authorBent Bisballe Nyeng <deva@aasimon.org>2016-03-13 17:32:24 +0100
committerBent Bisballe Nyeng <deva@aasimon.org>2016-03-13 17:32:24 +0100
commit28b5df96c2fc89652c724e48ad1ce352228450c6 (patch)
treece74a6e1bf401bd666949cfa1c5324306d7fc3d2 /src/audiocache.cc
parent08a929d3d32e50e7787428d130289c0f5fc2ff42 (diff)
Only open AudioCacheFile if needed.
Diffstat (limited to 'src/audiocache.cc')
-rw-r--r--src/audiocache.cc20
1 files changed, 11 insertions, 9 deletions
diff --git a/src/audiocache.cc b/src/audiocache.cc
index 1aa0320..bb53646 100644
--- a/src/audiocache.cc
+++ b/src/audiocache.cc
@@ -121,8 +121,8 @@ sample_t* AudioCache::open(const AudioFile& file, size_t initial_samples_needed,
c.preloaded_samples = file.data;
c.preloaded_samples_size = cropped_size;
- // Next read from disk will read from this point.
- c.pos = cropped_size;//c.preloaded_samples_size;
+ // Next potential read from disk will read from this point.
+ c.pos = cropped_size;
// Only load next buffer if there is more data in the file to be loaded...
if(c.pos < file.size)
@@ -160,7 +160,15 @@ sample_t* AudioCache::next(cacheid_t id, size_t& size)
if(c.localpos < c.preloaded_samples_size)
{
sample_t* s = c.preloaded_samples + c.localpos;
+
+ if((c.localpos + framesize) > c.preloaded_samples_size)
+ {
+ // Only a partial frame is returned. Reflect this in the size
+ size = c.preloaded_samples_size - c.localpos;
+ }
+
c.localpos += framesize;
+
return s;
}
@@ -196,6 +204,7 @@ sample_t* AudioCache::next(cacheid_t id, size_t& size)
c.pos += CHUNKSIZE(framesize);
// Does the file have remaining unread samples?
+ assert(c.afile); // Assert that we have an audio file.
if(c.pos < c.afile->getSize())
{
// Do we have a back buffer to read into?
@@ -232,13 +241,6 @@ 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);
}