Exemplo n.º 1
0
void S9xSyncSpeed ()
{
#if 0
	unsigned int timediffallowed = Settings.TurboMode ? 0 : Settings.FrameTime;

	while (!S9xSyncSound())
		usleep(10);

	uint32 skipFrms = Settings.SkipFrames;

	if (Settings.TurboMode)
		skipFrms = Settings.TurboSkipFrames;

	now = gettime();

	if (tb_diff_usec(now,prev) > timediffallowed)
	{
		/* Timer has already expired */
		if (IPPU.SkippedFrames < skipFrms)
		{
			IPPU.SkippedFrames++;
			IPPU.RenderThisFrame = FALSE;
		}
		else
		{
			IPPU.SkippedFrames = 0;
			IPPU.RenderThisFrame = TRUE;
		}
	}
	else
	{
		/*** Ahead - so hold up ***/
		while (tb_diff_usec(now,prev) < timediffallowed)
		{
			now = gettime();
			usleep(50);
		}
		IPPU.RenderThisFrame = TRUE;
		IPPU.SkippedFrames = 0;
	}

	prev = now;
#endif
	return;
}
Exemplo n.º 2
0
void SNESSystem::CPULoop()
{
	if (soundEnableFlag != soundEnableFlagOld)
	{
		S9xSetSoundControl(soundEnableFlag);
		soundEnableFlagOld = soundEnableFlag;
	}

	S9xSyncSound();
	S9xMainLoop();

	unsigned bytes = (S9xGetSampleCount() << 1) & ~3;
	ZeroMemory(sound_buffer, bytes);
	S9xMixSamples(sound_buffer, bytes >> 1);

	if (m_output != NULL)
	{
		m_output->write(sound_buffer, bytes);
	}
}
Exemplo n.º 3
0
/* Finishes syncing by using more accurate system sleep functions*/
void
S9xSyncSpeedFinish (void)
{
    if (!syncing)
        return;

    gettimeofday (&now, NULL);

    if (Settings.SoundSync)
    {
        while (!S9xSyncSound ())
        {
            usleep (100);

            gettimeofday (&next_frame_time, NULL);

            /* If we can't sync sound within a second, we're probably deadlocked */
            if (TIMER_DIFF (next_frame_time, now) > 1000000)
            {
                /* Flush out our sample buffer and give up. */
                S9xClearSamples ();

                break;
            }
        }

        next_frame_time = now;
        return;
    }

    if (TIMER_DIFF (next_frame_time, now) < -500000)
    {
        next_frame_time = now;
    }

    while (timercmp (&next_frame_time, &now, >))
    {
        int time_left = TIMER_DIFF (next_frame_time, now);

        if (time_left > 500000)
        {
            next_frame_time = now;
            break;
        }

        usleep (time_left);

        gettimeofday (&now, NULL);
    }

    next_frame_time.tv_usec += Settings.FrameTime;

    if (next_frame_time.tv_usec >= 1000000)
    {
        next_frame_time.tv_sec += next_frame_time.tv_usec / 1000000;
        next_frame_time.tv_usec %= 1000000;
    }

    syncing = 0;

    return;
}