Fixed checksum calculation of sysex bulk reading.

pull/4/head
Holger Wirtz 6 years ago
parent fdaeb8b79f
commit b9d7012d03
  1. 2
      MicroDexed.ino
  2. 4
      config.h
  3. 42
      dexed_sysex.cpp

@ -144,7 +144,7 @@ void setup()
#endif #endif
// load default SYSEX data // load default SYSEX data
//load_sysex(bank, EEPROM.read(EEPROM_VOICE_ADDR)); load_sysex(bank, EEPROM.read(EEPROM_VOICE_ADDR));
#ifdef DEBUG #ifdef DEBUG
show_patch(); show_patch();

@ -27,7 +27,7 @@
// Initial values // Initial values
#define MIDI_DEVICE Serial1 #define MIDI_DEVICE Serial1
#define USE_ONBOARD_USB_HOST 1 #define USE_ONBOARD_USB_HOST 1
#define VOLUME 0.5 #define VOLUME 0.2
#define SAMPLE_RATE 44100 #define SAMPLE_RATE 44100
#define DEFAULT_MIDI_CHANNEL MIDI_CHANNEL_OMNI #define DEFAULT_MIDI_CHANNEL MIDI_CHANNEL_OMNI
#define DEFAULT_SYSEXBANK 0 #define DEFAULT_SYSEXBANK 0
@ -42,7 +42,7 @@
#endif #endif
// Master key handling (comment for disabling) // Master key handling (comment for disabling)
//#define MASTER_KEY_MIDI MIDI_C6 #define MASTER_KEY_MIDI MIDI_C6
#define MASTER_NUM1 MIDI_C1 #define MASTER_NUM1 MIDI_C1
// Debug output // Debug output

@ -103,7 +103,8 @@ bool get_sysex_voice(char* dir, File sysex, uint8_t voice_number, uint8_t* data)
{ {
File file; File file;
uint16_t n; uint16_t n;
uint32_t calc_checksum = 0; int32_t bulk_checksum_calc = 0;
int8_t bulk_checksum;
char sysex_file[20]; char sysex_file[20];
strcpy(sysex_file, dir); strcpy(sysex_file, dir);
@ -149,35 +150,44 @@ bool get_sysex_voice(char* dir, File sysex, uint8_t voice_number, uint8_t* data)
#endif #endif
return (false); return (false);
} }
file.seek(4102); // Bulk checksum
bulk_checksum = file.read();
file.seek(6 + voice_number * 128); // start of 32*128 (=4096) bytes data file.seek(6); // start of bulk data
for (n = 0; n < 128; n++) for (n = 0; n < 4096; n++)
{ {
uint8_t d = file.read(); uint8_t d = file.read();
calc_checksum += (d & 0x7F); // calculate checksum if (n >= voice_number * 128 && n < (voice_number + 1) * 128)
data[n] = d; {
data[n - (voice_number * 128)] = d;
}
bulk_checksum_calc -= d;
} }
calc_checksum = uint8_t(~calc_checksum + 1); bulk_checksum_calc &= 0x7f;
#ifdef DEBUG #ifdef DEBUG
Serial.print(F("Checksum: 0x")); Serial.print(F(" Bulk checksum: 0x"));
Serial.println(calc_checksum, HEX); Serial.println(bulk_checksum, HEX);
#endif #endif
uint8_t c = uint8_t(file.read()); if (bulk_checksum_calc != bulk_checksum)
if (calc_checksum != c)
{ {
#ifdef DEBUG #ifdef DEBUG
Serial.print(F("E: checksum mismatch: 0x")); Serial.print(F("E: Bulk checksum mismatch: 0x"));
Serial.print(calc_checksum,HEX); Serial.print(bulk_checksum_calc, HEX);
Serial.print(F(" != 0x")); Serial.print(F(" != 0x"));
Serial.println(c,HEX); Serial.println(bulk_checksum, HEX);
#endif #endif
//return (false); return (false);
} }
} }
#ifdef DEBUG #ifdef DEBUG
Serial.print(F("Cannot open ")); else
Serial.println(sysex.name()); {
Serial.print(F("Cannot open "));
Serial.println(sysex.name());
}
#endif #endif
return (true); return (true);
} }

Loading…
Cancel
Save