DaisySP
Loading...
Searching...
No Matches
samplehold.h
1/*
2Copyright (c) 2020 Electrosmith, Corp, Paul Batchelor
3
4Use of this source code is governed by an MIT-style
5license that can be found in the LICENSE file or at
6https://opensource.org/licenses/MIT.
7*/
8
9#pragma once
10#ifndef DSY_SAMPLEHOLD_H
11#define DSY_SAMPLEHOLD_H
12
13#include <stdint.h>
14#ifdef __cplusplus
15
16namespace daisysp
17{
24{
25 public:
26 SampleHold() {}
27 ~SampleHold() {}
28
29 enum Mode
30 {
31 MODE_SAMPLE_HOLD,
32 MODE_TRACK_HOLD,
33 MODE_LAST,
34 };
35
41 inline float
42 Process(bool trigger, float input, Mode mode = MODE_SAMPLE_HOLD)
43 {
44 Update(trigger, input);
45 return mode == MODE_SAMPLE_HOLD ? sample_ : track_;
46 }
47
48 private:
49 float track_ = 0;
50 float sample_ = 0;
51 bool previous_ = false;
52
53
54 inline void Update(bool trigger, float input)
55 {
56 if(trigger)
57 {
58 if(!previous_)
59 {
60 sample_ = input;
61 }
62 track_ = input;
63 }
64 previous_ = trigger;
65 }
66};
67} // namespace daisysp
68#endif
69#endif
Definition samplehold.h:24
float Process(bool trigger, float input, Mode mode=MODE_SAMPLE_HOLD)
Definition samplehold.h:42
FIR Filter implementation, generic and ARM CMSIS DSP based.
Definition adenv.h:16