Hi, I’m new to JUCE development and I have a question about how best to approach storing recorded audio data between DAW sessions.
I’m working on a plugin similar to a live looper pedal. It records incoming audio samples in a single std::vector<float>.The vector has a fixed maximum size that is defined at initialization, about enough for 6 minutes of audio at 48 kHz.
The audio data is never stored on disk, so any recording is lost when the plugin session ends. Now I want to make sure that the recorded audio is stored on disk so that the sample memory persists between DAW sessions.
I can expand on the details and access patterns used with the samples vector if it helps. I didn’t want to bloat this post with too much information up front.
I’m wondering how an experienced JUCE developer would approach persisting this kind of audio data between DAW sessions. I am fairly new to plugin development so I don’t have an intuition for what is a good or bad approach. Any advice you can provide would be greatly appreciated.
Best way would be to store it in the preset and let the user decide if they want to also keep the buffer I think.
Keep it in the plugin memory the entire time until they are ready to commit then restore the buffer from the preset.
I would think with each session you would end up taking up a lot disk space unless they were temporary files, but temp files I assume will get deleted at some point by the OS.
6 minutes of stereo sound at 48 kHz is roughly 33 MB of data. If you store this inside the plug-in’s state, it gets saved inside the user’s project.
33 MB isn’t such a big deal, although DAWs might store the project’s plug-in state as base64-encoded binary data in an XML file, for example, which makes it more like 50 MB.
If the user has recorded less than 6 minutes, it will be worth storing only the actual data they recorded, not the whole buffer. This will make the project file smaller and saving faster.
A DAW such as REAPER will ask the plug-in to save itself every time the user changes a parameter, so ideally you want this to be fast enough to be unnoticeable.
The alternative is to store the recorded sound inside a file somewhere, but this would be outside of the DAW’s project file and the user will have to manage these files manually. You could make a folder named after your plug-in and store the recordings inside that folder. However, if the user moves the DAW project to a different computer, they would also have to copy the folder with these recordings.
(It would be nice if plug-in APIs could tell the host that a plug-in wants to store a file as part of the project, but that doesn’t exist, AFAIK.)
In my experience FLAC is very useful to store user data in DAW sessions in a compressed format. Unless you plan for an enormous amount of long files stored in the preset/session, I thinks that would work well for most cases.