h4yn0nnym0u5e
Well-known member
This code doesn't end cleanly: the last note off command is read, but before it gets acted on the stop command is prematurely fetched and acted on, rather than waiting for the next "note" (command, really) to be loaded.
The last line of the score contains:
Inserting a delay after the last note off would cause the stop command to be entirely missed and score decoding would run off the end of the array...
This demo is nearly a good test platform, but it also suffers from:
Jonathan
Code:
// read the next note from the table
c = [COLOR="#0000FF"][B]*sp++[/B][/COLOR];
opcode = c & 0xF0;
chan = c & 0x0F;
if(c < 0x80) {
// Delay
d_time = (c << 8) | *sp++;
delay(d_time);
return;
}
if([COLOR="#FF0000"][B]*sp[/B][/COLOR] == CMD_STOP) {
for (chan=0; chan<10; chan++) {
envs[chan]->noteOff();
waves[chan]->amplitude(0);
}
Serial.println("DONE");
while(1);
}
Code:
0x81, 0x88, 0,12, 0x82,[COLOR="#0000FF"] 0x89[/COLOR], [COLOR="#FF0000"]0xf0[/COLOR]};
This demo is nearly a good test platform, but it also suffers from:
- Stop command enters a while (1) loop, so analysis of correct shutdown after the last note is hindered
- pointless return statements in the other command-decoding if() blocks, which need to be removed if any analysis is to be done at intermediate points in the loop()
Jonathan