Browse Source

Relaxed the requirement for AudioSampleBuffer to have more than zero channels, and gave it a default constructor.

tags/2021-05-28
jules 11 years ago
parent
commit
a0c18acb1e
15 changed files with 32 additions and 37 deletions
  1. +1
    -3
      extras/Demo/Source/Demos/AudioLatencyDemo.cpp
  2. +18
    -8
      modules/juce_audio_basics/buffers/juce_AudioSampleBuffer.cpp
  3. +6
    -2
      modules/juce_audio_basics/buffers/juce_AudioSampleBuffer.h
  4. +0
    -1
      modules/juce_audio_basics/sources/juce_BufferingAudioSource.cpp
  5. +1
    -2
      modules/juce_audio_basics/sources/juce_ChannelRemappingAudioSource.cpp
  6. +1
    -3
      modules/juce_audio_basics/sources/juce_MixerAudioSource.cpp
  7. +0
    -2
      modules/juce_audio_basics/sources/juce_ResamplingAudioSource.cpp
  8. +0
    -1
      modules/juce_audio_devices/audio_io/juce_AudioDeviceManager.cpp
  9. +1
    -2
      modules/juce_audio_devices/native/juce_mac_CoreAudio.cpp
  10. +2
    -4
      modules/juce_audio_devices/native/juce_win32_DirectSound.cpp
  11. +0
    -1
      modules/juce_audio_devices/sources/juce_AudioSourcePlayer.cpp
  12. +0
    -1
      modules/juce_audio_formats/codecs/juce_FlacAudioFormat.cpp
  13. +1
    -3
      modules/juce_audio_formats/codecs/juce_OggVorbisAudioFormat.cpp
  14. +0
    -2
      modules/juce_audio_processors/processors/juce_AudioProcessorGraph.cpp
  15. +1
    -2
      modules/juce_audio_utils/players/juce_AudioProcessorPlayer.cpp

+ 1
- 3
extras/Demo/Source/Demos/AudioLatencyDemo.cpp View File

@@ -32,9 +32,7 @@ class LatencyTester : public AudioIODeviceCallback,
{
public:
LatencyTester (TextEditor& resultsBox_)
: testSound (1, 1),
recordedSound (1, 1),
playingSampleNum (0),
: playingSampleNum (0),
recordedSampleNum (-1),
sampleRate (0),
testIsRunning (false),


+ 18
- 8
modules/juce_audio_basics/buffers/juce_AudioSampleBuffer.cpp View File

@@ -22,13 +22,20 @@
==============================================================================
*/
AudioSampleBuffer::AudioSampleBuffer() noexcept
: numChannels (0), size (0), allocatedBytes (0),
channels (static_cast<float**> (preallocatedChannelSpace)),
isClear (false)
{
}
AudioSampleBuffer::AudioSampleBuffer (const int numChans,
const int numSamples) noexcept
: numChannels (numChans),
size (numSamples)
{
jassert (numSamples >= 0);
jassert (numChans > 0);
jassert (numChans >= 0);
allocateData();
}
@@ -63,7 +70,7 @@ void AudioSampleBuffer::allocateData()
const size_t channelListSize = sizeof (float*) * (size_t) (numChannels + 1);
allocatedBytes = (size_t) numChannels * (size_t) size * sizeof (float) + channelListSize + 32;
allocatedData.malloc (allocatedBytes);
channels = reinterpret_cast <float**> (allocatedData.getData());
channels = reinterpret_cast<float**> (allocatedData.getData());
float* chan = (float*) (allocatedData + channelListSize);
for (int i = 0; i < numChannels; ++i)
@@ -83,7 +90,8 @@ AudioSampleBuffer::AudioSampleBuffer (float* const* dataToReferTo,
size (numSamples),
allocatedBytes (0)
{
jassert (numChans > 0);
jassert (dataToReferTo != nullptr);
jassert (numChans >= 0);
allocateChannels (dataToReferTo, 0);
}
@@ -96,7 +104,8 @@ AudioSampleBuffer::AudioSampleBuffer (float* const* dataToReferTo,
allocatedBytes (0),
isClear (false)
{
jassert (numChans > 0);
jassert (dataToReferTo != nullptr);
jassert (numChans >= 0);
allocateChannels (dataToReferTo, startSample);
}
@@ -104,7 +113,8 @@ void AudioSampleBuffer::setDataToReferTo (float** dataToReferTo,
const int newNumChannels,
const int newNumSamples) noexcept
{
jassert (newNumChannels > 0);
jassert (dataToReferTo != nullptr);
jassert (newNumChannels >= 0);
allocatedBytes = 0;
allocatedData.free();
@@ -121,12 +131,12 @@ void AudioSampleBuffer::allocateChannels (float* const* const dataToReferTo, int
// (try to avoid doing a malloc here, as that'll blow up things like Pro-Tools)
if (numChannels < (int) numElementsInArray (preallocatedChannelSpace))
{
channels = static_cast <float**> (preallocatedChannelSpace);
channels = static_cast<float**> (preallocatedChannelSpace);
}
else
{
allocatedData.malloc ((size_t) numChannels + 1, sizeof (float*));
channels = reinterpret_cast <float**> (allocatedData.getData());
channels = reinterpret_cast<float**> (allocatedData.getData());
}
for (int i = 0; i < numChannels; ++i)
@@ -171,7 +181,7 @@ void AudioSampleBuffer::setSize (const int newNumChannels,
const bool clearExtraSpace,
const bool avoidReallocating) noexcept
{
jassert (newNumChannels > 0);
jassert (newNumChannels >= 0);
jassert (newNumSamples >= 0);
if (newNumSamples != size || newNumChannels != numChannels)


+ 6
- 2
modules/juce_audio_basics/buffers/juce_AudioSampleBuffer.h View File

@@ -34,6 +34,10 @@
class JUCE_API AudioSampleBuffer
{
public:
//==============================================================================
/** Creates an empty buffer with 0 channels and 0 length. */
AudioSampleBuffer() noexcept;
//==============================================================================
/** Creates a buffer with a specified number of channels and samples.
@@ -93,12 +97,12 @@ public:
using an external data buffer, in which case boths buffers will just point to the same
shared block of data.
*/
AudioSampleBuffer (const AudioSampleBuffer& other) noexcept;
AudioSampleBuffer (const AudioSampleBuffer&) noexcept;
/** Copies another buffer onto this one.
This buffer's size will be changed to that of the other buffer.
*/
AudioSampleBuffer& operator= (const AudioSampleBuffer& other) noexcept;
AudioSampleBuffer& operator= (const AudioSampleBuffer&) noexcept;
/** Destructor.
This will free any memory allocated by the buffer.


+ 0
- 1
modules/juce_audio_basics/sources/juce_BufferingAudioSource.cpp View File

@@ -31,7 +31,6 @@ BufferingAudioSource::BufferingAudioSource (PositionableAudioSource* s,
backgroundThread (thread),
numberOfSamplesToBuffer (jmax (1024, bufferSizeSamples)),
numberOfChannels (numChannels),
buffer (numChannels, 0),
bufferValidStart (0),
bufferValidEnd (0),
nextPlayPos (0),


+ 1
- 2
modules/juce_audio_basics/sources/juce_ChannelRemappingAudioSource.cpp View File

@@ -25,8 +25,7 @@
ChannelRemappingAudioSource::ChannelRemappingAudioSource (AudioSource* const source_,
const bool deleteSourceWhenDeleted)
: source (source_, deleteSourceWhenDeleted),
requiredNumberOfChannels (2),
buffer (2, 16)
requiredNumberOfChannels (2)
{
remappedInfo.buffer = &buffer;
remappedInfo.startSample = 0;


+ 1
- 3
modules/juce_audio_basics/sources/juce_MixerAudioSource.cpp View File

@@ -23,9 +23,7 @@
*/
MixerAudioSource::MixerAudioSource()
: tempBuffer (2, 0),
currentSampleRate (0.0),
bufferSizeExpected (0)
: currentSampleRate (0.0), bufferSizeExpected (0)
{
}


+ 0
- 2
modules/juce_audio_basics/sources/juce_ResamplingAudioSource.cpp View File

@@ -28,14 +28,12 @@ ResamplingAudioSource::ResamplingAudioSource (AudioSource* const inputSource,
: input (inputSource, deleteInputWhenDeleted),
ratio (1.0),
lastRatio (1.0),
buffer (numChannels_, 0),
bufferPos (0),
sampsInBuffer (0),
subSampleOffset (0),
numChannels (numChannels_)
{
jassert (input != nullptr);
zeromem (coefficients, sizeof (coefficients));
}


+ 0
- 1
modules/juce_audio_devices/audio_io/juce_AudioDeviceManager.cpp View File

@@ -95,7 +95,6 @@ AudioDeviceManager::AudioDeviceManager()
useInputNames (false),
inputLevel (0),
testSoundPosition (0),
tempBuffer (2, 2),
cpuUsageMs (0),
timeToCpuScale (0)
{


+ 1
- 2
modules/juce_audio_devices/native/juce_mac_CoreAudio.cpp View File

@@ -1026,8 +1026,7 @@ public:
AudioIODeviceCombiner (const String& deviceName)
: AudioIODevice (deviceName, "CoreAudio"),
Thread (deviceName), callback (nullptr),
currentSampleRate (0), currentBufferSize (0), active (false),
fifos (1, 1)
currentSampleRate (0), currentBufferSize (0), active (false)
{
}


+ 2
- 4
modules/juce_audio_devices/native/juce_win32_DirectSound.cpp View File

@@ -731,8 +731,6 @@ public:
isStarted (false),
bufferSizeSamples (0),
sampleRate (0.0),
inputBuffers (1, 1),
outputBuffers (1, 1),
callback (nullptr)
{
if (outputDeviceIndex_ >= 0)
@@ -871,8 +869,8 @@ private:
bool isStarted;
String lastError;
OwnedArray <DSoundInternalInChannel> inChans;
OwnedArray <DSoundInternalOutChannel> outChans;
OwnedArray<DSoundInternalInChannel> inChans;
OwnedArray<DSoundInternalOutChannel> outChans;
WaitableEvent startEvent;
int bufferSizeSamples;


+ 0
- 1
modules/juce_audio_devices/sources/juce_AudioSourcePlayer.cpp View File

@@ -26,7 +26,6 @@ AudioSourcePlayer::AudioSourcePlayer()
: source (nullptr),
sampleRate (0),
bufferSize (0),
tempBuffer (2, 8),
lastGain (1.0f),
gain (1.0f)
{


+ 0
- 1
modules/juce_audio_formats/codecs/juce_FlacAudioFormat.cpp View File

@@ -104,7 +104,6 @@ class FlacReader : public AudioFormatReader
public:
FlacReader (InputStream* const in)
: AudioFormatReader (in, flacFormatName),
reservoir (2, 0),
reservoirStart (0),
samplesInReservoir (0),
scanningForLength (false)


+ 1
- 3
modules/juce_audio_formats/codecs/juce_OggVorbisAudioFormat.cpp View File

@@ -106,7 +106,6 @@ class OggReader : public AudioFormatReader
public:
OggReader (InputStream* const inp)
: AudioFormatReader (inp, oggFormatName),
reservoir (2, 4096),
reservoirStart (0),
samplesInReservoir (0)
{
@@ -140,8 +139,7 @@ public:
bitsPerSample = 16;
sampleRate = info->rate;
reservoir.setSize ((int) numChannels,
(int) jmin (lengthInSamples, (int64) reservoir.getNumSamples()));
reservoir.setSize ((int) numChannels, (int) jmin (lengthInSamples, (int64) 4096));
}
}


+ 0
- 2
modules/juce_audio_processors/processors/juce_AudioProcessorGraph.cpp View File

@@ -923,9 +923,7 @@ void AudioProcessorGraph::Node::setParentGraph (AudioProcessorGraph* const graph
//==============================================================================
AudioProcessorGraph::AudioProcessorGraph()
: lastNodeId (0),
renderingBuffers (1, 1),
currentAudioInputBuffer (nullptr),
currentAudioOutputBuffer (1, 1),
currentMidiInputBuffer (nullptr)
{
}


+ 1
- 2
modules/juce_audio_utils/players/juce_AudioProcessorPlayer.cpp View File

@@ -28,8 +28,7 @@ AudioProcessorPlayer::AudioProcessorPlayer()
blockSize (0),
isPrepared (false),
numInputChans (0),
numOutputChans (0),
tempBuffer (1, 1)
numOutputChans (0)
{
}


Loading…
Cancel
Save