20 #include "mozzi_fixmath.h"
42 Ead(
unsigned int update_rate) : UPDATE_RATE(update_rate)
54 Q8n8attack =
float_to_Q8n8(millisToOneMinusRealPole(attack_ms));
65 Q8n8decay =
float_to_Q8n8(millisToOneMinusRealPole(decay_ms));
76 void set(
unsigned int attack_ms,
unsigned int decay_ms)
102 void start(
unsigned int attack_ms,
unsigned int decay_ms)
104 set(attack_ms, decay_ms);
124 attack_phase =
false;
127 Q8n24state -= (Q8n24state * Q8n8decay)>>8;
139 const unsigned int UPDATE_RATE;
144 float millisToOneMinusRealPole(
unsigned int milliseconds)
146 static const float NUMERATOR = 1000.0f * log(0.001f);
147 return -expm1(NUMERATOR / ((
float)UPDATE_RATE * milliseconds));
Exponential attack decay envelope.
void start(unsigned int attack_ms, unsigned int decay_ms)
Set attack and decay times in milliseconds, and start the envelope from the beginning.
Ead(unsigned int update_rate)
Constructor.
uint8_t next()
Calculate and return the next envelope value, in the range -128 to 127.
void setAttack(unsigned int attack_ms)
Set the attack time in milliseconds.
void setDecay(unsigned int decay_ms)
Set the decay time in milliseconds.
void start()
Start the envelope from the beginning.
void set(unsigned int attack_ms, unsigned int decay_ms)
Set attack and decay times in milliseconds.
Q0n8 Q8n24_to_Q0n8(Q8n24 a)
Convert Q8n24 fixed to Q0n8 uint8_t.
Q8n8 float_to_Q8n8(float a)
Convert float to Q8n8 fix.
#define Q8n24_FIX1
1 in Q8n24 format
uint32_t Q8n24
signed fractional number using 8 integer bits and 24 fractional bits, represents 0 to 255....
uint16_t Q8n8
unsigned fractional number using 8 integer bits and 8 fractional bits, represents 0 to 255....