diff options
author | dhewg | 2011-02-26 22:23:17 +0100 |
---|---|---|
committer | dhewg | 2011-02-27 09:04:37 +0100 |
commit | d4c0501d1fcc8c98d39b2b7ba627cccb29cbc476 (patch) | |
tree | a5b374de7026451abca95a4f8326bb957a23bbe3 /backends/platform | |
parent | 0e869a5cf0e455f7cd5ce5c39192f3433b931e97 (diff) | |
download | scummvm-rg350-d4c0501d1fcc8c98d39b2b7ba627cccb29cbc476.tar.gz scummvm-rg350-d4c0501d1fcc8c98d39b2b7ba627cccb29cbc476.tar.bz2 scummvm-rg350-d4c0501d1fcc8c98d39b2b7ba627cccb29cbc476.zip |
ANDROID: Check audio buffer for silence
Most games register a music channel, and when there is no music,
they still stream silence (and run through all the Converter::flow
code!). Scan the buffer for that to pause the AudioTrack. Ugly, but
worth it - reduces CPU usage on many games and hence saves battery life.
Diffstat (limited to 'backends/platform')
-rw-r--r-- | backends/platform/android/android.cpp | 20 |
1 files changed, 18 insertions, 2 deletions
diff --git a/backends/platform/android/android.cpp b/backends/platform/android/android.cpp index 860ff1f7ee..f20cf848d4 100644 --- a/backends/platform/android/android.cpp +++ b/backends/platform/android/android.cpp @@ -176,7 +176,7 @@ void *OSystem_Android::audioThreadFunc(void *arg) { byte *buf; int offset, left, written; - int samples; + int samples, i; struct timespec tv_delay; tv_delay.tv_sec = 0; @@ -188,6 +188,7 @@ void *OSystem_Android::audioThreadFunc(void *arg) { tv_full.tv_sec = 0; tv_full.tv_nsec = msecs_full * 1000 * 1000; + bool silence; uint silence_count = 0; while (!system->_audio_thread_exit) { @@ -196,9 +197,24 @@ void *OSystem_Android::audioThreadFunc(void *arg) { samples = mixer->mixCallback(buf, buf_size); + silence = samples < 1; + + // looks stupid, and it is, but currently there's no way to detect + // silence-only buffers from the mixer + if (!silence) { + silence = true; + + for (i = 0; i < samples; i += 2) + // SID streams constant crap + if (READ_UINT16(buf + i) > 32) { + silence = false; + break; + } + } + env->ReleasePrimitiveArrayCritical(bufa, buf, 0); - if (samples < 1) { + if (silence) { if (!paused) silence_count++; |