mirror of
https://github.com/juce-framework/JUCE.git
synced 2026-01-10 23:44:24 +00:00
Relaxed the requirement for AudioSampleBuffer to have more than zero channels, and gave it a default constructor.
This commit is contained in:
parent
c86a3104b2
commit
a0c18acb1e
15 changed files with 32 additions and 37 deletions
|
|
@ -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),
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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.
|
||||
|
|
|
|||
|
|
@ -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),
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -23,9 +23,7 @@
|
|||
*/
|
||||
|
||||
MixerAudioSource::MixerAudioSource()
|
||||
: tempBuffer (2, 0),
|
||||
currentSampleRate (0.0),
|
||||
bufferSizeExpected (0)
|
||||
: currentSampleRate (0.0), bufferSizeExpected (0)
|
||||
{
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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));
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -95,7 +95,6 @@ AudioDeviceManager::AudioDeviceManager()
|
|||
useInputNames (false),
|
||||
inputLevel (0),
|
||||
testSoundPosition (0),
|
||||
tempBuffer (2, 2),
|
||||
cpuUsageMs (0),
|
||||
timeToCpuScale (0)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
{
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -26,7 +26,6 @@ AudioSourcePlayer::AudioSourcePlayer()
|
|||
: source (nullptr),
|
||||
sampleRate (0),
|
||||
bufferSize (0),
|
||||
tempBuffer (2, 8),
|
||||
lastGain (1.0f),
|
||||
gain (1.0f)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
{
|
||||
}
|
||||
|
|
|
|||
|
|
@ -28,8 +28,7 @@ AudioProcessorPlayer::AudioProcessorPlayer()
|
|||
blockSize (0),
|
||||
isPrepared (false),
|
||||
numInputChans (0),
|
||||
numOutputChans (0),
|
||||
tempBuffer (1, 1)
|
||||
numOutputChans (0)
|
||||
{
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue