Commit 89e05216 authored by Jacob Vosmaer's avatar Jacob Vosmaer

Fewer calculations per update

parent d698dec1
......@@ -2,9 +2,8 @@
#include "voice.h"
static float _env_delta[NUM_VOICES];
static uint8_t _env_decay;
static uint8_t _env_amount;
static float _env_descent;
static float _env_amount;
float
pitch_env_delta(uint8_t voice)
......@@ -16,9 +15,8 @@ void
pitch_env_update_clock(uint8_t delta)
{
for_each_voice (v) {
float descent = 20000 / ((127 - _env_decay) + 1);
_env_delta[v] =
_env_delta[v] - (float)delta * _env_delta[v] / descent;
_env_delta[v] - (float)delta * _env_delta[v] * _env_descent;
if (_env_delta[v] < 0) {
_env_delta[v] = 0;
......@@ -33,7 +31,7 @@ pitch_env_set_decay(uint8_t decay)
decay = 127;
}
_env_decay = decay;
_env_descent = (1 + (127 - decay)) / 20000.0;
}
void
......@@ -43,7 +41,7 @@ pitch_env_set_amount(uint8_t amount)
amount = 127;
}
_env_amount = amount;
_env_amount = amount / 127.0;
}
void
......@@ -53,5 +51,5 @@ pitch_env_trigger(uint8_t voice)
return;
}
_env_delta[voice] = (_env_amount / 127.0);
_env_delta[voice] = _env_amount;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment