summaryrefslogtreecommitdiffstats
path: root/media/java
diff options
context:
space:
mode:
authorAndroid (Google) Code Review <android-gerrit@google.com>2009-09-29 18:12:54 -0400
committerAndroid (Google) Code Review <android-gerrit@google.com>2009-09-29 18:12:54 -0400
commit7d9871805beef4ea5e319f1a11ab32f610031845 (patch)
tree20b21245a39fe42200c3577ba201afb38affa272 /media/java
parentb80fbd4479dccbd2f3ab9645b49e41ca4d10371f (diff)
parenta2ef57dba9ac77d8eccacd646b2b8a8d99fe9d8b (diff)
downloadframeworks_base-7d9871805beef4ea5e319f1a11ab32f610031845.zip
frameworks_base-7d9871805beef4ea5e319f1a11ab32f610031845.tar.gz
frameworks_base-7d9871805beef4ea5e319f1a11ab32f610031845.tar.bz2
Merge change I19f2928b into eclair
* changes: Fix issue 2141503: Keyclick sound doesn't honor volume settings.
Diffstat (limited to 'media/java')
-rw-r--r--media/java/android/media/AudioManager.java8
-rw-r--r--media/java/android/media/AudioService.java21
2 files changed, 23 insertions, 6 deletions
diff --git a/media/java/android/media/AudioManager.java b/media/java/android/media/AudioManager.java
index d6463a1..bb16215a 100644
--- a/media/java/android/media/AudioManager.java
+++ b/media/java/android/media/AudioManager.java
@@ -725,7 +725,7 @@ public class AudioManager {
* false if otherwise
*/
public boolean isBluetoothA2dpOn() {
- if (AudioSystem.getDeviceConnectionState(AudioSystem.DEVICE_OUT_BLUETOOTH_A2DP,"")
+ if (AudioSystem.getDeviceConnectionState(AudioSystem.DEVICE_OUT_BLUETOOTH_A2DP,"")
== AudioSystem.DEVICE_STATE_UNAVAILABLE) {
return false;
} else {
@@ -750,7 +750,7 @@ public class AudioManager {
* false if otherwise
*/
public boolean isWiredHeadsetOn() {
- if (AudioSystem.getDeviceConnectionState(AudioSystem.DEVICE_OUT_WIRED_HEADSET,"")
+ if (AudioSystem.getDeviceConnectionState(AudioSystem.DEVICE_OUT_WIRED_HEADSET,"")
== AudioSystem.DEVICE_STATE_UNAVAILABLE) {
return false;
} else {
@@ -1063,7 +1063,9 @@ public class AudioManager {
* {@link #FX_KEYPRESS_SPACEBAR},
* {@link #FX_KEYPRESS_DELETE},
* {@link #FX_KEYPRESS_RETURN},
- * @param volume Sound effect volume
+ * @param volume Sound effect volume.
+ * The volume value is a raw scalar so UI controls should be scaled logarithmically.
+ * If a volume of -1 is specified, the AudioManager.STREAM_MUSIC stream volume minus 3dB will be used.
* NOTE: This version is for applications that have their own
* settings panel for enabling and controlling volume.
*/
diff --git a/media/java/android/media/AudioService.java b/media/java/android/media/AudioService.java
index 307cf22..f4c4586 100644
--- a/media/java/android/media/AudioService.java
+++ b/media/java/android/media/AudioService.java
@@ -619,11 +619,12 @@ public class AudioService extends IAudioService.Stub {
/** @see AudioManager#playSoundEffect(int) */
public void playSoundEffect(int effectType) {
sendMsg(mAudioHandler, MSG_PLAY_SOUND_EFFECT, SHARED_MSG, SENDMSG_NOOP,
- effectType, SOUND_EFFECT_VOLUME, null, 0);
+ effectType, -1, null, 0);
}
/** @see AudioManager#playSoundEffect(int, float) */
public void playSoundEffectVolume(int effectType, float volume) {
+ loadSoundEffects();
sendMsg(mAudioHandler, MSG_PLAY_SOUND_EFFECT, SHARED_MSG, SENDMSG_NOOP,
effectType, (int) (volume * 1000), null, 0);
}
@@ -634,6 +635,9 @@ public class AudioService extends IAudioService.Stub {
*/
public boolean loadSoundEffects() {
synchronized (mSoundEffectsLock) {
+ if (mSoundPool != null) {
+ return true;
+ }
mSoundPool = new SoundPool(NUM_SOUNDPOOL_CHANNELS, AudioSystem.STREAM_SYSTEM, 0);
if (mSoundPool == null) {
return false;
@@ -1197,10 +1201,20 @@ public class AudioService extends IAudioService.Stub {
if (mSoundPool == null) {
return;
}
+ float volFloat;
+ // use STREAM_MUSIC volume attenuated by 3 dB if volume is not specified by caller
+ if (volume < 0) {
+ // Same linear to log conversion as in native AudioSystem::linearToLog() (AudioSystem.cpp)
+ float dBPerStep = (float)((0.5 * 100) / MAX_STREAM_VOLUME[AudioSystem.STREAM_MUSIC]);
+ int musicVolIndex = (mStreamStates[AudioSystem.STREAM_MUSIC].mIndex + 5) / 10;
+ float musicVoldB = dBPerStep * (musicVolIndex - MAX_STREAM_VOLUME[AudioSystem.STREAM_MUSIC]);
+ volFloat = (float)Math.pow(10, (musicVoldB - 3)/20);
+ } else {
+ volFloat = (float) volume / 1000.0f;
+ }
if (SOUND_EFFECT_FILES_MAP[effectType][1] > 0) {
- float v = (float) volume / 1000.0f;
- mSoundPool.play(SOUND_EFFECT_FILES_MAP[effectType][1], v, v, 0, 0, 1.0f);
+ mSoundPool.play(SOUND_EFFECT_FILES_MAP[effectType][1], volFloat, volFloat, 0, 0, 1.0f);
} else {
MediaPlayer mediaPlayer = new MediaPlayer();
if (mediaPlayer != null) {
@@ -1209,6 +1223,7 @@ public class AudioService extends IAudioService.Stub {
mediaPlayer.setDataSource(filePath);
mediaPlayer.setAudioStreamType(AudioSystem.STREAM_SYSTEM);
mediaPlayer.prepare();
+ mediaPlayer.setVolume(volFloat, volFloat);
mediaPlayer.setOnCompletionListener(new OnCompletionListener() {
public void onCompletion(MediaPlayer mp) {
cleanupPlayer(mp);