Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a database for samples #7497

Open
wants to merge 8 commits into
base: master
Choose a base branch
from

Conversation

sakertooth
Copy link
Contributor

@sakertooth sakertooth commented Sep 14, 2024

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, the SampleLoader::create* functions where renamed to SampleLoader::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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant