diff --git a/gen_pitch_table.py b/gen_pitch_table.py index 5e46329..4985c5b 100644 --- a/gen_pitch_table.py +++ b/gen_pitch_table.py @@ -56,13 +56,13 @@ for i in range(start_pitch, end_pitch): print("};") print("") -print("// scale factors for bend values from 0 to 255") +print("// scale factors for bend values from 0 to 2047") 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 PROGMEM float midi_pitch_bend_scale[256] = {") +print("constexpr PROGMEM float midi_pitch_bend_scale[2048] = {") -for i in range(0, 256): - factor = pow(2, (8192 - i * 64) / 49152) +for i in range(0, 2048): + factor = pow(2, (8192 - i * 8) / 49152) print(" " + str(factor) + "f,\t// " + str(i)) print("};") \ No newline at end of file diff --git a/motor_control.cpp b/motor_control.cpp index 7dc0843..d69ef71 100644 --- a/motor_control.cpp +++ b/motor_control.cpp @@ -38,8 +38,8 @@ void MotorControl::TickPitchBend(int bend) { if (bend < 0 || bend >= 16384) return; if (tick_period_orig_half_micros == 0) return; - // Scale the MIDI bend value down to 0 - 255 - bend = bend / 64; + // Scale the MIDI bend value down to 0 - 2047 + bend = bend / 8; tick_period_half_micros = (unsigned long) (((float) tick_period_orig_half_micros) * pgm_read_float_near(midi_pitch_bend_scale + bend * sizeof(float))); }