void SDLSoundCallback(void * userdata, uint16_t * buffer, int length)
{
	// 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; i+=2)
		{
			buffer[i + 0] = *ltxd;
			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;
	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);
    
}
示例#2
0
void  MainEventLoopPass()
{
    EventRecord evt;
	Boolean		notHandled = true;

    if (!gDone)	 /* after cx switch back ensure not done */
    {
		if(WaitNextEvent(everyEvent, &evt, 1, gMouseRgn))
		{
			if (gMouseRgn)
				SetRectRgn(gMouseRgn, evt.where.h, evt.where.v, evt.where.h + 1, evt.where.v + 1);
					
			HandleNextEvent(&evt);
		}
	}
}