Browse Source

removed the malloc from the constructor of a read-only AudioSampleBuffer

tags/2021-05-28
jules 16 years ago
parent
commit
f8816abba0
4 changed files with 21 additions and 7 deletions
  1. +8
    -2
      juce_amalgamated.cpp
  2. +4
    -3
      juce_amalgamated.h
  3. +8
    -2
      src/juce_appframework/audio/dsp/juce_AudioSampleBuffer.cpp
  4. +1
    -0
      src/juce_appframework/audio/dsp/juce_AudioSampleBuffer.h

+ 8
- 2
juce_amalgamated.cpp View File

@@ -23699,7 +23699,11 @@ AudioSampleBuffer::AudioSampleBuffer (float** dataToReferTo,
{ {
jassert (numChannels_ > 0); jassert (numChannels_ > 0);


channels = (float**) juce_malloc ((numChannels_ + 1) * sizeof (float*));
// (try to avoid doing a malloc here, as that'll blow up things like Pro-Tools)
if (numChannels_ < numElementsInArray (preallocatedChannelSpace))
channels = (float**) preallocatedChannelSpace;
else
channels = (float**) juce_malloc ((numChannels_ + 1) * sizeof (float*));


for (int i = 0; i < numChannels_; ++i) for (int i = 0; i < numChannels_; ++i)
{ {
@@ -23788,7 +23792,9 @@ const AudioSampleBuffer& AudioSampleBuffer::operator= (const AudioSampleBuffer&
AudioSampleBuffer::~AudioSampleBuffer() throw() AudioSampleBuffer::~AudioSampleBuffer() throw()
{ {
juce_free (allocatedData); juce_free (allocatedData);
juce_free (channels);

if (channels != (float**) preallocatedChannelSpace)
juce_free (channels);
} }


float* AudioSampleBuffer::getSampleData (const int channelNumber, float* AudioSampleBuffer::getSampleData (const int channelNumber,


+ 4
- 3
juce_amalgamated.h View File

@@ -27182,6 +27182,7 @@ private:
int numChannels, size, allocatedBytes; int numChannels, size, allocatedBytes;
float** channels; float** channels;
float* allocatedData; float* allocatedData;
float* preallocatedChannelSpace [32];
}; };


#endif // __JUCE_AUDIOSAMPLEBUFFER_JUCEHEADER__ #endif // __JUCE_AUDIOSAMPLEBUFFER_JUCEHEADER__
@@ -45853,9 +45854,6 @@ private:
#endif #endif
#ifndef __JUCE_TOOLBARITEMCOMPONENT_JUCEHEADER__ #ifndef __JUCE_TOOLBARITEMCOMPONENT_JUCEHEADER__


#endif
#ifndef __JUCE_TREEVIEW_JUCEHEADER__

#endif #endif
#ifndef __JUCE_TEXTEDITOR_JUCEHEADER__ #ifndef __JUCE_TEXTEDITOR_JUCEHEADER__


@@ -46649,6 +46647,9 @@ private:
#endif #endif
#ifndef __JUCE_LABEL_JUCEHEADER__ #ifndef __JUCE_LABEL_JUCEHEADER__


#endif
#ifndef __JUCE_TREEVIEW_JUCEHEADER__

#endif #endif
#ifndef __JUCE_SLIDERPROPERTYCOMPONENT_JUCEHEADER__ #ifndef __JUCE_SLIDERPROPERTYCOMPONENT_JUCEHEADER__




+ 8
- 2
src/juce_appframework/audio/dsp/juce_AudioSampleBuffer.cpp View File

@@ -71,7 +71,11 @@ AudioSampleBuffer::AudioSampleBuffer (float** dataToReferTo,
{ {
jassert (numChannels_ > 0); jassert (numChannels_ > 0);
channels = (float**) juce_malloc ((numChannels_ + 1) * sizeof (float*));
// (try to avoid doing a malloc here, as that'll blow up things like Pro-Tools)
if (numChannels_ < numElementsInArray (preallocatedChannelSpace))
channels = (float**) preallocatedChannelSpace;
else
channels = (float**) juce_malloc ((numChannels_ + 1) * sizeof (float*));
for (int i = 0; i < numChannels_; ++i) for (int i = 0; i < numChannels_; ++i)
{ {
@@ -160,7 +164,9 @@ const AudioSampleBuffer& AudioSampleBuffer::operator= (const AudioSampleBuffer&
AudioSampleBuffer::~AudioSampleBuffer() throw() AudioSampleBuffer::~AudioSampleBuffer() throw()
{ {
juce_free (allocatedData); juce_free (allocatedData);
juce_free (channels);
if (channels != (float**) preallocatedChannelSpace)
juce_free (channels);
} }
float* AudioSampleBuffer::getSampleData (const int channelNumber, float* AudioSampleBuffer::getSampleData (const int channelNumber,


+ 1
- 0
src/juce_appframework/audio/dsp/juce_AudioSampleBuffer.h View File

@@ -409,6 +409,7 @@ private:
int numChannels, size, allocatedBytes; int numChannels, size, allocatedBytes;
float** channels; float** channels;
float* allocatedData; float* allocatedData;
float* preallocatedChannelSpace [32];
}; };


Loading…
Cancel
Save