HART  0.2.0
High level Audio Regression and Testing
Loading...
Searching...
No Matches
hart_mute.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <algorithm> // fill
4#include <bitset>
5#include <iomanip> // hex
6
7#include "hart_dsp.hpp"
9
10namespace hart
11{
12
13/// @brief Mutes selected channels in the signal
14/// @details Fills all specified channels to zeros.
15/// By default, mutes all the channels, unless specific channels are set.
16/// @ingroup DSP
17template <typename SampleType>
18class Mute:
19 public hart::DSP<SampleType, Mute<SampleType>>
20{
21public:
22 void prepare (double /*sampleRateHz*/, size_t numInputChannels, size_t numOutputChannels, size_t /*maxBlockSizeFrames*/) override
23 {
24 if (numInputChannels != numOutputChannels)
25 HART_THROW_OR_RETURN_VOID (hart::ChannelLayoutError, "Unsupported channel configuration");
26 }
27
28 void process (const AudioBuffer<SampleType>& input, AudioBuffer<SampleType>& output, const EnvelopeBuffers& /*envelopeBuffers*/, ChannelFlags channelsToProcess) override
29 {
30 if (input.getNumChannels() != output.getNumChannels())
31 HART_THROW_OR_RETURN_VOID (hart::ChannelLayoutError, "Channel number mismatch");
32
33 const size_t numChannels = output.getNumChannels();
34 const size_t numFrames = output.getNumFrames();
35 const bool isNonReplacing = &input != &output;
36
37 for (size_t channel = 0; channel < numChannels; ++channel)
38 {
39 if (channelsToProcess[channel] == true)
40 output.clear (channel, 0, numFrames);
41 else
42 {
43 if (isNonReplacing)
44 output.copyFrom (channel, 0, input, channel, 0, numFrames);
45 }
46 }
47 }
48
49 void reset() override {}
50
51 void setValue (int /*id*/, double /*value*/) override {}
52
53 double getValue (int /*id*/) const override { return 0.0; }
54
55 bool supportsChannelLayout (size_t numInputChannels, size_t numOutputChannels) const override
56 {
57 return numInputChannels == numOutputChannels;
58 }
59
60 bool supportsEnvelopeFor(int /*id*/) const override
61 {
62 return false;
63 }
64
67};
68
70
71} // namespace hart
Container for audio data.
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.
Thrown when a numbers of channels is mismatched.
Base for DSP effects.
Definition hart_dsp.hpp:345
Mutes selected channels in the signal.
Definition hart_mute.hpp:20
void setValue(int, double) override
Sets DSP value.
Definition hart_mute.hpp:51
void process(const AudioBuffer< SampleType > &input, AudioBuffer< SampleType > &output, const EnvelopeBuffers &, ChannelFlags channelsToProcess) override
Processes the audio.
Definition hart_mute.hpp:28
double getValue(int) const override
Retrieves DSP value.
Definition hart_mute.hpp:53
bool supportsEnvelopeFor(int) const override
Tells whether this effect accepts automation envelopes for a particular parameter.
Definition hart_mute.hpp:60
void prepare(double, size_t numInputChannels, size_t numOutputChannels, size_t) override
Prepare for processing.
Definition hart_mute.hpp:22
void reset() override
Resets to initial state.
Definition hart_mute.hpp:49
bool supportsChannelLayout(size_t numInputChannels, size_t numOutputChannels) const override
Tells the runner (host) whether this effect supports a specific i/o configuration.
Definition hart_mute.hpp:55
#define HART_DSP_COPYABLE(ClassName)
Implements a generic hart::DSP::copy() method.
Definition hart_dsp.hpp:602
#define HART_THROW_OR_RETURN_VOID(ExceptionType, message)
Throws an exception if HART_DO_NOT_THROW_EXCEPTIONS is set, prints a message and returns otherwise.
#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