void FCEUD_Update(uint8 *XBuf, int32 *Buffer, int Count) { static int skipcount = 0; int maxskip = maxconbskip; if(NoWaiting & 1) maxskip = ffbskip; if(Count) { int32 can=GetWriteSound(); static int uflow=0; int32 tmpcan; extern int FCEUDnetplay; if(can >= GetMaxSound()) uflow=1; /* Go into massive underflow mode. */ if(can > Count) can=Count; else uflow=0; FCEUD_WriteSoundData(Buffer,can); tmpcan = GetWriteSound(); if(((tmpcan < Count*0.90) && !uflow) || (skipcount >= maxskip)) { if(XBuf && (!NoWaiting || skipcount >= maxskip)) { skipcount = 0; FCEUD_BlitScreen(XBuf); } else { skipcount++; //FCEU_printf("Skipped0"); } Buffer+=can; Count-=can; if(Count) { if(NoWaiting) { can=GetWriteSound(); if(Count>can) Count=can; } FCEUD_WriteSoundData(Buffer,Count); } } else { skipcount++; //FCEU_printf("Skipped"); #ifdef NETWORK if(!NoWaiting && FCEUDnetplay && (uflow || tmpcan >= (Count * 0.90))) { if(Count > tmpcan) Count=tmpcan; while(tmpcan > 0) { //printf("Overwrite: %d\n", (Count <= tmpcan)?Count : tmpcan); FCEUD_WriteSoundData(Buffer, (Count <= tmpcan)?Count : tmpcan); tmpcan -= Count; } } #endif } } else { /* This complex statement deserves some explanation. Make sure this special speed throttling hasn't been disabled by the user first. Second, we don't want to throttle the speed if the fast-forward button is pressed down(or during certain network play conditions). Now, if we're at this point, we'll throttle speed if sound is disabled. Otherwise, it gets a bit more complicated. We'll throttle speed if focus to FCE Ultra has been lost and we're writing to the primary sound buffer because our sound code won't block. Blocking does seem to work when writing to a secondary buffer, so we won't throttle when a secondary buffer is used. */ int skipthis = 0; if(!(eoptions&EO_NOTHROTTLE)) if(!NoWaiting) if(!soundo || (soundo && nofocus && !(soundoptions&SO_SECONDARY)) ) skipthis = SpeedThrottle(); if(XBuf) { if((!skipthis && !NoWaiting) || (skipcount >= maxskip)) { FCEUD_BlitScreen(XBuf); skipcount = 0; } else { skipcount++; } } } UpdateFCEUWindow(); FCEUD_UpdateInput(); PPUViewDoBlit(); }
/** * Update the video, audio, and input subsystems with the provided * video (XBuf) and audio (Buffer) information. */ void FCEUD_Update(uint8 *XBuf, int32 *Buffer, int Count) { extern int FCEUDnetplay; #ifdef CREATE_AVI if(LoggingEnabled == 2 || (eoptions&EO_NOTHROTTLE)) { if(LoggingEnabled == 2) { int16* MonoBuf = new int16[Count]; int n; for(n=0; n<Count; ++n) MonoBuf[n] = Buffer[n] & 0xFFFF; NESVideoLoggingAudio ( MonoBuf, FSettings.SndRate, 16, 1, Count ); delete [] MonoBuf; } Count /= 2; if(inited & 1) { if(Count > GetWriteSound()) Count = GetWriteSound(); if (!mutecapture) if(Count > 0 && Buffer) WriteSound(Buffer,Count); } if(inited & 2) FCEUD_UpdateInput(); if(XBuf && (inited & 4)) BlitScreen(XBuf); //SpeedThrottle(); return; } #endif int ocount = Count; // apply frame scaling to Count Count = (int)(Count / g_fpsScale); if(Count) { int32 can=GetWriteSound(); static int uflow=0; int32 tmpcan; // don't underflow when scaling fps if(can >= GetMaxSound() && g_fpsScale==1.0) uflow=1; /* Go into massive underflow mode. */ if(can > Count) can=Count; else uflow=0; #ifdef CREATE_AVI if (!mutecapture) #endif WriteSound(Buffer,can); //if(uflow) puts("Underflow"); tmpcan = GetWriteSound(); // don't underflow when scaling fps if(g_fpsScale>1.0 || ((tmpcan < Count*0.90) && !uflow)) { if(XBuf && (inited&4) && !(NoWaiting & 2)) BlitScreen(XBuf); Buffer+=can; Count-=can; if(Count) { if(NoWaiting) { can=GetWriteSound(); if(Count>can) Count=can; #ifdef CREATE_AVI if (!mutecapture) #endif WriteSound(Buffer,Count); } else { while(Count>0) { #ifdef CREATE_AVI if (!mutecapture) #endif WriteSound(Buffer,(Count<ocount) ? Count : ocount); Count -= ocount; } } } } //else puts("Skipped"); else if(!NoWaiting && FCEUDnetplay && (uflow || tmpcan >= (Count * 1.8))) { if(Count > tmpcan) Count=tmpcan; while(tmpcan > 0) { // printf("Overwrite: %d\n", (Count <= tmpcan)?Count : tmpcan); #ifdef CREATE_AVI if (!mutecapture) #endif WriteSound(Buffer, (Count <= tmpcan)?Count : tmpcan); tmpcan -= Count; } } } else { if(!NoWaiting && (!(eoptions&EO_NOTHROTTLE) || FCEUI_EmulationPaused())) while (SpeedThrottle()) { FCEUD_UpdateInput(); } if(XBuf && (inited&4)) { BlitScreen(XBuf); } } FCEUD_UpdateInput(); //if(!Count && !NoWaiting && !(eoptions&EO_NOTHROTTLE)) // SpeedThrottle(); //if(XBuf && (inited&4)) //{ // BlitScreen(XBuf); //} //if(Count) // WriteSound(Buffer,Count,NoWaiting); //FCEUD_UpdateInput(); }