Commit 82eb6966 authored by Jacob Vosmaer's avatar Jacob Vosmaer

Remove bend duplication

parent a3fd3de9
......@@ -42,12 +42,6 @@ void (*control_change[NUM_PGM])(uint8_t ctl, uint8_t val) = {
mono_control_change,
};
void (*pitch_bend[NUM_PGM])(uint16_t bend) = {
poly_pitch_bend,
poly2_pitch_bend,
mono_pitch_bend,
};
void (*update_clock[NUM_PGM])(uint8_t delta) = {
poly_update_clock,
poly2_update_clock,
......@@ -168,7 +162,7 @@ main(void)
handle_cc(data1, data2);
break;
case MIDI_PITCH_BEND:
(*pitch_bend[current_program])((data2 << 7) | data1);
pitch_set_bend((data2 << 7) | data1);
break;
}
}
......
......@@ -11,7 +11,6 @@
INIT_LIST(notes, NUM_NOTES);
static uint16_t current_bend;
static uint8_t current_note;
const float detune_factor[NUM_VOICES] = {
......@@ -26,7 +25,6 @@ void
mono_init(void)
{
l_flush(notes);
current_bend = BEND_CENTER;
}
void
......@@ -89,12 +87,6 @@ mono_control_change(uint8_t ctl, uint8_t val)
}
}
void
mono_pitch_bend(uint16_t bend)
{
current_bend = bend;
}
void
mono_update_clock(uint8_t delta)
{
......@@ -107,6 +99,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, current_bend);
pitch_set_note(v, current_note, detune);
}
}
......@@ -7,7 +7,6 @@ void mono_init(void);
void mono_note_on(uint8_t note);
void mono_note_off(uint8_t note);
void mono_control_change(uint8_t ctl, uint8_t val);
void mono_pitch_bend(uint16_t bend);
void mono_update_clock(uint8_t delta);
#endif
......@@ -4,6 +4,12 @@
#include "voice.h"
#include <math.h>
enum { BEND_CENTER = 8192,
BEND_MAX = 16383,
};
static uint16_t _bend = BEND_CENTER;
static uint16_t _decay_counter[NUM_VOICES];
static uint16_t _env_delta[NUM_VOICES];
......@@ -23,7 +29,7 @@ pitch_init(void)
}
void
pitch_set_note(uint8_t voice, uint8_t note, int16_t detune, uint16_t bend)
pitch_set_note(uint8_t voice, uint8_t note, int16_t detune)
{
if ((voice >= NUM_VOICES) || (note > 127)) {
return;
......@@ -35,13 +41,19 @@ pitch_set_note(uint8_t voice, uint8_t note, int16_t detune, uint16_t bend)
data = safe_add(data, _env_delta[voice]);
float bend_factor =
((int16_t)(bend & BEND_MAX) - BEND_CENTER) / ((float)BEND_MAX);
((int16_t)(_bend & BEND_MAX) - BEND_CENTER) / ((float)BEND_MAX);
int16_t bend_data = dac_pitch_delta(4) * bend_factor;
data = safe_add(data, bend_data);
dac_send(dac_command_set(voice), data);
}
void
pitch_set_bend(uint16_t bend)
{
_bend = bend;
}
void
pitch_update_clock(uint8_t delta)
{
......
......@@ -3,7 +3,8 @@
#include <stdint.h>
void pitch_set_note(uint8_t voice, uint8_t note, int16_t detune, uint16_t bend);
void pitch_set_note(uint8_t voice, uint8_t note, int16_t detune);
void pitch_set_bend(uint16_t bend);
uint16_t pitch_delta(uint8_t semitones);
void pitch_update_clock(uint8_t delta);
void pitch_env_set_decay(uint8_t decay);
......@@ -11,8 +12,4 @@ void pitch_env_set_amount(uint8_t amount);
void pitch_env_trigger(uint8_t voice);
void pitch_init(void);
enum { BEND_CENTER = 8192,
BEND_MAX = 16383,
};
#endif
......@@ -9,13 +9,11 @@
static uint8_t playing[NUM_VOICES];
static uint8_t current_note[NUM_VOICES];
static uint16_t current_bend;
void
poly_init(void)
{
voice_init();
current_bend = BEND_CENTER;
for_each_voice (v) {
playing[v] = NUM_NOTES;
current_note[v] = NUM_NOTES;
......@@ -25,7 +23,7 @@ poly_init(void)
void
poly_set_pitch(uint8_t v, uint8_t note)
{
pitch_set_note(v, note, vibrato_detune(), current_bend);
pitch_set_note(v, note, vibrato_detune());
}
void
......@@ -68,12 +66,6 @@ poly_control_change(uint8_t ctl, uint8_t val)
}
}
void
poly_pitch_bend(uint16_t bend)
{
current_bend = bend;
}
void
poly_update_clock(uint8_t delta)
{
......
......@@ -7,7 +7,6 @@ void poly_init(void);
void poly_note_on(uint8_t note);
void poly_note_off(uint8_t note);
void poly_control_change(uint8_t ctl, uint8_t val);
void poly_pitch_bend(uint16_t bend);
void poly_update_clock(uint8_t delta);
#endif
......@@ -8,7 +8,6 @@
#include "voice.h"
static uint8_t playing[NUM_VOICES];
static uint16_t current_bend;
static uint8_t current_note[NUM_VOICES];
INIT_LIST(avail, NUM_VOICES);
......@@ -26,14 +25,6 @@ poly2_init(void)
current_note[i] = NUM_NOTES;
l_push(avail, i);
}
current_bend = BEND_CENTER;
}
void
poly2_set_pitch(uint8_t v, uint8_t note)
{
pitch_set_note(v, note, vibrato_detune(), current_bend);
}
void
......@@ -84,7 +75,6 @@ poly2_update_playing(void)
continue;
}
poly2_set_pitch(v, j);
gate_on(v);
playing[v] = j;
current_note[v] = j;
......@@ -116,18 +106,12 @@ poly2_control_change(uint8_t ctl, uint8_t val)
}
}
void
poly2_pitch_bend(uint16_t bend)
{
current_bend = bend;
}
void
poly2_update_clock(uint8_t delta)
{
(void)delta;
for_each_voice (v) {
poly2_set_pitch(v, current_note[v]);
pitch_set_note(v, current_note[v], vibrato_detune());
}
}
......@@ -7,7 +7,6 @@ void poly2_init(void);
void poly2_note_on(uint8_t note);
void poly2_note_off(uint8_t note);
void poly2_control_change(uint8_t ctl, uint8_t val);
void poly2_pitch_bend(uint16_t bend);
void poly2_update_clock(uint8_t delta);
#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