+ // 1st, check to see if the DSP is running. If not, fill the buffer with L/RXTD and exit.
+
+ if (!DSPIsRunning())
+ {
+ for(int i=0; i<(length/2); i+=2)
+ {
+ ((uint16_t *)buffer)[i + 0] = ltxd;
+ ((uint16_t *)buffer)[i + 1] = rtxd;
+ }
+
+ return;
+ }
+
+ // The length of time we're dealing with here is 1/48000 s, so we multiply this
+ // by the number of cycles per second to get the number of cycles for one sample.
+// uint32_t riscClockRate = (vjs.hardwareTypeNTSC ? RISC_CLOCK_RATE_NTSC : RISC_CLOCK_RATE_PAL);
+// uint32_t cyclesPerSample = riscClockRate / DAC_AUDIO_RATE;
+ // This is the length of time
+// timePerSample = (1000000.0 / (double)riscClockRate) * ();
+
+ // Now, run the DSP for that length of time for each sample we need to make
+
+ bufferIndex = 0;
+ sampleBuffer = buffer;
+// If length is the length of the sample buffer in BYTES, then shouldn't the # of
+// samples be / 4? No, because we bump the sample count by 2, so this is OK.
+ numberOfSamples = length / 2;
+ bufferDone = false;
+
+ SetCallbackTime(DSPSampleCallback, 1000000.0 / (double)DAC_AUDIO_RATE, EVENT_JERRY);
+
+ // These timings are tied to NTSC, need to fix that in event.cpp/h! [FIXED]
+ do
+ {
+ double timeToNextEvent = GetTimeToNextEvent(EVENT_JERRY);
+
+ if (vjs.DSPEnabled)
+ {
+ if (vjs.usePipelinedDSP)
+ DSPExecP2(USEC_TO_RISC_CYCLES(timeToNextEvent));
+ else
+ DSPExec(USEC_TO_RISC_CYCLES(timeToNextEvent));
+ }
+
+ HandleNextEvent(EVENT_JERRY);
+ }
+ while (!bufferDone);
+}
+
+
+void DSPSampleCallback(void)
+{
+ ((uint16_t *)sampleBuffer)[bufferIndex + 0] = ltxd;
+ ((uint16_t *)sampleBuffer)[bufferIndex + 1] = rtxd;
+ bufferIndex += 2;
+
+ if (bufferIndex == numberOfSamples)