no, I am already using the version, where you fixed the lock of the reset() function. So I implemented the following change in fillInactiveBuffer() (added a lock):
if (sound == nullptr) return;
Not sure, this is the best solution (too much locking???) but it seems to work.
But then I ran into a new jassert. It happens in juce_AudioSampleBuffer.h. And it is quite easy for me to reproduce. I just hold the sound, until it has finished playing:
const float* getReadPointer (int channelNumber, int sampleIndex) const noexcept
jassert (isPositiveAndBelow (channelNumber, numChannels));
jassert (isPositiveAndBelow (sampleIndex, size));
The problem is the last jassert. In my case, the sampleIndex is 11264 and size is 11000. I.e. we are trying to get a read pointer, which is larger than the buffer. The number 11000 is actually the preload size, i.e:
#define PRELOAD_SIZE 11000
#define BUFFER_SIZE_FOR_STREAM_BUFFERS 11000
The problem is the following: the streaming sampler is not only using the preload sizes as buffer sizes. Another buffer size is set in the setBufferSize() method of SampleLoader:
void SampleLoader::setBufferSize(int newBufferSize)
bufferSize = newBufferSize;
b1 = AudioSampleBuffer(2, bufferSize);
b2 = AudioSampleBuffer(2, bufferSize);
So there is on fixed buffer size (from the #define macro) and on variable buffer size from this function, which get mixed up. This new buffer size comes from the prepareToPlay() method in my audio engine. In my case, my audio engine is passed a quite large buffer size of 512. I multiplied this size with 32, as you did in you demo example. That results in a buffer size of 16384, which is larger than the PRELOAD_SIZE of 11000.
As a temporary fix I simply enlarged the preload buffers to 22000:
#define PRELOAD_SIZE 22000
#define BUFFER_SIZE_FOR_STREAM_BUFFERS 22000
That works for me, but it is not a good solution of course.
As a result(?), I ran into another assert. But this assert happens really very rarely and is quite difficult for me to reproduce. It’s this one:
writeBufferIsBeingFilled = true; // A poor man's mutex but gets the job done.
// check if the background thread is already loading this sound
Apparently it is possible, that the background thread already is loading the sound. No idea how/why.