Less lag for audio, fixed high CPU usage in background mode

This commit is contained in:
pelya
2010-11-23 20:48:36 +02:00
parent 4bc5978d78
commit 34c99e1f07
4 changed files with 21 additions and 7 deletions

View File

@@ -20,12 +20,12 @@ import java.lang.Thread;
class AudioThread { class AudioThread {
private Activity mParent; private MainActivity mParent;
private AudioTrack mAudio; private AudioTrack mAudio;
private byte[] mAudioBuffer; private byte[] mAudioBuffer;
private int mVirtualBufSize; private int mVirtualBufSize;
public AudioThread(Activity parent) public AudioThread(MainActivity parent)
{ {
mParent = parent; mParent = parent;
mAudio = null; mAudio = null;
@@ -35,13 +35,15 @@ class AudioThread {
public int fillBuffer() public int fillBuffer()
{ {
if( Globals.AudioBufferConfig == 0 && mAudio.getPlaybackHeadPosition() * 1000 / mAudio.getPlaybackRate() >= 30 ) if( Globals.AudioBufferConfig == 0 )
mAudio.flush();
mAudio.write( mAudioBuffer, 0, mVirtualBufSize );
if( mParent.isPaused() )
{ {
try{ try{
Thread.sleep(10); Thread.sleep(200);
} catch(InterruptedException e) {} } catch (InterruptedException e) {}
} }
mAudio.write( mAudioBuffer, 0, mVirtualBufSize );
return 1; return 1;
} }

View File

@@ -170,6 +170,7 @@ public class MainActivity extends Activity {
downloader.setStatusField(null); downloader.setStatusField(null);
} }
} }
_isPaused = true;
if( mGLView != null ) if( mGLView != null )
mGLView.onPause(); mGLView.onPause();
super.onPause(); super.onPause();
@@ -188,6 +189,12 @@ public class MainActivity extends Activity {
initSDL(); initSDL();
} }
} }
_isPaused = false;
}
public boolean isPaused()
{
return _isPaused;
} }
@Override @Override
@@ -358,5 +365,6 @@ public class MainActivity extends Activity {
private EditText _screenKeyboard = null; private EditText _screenKeyboard = null;
private boolean sdlInited = false; private boolean sdlInited = false;
public Settings.TouchMeasurementTool _touchMeasurementTool = null; public Settings.TouchMeasurementTool _touchMeasurementTool = null;
boolean _isPaused = false;
} }

View File

@@ -300,6 +300,10 @@ class DemoGLSurfaceView extends GLSurfaceView_SDL {
super.onPause(); super.onPause();
mRenderer.mPaused = true; mRenderer.mPaused = true;
}; };
public boolean isPaused() {
return mRenderer.mPaused;
}
@Override @Override
public void onResume() { public void onResume() {

View File

@@ -1 +1 @@
openttd sc2