Commit f060eb8c authored by Jacob Vosmaer's avatar Jacob Vosmaer

Fix lfo rate range

parent 30e8cbfd
......@@ -111,7 +111,7 @@ main(void)
midi_init();
clock_init();
program_change(PGM_POLY);
vibrato_precompute();
for (;;) {
do_clock_update();
......
#include "vibrato.h"
#include "dac.h"
#include <math.h>
static uint32_t phase;
static uint8_t phase_inc;
static int16_t vibrato;
static uint8_t depth;
enum {
NUM_CC = 128,
LFO_RANGE = 8, // LFO rate range in octaves
PHASE_MIN_INCR = 20000, // minimum phase increment
};
static float exp_table[NUM_CC];
void
vibrato_precompute(void)
{
for (uint8_t i = 0; i < NUM_CC; i++) {
exp_table[i] = pow(2, ((float) i * LFO_RANGE) / (NUM_CC - 1));
}
}
void
vibrato_set_rate(uint8_t val)
{
......@@ -37,7 +54,7 @@ enum {
void
vibrato_update(uint8_t delta)
{
phase += delta * 4096.0 * (1 + phase_inc);
phase += (float) delta * exp_table[phase_inc] * (float) PHASE_MIN_INCR;
uint16_t phase16 = phase >> 16;
if (phase16 < INT16_MAX) {
......
......@@ -8,5 +8,6 @@ void vibrato_init(void);
void vibrato_update(uint8_t delta);
void vibrato_set_rate(uint8_t val);
void vibrato_set_depth(uint8_t val);
void vibrato_precompute(void);
#endif
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