Commit 93221c1a authored by Jacob Vosmaer's avatar Jacob Vosmaer

Vibrato global, no reset. Remove math

parent 89e05216
......@@ -10,3 +10,4 @@ list-test
avrdude_port
pitch_env-plot.dat
pitch_env-plot
vibrato_rate-gen
PRG = crowbx
OBJ = crowbx.o midi.o dac.o uart.o gate.o poly.o mono.o list.o vibrato.o poly2.o poly_voice.o safe_add.o pitch.o buffer.o pitch_env.o
OBJ = crowbx.o midi.o dac.o uart.o gate.o poly.o mono.o list.o vibrato.o poly2.o poly_voice.o safe_add.o pitch.o buffer.o pitch_env.o vibrato_rate.o
MCU_TARGET = atmega328p
OPTIMIZE = -O3
......@@ -24,16 +24,22 @@ all: $(PRG).elf lst text
$(PRG).elf: $(OBJ)
$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $^ $(LIBS)
TESTCC = gcc -Wall -std=c99
LOCALCC = gcc -Wall -std=c99
vibrato_rate.c: vibrato_rate.h vibrato_rate-gen.c
$(LOCALCC) -lm -o vibrato_rate-gen vibrato_rate-gen.c
./vibrato_rate-gen > $@
clang-format -i -style=file $@
test:
$(TESTCC) -o midi-test midi-test.c midi.c
$(LOCALCC) -o midi-test midi-test.c midi.c
./midi-test
$(TESTCC) -o list-test list-test.c list.c
$(LOCALCC) -o list-test list-test.c list.c
./list-test
plot:
$(TESTCC) -o pitch_env-plot pitch_env-plot.c pitch_env.c
$(LOCALCC) -o pitch_env-plot pitch_env-plot.c pitch_env.c
./pitch_env-plot > pitch_env-plot.dat
gnuplot -e "plot 'pitch_env-plot.dat'"
......
......@@ -83,7 +83,6 @@ program_change(uint8_t pgm)
current_program = pgm;
vibrato_init();
gate_init();
(*pgm_init[current_program])();
}
......@@ -121,6 +120,12 @@ handle_cc(uint8_t cc, uint8_t val)
case CC_PITCH_ENV_AMOUNT:
pitch_env_set_amount(val);
break;
case CC_MOD_WHEEL:
vibrato_set_depth(val);
break;
case CC_VIB_RATE:
vibrato_set_rate(val);
break;
}
(*control_change[current_program])(cc, val);
......
......@@ -4,7 +4,6 @@
#include "midi.h"
#include "notes.h"
#include "pitch.h"
#include "vibrato.h"
#include "voice.h"
#include <util/delay.h>
......@@ -78,12 +77,6 @@ mono_control_change(uint8_t ctl, uint8_t val)
case CC_DETUNE:
detune_amount = val;
break;
case CC_MOD_WHEEL:
vibrato_set_depth(val);
break;
case CC_VIB_RATE:
vibrato_set_rate(val);
break;
}
}
......@@ -98,7 +91,6 @@ mono_update_clock(uint8_t delta)
for_each_voice (v) {
int16_t detune = detune_factor[v] * detune_amount;
detune += vibrato_detune();
pitch_set_note(v, current_note, detune);
}
}
......@@ -2,8 +2,8 @@
#include "dac.h"
#include "pitch_env.h"
#include "safe_add.h"
#include "vibrato.h"
#include "voice.h"
#include <math.h>
enum { BEND_CENTER = 8192,
BEND_MAX = 16383,
......@@ -26,6 +26,7 @@ pitch_set_note(uint8_t voice, uint8_t note, int16_t detune)
uint16_t data = dac_note_pitch(voice, note);
data = safe_add(data, detune);
data = safe_add(data, vibrato_detune());
data =
safe_add(data, pitch_env_delta(voice) * (float)dac_pitch_delta(5));
......
......@@ -4,7 +4,6 @@
#include "notes.h"
#include "pitch.h"
#include "poly_voice.h"
#include "vibrato.h"
#include "voice.h"
static uint8_t playing[NUM_VOICES];
......@@ -50,14 +49,8 @@ poly_note_off(uint8_t note)
void
poly_control_change(uint8_t ctl, uint8_t val)
{
switch (ctl) {
case CC_MOD_WHEEL:
vibrato_set_depth(val);
break;
case CC_VIB_RATE:
vibrato_set_rate(val);
break;
}
(void)ctl;
(void)val;
}
void
......@@ -66,6 +59,6 @@ poly_update_clock(uint8_t delta)
(void)delta;
for_each_voice (v) {
pitch_set_note(v, current_note[v], vibrato_detune());
pitch_set_note(v, current_note[v], 0);
}
}
......@@ -4,7 +4,6 @@
#include "midi.h"
#include "notes.h"
#include "pitch.h"
#include "vibrato.h"
#include "voice.h"
static uint8_t playing[NUM_VOICES];
......@@ -96,14 +95,8 @@ poly2_note_off(uint8_t note)
void
poly2_control_change(uint8_t ctl, uint8_t val)
{
switch (ctl) {
case CC_MOD_WHEEL:
vibrato_set_depth(val);
break;
case CC_VIB_RATE:
vibrato_set_rate(val);
break;
}
(void)ctl;
(void)val;
}
void
......@@ -112,6 +105,6 @@ poly2_update_clock(uint8_t delta)
(void)delta;
for_each_voice (v) {
pitch_set_note(v, current_note[v], vibrato_detune());
pitch_set_note(v, current_note[v], 0);
}
}
#include "vibrato.h"
#include "dac.h"
#include <math.h>
#include "vibrato_rate.h"
static uint32_t phase;
static uint8_t rate;
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] = (float)PHASE_MIN_INCR *
pow(2, ((float)i * LFO_RANGE) / (NUM_CC - 1));
}
}
void
......@@ -38,7 +27,6 @@ vibrato_set_depth(uint8_t val)
void
vibrato_init(void)
{
vibrato_set_depth(0);
}
int16_t
......@@ -53,7 +41,7 @@ enum { VIB_MID = INT16_MAX >> 1,
void
vibrato_update(uint8_t delta)
{
phase += delta * exp_table[rate];
phase += delta * vibrato_rate_table[rate];
uint16_t phase16 = phase >> 16;
if (phase16 < INT16_MAX) {
......
#include "vibrato_rate.h"
#include <math.h>
#include <stdio.h>
enum { LFO_RANGE = 8, // LFO rate range in octaves
PHASE_MIN_INCR = 20000, // minimum phase increment
};
int
main(int argc, char **argv)
{
printf("/* \n");
printf("* Auto-generated by vibrato_rate-gen, do not modify.\n");
printf("* */\n");
printf("\n");
printf("#include \"vibrato_rate.h\"\n");
printf("\n");
printf("float vibrato_rate_table[NUM_CC] = {\n");
for (int i = 0; i < NUM_CC; i++) {
float val = (float)PHASE_MIN_INCR *
pow(2, ((float)i * LFO_RANGE) / (NUM_CC - 1));
printf("%f,\n", val);
}
printf("};\n");
return 0;
}
/*
* Auto-generated by vibrato_rate-gen, do not modify.
* */
#include "vibrato_rate.h"
float vibrato_rate_table[NUM_CC] = {
20000.000000, 20892.601562, 21825.039062, 22799.091797,
23816.617188, 24879.554688, 25989.929688, 27149.861328,
28361.562500, 29627.341797, 30949.611328, 32330.894531,
33773.824219, 35281.152344, 36855.750000, 38500.625000,
40218.910156, 42013.882812, 43888.968750, 45847.734375,
47893.917969, 50031.425781, 52264.335938, 54596.894531,
57033.558594, 59578.968750, 62237.984375, 65015.667969,
67917.320312, 70948.468750, 74114.914062, 77422.664062,
80878.039062, 84487.632812, 88258.312500, 92197.289062,
96312.070312, 100610.484375, 105100.734375, 109791.382812,
114691.375000, 119810.054688, 125157.187500, 130742.953125,
136578.046875, 142673.531250, 149041.046875, 155692.765625,
162641.328125, 169900.015625, 177482.671875, 185403.718750,
193678.328125, 202322.203125, 211351.859375, 220784.500000,
230638.109375, 240931.500000, 251684.281250, 262916.968750,
274651.000000, 286908.687500, 299713.437500, 313089.656250,
327062.875000, 341659.687500, 356907.968750, 372836.781250,
389476.500000, 406858.875000, 425017.000000, 443985.531250,
463800.750000, 484500.218750, 506123.468750, 528711.812500,
552308.187500, 576957.750000, 602707.375000, 629606.250000,
657705.625000, 687059.062500, 717722.500000, 749754.500000,
783216.062500, 818171.000000, 854686.000000, 892830.687500,
932678.062500, 974303.562500, 1017786.750000, 1063210.625000,
1110661.750000, 1160230.625000, 1212011.750000, 1266103.875000,
1322610.125000, 1381638.250000, 1443300.875000, 1507715.500000,
1575004.875000, 1645297.375000, 1718727.000000, 1795433.875000,
1875564.875000, 1959271.375000, 2046713.750000, 2138058.750000,
2233480.250000, 2333160.500000, 2437289.750000, 2546066.000000,
2659697.000000, 2778399.250000, 2902399.500000, 3031933.750000,
3167249.000000, 3308603.500000, 3456266.500000, 3610519.750000,
3771658.750000, 3939988.000000, 4115829.750000, 4299519.500000,
4491407.000000, 4691859.000000, 4901256.500000, 5120000.000000,
};
#ifndef _vibrato_rate_h
#define _vibrato_rate_h
enum { NUM_CC = 128,
};
extern float vibrato_rate_table[NUM_CC];
#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