summaryrefslogtreecommitdiffstats
path: root/services/audioflinger/AudioResampler.h
diff options
context:
space:
mode:
authorAndy Hung <hunga@google.com>2014-02-19 12:45:19 -0800
committerAndy Hung <hunga@google.com>2014-02-19 12:48:59 -0800
commit24781fff62a4cf7279d3dac83c33e2ac612712ba (patch)
tree8730de2f28936dca32643c5806e71c6bdc73f9f5 /services/audioflinger/AudioResampler.h
parent1ebd04b5f4ffe774c37054aac305cd9e6c73d2b2 (diff)
downloadframeworks_av-24781fff62a4cf7279d3dac83c33e2ac612712ba.zip
frameworks_av-24781fff62a4cf7279d3dac83c33e2ac612712ba.tar.gz
frameworks_av-24781fff62a4cf7279d3dac83c33e2ac612712ba.tar.bz2
Fix resampler to allow output of single frame
Bug: 13073201 Change-Id: If7818a3389a191a37277bbd8e96a59ef8ce68509 Signed-off-by: Andy Hung <hunga@google.com>
Diffstat (limited to 'services/audioflinger/AudioResampler.h')
-rw-r--r--services/audioflinger/AudioResampler.h32
1 files changed, 32 insertions, 0 deletions
diff --git a/services/audioflinger/AudioResampler.h b/services/audioflinger/AudioResampler.h
index dc33f29..0592855 100644
--- a/services/audioflinger/AudioResampler.h
+++ b/services/audioflinger/AudioResampler.h
@@ -110,6 +110,38 @@ protected:
uint64_t mLocalTimeFreq;
int64_t mPTS;
+ // returns the inFrameCount required to generate outFrameCount frames.
+ //
+ // Placed here to be a consistent for all resamplers.
+ //
+ // Right now, we use the upper bound without regards to the current state of the
+ // input buffer using integer arithmetic, as follows:
+ //
+ // (static_cast<uint64_t>(outFrameCount)*mInSampleRate + (mSampleRate - 1))/mSampleRate;
+ //
+ // The double precision equivalent (float may not be precise enough):
+ // ceil(static_cast<double>(outFrameCount) * mInSampleRate / mSampleRate);
+ //
+ // this relies on the fact that the mPhaseIncrement is rounded down from
+ // #phases * mInSampleRate/mSampleRate and the fact that Sum(Floor(x)) <= Floor(Sum(x)).
+ // http://www.proofwiki.org/wiki/Sum_of_Floors_Not_Greater_Than_Floor_of_Sums
+ //
+ // (so long as double precision is computed accurately enough to be considered
+ // greater than or equal to the Floor(x) value in int32_t arithmetic; thus this
+ // will not necessarily hold for floats).
+ //
+ // TODO:
+ // Greater accuracy and a tight bound is obtained by:
+ // 1) subtract and adjust for the current state of the AudioBufferProvider buffer.
+ // 2) using the exact integer formula where (ignoring 64b casting)
+ // inFrameCount = (mPhaseIncrement * (outFrameCount - 1) + mPhaseFraction) / phaseWrapLimit;
+ // phaseWrapLimit is the wraparound (1 << kNumPhaseBits), if not specified explicitly.
+ //
+ inline size_t getInFrameCountRequired(size_t outFrameCount) {
+ return (static_cast<uint64_t>(outFrameCount)*mInSampleRate
+ + (mSampleRate - 1))/mSampleRate;
+ }
+
private:
const src_quality mQuality;