AbstractFifo use

I've been trying to write a ring buffer for audio that I can continually copy into. I've implemented AbstractFifo to manage the buffering but hit a problem with getting the fifo to loop back to the buffer start when it reaches the end. I'm using AbstractFifo.prepareToWrite() & AbstractFifo.finishedWrite to write into my buffer, the same as in the documentation, which works. The problem is that it fills to the end of the buffer and then stops, it never loops back to the start to continue filling. How do I get it to loop back automatically as the documentation suggests it does?

Sounds like you've got a bug in your code?  Post an example showing what you're doing maybe it's an easy fix...?

This is the function I'm using to fill the buffer. The only other functions working with this are one setting rBuffer & abstractFifo to the same size and another where I return the peak sample in rBuffer. I'm not doing any reading from rBuffer or anything, just writing to it and occasionally finding the peak sample:

void fillTheBuffer(const AudioSampleBuffer& buffer)

{

    //rBuffer.getNumSamples() and abstractFifo.getTotalSamples() are always the same when this function is called.
    //rBuffer.getNumChannels() & buffer.getNumChannels() are always the same.

      
    //prepare fifo:

    int start1, size1, start2, size2;

    abstractFifo.prepareToWrite(buffer.getNumSamples(), start1, size1, start2, size2);

    

    //copy data:

    for(int chan = 0; chan < rBuffer.getNumChannels(); chan++)

    {

        if (size1 > 0)

        {

            rBuffer.copyFrom(chan, start1, buffer, chan, 0, size1);

        }

        if (size2 > 0)

        {

            rBuffer.copyFrom(chan, start2, buffer, chan, size1, size2);

        }

    }


    abstractFifo.finishedWrite (size1 + size2);

}

I'm missing the corresponding read calls here. Only when written values have been read, their place in the buffer is marked as "free" and can be filled again. At the moment, the buffer simply runs full.

oh right, I didn't see that in the docs. So in my example (since i'm not reading from rBuffer at all) I should call abstractFifo.finishedRead(size1 + size2) at the end of that function, after finishedWrite(size1 + size2), to free the samples as I go and enable it to loop back and keep writing?

Exactly, that way you'd pretend that you've read it all.

Solved - thanks!