public int Read(float[] buffer, int offset, int count)
        {
            BufferedData srcBuffer = buffers[bufferIndex];

            if (!srcBuffer.IsValid)
            {
                return(0);
            }

            int samplesRead = srcBuffer.CopySamples(buffer, offset, count);

            while (samplesRead < count)
            {
                if (srcBuffer.EndOfStream)
                {
                    return(samplesRead);
                }

                // A buffer swap will be required
                WaitForBufferTask();

                bufferIndex = (bufferIndex + 1) % buffers.Length;
                srcBuffer   = buffers[bufferIndex];

                if (!srcBuffer.EndOfStream)
                {
                    StartFillBufferTask();
                }

                samplesRead += srcBuffer.CopySamples(buffer, offset + samplesRead, count - samplesRead);
            }

            return(samplesRead);
        }