20 #include <pluginterfaces/vst/ivstaudioprocessor.h> 21 #include <pongasoft/logging/logging.h> 29 using namespace Steinberg;
30 using namespace Steinberg::Vst;
41 template<
typename SampleType>
52 fAbsoluteMax = std::max(fAbsoluteMax, iSample < 0 ? -iSample : iSample);
55 SampleType fAbsoluteMax = 0;
77 return fBuffers.getNumSamples();
93 return fChannel < fBuffers.getNumChannels() ? fBuffers.getBuffer()[fChannel] :
nullptr;
109 return fChannel < fBuffers.getNumChannels() ? fBuffers.getBuffer()[fChannel] :
nullptr;
115 inline bool isSilent()
const {
return fBuffers.isSilent(fChannel); }
122 fBuffers.setSilenceFlag(fChannel, iSilent);
130 return fChannel < fBuffers.getNumChannels() && getBuffer() !=
nullptr;
143 int32 numSamples = std::min(getNumSamples(), fromChannel.
getNumSamples());
146 auto ptrTo = getBuffer();
149 if(!ptrFrom || !ptrTo)
152 std::copy(ptrFrom, ptrFrom + numSamples, ptrTo);
169 auto buffer = getBuffer();
175 std::fill(buffer, buffer + getNumSamples(), 0);
177 setSilenceFlag(
true);
192 template<
typename UnaryFunction>
195 auto buffer = getBuffer();
199 return std::for_each(buffer, buffer + getNumSamples(), f);
217 template<
typename UnaryFunction>
220 auto buffer = getBuffer();
224 return std::for_each(buffer, buffer + getNumSamples(), f);
250 template<
typename UnaryOperation>
253 auto outputBuffer = getBuffer();
254 auto inputBuffer = iFromChannel.
getBuffer();
256 if(outputBuffer && inputBuffer)
258 int32
const numSamples = std::min(getNumSamples(), iFromChannel.
getNumSamples());
262 std::transform<decltype(inputBuffer), decltype(outputBuffer), UnaryOperation &>(inputBuffer, inputBuffer + numSamples, outputBuffer, f);
271 template<
typename UnaryOperation>
274 return oToChannel.
copyFrom(*
this, f);
286 AudioBuffers(AudioBusBuffers &buffer, int32 numSamples) : fBuffer(buffer), fNumSamples(numSamples)
292 return fBuffer.numChannels == 0 || fBuffer.silenceFlags == (static_cast<uint64>(1) << fBuffer.numChannels) - 1;
301 uint64 silenceFlags = 0;
303 auto buffer = getBuffer();
305 for(int32 channel = 0; channel < getNumChannels(); channel++)
309 auto ptr = buffer[channel];
314 for(
int j = 0; j < getNumSamples(); ++j, ptr++)
323 BIT_SET(silenceFlags, channel);
326 fBuffer.silenceFlags = silenceFlags;
342 if(iChannel < getNumChannels())
345 BIT_SET(fBuffer.silenceFlags, iChannel);
347 BIT_CLEAR(fBuffer.silenceFlags, iChannel);
357 fBuffer.silenceFlags = 0;
365 if(iChannel < getNumChannels())
367 return BIT_TEST(fBuffer.silenceFlags, iChannel);
380 return Channel{*
this, iChannel};
392 return Channel{*const_cast<class_type *>(
this), iChannel};
416 inline SampleType **getBuffer();
419 inline SampleType
const *
const *getBuffer()
const;
449 template<
typename UnaryFunction>
452 for(int32 channel = 0; channel < getNumChannels(); channel++)
454 f = getAudioChannel(channel).forEachSample(f);
472 template<
typename UnaryFunction>
475 for(int32 channel = 0; channel < getNumChannels(); channel++)
477 f = getAudioChannel(channel).forEachSample(f);
493 auto fromSamples = fromBuffer.
getBuffer();
494 auto toSamples = getBuffer();
497 if(fromSamples == toSamples)
501 if(!fromSamples || !toSamples)
504 int32 numChannels = std::min(getNumChannels(), fromBuffer.
getNumChannels());
505 int32 numSamples = std::min(getNumSamples(), fromBuffer.
getNumSamples());
507 for(int32 channel = 0; channel < numChannels; channel++)
509 auto ptrFrom = fromSamples[channel];
510 auto ptrTo = toSamples[channel];
513 if(!ptrFrom || !ptrTo)
516 std::copy(ptrFrom, ptrFrom + numSamples, ptrTo);
540 template<
typename UnaryOperation>
543 int32 numChannels = std::min(getNumChannels(), iFromBuffer.
getNumChannels());
545 for(int32 channel = 0; channel < numChannels; channel++)
547 f = getAudioChannel(channel).copyFrom(iFromBuffer.
getAudioChannel(channel), f);
556 template<
typename UnaryOperation>
571 for(int32 channel = 0; channel < getNumChannels(); channel++)
573 getAudioChannel(channel).clear();
Represents all the buffers (example for a stereo channel there is 2 underlying sample buffers)
Definition: AudioBuffer.h:42
UnaryOperation copyFrom(class_type const &iFromBuffer, UnaryOperation f)
Copy iFromBuffer to this buffer, applying f to each sample for each channel or in other words,...
Definition: AudioBuffer.h:541
AudioBusBuffers & fBuffer
Definition: AudioBuffer.h:580
Unary operator adapter for computing the absolute max.
Definition: AudioBuffer.h:48
Channel getRightChannel()
Definition: AudioBuffer.h:408
constexpr int32 DEFAULT_RIGHT_CHANNEL
Definition: AudioBuffer.h:34
AudioBuffers< Sample32 > AudioBuffers32
Definition: AudioBuffer.h:596
UnaryOperation copyTo(class_type &iToBuffer, UnaryOperation f) const
Same as copyFrom with the roles reversed.
Definition: AudioBuffer.h:557
Represents a single channel (for example left audio channel).
Definition: AudioBuffer.h:65
AudioBuffers< SampleType > class_type
Definition: AudioBuffer.h:282
const Channel getAudioChannel(int32 iChannel) const
Return the audio channel for the provided channel.
Definition: AudioBuffer.h:389
void setSilenceFlag(int32 iChannel, bool iSilent)
Sets a single channel silence flag.
Definition: AudioBuffer.h:340
AudioBusBuffers & getAudioBusBuffers()
Returns the AudioBusBuffers original buffer.
Definition: AudioBuffer.h:422
const int32 fNumSamples
Definition: AudioBuffer.h:581
SampleType const * getBuffer() const
Note that this pointer is NOT guaranteed to be not null as demonstrated by this piece of logic in the...
Definition: AudioBuffer.h:107
tresult clear()
Clears the buffer (and sets the silence flag)
Definition: AudioBuffer.h:569
AudioBuffers(AudioBusBuffers &buffer, int32 numSamples)
Definition: AudioBuffer.h:286
SampleType absoluteMax() const
Definition: AudioBuffer.h:562
const Channel getLeftChannel() const
Definition: AudioBuffer.h:403
int32 getNumSamples() const
Definition: AudioBuffer.h:75
Channel getLeftChannel()
Definition: AudioBuffer.h:398
UnaryOperation copyTo(Channel &oToChannel, UnaryOperation f) const
Same as copyFrom with the roles reversed.
Definition: AudioBuffer.h:272
UnaryFunction forEachSample(UnaryFunction f) const
Applies the provided unary function to each sample (if the channel is active).
Definition: AudioBuffer.h:218
void clearSilentFlag()
Makes the buffer NON silent (by setting the flag to 0).
Definition: AudioBuffer.h:355
bool isActive() const
Definition: AudioBuffer.h:128
int32 getNumChannels() const
Definition: AudioBuffer.h:430
AudioBuffers & fBuffers
Definition: AudioBuffer.h:278
void operator()(SampleType iSample)
Definition: AudioBuffer.h:50
bool isSilent() const
Definition: AudioBuffer.h:115
bool adjustSilenceFlags()
Computes and adjust the silence flags.
Definition: AudioBuffer.h:299
AudioBuffers< Sample64 > AudioBuffers64
Definition: AudioBuffer.h:597
void setSilenceFlags(uint64 iFlags) const
Definition: AudioBuffer.h:335
UnaryFunction forEachSample(UnaryFunction f) const
Applies the provided unary function to each sample of each channel.
Definition: AudioBuffer.h:473
#define BIT_CLEAR(a, b)
Definition: AudioUtils.h:32
bool isSilent(int32 iChannel) const
Definition: AudioBuffer.h:363
UnaryOperation copyFrom(Channel const &iFromChannel, UnaryOperation f)
Copy iFromChannel to this channel, applying f to each sample or in other words, for each sample.
Definition: AudioBuffer.h:251
UnaryFunction forEachSample(UnaryFunction f)
Applies the provided unary function to each sample of each channel.
Definition: AudioBuffer.h:450
constexpr int32 DEFAULT_LEFT_CHANNEL
Definition: AudioBuffer.h:33
Channel getAudioChannel(int32 iChannel)
Return the audio channel for the provided channel.
Definition: AudioBuffer.h:378
bool isSilent(Sample32 value)
Definition: AudioUtils.h:62
Channel(AudioBuffers &iBuffers, int32 iChannel)
Definition: AudioBuffer.h:68
int32 fChannel
Definition: AudioBuffer.h:279
#define BIT_TEST(a, b)
Definition: AudioUtils.h:33
bool isSilent() const
Definition: AudioBuffer.h:290
SampleType absoluteMax() const
Definition: AudioBuffer.h:160
tresult copyTo(class_type &toBuffer) const
Copy the content of THIS buffer to the provided buffer (up to num samples)
Definition: AudioBuffer.h:486
tresult copyTo(Channel &toChannel) const
Copy the content of THIS channel to the provided channel (up to num samples)
Definition: AudioBuffer.h:136
SampleType * getBuffer()
Note that this pointer is NOT guaranteed to be not null as demonstrated by this piece of logic in the...
Definition: AudioBuffer.h:91
int32 getNumSamples() const
Definition: AudioBuffer.h:435
uint64 getSilenceFlags() const
Definition: AudioBuffer.h:332
#define BIT_SET(a, b)
Definition: AudioUtils.h:31
tresult copyFrom(class_type const &fromBuffer)
Copy the content of the provided buffer to THIS buffer (up to num samples)
Definition: AudioBuffer.h:491
AudioBusBuffers const & getAudioBusBuffers() const
Returns the AudioBusBuffers original buffer (const version)
Definition: AudioBuffer.h:425
const Channel getRightChannel() const
Definition: AudioBuffer.h:413
void setSilenceFlag(bool iSilent)
Sets a single channel silence flag.
Definition: AudioBuffer.h:120
SampleType ** getBuffer()
Returns the underlying (sample) buffer.
tresult copyFrom(Channel const &fromChannel)
Copy the content of the provided channel to THIS channel (up to num samples)
Definition: AudioBuffer.h:141
void clear()
Clears the channel (and sets the silence flag)
Definition: AudioBuffer.h:167
UnaryFunction forEachSample(UnaryFunction f)
Applies the provided unary function to each sample (if the channel is active).
Definition: AudioBuffer.h:193