Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Adds a in-memory database for samples. Callers can fetch data from the database using two overloads: one for audio files, and another for Base64 strings. The database stores weak pointers to the samples and returns shared pointers to the callers. However, the database in the future will probably need to store the weak pointers along with sample thumbnails and possibly other kinds of metadata for each sample, which should be fairly easy to do as all that needs to be done is to store a collection of the data we need in a
struct
/class
instead of just the weak pointer to the buffer.For audio files, we check the last write time for the file to see if it needs updating each time it is fetched, and update it if necessary. For Base64 strings, we just compare the contents.
SampleLoader
loads audio data by querying the database for it, rather than creating them manually. As such, theSampleLoader::create*
functions where renamed toSampleLoader::load*
.The memory usage has dropped significantly when using duplicate samples (
htop
readings went from 28.5% to 3.6% for me with a project that had a number of sample clips, each ~3 minutes long), and projects load faster (There is still some delay because of the waveform drawing, but this should be addressed soon. The speedup is more noticeable when you zoom all the way out before loading a project as a result).Should supersede #7058 I believe.
PS: This is sample caching, but branded under being a sample database instead of a sample cache. Since this PR uses two hashmaps (which can resemble tables in a database), a database seems like a more accurate term, but if there are objections we can stick to saying it is a sample cache.