- if (PsndOut == 0 && currentConfig.Frameskip >= 0) {
- frames_done = frames_shown = 0;
- } else {
- // it is quite common for this implementation to leave 1 fame unfinished
- // when second changes, but we don't want buffer to starve.
- if (PsndOut && frames_done < target_fps && frames_done > target_fps-5) {
- updateKeys();
- SkipFrame(1); frames_done++;
+ if (PsndOut != NULL)
+ {
+ /* some code which tries to sync things to audio clock, the dirty way */
+ static int audio_skew_prev = 0;
+ int audio_skew, adj, co = 9, shift = 7;
+ audio_skew = snd_all_samples*2 - FrameworkAudio_BufferPos();
+ if (PsndRate == 22050) co = 10;
+ if (PsndRate > 22050) co = 11;
+ if (PicoOpt&8) shift++;
+ if (audio_skew < 0) {
+ adj = -((-audio_skew) >> shift);
+ if (audio_skew > -(6<<co)) adj>>=1;
+ if (audio_skew > -(4<<co)) adj>>=1;
+ if (audio_skew > -(2<<co)) adj>>=1;
+ if (audio_skew > audio_skew_prev) adj>>=2; // going up already
+ } else {
+ adj = audio_skew >> shift;
+ if (audio_skew < (6<<co)) adj>>=1;
+ if (audio_skew < (4<<co)) adj>>=1;
+ if (audio_skew < (2<<co)) adj>>=1;
+ if (audio_skew < audio_skew_prev) adj>>=2;