AudioSampleBuffer still broken

void AudioSampleBuffer::setSize (const int newNumChannels,

                                 const int newNumSamples,

                                 const bool keepExistingContent,

                                 const bool clearExtraSpace,

                                 const bool avoidReallocating) throw()

{

    jassert (newNumChannels > 0);



    if (newNumSamples != size || newNumChannels != numChannels)

    {

        const int newTotalBytes = newNumChannels * newNumSamples * sizeof (float) + 32;



        if (keepExistingContent)

        {

            float* const newData = (clearExtraSpace) ? (float*) juce_calloc (newTotalBytes)

                                                     : (float*) juce_malloc (newTotalBytes);



            const int sizeToCopy = sizeof (float) * jmin (newNumSamples, size);



            for (int i = jmin (newNumChannels, numChannels); --i >= 0;)

            {

                memcpy (newData + i * newNumSamples,

                        channels[i],

                        sizeToCopy);

            }



            juce_free (allocatedData);



            allocatedData = newData;

            allocatedBytes = newTotalBytes;

        }

        else

        {

            if (avoidReallocating && allocatedBytes >= newTotalBytes)

            {

                if (clearExtraSpace)

                    zeromem (allocatedData, newTotalBytes);

            }

            else

            {

                juce_free (allocatedData);



                allocatedData = (clearExtraSpace) ? (float*) juce_calloc (newTotalBytes)

                                                  : (float*) juce_malloc (newTotalBytes);

                allocatedBytes = newTotalBytes;

            }

        }



        size = newNumSamples;



        if (newNumChannels > numChannels)

            channels = (float**) juce_realloc (channels, (newNumChannels + 1) * sizeof (float*));



        numChannels = newNumChannels;



        float* chan = allocatedData;

        for (int i = 0; i < newNumChannels; ++i)

        {

            channels[i] = chan;

            chan += size;

        }



        channels [newNumChannels] = 0;

    }

}

Thanks - I bumped into that one too, and checked in a fix.

Thanks - I bumped into that one too, and checked in a fix.

I’m curious–exactly what is broken in AudioSampleBuffer? I’m afraid I can’t tell from examining the code sample or from doing differences on the code. In fact, the main thing that’s changed is that reallocation is done on newNumChannels + 1 instead of numNewChannels and I’m wondering why that is necessary.

Thanks – Jeff.

As far as I know nothing is now broken in that class. The reason it has an extra element in the array is just so that the array of pointers to channels is zero-terminated, which is sometimes handy when you’re using it in plugins, etc.