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);
356 if(iChannel < getNumChannels())
358 return BIT_TEST(fBuffer.silenceFlags, iChannel);
371 return Channel{*
this, iChannel};
383 return Channel{*const_cast<class_type *>(
this), iChannel};
407 inline SampleType **getBuffer();
410 inline SampleType
const *
const *getBuffer()
const;
434 template<
typename UnaryFunction>
437 for(int32 channel = 0; channel < getNumChannels(); channel++)
439 f = getAudioChannel(channel).forEachSample(f);
457 template<
typename UnaryFunction>
460 for(int32 channel = 0; channel < getNumChannels(); channel++)
462 f = getAudioChannel(channel).forEachSample(f);
478 auto fromSamples = fromBuffer.
getBuffer();
479 auto toSamples = getBuffer();
482 if(fromSamples == toSamples)
486 if(!fromSamples || !toSamples)
489 int32 numChannels = std::min(getNumChannels(), fromBuffer.
getNumChannels());
490 int32 numSamples = std::min(getNumSamples(), fromBuffer.
getNumSamples());
492 for(int32 channel = 0; channel < numChannels; channel++)
494 auto ptrFrom = fromSamples[channel];
495 auto ptrTo = toSamples[channel];
498 if(!ptrFrom || !ptrTo)
501 std::copy(ptrFrom, ptrFrom + numSamples, ptrTo);
525 template<
typename UnaryOperation>
528 int32 numChannels = std::min(getNumChannels(), iFromBuffer.
getNumChannels());
530 for(int32 channel = 0; channel < numChannels; channel++)
532 f = getAudioChannel(channel).copyFrom(iFromBuffer.
getAudioChannel(channel), f);
541 template<
typename UnaryOperation>
556 for(int32 channel = 0; channel < getNumChannels(); channel++)
558 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:526
AudioBusBuffers & fBuffer
Definition: AudioBuffer.h:565
Unary operator adapter for computing the absolute max.
Definition: AudioBuffer.h:48
Channel getRightChannel()
Definition: AudioBuffer.h:399
constexpr int32 DEFAULT_RIGHT_CHANNEL
Definition: AudioBuffer.h:34
AudioBuffers< Sample32 > AudioBuffers32
Definition: AudioBuffer.h:581
UnaryOperation copyTo(class_type &iToBuffer, UnaryOperation f) const
Same as copyFrom with the roles reversed.
Definition: AudioBuffer.h:542
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:380
void setSilenceFlag(int32 iChannel, bool iSilent)
Sets a single channel silence flag.
Definition: AudioBuffer.h:340
const int32 fNumSamples
Definition: AudioBuffer.h:566
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:554
AudioBuffers(AudioBusBuffers &buffer, int32 numSamples)
Definition: AudioBuffer.h:286
SampleType absoluteMax() const
Definition: AudioBuffer.h:547
const Channel getLeftChannel() const
Definition: AudioBuffer.h:394
int32 getNumSamples() const
Definition: AudioBuffer.h:75
Channel getLeftChannel()
Definition: AudioBuffer.h:389
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
bool isActive() const
Definition: AudioBuffer.h:128
int32 getNumChannels() const
Definition: AudioBuffer.h:415
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:582
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:458
#define BIT_CLEAR(a, b)
Definition: AudioUtils.h:31
bool isSilent(int32 iChannel) const
Definition: AudioBuffer.h:354
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:435
constexpr int32 DEFAULT_LEFT_CHANNEL
Definition: AudioBuffer.h:33
Channel getAudioChannel(int32 iChannel)
Return the audio channel for the provided channel.
Definition: AudioBuffer.h:369
bool isSilent(Sample32 value)
Definition: AudioUtils.h:49
Channel(AudioBuffers &iBuffers, int32 iChannel)
Definition: AudioBuffer.h:68
int32 fChannel
Definition: AudioBuffer.h:279
#define BIT_TEST(a, b)
Definition: AudioUtils.h:32
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:471
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:420
uint64 getSilenceFlags() const
Definition: AudioBuffer.h:332
#define BIT_SET(a, b)
Definition: AudioUtils.h:30
tresult copyFrom(class_type const &fromBuffer)
Copy the content of the provided buffer to THIS buffer (up to num samples)
Definition: AudioBuffer.h:476
const Channel getRightChannel() const
Definition: AudioBuffer.h:404
void setSilenceFlag(bool iSilent)
Sets a single channel silence flag.
Definition: AudioBuffer.h:120
SampleType ** getBuffer()
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