AudioSampleBuffer issue


#1

i think there is a bug in AudioSampleBuffer

if you increase the number of channels vie setSize, the newChannels[i] Array will be only filed with the number of the old channels, if you trying to access the “new” channels, you get a memory access violation…


#2

oh, i forget when keepExistingContent = true


#3

Thanks! Should look like this:

[code]void AudioSampleBuffer::setSize (const int newNumChannels,
const int newNumSamples,
const bool keepExistingContent,
const bool clearExtraSpace,
const bool avoidReallocating) noexcept
{
jassert (newNumChannels > 0);

if (newNumSamples != size || newNumChannels != numChannels)
{
    const size_t channelListSize = (newNumChannels + 1) * sizeof (float*);
    const size_t newTotalBytes = (newNumChannels * newNumSamples * sizeof (float)) + channelListSize + 32;

    if (keepExistingContent)
    {
        HeapBlock <char, true> newData;
        newData.allocate (newTotalBytes, clearExtraSpace);

        const size_t numBytesToCopy = sizeof (float) * jmin (newNumSamples, size);

        float** const newChannels = reinterpret_cast <float**> (newData.getData());
        float* newChan = reinterpret_cast <float*> (newData + channelListSize);

        for (int j = 0; j < newNumChannels; ++j)
        {
            newChannels[j] = newChan;
            newChan += newNumSamples;
        }
        
        const int numChansToCopy = jmin (numChannels, newNumChannels);
        for (int i = 0; i < numChansToCopy; ++i)
            memcpy (newChannels[i], channels[i], numBytesToCopy);

        allocatedData.swapWith (newData);
        allocatedBytes = (int) newTotalBytes;
        channels = newChannels;
    }

[/code]


#4

does not work, but i think i have to wait until the next check in :wink:

2977: ‘juce::HeapBlock’ : too many template arguments
1> c:\cpp_projects\jucegit_pure\src\memory…/memory/juce_HeapBlock.h(73) : see declaration of ‘juce::HeapBlock’


#5

Oh yeah, sorry - you can just use a HeapBlock until I’ve checked in the next version.