HART  0.2.0
High level Audio Regression and Testing
Loading...
Searching...
No Matches
hart_stereo_to_mid_side.hpp
Go to the documentation of this file.
1#pragma once
2
3#include "hart_dsp.hpp"
4#include "hart_utils.hpp" // Channel, MidSideChannel
5
6namespace hart
7{
8
9/// @brief Converts regular stereo signal into mid-side signal
10/// @details Mid = L + R, Side = L - R
11/// @note Obviously, this DSP only supports stereo signals
12/// @see hart::MidSideChannel
13/// @ingroup DSP
14template <typename SampleType>
16 public hart::DSP<SampleType, StereoToMidSide<SampleType>>
17{
18public:
19 void prepare (double /* sampleRateHz */, size_t numInputChannels, size_t /* numOutputChannels */, size_t /* maxBlockSizeFrames */) override
20 {
21 if (numInputChannels != 2)
22 HART_THROW_OR_RETURN_VOID (ChannelLayoutError, "StereoToMidSide only supports stereo configuration!");
23 }
24
25 void process (const AudioBuffer<SampleType>& input, AudioBuffer<SampleType>& output, const EnvelopeBuffers& /* envelopeBuffers */, ChannelFlags /* channelsToProcess */) override
26 {
27 hassert (output.getNumFrames() == input.getNumFrames());
28 hassert (input.getNumChannels() == 2);
29 hassert (input.getNumChannels() == output.getNumChannels());
30
31 for (size_t frame = 0; frame < input.getNumFrames(); ++frame)
32 {
33 output[MidSideChannel::mid][frame] = input[Channel::left][frame] + input[Channel::right][frame];
34 output[MidSideChannel::side][frame] = input[Channel::left][frame] - input[Channel::right][frame];
35 }
36 }
37
38 virtual bool supportsChannelLayout (size_t numInputChannels, size_t numOutputChannels) const override
39 {
40 return numInputChannels == 2 && numOutputChannels == 2;
41 }
42
43 void setValue (int /* paramId */, double /* value */) override {}
44 void reset() override {}
45 HART_DEFINE_GENERIC_REPRESENT (StereoToMidSide)
47};
48
50
51} // namespace hart
Container for audio data.
A set of boolean flags mapped to each audio channel.
Thrown when a numbers of channels is mismatched.
Base for DSP effects.
Definition hart_dsp.hpp:342
Converts regular stereo signal into mid-side signal.
virtual bool supportsChannelLayout(size_t numInputChannels, size_t numOutputChannels) const override
Tells the runner (host) whether this effect supports a specific i/o configuration.
void prepare(double, size_t numInputChannels, size_t, size_t) override
Prepare for processing.
void setValue(int, double) override
Sets DSP value.
void process(const AudioBuffer< SampleType > &input, AudioBuffer< SampleType > &output, const EnvelopeBuffers &, ChannelFlags) override
Processes the audio.
void reset() override
Resets to initial state.
#define HART_DSP_COPYABLE(ClassName)
Implements a generic hart::DSP::copy() method.
Definition hart_dsp.hpp:599
#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 hassert(condition)
Triggers a HartAssertException if the condition is false
#define HART_DEFINE_GENERIC_REPRESENT(ClassName)
Defines a basic string representation of your class.
Channel
Helper values for channel indices.
MidSideChannel
Helper values for mid-side channel indices.
#define HART_DSP_DECLARE_ALIASES_FOR(ClassName)
Definition hart_dsp.hpp:616