diff options
author | Glenn Kasten <gkasten@google.com> | 2012-06-18 10:52:41 -0700 |
---|---|---|
committer | Android Git Automerger <android-git-automerger@android.com> | 2012-06-18 10:52:41 -0700 |
commit | ff3e9fa062e2afb2b8ebb0f47c8ad90fdd890dbd (patch) | |
tree | 7a686dda701ec11ce0e6f8954cd982f77acc4242 /services | |
parent | 2c08dc66c2980a50e90befe84f836b7ebf17fe94 (diff) | |
parent | 16f07fb7bb4c284cc0b16f55fe5eabd4a4802590 (diff) | |
download | frameworks_av-ff3e9fa062e2afb2b8ebb0f47c8ad90fdd890dbd.zip frameworks_av-ff3e9fa062e2afb2b8ebb0f47c8ad90fdd890dbd.tar.gz frameworks_av-ff3e9fa062e2afb2b8ebb0f47c8ad90fdd890dbd.tar.bz2 |
am 16f07fb7: am 972af221: FastMixer compensates for SRC jitter in audio HAL
* commit '16f07fb7bb4c284cc0b16f55fe5eabd4a4802590':
FastMixer compensates for SRC jitter in audio HAL
Diffstat (limited to 'services')
-rw-r--r-- | services/audioflinger/FastMixer.cpp | 20 |
1 files changed, 14 insertions, 6 deletions
diff --git a/services/audioflinger/FastMixer.cpp b/services/audioflinger/FastMixer.cpp index 19ee9b3..2c5d751 100644 --- a/services/audioflinger/FastMixer.cpp +++ b/services/audioflinger/FastMixer.cpp @@ -65,6 +65,7 @@ bool FastMixer::threadLoop() long periodNs = 0; // expected period; the time required to render one mix buffer long underrunNs = 0; // underrun likely when write cycle is greater than this value long overrunNs = 0; // overrun likely when write cycle is less than this value + long forceNs = 0; // if overrun detected, force the write cycle to take this much time long warmupNs = 0; // warmup complete when write cycle is greater than to this value FastMixerDumpState dummyDumpState, *dumpState = &dummyDumpState; bool ignoreNextOverrun = true; // used to ignore initial overrun and first after an underrun @@ -221,11 +222,14 @@ bool FastMixer::threadLoop() periodNs = (frameCount * 1000000000LL) / sampleRate; // 1.00 underrunNs = (frameCount * 1750000000LL) / sampleRate; // 1.75 overrunNs = (frameCount * 250000000LL) / sampleRate; // 0.25 + forceNs = (frameCount * 750000000LL) / sampleRate; // 0.75 warmupNs = (frameCount * 500000000LL) / sampleRate; // 0.50 } else { periodNs = 0; underrunNs = 0; overrunNs = 0; + forceNs = 0; + warmupNs = 0; } mixBufferState = UNDEFINED; #if !LOG_NDEBUG @@ -468,6 +472,8 @@ bool FastMixer::threadLoop() dumpState->mWarmupCycles = warmupCycles; } } + sleepNs = -1; + if (isWarm) { if (sec > 0 || nsec > underrunNs) { #if defined(ATRACE_TAG) && (ATRACE_TAG != ATRACE_TAG_NEVER) ScopedTrace st(ATRACE_TAG, "underrun"); @@ -476,7 +482,6 @@ bool FastMixer::threadLoop() ALOGV("underrun: time since last cycle %d.%03ld sec", (int) sec, nsec / 1000000L); dumpState->mUnderruns++; - sleepNs = -1; ignoreNextOverrun = true; } else if (nsec < overrunNs) { if (ignoreNextOverrun) { @@ -487,14 +492,17 @@ bool FastMixer::threadLoop() (int) sec, nsec / 1000000L); dumpState->mOverruns++; } - // Code for non blocking audio HAL. Sleep time must be tuned to allow - // catching up after an underrun - // sleepNs = periodNs - overrunNs; - sleepNs = -1; + // This forces a minimum cycle time. It: + // - compensates for an audio HAL with jitter due to sample rate conversion + // - works with a variable buffer depth audio HAL that never pulls at a rate + // < than overrunNs per buffer. + // - recovers from overrun immediately after underrun + // It doesn't work with a non-blocking audio HAL. + sleepNs = forceNs - nsec; } else { - sleepNs = -1; ignoreNextOverrun = false; } + } #ifdef FAST_MIXER_STATISTICS // advance the FIFO queue bounds size_t i = bounds & (FastMixerDumpState::kSamplingN - 1); |