Jamba C++ API  5.1.1
AudioBuffers< SampleType >::Channel Class Reference

Represents a single channel (for example left audio channel). More...

#include <AudioBuffer.h>

Public Member Functions

SampleType absoluteMax () const
 
 Channel (AudioBuffers &iBuffers, int32 iChannel)
 
void clear ()
 Clears the channel (and sets the silence flag) More...
 
tresult copyFrom (Channel const &fromChannel)
 Copy the content of the provided channel to THIS channel (up to num samples) More...
 
template<typename UnaryOperation >
UnaryOperation copyFrom (Channel const &iFromChannel, UnaryOperation f)
 Copy iFromChannel to this channel, applying f to each sample or in other words, for each sample. More...
 
tresult copyTo (Channel &toChannel) const
 Copy the content of THIS channel to the provided channel (up to num samples) More...
 
template<typename UnaryOperation >
UnaryOperation copyTo (Channel &oToChannel, UnaryOperation f) const
 Same as copyFrom with the roles reversed. More...
 
template<typename UnaryFunction >
UnaryFunction forEachSample (UnaryFunction f)
 Applies the provided unary function to each sample (if the channel is active). More...
 
template<typename UnaryFunction >
UnaryFunction forEachSample (UnaryFunction f) const
 Applies the provided unary function to each sample (if the channel is active). More...
 
SampleType * getBuffer ()
 Note that this pointer is NOT guaranteed to be not null as demonstrated by this piece of logic in the Audio Unit wrapper code: More...
 
SampleType const * getBuffer () const
 Note that this pointer is NOT guaranteed to be not null as demonstrated by this piece of logic in the Audio Unit wrapper code: More...
 
int32 getNumSamples () const
 
bool isActive () const
 
bool isSilent () const
 
void setSilenceFlag (bool iSilent)
 Sets a single channel silence flag. More...
 

Private Attributes

AudioBuffersfBuffers
 
int32 fChannel
 

Detailed Description

template<typename SampleType>
class pongasoft::VST::AudioBuffers< SampleType >::Channel

Represents a single channel (for example left audio channel).

Note an instance of this class may represent an invalid/non active channel in which case the various methods will react accordingly (ex: getBuffer returns nullptr, forEachSample doesn't do anything, etc...)

Constructor & Destructor Documentation

◆ Channel()

Channel ( AudioBuffers iBuffers,
int32  iChannel 
)
inline

Member Function Documentation

◆ absoluteMax()

SampleType absoluteMax ( ) const
inline
Returns
the max sample (absolute) for this channel

◆ clear()

void clear ( )
inline

Clears the channel (and sets the silence flag)

◆ copyFrom() [1/2]

tresult copyFrom ( Channel const &  fromChannel)
inline

Copy the content of the provided channel to THIS channel (up to num samples)

◆ copyFrom() [2/2]

UnaryOperation copyFrom ( Channel const &  iFromChannel,
UnaryOperation  f 
)
inline

Copy iFromChannel to this channel, applying f to each sample or in other words, for each sample.

getBuffer[i] = f(iFromChannel.getBuffer[i]);

This handles properly inactive channels (nothing done if either of the channel is inactive) and channels of different sizes.

Example:

AudioBuffers<SampleType> in(data.inputs[0], data.numSamples);
AudioBuffers<SampleType> out(data.outputs[0], data.numSamples);

double gain = 0.5;
out.getLeftChannel().copyFrom(in.getLeftChannel(), [gain](SampleType iSample) { return iSample * gain; });
Template Parameters
UnaryOperationcan be a lambda, a function object (etc...) but should provide an api similar to std::function<SampleType(SampleType)>
Returns
the function provided

◆ copyTo() [1/2]

tresult copyTo ( Channel toChannel) const
inline

Copy the content of THIS channel to the provided channel (up to num samples)

◆ copyTo() [2/2]

UnaryOperation copyTo ( Channel oToChannel,
UnaryOperation  f 
) const
inline

Same as copyFrom with the roles reversed.

◆ forEachSample() [1/2]

UnaryFunction forEachSample ( UnaryFunction  f)
inline

Applies the provided unary function to each sample (if the channel is active).

Example:

double gain = 0.5;
leftChannel.forEachSample([gain](SampleType &iSample) { iSample *= gain; });
Template Parameters
UnaryFunctioncan be a lambda, a function object (etc...) but should provide an api similar to std::function<void(SampleType)> or std::function<void(SampleType &)>
Returns
the function (similar api as std::for_each)

◆ forEachSample() [2/2]

UnaryFunction forEachSample ( UnaryFunction  f) const
inline

Applies the provided unary function to each sample (if the channel is active).

Because the method is const, the unary function cannot modify the elements.

Example:

auto max = leftChannel.forEachSample(AbsoluteMaxOp()).fAbsoluteMax;
Template Parameters
UnaryFunctioncan be a lambda, a function object (etc...) but should provide an api similar to std::function<void(SampleType)> or std::function<void(SampleType const &)>
Returns
the function (similar api as std::for_each)

◆ getBuffer() [1/2]

SampleType* getBuffer ( )
inline

Note that this pointer is NOT guaranteed to be not null as demonstrated by this piece of logic in the Audio Unit wrapper code:

...
   processData.inputs[i].channelBuffers32[channel] =
    input->IsActive () ? (Sample32*)input->GetBufferList ().mBuffers[channel].mData : 0;
...
Returns
the underlying sample buffer or nullptr if not active

◆ getBuffer() [2/2]

SampleType const* getBuffer ( ) const
inline

Note that this pointer is NOT guaranteed to be not null as demonstrated by this piece of logic in the Audio Unit wrapper code:

...
processData.inputs[i].channelBuffers32[channel] =
input->IsActive () ? (Sample32*)input->GetBufferList ().mBuffers[channel].mData : 0;
...
Returns
the underlying sample buffer or nullptr if not active

◆ getNumSamples()

int32 getNumSamples ( ) const
inline
Returns
number of samples in the buffer

◆ isActive()

bool isActive ( ) const
inline
Returns
true if this channel is active, meaning there is such a channel and its buffer is not null

◆ isSilent()

bool isSilent ( ) const
inline
Returns
true if this channel is silent (according to silenceFlags)

◆ setSilenceFlag()

void setSilenceFlag ( bool  iSilent)
inline

Sets a single channel silence flag.

Member Data Documentation

◆ fBuffers

AudioBuffers& fBuffers
private

◆ fChannel

int32 fChannel
private

The documentation for this class was generated from the following file: