Commit e5719cc1 authored by Jacob Vosmaer's avatar Jacob Vosmaer

Delete pitch code

parent 56bcd524
PRG = crowbx
OBJ = crowbx.o midi.o list.o pitch_env.o vibrato_rate.o voice.o
OBJ = crowbx.o midi.o list.o voice.o
MCU_TARGET = atmega328p
OPTIMIZE = -O3
......
......@@ -19,17 +19,11 @@ The hardware consists of:
The software is work in progress. The MIDI channel is hard-coded to 1.
All programs below support vibrato (global pitch LFO) with depth
controlled by the mod wheel and rate by CC 76. You can also set a
positive pitch DR envelope. CC 15 is decay/release time, CC 16 is
pitch envelope amount.
Pitch bend has a range of +/- 2 semitones.
- MIDI program 0: poly mode (last note priority)
- MIDI program 1: poly mode (first note priority)
- MIDI program 2: unison (use CC 14 for detune, CC 17 for number of stacked voices)
- MIDI program 3: mono (voice 1 only)
## License
......
......@@ -7,8 +7,6 @@
#include "array_size.h"
#include "list.h"
#include "midi.h"
#include "pitch_env.h"
#include "vibrato_rate.h"
#include "voice.h"
uint16_t clamp_add(uint16_t x, int16_t delta) {
......@@ -139,8 +137,6 @@ void gate_on(uint8_t v) {
}
gate_off(v);
pitch_env_trigger(v);
gate_on_legato(v);
}
......@@ -150,43 +146,6 @@ void gate_init(void) {
enum { NUM_NOTES = 128 };
struct {
uint32_t phase;
int16_t amount;
uint8_t rate;
uint8_t depth;
} vibrato;
void vibrato_set_rate(uint8_t val) { vibrato.rate = val; }
void vibrato_set_depth(uint8_t val) { vibrato.depth = val; }
int16_t vibrato_detune(void) { return vibrato.amount; }
void vibrato_update(uint8_t delta) {
enum { VIB_MID = INT16_MAX >> 1 };
vibrato.phase +=
delta * pgm_read_float(&(vibrato_rate_table[vibrato.rate]));
uint16_t phase16 = vibrato.phase >> 16;
if (phase16 < INT16_MAX) {
vibrato.amount = phase16 - VIB_MID;
} else {
vibrato.amount = phase16 - INT16_MAX;
vibrato.amount = INT16_MAX - vibrato.amount;
vibrato.amount -= VIB_MID;
}
float pitch_factor = dac_pitch_delta(7) / ((float)INT16_MAX);
vibrato.amount *= pitch_factor;
float depth_factor = vibrato.depth / 127.0;
vibrato.amount *= depth_factor;
if (!vibrato.depth) {
vibrato.amount = 0;
}
}
struct {
int16_t bend_data;
uint16_t base_pitch[NUM_VOICES];
......@@ -209,15 +168,9 @@ void pitch_set_bend(uint16_t bend) {
pitch.bend_data = dac_pitch_delta(4) * bend_factor;
}
void pitch_update_clock(uint8_t delta) {
pitch_env_update_clock(delta);
void pitch_update(void) {
for_each_voice (v) {
uint16_t data =
clamp_add(pitch.base_pitch[v], vibrato_detune());
data = clamp_add(data, pitch_env_delta(v) *
(float)dac_pitch_delta(5));
data = clamp_add(data, pitch.bend_data);
uint16_t data = clamp_add(pitch.base_pitch[v], pitch.bend_data);
dac_send(dac_command_set(v), data);
}
}
......@@ -482,8 +435,7 @@ void do_clock_update(void) {
return;
}
vibrato_update(delta);
pitch_update_clock(delta);
pitch_update();
}
void handle_cc(uint8_t cc, uint8_t val) {
......@@ -491,21 +443,6 @@ void handle_cc(uint8_t cc, uint8_t val) {
return;
}
switch (cc) {
case CC_PITCH_ENV_DECAY:
pitch_env_set_decay(val);
break;
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;
}
if (programs[current_program].control_change) {
programs[current_program].control_change(cc, val);
}
......
#include "pitch_env.h"
#include <stdio.h>
int main(int argc, char **argv) {
pitch_env_set_amount(127);
pitch_env_set_decay(12);
pitch_env_trigger(0);
for (int i = 0; i < 100; i++) {
pitch_env_update_clock(10);
printf("%d %g\n", i, pitch_env_delta(0));
}
return 0;
}
#include "pitch_env.h"
#include "voice.h"
static float _env_delta[NUM_VOICES];
static float _env_descent;
static float _env_amount;
float pitch_env_delta(uint8_t voice) { return _env_delta[voice]; }
void pitch_env_update_clock(uint8_t delta) {
for_each_voice (v) {
_env_delta[v] =
_env_delta[v] - (float)delta * _env_delta[v] * _env_descent;
if (_env_delta[v] < 0) {
_env_delta[v] = 0;
}
}
}
void pitch_env_set_decay(uint8_t decay) {
if (decay > 127) {
decay = 127;
}
_env_descent = (1 + (127 - decay)) / 20000.0;
}
void pitch_env_set_amount(uint8_t amount) {
if (amount > 127) {
amount = 127;
}
_env_amount = amount / 127.0;
}
void pitch_env_trigger(uint8_t voice) {
if (voice >= NUM_VOICES) {
return;
}
_env_delta[voice] = _env_amount;
}
#ifndef PITCH_ENV_H
#define PITCH_ENV_H
#include <stdint.h>
void pitch_env_update_clock(uint8_t delta);
void pitch_env_set_decay(uint8_t decay);
void pitch_env_set_amount(uint8_t amount);
void pitch_env_trigger(uint8_t voice);
float pitch_env_delta(uint8_t voice);
#endif
#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 <avr/pgmspace.h>\n");
printf("#include \"vibrato_rate.h\"\n");
printf("\n");
printf("const float vibrato_rate_table[NUM_CC] PROGMEM = {\n");
float factor = pow(2, ((float)LFO_RANGE) / (NUM_CC - 1));
float val = PHASE_MIN_INCR;
for (int i = 0; i < NUM_CC; i++) {
printf("%f,\n", val);
val *= factor;
}
printf("};\n");
return 0;
}
/*
* Auto-generated by vibrato_rate-gen, do not modify.
* */
#include "vibrato_rate.h"
#include <avr/pgmspace.h>
const float vibrato_rate_table[NUM_CC] PROGMEM = {
20000.000000, 20892.601562, 21825.039062, 22799.091797,
23816.617188, 24879.554688, 25989.929688, 27149.861328,
28361.560547, 29627.337891, 30949.607422, 32330.890625,
33773.820312, 35281.148438, 36855.746094, 38500.621094,
40218.906250, 42013.878906, 43888.960938, 45847.726562,
47893.914062, 50031.421875, 52264.328125, 54596.886719,
57033.546875, 59578.957031, 62237.968750, 65015.652344,
67917.304688, 70948.460938, 74114.890625, 77422.640625,
80878.015625, 84487.609375, 88258.296875, 92197.265625,
96312.031250, 100610.445312, 105100.695312, 109791.343750,
114691.335938, 119810.015625, 125157.140625, 130742.906250,
136577.968750, 142673.453125, 149040.984375, 155692.687500,
162641.265625, 169899.953125, 177482.593750, 185403.656250,
193678.234375, 202322.109375, 211351.750000, 220784.390625,
230638.015625, 240931.406250, 251684.187500, 262916.875000,
274650.875000, 286908.562500, 299713.312500, 313089.531250,
327062.718750, 341659.531250, 356907.812500, 372836.625000,
389476.343750, 406858.687500, 425016.812500, 443985.343750,
463800.437500, 484499.875000, 506123.125000, 528711.437500,
552307.875000, 576957.375000, 602707.000000, 629605.875000,
657705.187500, 687058.625000, 717722.062500, 749754.062500,
783215.625000, 818170.562500, 854685.562500, 892830.250000,
932677.312500, 974302.750000, 1017785.937500, 1063209.750000,
1110660.875000, 1160229.750000, 1212010.875000, 1266103.000000,
1322609.250000, 1381637.375000, 1443299.875000, 1507714.375000,
1575003.750000, 1645296.250000, 1718725.875000, 1795432.750000,
1875563.000000, 1959269.500000, 2046711.750000, 2138056.500000,
2233478.000000, 2333158.250000, 2437287.250000, 2546063.500000,
2659694.500000, 2778396.750000, 2902396.750000, 3031930.750000,
3167246.000000, 3308600.250000, 3456263.250000, 3610516.500000,
3771654.000000, 3939983.000000, 4115824.750000, 4299514.000000,
4491401.500000, 4691853.000000, 4901250.500000, 5119993.500000,
};
#ifndef VIBRATO_RATE_H
#define VIBRATO_RATE_H
enum { NUM_CC = 128,
};
extern const 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