-
Notifications
You must be signed in to change notification settings - Fork 25
/
effectchain.h
100 lines (81 loc) · 1.85 KB
/
effectchain.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
/*
* Copyright (C) 2024 Judd Niemann - All Rights Reserved.
* You may use, distribute and modify this code under the
* terms of the GNU Lesser General Public License, version 2.1
*
* You should have received a copy of GNU Lesser General Public License v2.1
* with this file. If not, please refer to: https://github.com/jniemann66/ReSampler
*/
// effectchain.h : defines container for effects
// if takeOwnership is set to true, effectchain will delete the effects upon destruction
#ifndef EFFECTCHAIN_H
#define EFFECTCHAIN_H
#include "effect.h"
#include <vector>
namespace ReSampler {
template <typename FloatType>
class EffectChain
{
public:
virtual ~EffectChain()
{
if(takeOwnership) {
for(auto effect : effects) {
delete effect;
}
}
}
// add() : adds an effect to the chain
void add(Effect<FloatType>* effect)
{
effect->setBufferSize(outputBufferSize);
effect->setChannelCount(channelCount);
effects.push_back(effect);
}
// process() : runs input through chain of effects
const FloatType* process(const FloatType* inputBuffer, int sampleCount)
{
const FloatType* lastBuffer = inputBuffer;
for(auto& effect : effects) {
lastBuffer = effect->process(lastBuffer, sampleCount);
}
return lastBuffer;
}
// getters
bool empty() const
{
return effects.empty();
}
int getOutputBufferSize() const
{
return outputBufferSize;
}
int getChannelCount() const
{
return channelCount;
}
bool getTakeOwnership() const
{
return takeOwnership;
}
// setters
void setOutputBufferSize(int value)
{
outputBufferSize = value;
}
void setChannelCount(int value)
{
channelCount = value;
}
void setTakeOwnership(bool value)
{
takeOwnership = value;
}
private:
std::vector<Effect<FloatType>*> effects;
int outputBufferSize;
int channelCount;
bool takeOwnership{true};
};
} // namespace ReSampler
#endif // EFFECTCHAIN_H