I’ve been experimenting with the juce QTAudioFormat that allows MP3 decoding.
Since the decoder is rather slow, I load the file in a background worker thread so that I can keep the program UI and other functions moving along and start playing the file immediately.
I also took a look at the audioThumbnail class … awesome. I love that I can just start it with a few simple commands and it will create the thumbnail in (another) background thread.
Thread safety? … ohhhh, you see where this is going. Two background threads trying to access the same resource can be bad news … and is at least with MP3’s.
I’m pretty familiar with thread safety issues, but am not sure how the audiothumbnail class works exactly … or if I have access to that thread? I tried creating a criticalSection object … but since I have no way to tell the audiothumbnail thread to use it, I’m at a loss.
Is there a way to lock a resource in juce … as in lock(file) … so that only one thread will access a file, or buffer, etc. … at a time? Or can I sync the audiothumbnail thread … use threadpool or timeslice to only trigger the thread as the file reader thread exits, and vice versa … ?
I feel there is an easy answer here and I just haven’t found it in the source tree yet (juce seems to have built in solutions for every problem when I look long enough).
Anyway, any help is appreciated.