Quantcast
Channel: YamahaMusicians.com
Viewing all articles
Browse latest Browse all 2726

Yamaha SY77 Forum - Covers the Sy77 Keyboard and TG77 Module • Re: SY77 SysEx checksum formula?

$
0
0
I like the code here, but I don't understand why you checkSum &= 0x7F; /* Clamp to 7 bits */ before the one's complement. Is it necessary?

I've been using Derek's algorithm for both Roland and Yamaha machines, which is similar, but then I thought the following might be even simpler, but I'm no C expert?

In the Roland manuals they seem to offer a very convoluted and confusing explanation of the checksum algorithm.

Code:

  /*possible Yamaha sysex message data starts at byte 5*/  unsigned data[] = {0xf0,0x43,0x7f,0x7f,0x7f,0x01,0x00,0x00,0x29,0x05,0x00,0xf7};  unsigned dataLength=sizeof(data) / sizeof(data[0]);  unsigned checkSum = 0;   unsigned i;  for (i = 5; i < dataLength-2; ++i) {     /* Read/write data from/to packet */    checkSum += data[i]; /* Incorporate byte into sum using array index */  }  *data = 128 - checkSum & 127; /* Write the check sum after the packet */
There are many ways of writing the code. For example, I would change the last line to:

Code:

  *data = (-checkSum) & 0x7f;
However, the question is, what are the criteria for the code? Correctness? Performance? Maintainability?

Statistics: Posted by mx49 — Mon Apr 22, 2024 6:05 pm



Viewing all articles
Browse latest Browse all 2726

Trending Articles