HART  0.2.0
High level Audio Regression and Testing
Loading...
Searching...
No Matches
hart_flip.hpp
Go to the documentation of this file.
1#pragma once
2
3#include "dsp/hart_dsp.hpp"
4#include "hart_utils.hpp" // HART_DEFINE_GENERIC_REPRESENT()
5
6namespace hart
7{
8
9/// @brief Flips the polarity
10/// @details Just flips the sign of every sample at selected channels.
11/// @tparam SampleType Type of audio sample data, typically `float` or `double`.
12template <typename SampleType>
13class Flip :
14 public DSP<SampleType, Flip<SampleType>>
15{
16public:
17 void prepare (double /* sampleRateHz */, size_t /* numInputChannels */, size_t /* numOutputChannels */, size_t /* maxBlockSizeFrames */) override
18 {
19 }
20
21 void process (const AudioBuffer<SampleType>& input, AudioBuffer<SampleType>& output, const EnvelopeBuffers& /* envelopeBuffers */, ChannelFlags channelsToProcess) override
22 {
23 hassert (input.getNumChannels() == output.getNumChannels());
24 hassert (input.getNumFrames() == output.getNumFrames());
25
26 const size_t numChannels = input.getNumChannels();
27 const size_t numFrames = input.getNumFrames();
28
29 for (size_t channel = 0; channel < numChannels; ++channel)
30 {
31 const SampleType* inputData = input[channel];
32 SampleType* outputData = output[channel];
33
34 if (channelsToProcess[channel] == true)
35 {
36 // Flip polarity
37 for (size_t frame = 0; frame < numFrames; ++frame)
38 outputData[frame] = -inputData[frame];
39 }
40 else
41 {
42 // Bypass
43 for (size_t frame = 0; frame < numFrames; ++frame)
44 outputData[frame] = inputData[frame];
45 }
46 }
47 }
48
49 void setValue (int /* paramId */, double /* value */)
50 {
51 // Doesn't support any settable parameters
53 }
54
55 bool supportsChannelLayout (size_t numInputChannels, size_t numOutputChannels) const
56 {
57 return numInputChannels == numOutputChannels;
58 }
59
63};
64
66
67} // namespace hart
A set of boolean flags mapped to each audio channel.
std::bitset< m_maxChannels >::reference operator[](size_t channel)
Access the flag value for a specific channel.
Base for DSP effects.
Definition hart_dsp.hpp:345
Flips the polarity.
Definition hart_flip.hpp:15
void setValue(int, double)
Sets DSP value.
Definition hart_flip.hpp:49
void process(const AudioBuffer< SampleType > &input, AudioBuffer< SampleType > &output, const EnvelopeBuffers &, ChannelFlags channelsToProcess) override
Processes the audio.
Definition hart_flip.hpp:21
void prepare(double, size_t, size_t, size_t) override
Prepare for processing.
Definition hart_flip.hpp:17
bool supportsChannelLayout(size_t numInputChannels, size_t numOutputChannels) const
Tells the runner (host) whether this effect supports a specific i/o configuration.
Definition hart_flip.hpp:55
#define HART_DSP_COPYABLE(ClassName)
Implements a generic hart::DSP::copy() method.
Definition hart_dsp.hpp:602
#define HART_DSP_MOVABLE(ClassName)
Implements a generic hart::DSP::move() method.
Definition hart_dsp.hpp:610
#define hassert(condition)
Triggers a HartAssertException if the condition is false
#define hassertfalse
Triggers a HartAssertException
#define HART_DEFINE_GENERIC_REPRESENT(ClassName)
Defines a basic string representation of your class.
#define HART_DSP_DECLARE_ALIASES_FOR(ClassName)
Definition hart_dsp.hpp:619