【音频系列】——音量调节、音量增益修改与通信音量无法静音的问题
程序员文章站
2022-05-11 23:17:53
...
一、标准Android系统(基于Android M,其他基本也是这样)音量调节基本流程:
见大神三部曲
简明梳理了音量设置代码流程
对音量的增益转换进行了说明
3、[RK3288][Android6.0] 调试笔记 --- Audio的Voice Call无法静音问题:http://blog.csdn.net/kris_fei/article/details/72961528
对于如通话音量的特殊处理做了说明,基于第二篇的音量增益转换,说明了通话音量无法静音的原因与修改方法
二、MTK平台音量调节特殊处理——STREAM_VOICE_CALL无法静音
1、参照大神第三篇说明修改后,仍然无法静音。
2、在进一步了解音量调节的流程后,修改了STREAM_VOICE_CALL的最小音量等级为0(一般系统默认的通话最小音量等级为非0,防止误设置通话音量导致通话没有声音),如下所示(下述修改同时调整最大音量等级为15),仍然无法静音
diff --git a/frameworks/base/services/core/java/com/android/server/audio/AudioService.java b/frameworks/base/services/core/java/com/android/server/audio/AudioService.java
old mode 100644
new mode 100755
index 46dd821..5023bc9
--- a/frameworks/base/services/core/java/com/android/server/audio/AudioService.java
+++ b/frameworks/base/services/core/java/com/android/server/audio/AudioService.java
@@ -275,7 +275,7 @@ public class AudioService extends IAudioService.Stub {
/** Maximum volume index values for audio streams */
/// M: Modify the max stream volume @{
private static int[] MAX_STREAM_VOLUME = new int[] {
- 7, // STREAM_VOICE_CALL
+ 15, // STREAM_VOICE_CALL
15, // STREAM_SYSTEM
15, // STREAM_RING
15, // STREAM_MUSIC
@@ -289,17 +289,17 @@ public class AudioService extends IAudioService.Stub {
/** Minimum volume index values for audio streams */
private static int[] MIN_STREAM_VOLUME = new int[] {
- 1, // STREAM_VOICE_CALL
+ 0, // STREAM_VOICE_CALL
0, // STREAM_SYSTEM
0, // STREAM_RING
0, // STREAM_MUSIC
0, // STREAM_ALARM
0, // STREAM_NOTIFICATION
1, // STREAM_BLUETOOTH_SCO
0, // STREAM_SYSTEM_ENFORCED
0, // STREAM_DTMF
0 // STREAM_TTS
};
3、修改了硬件层面的增益,将通话音量最低级增益设置为0,无法静音(该步骤无用,但是对于音量增益的修改可以起到效果)。所修改文件的音量增益包含各个类型的音量,如媒体音量增益,听筒音量增益,通话音量增益等,针对我们项目,我们需要修改通话音量增益项:VER1_AUD_VOLUME_SPH ,四行分别对应正常通话模式(听筒模式)、耳机模式、扬声器模式、耳机和喇叭同时出声的模式 ,每行代表若干个音量增益等级的对应增益。具体修改方式如下(我们用的是扬声器,实际只修改第三行即可。其他音量类型的增益修改也可以通过修改该文件中对应项实现):
diff --git a/vendor/mediatek/proprietary/custom/la68/cgen/cfgdefault/audio_ver1_volume_custom_default.h b/vendor/mediatek/proprietary/custom/la68/cgen/cfgdefault/audio_ver1_volume_custom_default.h old mode 100644 new mode 100755 index 6ac3f79..f98943c --- a/vendor/mediatek/proprietary/custom/la68/cgen/cfgdefault/audio_ver1_volume_custom_default.h +++ b/vendor/mediatek/proprietary/custom/la68/cgen/cfgdefault/audio_ver1_volume_custom_default.h @@ -129,11 +129,12 @@ 32,48,64,80,96,112,128,144,160,176,192,208,224,255,255 #define VER1_AUD_VOLUME_SPH \ - 72,84,96,108,120,132,144,0,0,0,0,0,0,0,0,\ - 52,64,76,88,100,112,124,0,0,0,0,0,0,0,0,\ - 76,88,100,112,124,136,148,0,0,0,0,0,0,0,0,\ - 40,52,64,76,88,100,112,0,0,0,0,0,0,0,0 - + 0,84,96,108,120,132,144,0,0,0,0,0,0,0,0,\ //Normal Mode:听筒模式 + 0,64,76,88,100,112,124,0,0,0,0,0,0,0,0,\ //HeadSet Mode:耳机模式 + 0,88,100,112,124,136,148,0,0,0,0,0,0,0,0,\ //LoudSpeaker Mode:扬声器模式 + 0,52,64,76,88,100,112,0,0,0,0,0,0,0,0 //耳机和喇叭同时出声的模式
4、冷静分析,从容应答(参照大神三部曲一,跟着走流程),在进行音量增益转换前,MTK走了自己的定制增益转换路线,MTK定制源码吞不下去,所以修改方法:在判断是否要将通话音量设置为0 后,直接将MTK定制转换的增益强行修改为VOLUME_MIN_DB(即-758.0db)。结果,这一波源码没白吞,喜大普奔。通话音量可以静音啦。
diff --git a/frameworks/av/services/audiopolicy/managerdefault/AudioPolicyManager.cpp b/frameworks/av/services/audiopolicy/managerdefault/AudioPolicyManager.cpp old mode 100644 new mode 100755 index 623003d..59b2a7d --- a/frameworks/av/services/audiopolicy/managerdefault/AudioPolicyManager.cpp +++ b/frameworks/av/services/audiopolicy/managerdefault/AudioPolicyManager.cpp @@ -5633,7 +5633,10 @@ status_t AudioPolicyManager::checkAndSetVolume(audio_stream_type_t stream, volumeDb = -758.0;// set 0 to audioflinger } #endif //在此之前会进行一波软件层面的音量增益转换,转换出对应等级的音量dB值(见大神三部曲二分析) + if((stream == AUDIO_STREAM_VOICE_CALL) && index==0) + { + volumeDb = -758.0; //该值宏为VOLUME_MIN_DB,即静音值 + } outputDesc->setVolume(volumeDb, stream, device, delayMs, force);
三、补充
如果上述步骤修改完仍然无法静音,有可能是被限制住了,需要修改一个全局变量,该变量会被拿来比对是否支持静音,只要在其中增加要支持静音的音频流类型即可。修改如下:
diff --git a/frameworks/base/media/java/android/media/AudioSystem.java b/frameworks/base/media/java/android/media/AudioSystem.java old mode 100644 new mode 100755 index e5ccd47..0fda326 --- a/frameworks/base/media/java/android/media/AudioSystem.java +++ b/frameworks/base/media/java/android/media/AudioSystem.java @@ -754,6 +754,7 @@ public class AudioSystem (1 << STREAM_MUSIC) | (1 << STREAM_RING) | (1 << STREAM_NOTIFICATION) | + (1 << STREAM_VOICE_CALL) | (1 << STREAM_SYSTEM); /**
四、待完善