diff options
author | Glenn Kasten <gkasten@google.com> | 2012-03-09 12:08:48 -0800 |
---|---|---|
committer | Glenn Kasten <gkasten@google.com> | 2012-03-12 15:14:24 -0700 |
commit | 9779e9f5aca5e8179ac02aafaeaa7cb1d65765d2 (patch) | |
tree | 83b6feec96513f2a1779fe0cf778b70890b75a86 | |
parent | 80515d2adfad8dac05ea3dd7972f6e6d85cb789a (diff) | |
download | frameworks_base-9779e9f5aca5e8179ac02aafaeaa7cb1d65765d2.zip frameworks_base-9779e9f5aca5e8179ac02aafaeaa7cb1d65765d2.tar.gz frameworks_base-9779e9f5aca5e8179ac02aafaeaa7cb1d65765d2.tar.bz2 |
Inline applyVolume() into threadLoop_mix()
Also the declaration of applyVolume in PlaybackThread was dead.
Change-Id: I4b1a9848d07d3d7f340baea05b17f667c78df868
-rw-r--r-- | services/audioflinger/AudioFlinger.cpp | 148 | ||||
-rw-r--r-- | services/audioflinger/AudioFlinger.h | 5 |
2 files changed, 73 insertions, 80 deletions
diff --git a/services/audioflinger/AudioFlinger.cpp b/services/audioflinger/AudioFlinger.cpp index 2f49808..d537a20 100644 --- a/services/audioflinger/AudioFlinger.cpp +++ b/services/audioflinger/AudioFlinger.cpp @@ -2729,80 +2729,6 @@ AudioFlinger::DirectOutputThread::~DirectOutputThread() { } -void AudioFlinger::DirectOutputThread::applyVolume() -{ - // Do not apply volume on compressed audio - if (!audio_is_linear_pcm(mFormat)) { - return; - } - - // convert to signed 16 bit before volume calculation - if (mFormat == AUDIO_FORMAT_PCM_8_BIT) { - size_t count = mFrameCount * mChannelCount; - uint8_t *src = (uint8_t *)mMixBuffer + count-1; - int16_t *dst = mMixBuffer + count-1; - while(count--) { - *dst-- = (int16_t)(*src--^0x80) << 8; - } - } - - size_t frameCount = mFrameCount; - int16_t *out = mMixBuffer; - if (rampVolume) { - if (mChannelCount == 1) { - int32_t d = ((int32_t)leftVol - (int32_t)mLeftVolShort) << 16; - int32_t vlInc = d / (int32_t)frameCount; - int32_t vl = ((int32_t)mLeftVolShort << 16); - do { - out[0] = clamp16(mul(out[0], vl >> 16) >> 12); - out++; - vl += vlInc; - } while (--frameCount); - - } else { - int32_t d = ((int32_t)leftVol - (int32_t)mLeftVolShort) << 16; - int32_t vlInc = d / (int32_t)frameCount; - d = ((int32_t)rightVol - (int32_t)mRightVolShort) << 16; - int32_t vrInc = d / (int32_t)frameCount; - int32_t vl = ((int32_t)mLeftVolShort << 16); - int32_t vr = ((int32_t)mRightVolShort << 16); - do { - out[0] = clamp16(mul(out[0], vl >> 16) >> 12); - out[1] = clamp16(mul(out[1], vr >> 16) >> 12); - out += 2; - vl += vlInc; - vr += vrInc; - } while (--frameCount); - } - } else { - if (mChannelCount == 1) { - do { - out[0] = clamp16(mul(out[0], leftVol) >> 12); - out++; - } while (--frameCount); - } else { - do { - out[0] = clamp16(mul(out[0], leftVol) >> 12); - out[1] = clamp16(mul(out[1], rightVol) >> 12); - out += 2; - } while (--frameCount); - } - } - - // convert back to unsigned 8 bit after volume calculation - if (mFormat == AUDIO_FORMAT_PCM_8_BIT) { - size_t count = mFrameCount * mChannelCount; - int16_t *src = mMixBuffer; - uint8_t *dst = (uint8_t *)mMixBuffer; - while(count--) { - *dst++ = (uint8_t)(((int32_t)*src++ + (1<<7)) >> 8)^0x80; - } - } - - mLeftVolShort = leftVol; - mRightVolShort = rightVol; -} - AudioFlinger::PlaybackThread::mixer_state AudioFlinger::DirectOutputThread::prepareTracks_l( Vector< sp<Track> > *tracksToRemove ) @@ -2963,7 +2889,79 @@ void AudioFlinger::DirectOutputThread::threadLoop_mix() sleepTime = 0; standbyTime = systemTime() + standbyDelay; mActiveTrack.clear(); - applyVolume(); + + // apply volume + + // Do not apply volume on compressed audio + if (!audio_is_linear_pcm(mFormat)) { + return; + } + + // convert to signed 16 bit before volume calculation + if (mFormat == AUDIO_FORMAT_PCM_8_BIT) { + size_t count = mFrameCount * mChannelCount; + uint8_t *src = (uint8_t *)mMixBuffer + count-1; + int16_t *dst = mMixBuffer + count-1; + while(count--) { + *dst-- = (int16_t)(*src--^0x80) << 8; + } + } + + frameCount = mFrameCount; + int16_t *out = mMixBuffer; + if (rampVolume) { + if (mChannelCount == 1) { + int32_t d = ((int32_t)leftVol - (int32_t)mLeftVolShort) << 16; + int32_t vlInc = d / (int32_t)frameCount; + int32_t vl = ((int32_t)mLeftVolShort << 16); + do { + out[0] = clamp16(mul(out[0], vl >> 16) >> 12); + out++; + vl += vlInc; + } while (--frameCount); + + } else { + int32_t d = ((int32_t)leftVol - (int32_t)mLeftVolShort) << 16; + int32_t vlInc = d / (int32_t)frameCount; + d = ((int32_t)rightVol - (int32_t)mRightVolShort) << 16; + int32_t vrInc = d / (int32_t)frameCount; + int32_t vl = ((int32_t)mLeftVolShort << 16); + int32_t vr = ((int32_t)mRightVolShort << 16); + do { + out[0] = clamp16(mul(out[0], vl >> 16) >> 12); + out[1] = clamp16(mul(out[1], vr >> 16) >> 12); + out += 2; + vl += vlInc; + vr += vrInc; + } while (--frameCount); + } + } else { + if (mChannelCount == 1) { + do { + out[0] = clamp16(mul(out[0], leftVol) >> 12); + out++; + } while (--frameCount); + } else { + do { + out[0] = clamp16(mul(out[0], leftVol) >> 12); + out[1] = clamp16(mul(out[1], rightVol) >> 12); + out += 2; + } while (--frameCount); + } + } + + // convert back to unsigned 8 bit after volume calculation + if (mFormat == AUDIO_FORMAT_PCM_8_BIT) { + size_t count = mFrameCount * mChannelCount; + int16_t *src = mMixBuffer; + uint8_t *dst = (uint8_t *)mMixBuffer; + while(count--) { + *dst++ = (uint8_t)(((int32_t)*src++ + (1<<7)) >> 8)^0x80; + } + } + + mLeftVolShort = leftVol; + mRightVolShort = rightVol; } void AudioFlinger::DirectOutputThread::threadLoop_sleepTime() diff --git a/services/audioflinger/AudioFlinger.h b/services/audioflinger/AudioFlinger.h index 5049364..f3c8dd2 100644 --- a/services/audioflinger/AudioFlinger.h +++ b/services/audioflinger/AudioFlinger.h @@ -828,9 +828,6 @@ protected: virtual void threadLoop_write(); virtual void threadLoop_standby(); - // Non-trivial for DIRECT only - virtual void applyVolume() { } - // prepareTracks_l reads and writes mActiveTracks, and also returns the // pending set of tracks to remove via Vector 'tracksToRemove'. The caller is // responsible for clearing or destroying this Vector later on, when it @@ -1041,8 +1038,6 @@ public: uint16_t rightVol; private: - void applyVolume(); // FIXME inline into threadLoop_mix() - // prepareTracks_l() tells threadLoop_mix() the name of the single active track sp<Track> mActiveTrack; }; |