- if (LeftFIFOTailPtr + 2 != LeftFIFOHeadPtr)
- {
- SDL_LockAudio(); // Is it necessary to do this? Mebbe.
- // We use a circular buffer 'cause it's easy. Note that the callback function
- // takes care of dumping audio to the soundcard...! Also note that we're writing
- // the samples in the buffer in an interleaved L/R format.
- LeftFIFOTailPtr = (LeftFIFOTailPtr + 2) % BUFFER_SIZE;
- DACBuffer[LeftFIFOTailPtr] = data;
-// Aaron's code does this, but I don't know why...
-//Flipping this bit makes the audio MUCH louder. Need to look at the amplitude of the
-//waveform to see if any massaging is needed here...
-//Looks like a cheap & dirty way to convert signed samples to unsigned...
-// DACBuffer[LeftFIFOTailPtr] = data ^ 0x8000;
- SDL_UnlockAudio();
- }
-#ifdef DEBUG_DAC
- else
- WriteLog("DAC: Ran into FIFO's left tail pointer!\n");
-#endif
+ // Spin until buffer has been drained (for too fast processors!)...
+//Small problem--if Head == 0 and Tail == buffer end, then this will fail... !!! FIX !!!
+//[DONE]
+ // Also, we're taking advantage of the fact that the buffer is a multiple of two
+ // in this check...
+ while ((LeftFIFOTailPtr + 2) & (BUFFER_SIZE - 1) == LeftFIFOHeadPtr);
+
+ SDL_LockAudio(); // Is it necessary to do this? Mebbe.
+ // We use a circular buffer 'cause it's easy. Note that the callback function
+ // takes care of dumping audio to the soundcard...! Also note that we're writing
+ // the samples in the buffer in an interleaved L/R format.
+ LeftFIFOTailPtr = (LeftFIFOTailPtr + 2) % BUFFER_SIZE;
+ DACBuffer[LeftFIFOTailPtr] = data;
+ SDL_UnlockAudio();