DaisySP
Loading...
Searching...
No Matches
adenv.h
1/*
2Copyright (c) 2020 Electrosmith, Corp
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 ADENV_H
11#define ADENV_H
12#include <stdint.h>
13#ifdef __cplusplus
14
15namespace daisysp
16{
31
39class AdEnv
40{
41 public:
42 AdEnv() {}
43 ~AdEnv() {}
55 void Init(float sample_rate);
56
61 float Process();
62
64 inline void Trigger() { trigger_ = 1; }
66 inline void SetTime(uint8_t seg, float time) { segment_time_[seg] = time; }
70 inline void SetCurve(float scalar) { curve_scalar_ = scalar; }
74 inline void SetMin(float min) { min_ = min; }
78 inline void SetMax(float max) { max_ = max; }
80 inline float GetValue() const { return (output_ * (max_ - min_)) + min_; }
84 inline uint8_t GetCurrentSegment() { return current_segment_; }
87 inline bool IsRunning() const { return current_segment_ != ADENV_SEG_IDLE; }
88
89 private:
90 uint8_t current_segment_, prev_segment_;
91 float segment_time_[ADENV_SEG_LAST];
92 float sample_rate_, min_, max_, output_, curve_scalar_;
93 float c_inc_, curve_x_, retrig_val_;
94 uint32_t phase_;
95 uint8_t trigger_;
96};
97
98} // namespace daisysp
99#endif
100#endif
Definition adenv.h:40
void SetTime(uint8_t seg, float time)
Definition adenv.h:66
uint8_t GetCurrentSegment()
Definition adenv.h:84
float GetValue() const
Definition adenv.h:80
void SetMax(float max)
Definition adenv.h:78
void Trigger()
Definition adenv.h:64
void Init(float sample_rate)
Definition adenv.cpp:51
float Process()
Definition adenv.cpp:66
void SetMin(float min)
Definition adenv.h:74
bool IsRunning() const
Definition adenv.h:87
void SetCurve(float scalar)
Definition adenv.h:70
FIR Filter implementation, generic and ARM CMSIS DSP based.
Definition adenv.h:16
AdEnvSegment
Definition adenv.h:21
@ ADENV_SEG_LAST
Definition adenv.h:29
@ ADENV_SEG_DECAY
Definition adenv.h:27
@ ADENV_SEG_IDLE
Definition adenv.h:23
@ ADENV_SEG_ATTACK
Definition adenv.h:25