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>
57 return fBuffers.getNumSamples();
71 return fChannel < fBuffers.getNumChannels() ? fBuffers.getBuffer()[fChannel] :
nullptr;
77 inline bool isSilent()
const {
return fBuffers.isSilent(fChannel); }
84 fBuffers.setSilenceFlag(fChannel, iSilent);
92 return fChannel < fBuffers.getNumChannels() && getBuffer() !=
nullptr;
105 int32 numSamples = std::min(getNumSamples(), fromChannel.
getNumSamples());
108 auto ptrTo = getBuffer();
111 if(!ptrFrom || !ptrTo)
114 std::copy(ptrFrom, ptrFrom + numSamples, ptrTo);
123 auto buffer = getBuffer();
129 std::fill(buffer, buffer + getNumSamples(), 0);
131 setSilenceFlag(
true);
143 AudioBuffers(AudioBusBuffers &buffer, int32 numSamples) : fBuffer(buffer), fNumSamples(numSamples)
149 return fBuffer.numChannels == 0 || fBuffer.silenceFlags == (static_cast<uint64>(1) << fBuffer.numChannels) - 1;
158 uint64 silenceFlags = 0;
160 auto buffer = getBuffer();
162 for(int32 channel = 0; channel < getNumChannels(); channel++)
166 auto ptr = buffer[channel];
171 for(
int j = 0; j < getNumSamples(); ++j, ptr++)
180 BIT_SET(silenceFlags, channel);
183 fBuffer.silenceFlags = silenceFlags;
199 if(iChannel < getNumChannels())
202 BIT_SET(fBuffer.silenceFlags, iChannel);
204 BIT_CLEAR(fBuffer.silenceFlags, iChannel);
213 if(iChannel < getNumChannels())
215 return BIT_TEST(fBuffer.silenceFlags, iChannel);
225 return Channel{*
this, iChannel};
239 inline SampleType **getBuffer()
const;
261 SampleType **fromSamples = fromBuffer.
getBuffer();
262 SampleType **toSamples = getBuffer();
265 if(fromSamples == toSamples)
269 if(!fromSamples || !toSamples)
272 int32 numChannels = std::min(getNumChannels(), fromBuffer.
getNumChannels());
273 int32 numSamples = std::min(getNumSamples(), fromBuffer.
getNumSamples());
275 for(int32 channel = 0; channel < numChannels; channel++)
277 auto ptrFrom = fromSamples[channel];
278 auto ptrTo = toSamples[channel];
281 if(!ptrFrom || !ptrTo)
284 std::copy(ptrFrom, ptrFrom + numSamples, ptrTo);
297 auto buffer = getBuffer();
303 for(int32 channel = 0; channel < getNumChannels(); channel++)
305 auto ptr = buffer[channel];
311 for(
int j = 0; j < getNumSamples(); ++j, ptr++)
317 max = std::max(max, sample);
328 auto buffer = getBuffer();
334 for(int32 channel = 0; channel < getNumChannels(); channel++)
336 auto ptr = buffer[channel];
342 std::fill(ptr, ptr + getNumSamples(), 0);
345 if(getNumChannels() > 0)
346 fBuffer.silenceFlags = (static_cast<uint64>(1) << getNumChannels()) - 1;
Definition: AudioBuffer.h:42
constexpr int32 DEFAULT_RIGHT_CHANNEL
Definition: AudioBuffer.h:34
AudioBuffers< Sample64 > AudioBuffers64
Definition: AudioBuffer.h:363
Definition: AudioBuffer.h:45
tresult clear()
Definition: AudioBuffer.h:326
AudioBuffers< Sample32 > AudioBuffers32
Definition: AudioBuffer.h:362
SampleType absoluteMax()
Definition: AudioBuffer.h:293
tresult copyTo(Channel &toChannel) const
Definition: AudioBuffer.h:98
bool isActive() const
Definition: AudioBuffer.h:90
AudioBuffers< SampleType > class_type
Definition: AudioBuffer.h:139
uint64 getSilenceFlags() const
Definition: AudioBuffer.h:189
int32 getNumSamples() const
Definition: AudioBuffer.h:55
tresult copyTo(class_type &toBuffer) const
Definition: AudioBuffer.h:254
int32 fChannel
Definition: AudioBuffer.h:136
bool adjustSilenceFlags()
Definition: AudioBuffer.h:156
tresult copyFrom(Channel const &fromChannel)
Definition: AudioBuffer.h:103
SampleType * getBuffer() const
Definition: AudioBuffer.h:69
int32 getNumSamples() const
Definition: AudioBuffer.h:249
AudioBusBuffers & fBuffer
Definition: AudioBuffer.h:352
Channel getLeftChannel()
Definition: AudioBuffer.h:231
#define BIT_CLEAR(a, b)
Definition: AudioUtils.h:31
bool isSilent() const
Definition: AudioBuffer.h:77
bool isSilent(Sample32 value)
Definition: AudioUtils.h:49
int32 getNumChannels() const
Definition: AudioBuffer.h:244
void setSilenceFlag(bool iSilent)
Definition: AudioBuffer.h:82
#define BIT_TEST(a, b)
Definition: AudioUtils.h:32
tresult copyFrom(class_type const &fromBuffer)
Definition: AudioBuffer.h:259
constexpr int32 DEFAULT_LEFT_CHANNEL
Definition: AudioBuffer.h:33
void clear()
Definition: AudioBuffer.h:121
SampleType ** getBuffer() const
#define BIT_SET(a, b)
Definition: AudioUtils.h:30
Channel(AudioBuffers &iBuffers, int32 iChannel)
Definition: AudioBuffer.h:48
void setSilenceFlag(int32 iChannel, bool iSilent)
Definition: AudioBuffer.h:197
void setSilenceFlags(uint64 iFlags) const
Definition: AudioBuffer.h:192
bool isSilent() const
Definition: AudioBuffer.h:147
Channel getAudioChannel(int32 iChannel)
Definition: AudioBuffer.h:223
AudioBuffers(AudioBusBuffers &buffer, int32 numSamples)
Definition: AudioBuffer.h:143
AudioBuffers & fBuffers
Definition: AudioBuffer.h:135
Channel getRightChannel()
Definition: AudioBuffer.h:236
const int32 fNumSamples
Definition: AudioBuffer.h:353
bool isSilent(int32 iChannel) const
Definition: AudioBuffer.h:211