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();
Definition: AudioBuffer.h:42
UnaryOperation copyFrom(Channel const &iFromChannel, UnaryOperation f)
Definition: AudioBuffer.h:251
Definition: AudioBuffer.h:48
constexpr int32 DEFAULT_RIGHT_CHANNEL
Definition: AudioBuffer.h:34
void operator()(SampleType iSample)
Definition: AudioBuffer.h:50
UnaryFunction forEachSample(UnaryFunction f) const
Definition: AudioBuffer.h:218
AudioBuffers< Sample64 > AudioBuffers64
Definition: AudioBuffer.h:582
Definition: AudioBuffer.h:65
tresult clear()
Definition: AudioBuffer.h:554
AudioBuffers< Sample32 > AudioBuffers32
Definition: AudioBuffer.h:581
SampleType absoluteMax() const
Definition: AudioBuffer.h:160
SampleType ** getBuffer()
SampleType absoluteMax() const
Definition: AudioBuffer.h:547
tresult copyTo(Channel &toChannel) const
Definition: AudioBuffer.h:136
bool isActive() const
Definition: AudioBuffer.h:128
UnaryOperation copyFrom(class_type const &iFromBuffer, UnaryOperation f)
Definition: AudioBuffer.h:526
AudioBuffers< SampleType > class_type
Definition: AudioBuffer.h:282
uint64 getSilenceFlags() const
Definition: AudioBuffer.h:332
int32 getNumSamples() const
Definition: AudioBuffer.h:75
tresult copyTo(class_type &toBuffer) const
Definition: AudioBuffer.h:471
int32 fChannel
Definition: AudioBuffer.h:279
SampleType const * getBuffer() const
Definition: AudioBuffer.h:107
bool adjustSilenceFlags()
Definition: AudioBuffer.h:299
UnaryFunction forEachSample(UnaryFunction f)
Definition: AudioBuffer.h:435
tresult copyFrom(Channel const &fromChannel)
Definition: AudioBuffer.h:141
UnaryFunction forEachSample(UnaryFunction f)
Definition: AudioBuffer.h:193
int32 getNumSamples() const
Definition: AudioBuffer.h:420
AudioBusBuffers & fBuffer
Definition: AudioBuffer.h:565
UnaryOperation copyTo(class_type &iToBuffer, UnaryOperation f) const
Definition: AudioBuffer.h:542
Channel getLeftChannel()
Definition: AudioBuffer.h:389
#define BIT_CLEAR(a, b)
Definition: AudioUtils.h:31
bool isSilent() const
Definition: AudioBuffer.h:115
bool isSilent(Sample32 value)
Definition: AudioUtils.h:49
int32 getNumChannels() const
Definition: AudioBuffer.h:415
const Channel getLeftChannel() const
Definition: AudioBuffer.h:394
void setSilenceFlag(bool iSilent)
Definition: AudioBuffer.h:120
#define BIT_TEST(a, b)
Definition: AudioUtils.h:32
tresult copyFrom(class_type const &fromBuffer)
Definition: AudioBuffer.h:476
constexpr int32 DEFAULT_LEFT_CHANNEL
Definition: AudioBuffer.h:33
void clear()
Definition: AudioBuffer.h:167
#define BIT_SET(a, b)
Definition: AudioUtils.h:30
SampleType * getBuffer()
Definition: AudioBuffer.h:91
const Channel getAudioChannel(int32 iChannel) const
Definition: AudioBuffer.h:380
Channel(AudioBuffers &iBuffers, int32 iChannel)
Definition: AudioBuffer.h:68
void setSilenceFlag(int32 iChannel, bool iSilent)
Definition: AudioBuffer.h:340
void setSilenceFlags(uint64 iFlags) const
Definition: AudioBuffer.h:335
bool isSilent() const
Definition: AudioBuffer.h:290
Channel getAudioChannel(int32 iChannel)
Definition: AudioBuffer.h:369
UnaryFunction forEachSample(UnaryFunction f) const
Definition: AudioBuffer.h:458
AudioBuffers(AudioBusBuffers &buffer, int32 numSamples)
Definition: AudioBuffer.h:286
AudioBuffers & fBuffers
Definition: AudioBuffer.h:278
const Channel getRightChannel() const
Definition: AudioBuffer.h:404
Channel getRightChannel()
Definition: AudioBuffer.h:399
UnaryOperation copyTo(Channel &oToChannel, UnaryOperation f) const
Definition: AudioBuffer.h:272
const int32 fNumSamples
Definition: AudioBuffer.h:566
bool isSilent(int32 iChannel) const
Definition: AudioBuffer.h:354