WE Core
Loading...
Searching...
No Matches
StereoWidthProcessor.h
Go to the documentation of this file.
1/*
2 * File: StereoWidthProcessor.h
3 *
4 * Created: 03/12/2020
5 *
6 * This file is part of WECore.
7 *
8 * WECore is free software: you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation, either version 3 of the License, or
11 * (at your option) any later version.
12 *
13 * WECore is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with WECore. If not, see <http://www.gnu.org/licenses/>.
20 */
21
22#pragma once
23
24#include <vector>
25
26#include "EffectsProcessor.h"
28
30
34 template <typename SampleType>
35 class StereoWidthProcessor : public EffectsProcessor2in2out<SampleType> {
36 public:
37 StereoWidthProcessor() : _width(Parameters::WIDTH.defaultValue) {}
38 virtual ~StereoWidthProcessor() override = default;
39
50 void setWidth(double val) { _width = Parameters::WIDTH.BoundsCheck(val); }
51
55 double getWidth() const { return _width; }
56
57
58 inline virtual void process2in2out(SampleType* inSamplesLeft,
59 SampleType* inSamplesRight,
60 size_t numSamples) override;
61
62 private:
63 double _width;
64 };
65
66 template <typename SampleType>
68 SampleType* inSamplesRight,
69 size_t numSamples) {
70
71 for (size_t index {0}; index < numSamples; index++) {
72
73 double mid {(inSamplesLeft[index] + inSamplesRight[index]) * 0.5};
74 double side {(inSamplesRight[index] - inSamplesLeft[index]) * (_width / 2)};
75
76 inSamplesLeft[index] = mid - side;
77 inSamplesRight[index] = mid + side;
78 }
79 }
80}
virtual void process2in2out(SampleType *inSamplesLeft, SampleType *inSamplesRight, size_t numSamples) override
virtual ~StereoWidthProcessor() override=default
const ParameterDefinition::RangedParameter< double > WIDTH(0, 2, 1)