summaryrefslogtreecommitdiffstats
path: root/services/audioflinger/AudioMixer.cpp
diff options
context:
space:
mode:
authorAndy Hung <hunga@google.com>2014-05-30 10:42:03 -0700
committerAndy Hung <hunga@google.com>2014-05-30 17:07:44 -0700
commit6be494077f8d7970f3a88129c5d139c5a0c88f6d (patch)
tree8c77f163bd84e808693832666d29b42f73361fc5 /services/audioflinger/AudioMixer.cpp
parent97ae82408469286426d8dc57a361350f74e24a8b (diff)
downloadframeworks_av-6be494077f8d7970f3a88129c5d139c5a0c88f6d.zip
frameworks_av-6be494077f8d7970f3a88129c5d139c5a0c88f6d.tar.gz
frameworks_av-6be494077f8d7970f3a88129c5d139c5a0c88f6d.tar.bz2
Change parameter type for volume to float in AudioMixer
Change-Id: I4da1505ce852505f86f8e5b87f60e8edceeb30e0
Diffstat (limited to 'services/audioflinger/AudioMixer.cpp')
-rw-r--r--services/audioflinger/AudioMixer.cpp20
1 files changed, 14 insertions, 6 deletions
diff --git a/services/audioflinger/AudioMixer.cpp b/services/audioflinger/AudioMixer.cpp
index 2a8ece6..d73292e 100644
--- a/services/audioflinger/AudioMixer.cpp
+++ b/services/audioflinger/AudioMixer.cpp
@@ -543,7 +543,7 @@ void AudioMixer::disable(int name)
* set by ramp, which is either 0 for immediate, or typically one state
* framecount period.
*
- * @param newValue new volume target in U4.12.
+ * @param newFloatValue new volume target in float [0.0, 1.0].
* @param ramp number of frames to increment over. ramp is 0 if the volume
* should be set immediately.
* @param volume reference to the U4.12 target volume, set on return.
@@ -551,8 +551,15 @@ void AudioMixer::disable(int name)
* @param volumeInc reference to the increment per output audio frame, set on return.
* @return true if the volume has changed, false if volume is same.
*/
-static inline bool setVolumeRampVariables(int32_t newValue, int32_t ramp,
+static inline bool setVolumeRampVariables(float newFloatValue, int32_t ramp,
int16_t &volume, int32_t &prevVolume, int32_t &volumeInc) {
+ int32_t newValue = newFloatValue * AudioMixer::UNITY_GAIN_INT;
+ if (newValue > AudioMixer::UNITY_GAIN_INT) {
+ newValue = AudioMixer::UNITY_GAIN_INT;
+ } else if (newValue < 0) {
+ ALOGE("negative volume %.7g", newFloatValue);
+ newValue = 0; // should never happen, but for safety check.
+ }
if (newValue == volume) {
return false;
}
@@ -668,22 +675,23 @@ void AudioMixer::setParameter(int name, int target, int param, void *value)
switch (param) {
case VOLUME0:
case VOLUME1:
- if (setVolumeRampVariables(valueInt,
+ if (setVolumeRampVariables(*reinterpret_cast<float*>(value),
target == RAMP_VOLUME ? mState.frameCount : 0,
track.volume[param - VOLUME0], track.prevVolume[param - VOLUME0],
track.volumeInc[param - VOLUME0])) {
ALOGV("setParameter(%s, VOLUME%d: %04x)",
- target == VOLUME ? "VOLUME" : "RAMP_VOLUME", param - VOLUME0, valueInt);
+ target == VOLUME ? "VOLUME" : "RAMP_VOLUME", param - VOLUME0,
+ track.volume[param - VOLUME0]);
invalidateState(1 << name);
}
break;
case AUXLEVEL:
//ALOG_ASSERT(0 <= valueInt && valueInt <= MAX_GAIN_INT, "bad aux level %d", valueInt);
- if (setVolumeRampVariables(valueInt,
+ if (setVolumeRampVariables(*reinterpret_cast<float*>(value),
target == RAMP_VOLUME ? mState.frameCount : 0,
track.auxLevel, track.prevAuxLevel, track.auxInc)) {
ALOGV("setParameter(%s, AUXLEVEL: %04x)",
- target == VOLUME ? "VOLUME" : "RAMP_VOLUME", valueInt);
+ target == VOLUME ? "VOLUME" : "RAMP_VOLUME", track.auxLevel);
invalidateState(1 << name);
}
break;