Skip to content

Commit

Permalink
Merge pull request #1030 from paulfd/filepool-loaded-files
Browse files Browse the repository at this point in the history
Make loadedFiles behave like preloadedFiles
  • Loading branch information
paulfd authored Nov 19, 2021
2 parents 5fdbb76 + f8b874c commit ec439d2
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion src/sfizz/FilePool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,9 @@ void sfz::FilePool::resetPreloadCallCounts() noexcept
{
for (auto& preloadedFile: preloadedFiles)
preloadedFile.second.preloadCallCount = 0;

for (auto& loadedFile: loadedFiles)
loadedFile.second.preloadCallCount = 0;
}

void sfz::FilePool::removeUnusedPreloadedData() noexcept
Expand All @@ -350,6 +353,14 @@ void sfz::FilePool::removeUnusedPreloadedData() noexcept
preloadedFiles.erase(copyIt);
}
}

for (auto it = loadedFiles.begin(), end = loadedFiles.end(); it != end; ) {
auto copyIt = it++;
if (copyIt->second.preloadCallCount == 0) {
DBG("[sfizz] Removing unused loaded data: " << copyIt->first.filename());
preloadedFiles.erase(copyIt);
}
}
}

sfz::FileDataHolder sfz::FilePool::loadFile(const FileId& fileId) noexcept
Expand All @@ -364,14 +375,16 @@ sfz::FileDataHolder sfz::FilePool::loadFile(const FileId& fileId) noexcept
const auto frames = static_cast<uint32_t>(reader->frames());
const auto existingFile = loadedFiles.find(fileId);
if (existingFile != loadedFiles.end()) {
existingFile->second.preloadCallCount++;
return { &existingFile->second };
} else {
fileInformation->sampleRate = static_cast<double>(reader->sampleRate());
auto insertedPair = preloadedFiles.insert_or_assign(fileId, {
auto insertedPair = loadedFiles.insert_or_assign(fileId, {
readFromFile(*reader, frames),
*fileInformation
});
insertedPair.first->second.status = FileData::Status::Preloaded;
insertedPair.first->second.preloadCallCount++;
return { &insertedPair.first->second };
}
}
Expand Down Expand Up @@ -474,6 +487,7 @@ void sfz::FilePool::clear()
garbageToCollect.clear();
lastUsedFiles.clear();
preloadedFiles.clear();
loadedFiles.clear();
}

uint32_t sfz::FilePool::getPreloadSize() const noexcept
Expand Down

0 comments on commit ec439d2

Please sign in to comment.