First of all I’m quite new to JUCE so please excuse me if I may sound too newbie. Also thanks for this great library!
So I am on my way to write a plugin that reads samples from disk by streaming. That is, preloads the beginning of the sample file then continuously reads a bit more when required. My first approach would be to use some producer-consumer pattern here, but as I said I am quite new to JUCE so I am wondering what would be the building blocks that I could use for this task?
I know there are quite a lot of classes dealing with various aspects of this problem (ex. ThreadedWriter which I think does exactly the opposite) but I need some directions before going through each and every class that might be or not useful to me.
I also could manage any high level concepts regarding disk streaming, if anyone would share something like that with me Thus any advice is welcomed.
Hm, are you saying that if I get a bit deeper with these classes they might actually provide me the streaming feature? I was quite sure JUCE does not support disk streaming for samples…
I obtain audio samples from files on disk all the time via those exact classes. So to answer your question; yes!
:? My goal isn’t to lead you astray.
Have you actually tried to use these classes? It does involve work of your own to continously stream.
Yoohoo! Thats’ great! Thanks!
Inspired by the demo applications I have basically used the SamplerSound class, mostly as is, where it actually reads all the samples into a big buffer using an AudioFormatReader. I was convinced that these *AudioSource classes are only for the audio transport stuff but now I realize they also serve to retrieve samples in smaller chunks and in this new light I think BufferingAudioSource would actually take care of loading the data using a thread.
I have managed to connect the pieces and read my sample files using BufferingAudioSource. Problem is that when I play on multiple voices I have a glitches until buffer is filled (couple of ms). I prepare the source in the voice, on the startNote event, and I think this is mostly where the break is resulting from. On the other hand if I keep the source in the sound class, looks like the thread is unable to provide samples fast enough when playing same note multiple times before completion of the last note. I kinda hit a wall here. What could I be doing wrong here? How could I prepare the source in the sound class before any note is on, and also keeping up with reading non-sequentially for 8-16 voices with a single thread? Or maybe should I use more threads? Any suggestions please?
How long is your source file? Surely if you’re building a sampler it would be best to read the whole file into memory (perhaps the initial read could be on a background thread) so you have instant access to all the samples. If you’re constantly re-reading the file from disk and jumping around inside it you will definitely get periods of silence as the low priority background thread struggles to keep up with the high priority audio thread which will sound like clicks and glitches.
Have you looked at the Juce Demo Synth Playback page? This uses the Sampler classes to load a cello sound.
The file is pretty big and there are lots of them so fully loading all of them in memory is not quite the best solution. Basically I have started from the demo but trying to advance to some smarter solution.