Looking back, I realize I must have spent two weeks just writing the Electric Duet player, because the time through the player loop had to be constant. The loop read through the notes to be played, synthesized them, and changed their duty cycle, but had to use the exact same number of machine cycles regardless of what it did, so the music stayed in tune.
Near the end of the project, I had two problems: the music was slightly off-pitch -- middle A wasn't exactly 440 Hz -- and the number of machine cycles wasn't quite constant (it varied between 40 and 41 cycles depending on which branches the code took).
Finally I realized I could insert a single NOP (no-operation) instruction at a critical location. The NOP forced the number of cycles to be a constant, regardless of the path through the loop, and I then realized that it also slightly changed the output frequency to be tuned exactly right.
I will always remember that moment. :)