summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndré Nusser <andre.nusser@googlemail.com>2016-01-29 12:54:02 +0100
committerAndré Nusser <andre.nusser@googlemail.com>2016-01-29 12:54:02 +0100
commit1b32041bb54e1c9310853c9942498ec223d8106a (patch)
tree64fb06c0a3fefd119cccd17483cb6c1355c3de23
parent8faba64d538753d09765f2fe003cc08bc5ff2712 (diff)
wip 2
-rw-r--r--src/audiocache.cc15
-rw-r--r--test/audiocachetest.cc2
2 files changed, 10 insertions, 7 deletions
diff --git a/src/audiocache.cc b/src/audiocache.cc
index e098fd0..2ca0616 100644
--- a/src/audiocache.cc
+++ b/src/audiocache.cc
@@ -96,17 +96,20 @@ sample_t* AudioCache::open(const AudioFile& file, size_t initial_samples_needed,
c.front = nullptr; // This is allocated when needed.
c.back = nullptr; // This is allocated when needed.
- // cropped_size is the preload chunk size cropped to sample length.
- size_t cropped_size = file.preloadedsize - c.localpos;
- cropped_size /= framesize;
- cropped_size *= framesize;
- cropped_size += initial_samples_needed;
+ size_t cropped_size;
if(file.preloadedsize == file.size)
{
// We have preloaded the entire file, so use it.
cropped_size = file.preloadedsize;
}
+ else
+ {
+ // cropped_size is the preload chunk size cropped to sample length.
+ cropped_size = file.preloadedsize - c.localpos;
+ cropped_size -= cropped_size % framesize;
+ cropped_size += initial_samples_needed;
+ }
c.preloaded_samples = file.data;
c.preloaded_samples_size = cropped_size;
@@ -114,7 +117,7 @@ sample_t* AudioCache::open(const AudioFile& file, size_t initial_samples_needed,
// Next read from disk will read from this point.
c.pos = cropped_size;//c.preloaded_samples_size;
- // Only load next buffer if there are more data in the file to be loaded...
+ // Only load next buffer if there is more data in the file to be loaded...
if(c.pos < file.size)
{
if(c.back == nullptr)
diff --git a/test/audiocachetest.cc b/test/audiocachetest.cc
index 5db5940..3ac63bf 100644
--- a/test/audiocachetest.cc
+++ b/test/audiocachetest.cc
@@ -81,7 +81,7 @@ public:
printf("open: initial_samples_needed: %d\n", (int)initial_samples_needed);
sample_t *samples =
- audio_cache.open(&audio_file, initial_samples_needed, channel, id);
+ audio_cache.open(audio_file, initial_samples_needed, channel, id);
size_t size = initial_samples_needed;
size_t offset = 0;