From ac6020508acedd316391dee42329040bf45f8d90 Mon Sep 17 00:00:00 2001 From: Glenn Kasten Date: Mon, 1 Oct 2012 14:04:31 -0700 Subject: Integrate improved coefficient sinc resampler: VHQ Summary: Very high quality is enabled only for 44.1 -> 48 or 48 -> 44.1, and uses low quality for all other use cases. Track estimated CPU load and throttles the quality based on load; as currently configured it should allow up to 2 instances of very high quality. Medium quality and high quality are currently disabled unless explicitly requested. Details: Only load .so the first time it is needed. Cleanup code style: formatting, indentation, whitespace. Restore medium quality resampler, but it is not used (see next line). Fix memory leak for sinc resampler. Check sample rate in resampler constructor. Add logs for debugging. Rename DEFAULT to DEFAULT_QUALITY for consistency with other quality levels. Renumber VERY_HIGH_QUALITY from 255 to 4. Use enum src_quality consistently. Improve parsing of property af.resampler.quality. Fix reentrancy bug - allow an instance of high quality and an instance of very high quality to both be active concurrently. Bug: 7229644 Change-Id: I0ce6b913b05038889f50462a38830b61a602a9f7 --- services/audioflinger/AudioResampler.h | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) (limited to 'services/audioflinger/AudioResampler.h') diff --git a/services/audioflinger/AudioResampler.h b/services/audioflinger/AudioResampler.h index 71cdfda..2b8694f 100644 --- a/services/audioflinger/AudioResampler.h +++ b/services/audioflinger/AudioResampler.h @@ -35,15 +35,15 @@ public: // certain fixed rate conversions. Sample rate cannot be // changed dynamically. enum src_quality { - DEFAULT=0, + DEFAULT_QUALITY=0, LOW_QUALITY=1, MED_QUALITY=2, HIGH_QUALITY=3, - VERY_HIGH_QUALITY=255 + VERY_HIGH_QUALITY=4, }; static AudioResampler* create(int bitDepth, int inChannelCount, - int32_t sampleRate, int quality=DEFAULT); + int32_t sampleRate, src_quality quality=DEFAULT_QUALITY); virtual ~AudioResampler(); @@ -61,6 +61,9 @@ public: virtual void reset(); virtual size_t getUnreleasedFrames() const { return mInputIndex; } + // called from destructor, so must not be virtual + src_quality getQuality() const { return mQuality; } + protected: // number of bits for phase fraction - 30 bits allows nearly 2x downsampling static const int kNumPhaseBits = 30; @@ -71,7 +74,7 @@ protected: // multiplier to calculate fixed point phase increment static const double kPhaseMultiplier = 1L << kNumPhaseBits; - AudioResampler(int bitDepth, int inChannelCount, int32_t sampleRate); + AudioResampler(int bitDepth, int inChannelCount, int32_t sampleRate, src_quality quality); // prevent copying AudioResampler(const AudioResampler&); @@ -94,6 +97,19 @@ protected: uint32_t mPhaseFraction; uint64_t mLocalTimeFreq; int64_t mPTS; + +private: + const src_quality mQuality; + + // Return 'true' if the quality level is supported without explicit request + static bool qualityIsSupported(src_quality quality); + + // For pthread_once() + static void init_routine(); + + // Return the estimated CPU load for specific resampler in MHz. + // The absolute number is irrelevant, it's the relative values that matter. + static uint32_t qualityMHz(src_quality quality); }; // ---------------------------------------------------------------------------- -- cgit v1.1