audio policy: volume in dBs
Volumes are now stored and exchanged in dBs to be
consistent with the volume tables.
They are converted if needed when applied to the target
gain controller.
Change-Id: I916cbb0bbe65c916444b8c65a2bdca9645c58399
diff --git a/services/audiopolicy/enginedefault/src/Engine.cpp b/services/audiopolicy/enginedefault/src/Engine.cpp
index 26a0d09..50f1609 100755
--- a/services/audiopolicy/enginedefault/src/Engine.cpp
+++ b/services/audiopolicy/enginedefault/src/Engine.cpp
@@ -63,13 +63,14 @@
return (mApmObserver != NULL) ? NO_ERROR : NO_INIT;
}
-float Engine::volIndexToAmpl(Volume::device_category category, audio_stream_type_t streamType,
+float Engine::volIndexToDb(Volume::device_category category, audio_stream_type_t streamType,
int indexInUi)
{
const StreamDescriptor &streamDesc = mApmObserver->getStreamDescriptors().valueAt(streamType);
- return Gains::volIndexToAmpl(category, streamDesc, indexInUi);
+ return Gains::volIndexToDb(category, streamDesc, indexInUi);
}
+
status_t Engine::initStreamVolume(audio_stream_type_t stream, int indexMin, int indexMax)
{
ALOGV("initStreamVolume() stream %d, min %d, max %d", stream , indexMin, indexMax);
diff --git a/services/audiopolicy/enginedefault/src/Engine.h b/services/audiopolicy/enginedefault/src/Engine.h
index f44556c..56a4748 100755
--- a/services/audiopolicy/enginedefault/src/Engine.h
+++ b/services/audiopolicy/enginedefault/src/Engine.h
@@ -101,10 +101,10 @@
{
return mPolicyEngine->initializeVolumeCurves(isSpeakerDrcEnabled);
}
- virtual float volIndexToAmpl(Volume::device_category deviceCategory,
+ virtual float volIndexToDb(Volume::device_category deviceCategory,
audio_stream_type_t stream,int indexInUi)
{
- return mPolicyEngine->volIndexToAmpl(deviceCategory, stream, indexInUi);
+ return mPolicyEngine->volIndexToDb(deviceCategory, stream, indexInUi);
}
private:
Engine *mPolicyEngine;
@@ -141,7 +141,7 @@
audio_devices_t getDeviceForStrategy(routing_strategy strategy) const;
audio_devices_t getDeviceForInputSource(audio_source_t inputSource) const;
- float volIndexToAmpl(Volume::device_category category,
+ float volIndexToDb(Volume::device_category category,
audio_stream_type_t stream, int indexInUi);
status_t initStreamVolume(audio_stream_type_t stream, int indexMin, int indexMax);
void initializeVolumeCurves(bool isSpeakerDrcEnabled);
diff --git a/services/audiopolicy/enginedefault/src/Gains.cpp b/services/audiopolicy/enginedefault/src/Gains.cpp
index a684fdd..78f2909 100644
--- a/services/audiopolicy/enginedefault/src/Gains.cpp
+++ b/services/audiopolicy/enginedefault/src/Gains.cpp
@@ -197,10 +197,10 @@
};
//static
-float Gains::volIndexToAmpl(audio_devices_t device, const StreamDescriptor& streamDesc,
- int indexInUi)
+float Gains::volIndexToDb(Volume::device_category deviceCategory,
+ const StreamDescriptor& streamDesc,
+ int indexInUi)
{
- Volume::device_category deviceCategory = Volume::getDeviceCategory(device);
const VolumeCurvePoint *curve = streamDesc.getVolumeCurvePoint(deviceCategory);
// the volume index in the UI is relative to the min and max volume indices for this stream type
@@ -212,7 +212,7 @@
// find what part of the curve this index volume belongs to, or if it's out of bounds
int segment = 0;
if (volIdx < curve[Volume::VOLMIN].mIndex) { // out of bounds
- return 0.0f;
+ return VOLUME_MIN_DB;
} else if (volIdx < curve[Volume::VOLKNEE1].mIndex) {
segment = 0;
} else if (volIdx < curve[Volume::VOLKNEE2].mIndex) {
@@ -220,7 +220,7 @@
} else if (volIdx <= curve[Volume::VOLMAX].mIndex) {
segment = 2;
} else { // out of bounds
- return 1.0f;
+ return 0.0f;
}
// linear interpolation in the attenuation table in dB
@@ -231,17 +231,25 @@
((float)(curve[segment+1].mIndex -
curve[segment].mIndex)) );
- float amplification = exp( decibels * 0.115129f); // exp( dB * ln(10) / 20 )
-
- ALOGVV("VOLUME vol index=[%d %d %d], dB=[%.1f %.1f %.1f] ampl=%.5f",
+ ALOGVV("VOLUME vol index=[%d %d %d], dB=[%.1f %.1f %.1f]",
curve[segment].mIndex, volIdx,
curve[segment+1].mIndex,
curve[segment].mDBAttenuation,
decibels,
- curve[segment+1].mDBAttenuation,
- amplification);
+ curve[segment+1].mDBAttenuation);
- return amplification;
+ return decibels;
}
+
+//static
+float Gains::volIndexToAmpl(Volume::device_category deviceCategory,
+ const StreamDescriptor& streamDesc,
+ int indexInUi)
+{
+ return Volume::DbToAmpl(volIndexToDb(deviceCategory, streamDesc, indexInUi));
+}
+
+
+
}; // namespace android
diff --git a/services/audiopolicy/enginedefault/src/Gains.h b/services/audiopolicy/enginedefault/src/Gains.h
index b5601ca..7620b7d 100644
--- a/services/audiopolicy/enginedefault/src/Gains.h
+++ b/services/audiopolicy/enginedefault/src/Gains.h
@@ -29,8 +29,13 @@
class Gains
{
public :
- static float volIndexToAmpl(audio_devices_t device, const StreamDescriptor& streamDesc,
- int indexInUi);
+ static float volIndexToAmpl(Volume::device_category deviceCategory,
+ const StreamDescriptor& streamDesc,
+ int indexInUi);
+
+ static float volIndexToDb(Volume::device_category deviceCategory,
+ const StreamDescriptor& streamDesc,
+ int indexInUi);
// default volume curve
static const VolumeCurvePoint sDefaultVolumeCurve[Volume::VOLCNT];