I did something similar using a
I add samples to be loaded one by one to a queue and start the
TimeSliceThread if necessary, it then processes the queue (albeit in FILO order, but would be trivial to implement as FIFO), loading a 16kb chunk at a time via an
useTimeSlice() (I should probably try to optimise the chunk size before release).
Whilst loading I return
useTimeSlice so that the next call will be scheduled asap, and return
-1 once the queue has been fully processed, which stops the
ScopedLock to make sure any access to the queue is thread safe and it worked out pretty well for me, no issues that I’ve discovered thus far.
edit: returning -1 doesn’t stop the thread, it removes the client from the list of clients to be serviced by the thread, and I assume that the thread consumes little to no resources when there are no clients to be serviced