-//WriteLog("DAC: About to write some data!\n");
- int numLeftSamplesReady
- = (LeftFIFOTailPtr + (LeftFIFOTailPtr < LeftFIFOHeadPtr ? BUFFER_SIZE : 0))
- - LeftFIFOHeadPtr;
- int numRightSamplesReady
- = (RightFIFOTailPtr + (RightFIFOTailPtr < RightFIFOHeadPtr ? BUFFER_SIZE : 0))
- - RightFIFOHeadPtr;
- int numSamplesReady
- = (numLeftSamplesReady < numRightSamplesReady
- ? numLeftSamplesReady : numRightSamplesReady);//Hmm. * 2;
-
-//The numbers look good--it's just that the DSP can't get enough samples in the DAC buffer!
-//WriteLog("DAC: Left/RightFIFOHeadPtr: %u/%u, Left/RightFIFOTailPtr: %u/%u\n", LeftFIFOHeadPtr, RightFIFOHeadPtr, LeftFIFOTailPtr, RightFIFOTailPtr);
-//WriteLog(" numLeft/RightSamplesReady: %i/%i, numSamplesReady: %i, length of buffer: %i\n", numLeftSamplesReady, numRightSamplesReady, numSamplesReady, length);
-
-/* if (numSamplesReady > length)
- numSamplesReady = length;//*/
- if (numSamplesReady > length / 2) // length / 2 because we're comparing 16-bit lengths
- numSamplesReady = length / 2;
-//else
-// WriteLog(" Not enough samples to fill the buffer (short by %u L/R samples)...\n", (length / 2) - numSamplesReady);
-//WriteLog("DAC: %u samples ready.\n", numSamplesReady);
-
- // Actually, it's a bit more involved than this, but this is the general idea:
-// memcpy(buffer, DACBuffer, length);
- for(int i=0; i<numSamplesReady; i++)
- // Could also use (as long as BUFFER_SIZE is a multiple of 2):
- ((uint16 *)buffer)[i] = DACBuffer[(LeftFIFOHeadPtr + i) % BUFFER_SIZE];
-// buffer[i] = DACBuffer[(LeftFIFOHeadPtr + i) & (BUFFER_SIZE - 1)];
-
- LeftFIFOHeadPtr = (LeftFIFOHeadPtr + numSamplesReady) % BUFFER_SIZE;
- RightFIFOHeadPtr = (RightFIFOHeadPtr + numSamplesReady) % BUFFER_SIZE;
- // Could also use (as long as BUFFER_SIZE is a multiple of 2):
-// LeftFIFOHeadPtr = (LeftFIFOHeadPtr + (numSamplesReady)) & (BUFFER_SIZE - 1);
-// RightFIFOHeadPtr = (RightFIFOHeadPtr + (numSamplesReady)) & (BUFFER_SIZE - 1);
-//WriteLog(" -> Left/RightFIFOHeadPtr: %u/%u, Left/RightFIFOTailPtr: %u/%u\n", LeftFIFOHeadPtr, RightFIFOHeadPtr, LeftFIFOTailPtr, RightFIFOTailPtr);