pitch_table: use PROGMEM for pitch bend lookup table

This way we can fit more bend values inside our synthesizer
This commit is contained in:
Peter Cai 2021-06-11 18:53:42 +08:00
parent c0d04c13fc
commit 7a3f62499f
2 changed files with 3 additions and 2 deletions

View file

@ -39,6 +39,7 @@ def pitch_to_name(pitch):
return pitch_names[(pitch - pitch_A0) % 12] + str(int((pitch - pitch_C1) / 12) + 1)
print("#pragma once")
print("#include <avr/pgmspace.h>")
print("")
print("constexpr unsigned int midi_pitch_offset = " + str(start_pitch) + ";")
print("constexpr unsigned int midi_pitch_max = " + str(end_pitch) + ";")
@ -58,7 +59,7 @@ print("")
print("// scale factors for bend values from 0 to 255")
print("// We don't support the full 16385 levels of MIDI bend")
print("// MIDI bend values have to be converted first to the nearest supported one")
print("constexpr float midi_pitch_bend_scale[256] = {")
print("constexpr PROGMEM float midi_pitch_bend_scale[256] = {")
for i in range(0, 256):
factor = pow(2, (8192 - i * 64) / 49152)

View file

@ -41,7 +41,7 @@ void MotorControl::TickPitchBend(int bend) {
// Scale the MIDI bend value down to 0 - 255
bend = bend / 64;
tick_period_half_micros = (unsigned long) (((float) tick_period_orig_half_micros) * midi_pitch_bend_scale[bend]);
tick_period_half_micros = (unsigned long) (((float) tick_period_orig_half_micros) * pgm_read_float_near(midi_pitch_bend_scale + bend * sizeof(float)));
}
void MotorControl::TickOff() {