WE Core
Loading...
Searching...
No Matches
ModulationSource.h
Go to the documentation of this file.
1
/*
2
* File: ModulationSource.h
3
*
4
* Created: 22/11/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
namespace
WECore
{
25
33
template
<
typename
SampleType>
34
class
ModulationSource
{
35
static_assert
(std::is_floating_point<SampleType>::value,
36
"Must be provided with a floating point template type"
);
37
38
public
:
39
ModulationSource
() :
_cachedOutput
(0) {}
40
virtual
~ModulationSource
() =
default
;
41
46
inline
SampleType
getNextOutput
(SampleType inSample);
47
51
virtual
SampleType
getLastOutput
()
const
{
return
_cachedOutput
; }
52
56
inline
void
reset
();
57
58
protected
:
59
SampleType
_cachedOutput
;
60
67
virtual
SampleType
_getNextOutputImpl
(SampleType inSample) = 0;
68
72
virtual
void
_resetImpl
() = 0;
73
};
74
75
template
<
typename
SampleType>
76
SampleType
ModulationSource<SampleType>::getNextOutput
(SampleType inSample) {
77
_cachedOutput = _getNextOutputImpl(inSample);
78
return
_cachedOutput;
79
}
80
81
template
<
typename
SampleType>
82
void
ModulationSource<SampleType>::reset
() {
83
_resetImpl();
84
_cachedOutput = 0;
85
}
86
87
template
<
typename
SampleType>
88
struct
ModulationSourceWrapper
{
89
std::shared_ptr<ModulationSource<SampleType>>
source
;
90
double
amount
;
91
};
92
93
template
<
typename
SampleType>
94
SampleType
calcModValue
(
const
std::vector<
ModulationSourceWrapper<SampleType>
>& sources) {
95
SampleType retVal {0};
96
97
for
(
const
ModulationSourceWrapper<SampleType>
& source : sources) {
98
retVal += source.source->getLastOutput() * source.amount;
99
}
100
101
return
retVal;
102
}
103
}
WECore::ModulationSource
Definition
ModulationSource.h:34
WECore::ModulationSource::_getNextOutputImpl
virtual SampleType _getNextOutputImpl(SampleType inSample)=0
WECore::ModulationSource::getNextOutput
SampleType getNextOutput(SampleType inSample)
Definition
ModulationSource.h:76
WECore::ModulationSource::ModulationSource
ModulationSource()
Definition
ModulationSource.h:39
WECore::ModulationSource::getLastOutput
virtual SampleType getLastOutput() const
Definition
ModulationSource.h:51
WECore::ModulationSource::_resetImpl
virtual void _resetImpl()=0
WECore::ModulationSource::_cachedOutput
SampleType _cachedOutput
Definition
ModulationSource.h:59
WECore::ModulationSource::~ModulationSource
virtual ~ModulationSource()=default
WECore::ModulationSource::reset
void reset()
Definition
ModulationSource.h:82
WECore
Definition
CarveDSPUnit.h:55
WECore::calcModValue
SampleType calcModValue(const std::vector< ModulationSourceWrapper< SampleType > > &sources)
Definition
ModulationSource.h:94
WECore::ModulationSourceWrapper
Definition
ModulationSource.h:88
WECore::ModulationSourceWrapper::amount
double amount
Definition
ModulationSource.h:90
WECore::ModulationSourceWrapper::source
std::shared_ptr< ModulationSource< SampleType > > source
Definition
ModulationSource.h:89
WECore
WEFilters
ModulationSource.h
Generated by
1.12.0