summaryrefslogtreecommitdiffstats
path: root/services/audiopolicy/common
diff options
context:
space:
mode:
authorEric Laurent <elaurent@google.com>2015-03-18 18:30:19 -0700
committerEric Laurent <elaurent@google.com>2015-04-08 18:08:24 -0700
commitffbc80f5908eaf67a033c6e93a343c39dd6894eb (patch)
treec97aa681b8c70d7429f7be93f851f04e9dee5900 /services/audiopolicy/common
parentc75307b73d324d590d0dbc05b44bce9aa89b7145 (diff)
downloadframeworks_av-ffbc80f5908eaf67a033c6e93a343c39dd6894eb.zip
frameworks_av-ffbc80f5908eaf67a033c6e93a343c39dd6894eb.tar.gz
frameworks_av-ffbc80f5908eaf67a033c6e93a343c39dd6894eb.tar.bz2
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
Diffstat (limited to 'services/audiopolicy/common')
-rwxr-xr-xservices/audiopolicy/common/include/Volume.h22
-rw-r--r--services/audiopolicy/common/managerdefinitions/include/AudioOutputDescriptor.h2
-rw-r--r--services/audiopolicy/common/managerdefinitions/src/AudioOutputDescriptor.cpp6
3 files changed, 26 insertions, 4 deletions
diff --git a/services/audiopolicy/common/include/Volume.h b/services/audiopolicy/common/include/Volume.h
index a4cc759..4205589 100755
--- a/services/audiopolicy/common/include/Volume.h
+++ b/services/audiopolicy/common/include/Volume.h
@@ -18,6 +18,10 @@
#include <system/audio.h>
#include <utils/Log.h>
+#include <math.h>
+
+// Absolute min volume in dB (can be represented in single precision normal float value)
+#define VOLUME_MIN_DB (-758)
class VolumeCurvePoint
{
@@ -32,7 +36,7 @@ public:
/**
* 4 points to define the volume attenuation curve, each characterized by the volume
* index (from 0 to 100) at which they apply, and the attenuation in dB at that index.
- * we use 100 steps to avoid rounding errors when computing the volume in volIndexToAmpl()
+ * we use 100 steps to avoid rounding errors when computing the volume in volIndexToDb()
*
* @todo shall become configurable
*/
@@ -134,4 +138,20 @@ public:
}
}
+ static inline float DbToAmpl(float decibels)
+ {
+ if (decibels <= VOLUME_MIN_DB) {
+ return 0.0f;
+ }
+ return exp( decibels * 0.115129f); // exp( dB * ln(10) / 20 )
+ }
+
+ static inline float AmplToDb(float amplification)
+ {
+ if (amplification == 0) {
+ return VOLUME_MIN_DB;
+ }
+ return 20 * log10(amplification);
+ }
+
};
diff --git a/services/audiopolicy/common/managerdefinitions/include/AudioOutputDescriptor.h b/services/audiopolicy/common/managerdefinitions/include/AudioOutputDescriptor.h
index c6bb975..f1aee46 100644
--- a/services/audiopolicy/common/managerdefinitions/include/AudioOutputDescriptor.h
+++ b/services/audiopolicy/common/managerdefinitions/include/AudioOutputDescriptor.h
@@ -74,7 +74,7 @@ public:
audio_patch_handle_t mPatchHandle;
uint32_t mRefCount[AUDIO_STREAM_CNT]; // number of streams of each type using this output
nsecs_t mStopTime[AUDIO_STREAM_CNT];
- float mCurVolume[AUDIO_STREAM_CNT]; // current stream volume
+ float mCurVolume[AUDIO_STREAM_CNT]; // current stream volume in dB
int mMuteCount[AUDIO_STREAM_CNT]; // mute request counter
bool mStrategyMutedByDevice[NUM_STRATEGIES]; // strategies muted because of incompatible
// device selection. See checkDeviceMuteStrategies()
diff --git a/services/audiopolicy/common/managerdefinitions/src/AudioOutputDescriptor.cpp b/services/audiopolicy/common/managerdefinitions/src/AudioOutputDescriptor.cpp
index 0837a54..596aa1d 100644
--- a/services/audiopolicy/common/managerdefinitions/src/AudioOutputDescriptor.cpp
+++ b/services/audiopolicy/common/managerdefinitions/src/AudioOutputDescriptor.cpp
@@ -21,6 +21,7 @@
#include "AudioOutputDescriptor.h"
#include "IOProfile.h"
#include "AudioGain.h"
+#include "Volume.h"
#include "HwModule.h"
#include <media/AudioPolicy.h>
@@ -354,11 +355,12 @@ bool SwAudioOutputDescriptor::setVolume(float volume,
if (changed) {
// Force VOICE_CALL to track BLUETOOTH_SCO stream volume when bluetooth audio is
// enabled
+ float volume = Volume::DbToAmpl(mCurVolume[stream]);
if (stream == AUDIO_STREAM_BLUETOOTH_SCO) {
mClientInterface->setStreamVolume(
- AUDIO_STREAM_VOICE_CALL, mCurVolume[stream], mIoHandle, delayMs);
+ AUDIO_STREAM_VOICE_CALL, volume, mIoHandle, delayMs);
}
- mClientInterface->setStreamVolume(stream, mCurVolume[stream], mIoHandle, delayMs);
+ mClientInterface->setStreamVolume(stream, volume, mIoHandle, delayMs);
}
return changed;
}