This routine is called by the SB16 interrupt instead of FillHalfBuffer which was used in the last tutorial. First, we declare start to point to the beginning of our DMA buffer. Secondly, we change SideToFill to the other half of the DMA buffer. I use the variable SideToFill as a flag to tell us which half of the DMA buffer we will be filling. The for loop goes through half of the DMA buffer setting each element equal to whatever MixSamples returns.
Lets go through it section by section.
All this monster is responsible for, is grabbing one sample from each of the sounds that want to be played, mixing them, and sending them off into the DMA buffer. We first declare Total and SoundCount. We will be using Total to add up all our samples and SoundCount will keep track of how many sounds we will be mixing at a time. To traverse through our double linked list, we must start at the beginning, so lets initialize CurrentSample to SampleHead. If CurrentSample equals SampleTail, then we know that we are out of luck, no mixing is needed right now, so lets just return silence which is 0 for char.