[Fuse-for-macosx-commits] SF.net SVN: fuse-for-macosx: [387] trunk/fuse/fusepb/models/Emulator.m
                
                Brought to you by:
                
                    fredm
                    
                
            
            
        
        
        
    | 
      
      
      From: <fr...@us...> - 2007-06-17 13:35:22
      
     | 
| Revision: 387
          http://svn.sourceforge.net/fuse-for-macosx/?rev=387&view=rev
Author:   fredm
Date:     2007-06-17 06:35:22 -0700 (Sun, 17 Jun 2007)
Log Message:
-----------
Short circuit sound-enabled emlation loop if we have run out of puff so the
user can still have a shot at using the menus to control the emulator.
Modified Paths:
--------------
    trunk/fuse/fusepb/models/Emulator.m
Modified: trunk/fuse/fusepb/models/Emulator.m
===================================================================
--- trunk/fuse/fusepb/models/Emulator.m	2007-06-17 12:26:52 UTC (rev 386)
+++ trunk/fuse/fusepb/models/Emulator.m	2007-06-17 13:35:22 UTC (rev 387)
@@ -146,9 +146,17 @@
 -(void) updateEmulationForTimeDelta:(CFAbsoluteTime)deltaTime
 {
   if( sound_enabled ) {
-    /* emulate until fifo is full */
-    while( sfifo_space( &sound_fifo ) >= (sound_stereo+1) * 2 * sound_framesiz ) {
+    int too_long = 0;
+    /* emulate until fifo is full or it takes more than a frames-worth of
+       time to do a frame because we will never catch up */
+    while( ( sfifo_space( &sound_fifo ) >=
+             (sound_stereo+1) * 2 * sound_framesiz ) && !too_long ) {
+      CFTimeInterval startTime = CFAbsoluteTimeGetCurrent();
       event_do_frame();
+      CFTimeInterval endTime = CFAbsoluteTimeGetCurrent();
+      if( (endTime - startTime) > 
+          (0.8 * sound_framesiz / (float)settings_current.sound_freq ) ) 
+        too_long = 1;
     }
   } else {
     float speed = ( settings_current.emulation_speed < 1 ?
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
 |