当前位置:网站首页>关于es8316的音频爆破音的解决
关于es8316的音频爆破音的解决
2022-07-06 04:38:00 【永不秃头的程序员】
最近在项目中遇到了一个关于播放音频前后,喇叭会产生 哒 的一声,目前没有找到真正原因,但是可以做软件规避。
一、规避思路
对喇叭的功放角进行控制,在使用喇叭之前打开功放角,在使用完喇叭过后关闭功放角,这样就可以规避这种声音的出现。
二、相关代码
frameworks/av/
diff --git a/services/audiopolicy/service/AudioPolicyInterfaceImpl.cpp b/services/audiopolicy/service/AudioPolicyInterfaceImpl.cpp
index dce34db..1b2db64 100644
--- a/services/audiopolicy/service/AudioPolicyInterfaceImpl.cpp
+++ b/services/audiopolicy/service/AudioPolicyInterfaceImpl.cpp
@@ -31,6 +31,12 @@
#include <media/AudioUtilmtk.h>
#endif
//这里添加节点路径
+const char *SPEAKER_ENABLE_PATH = "/sys/class/gpio/gpio114/value";
+static bool stream_system_on = false;
+static bool stream_notification_on = false;
+static bool stream_music_on = false;
+static bool stream_other_on = false;
+
namespace android {
@@ -270,8 +276,33 @@
sp<AudioPlaybackClient> client;
sp<AudioPolicyEffects>audioPolicyEffects;
//打开audio的流程时候使能功放
+ FILE *fp = fopen(SPEAKER_ENABLE_PATH, "w");
+ if (fp != NULL) {
+ char buf[2] = "1";
+ if (fwrite(buf, 1, 1, fp))
+ ALOGE("%s() fwrite success", __FUNCTION__);
+ else
+ ALOGE("%s() fwrite fail", __FUNCTION__);
+ fclose(fp);
+ } else
+ ALOGE("+%s() open failed", __FUNCTION__);
+
getPlaybackClientAndEffects(portId, client, audioPolicyEffects, __func__);
+ switch (client->stream) {
+ case 1: //AUDIO_STREAM_SYSTEM button sound
+ stream_system_on = true;
+ break;
+ case 3: //AUDIO_STREAM_MUSIC
+ stream_music_on = true;
+ break;
+ case 5://AUDIO_STREAM_NOTIFICATION
+ stream_notification_on = true;
+ break;
+ default:
+ stream_other_on = true;
+ }
+
if (audioPolicyEffects != 0) {
// create audio processors according to stream
status_t status = audioPolicyEffects->addOutputSessionEffects(
@@ -307,6 +338,34 @@
getPlaybackClientAndEffects(portId, client, audioPolicyEffects, __func__);
+ switch (client->stream) {
+ case 1: //AUDIO_STREAM_SYSTEM button sound
+ stream_system_on = false;
+ break;
+ case 3: //AUDIO_STREAM_MUSIC
+ stream_music_on = false;
+ break;
+ case 5://AUDIO_STREAM_NOTIFICATION
+ stream_notification_on = false;
+ break;
+ default:
+ stream_other_on = false;
+ }
+ //关闭audio的流程时候关闭功放
+ if ((stream_system_on == false) && (stream_music_on == false) &&
+ (stream_notification_on == false) && (stream_other_on == false)) {
+ FILE *fp = fopen(SPEAKER_ENABLE_PATH, "w");
+ if (fp != NULL) {
+ char buf[2] = "0";
+ if (fwrite(buf, 1, 1, fp))
+ ALOGE("%s() fwrite success", __FUNCTION__);
+ else
+ ALOGE("%s() fwrite fail", __FUNCTION__);
+ fclose(fp);
+ } else
+ ALOGE("+%s() open failed", __FUNCTION__);
+ }
+
if (audioPolicyEffects != 0) {
// release audio processors from the stream
status_t status = audioPolicyEffects->releaseOutputSessionEffects(
device/nxp/
添加对应权限
diff --git a/init.mt8168.rc b/init.mt8168.rc
index 40ef21b..015f327 100644
--- a/init.mt8168.rc
+++ b/init.mt8168.rc
@@ -623,6 +623,10 @@
# EEPROM
chmod 0666 /sys/bus/i2c/devices/2-0050/eeprom
+# SPEAKER_ENABLE
+ chown system system /sys/class/gpio/gpio114/value
+ chmod 0666 /sys/class/gpio/gpio114/value
+
on property:vold.decrypt=trigger_reset_main
write /proc/bootprof "INIT:vold.decrypt=trigger_reset_main"
setprop sys.boot_completed 0
kernel中将frameworks需要的节点申请出来
diff --git a/drivers/misc/biol_misc.c b/drivers/misc/biol_misc.c
index 6d98a60ed992..a651892d2dda 100644
--- a/drivers/misc/biol_misc.c
+++ b/drivers/misc/biol_misc.c
@@ -122,8 +122,9 @@ static int sbc_biol_probe(struct platform_device *pdev)
amp_en = of_get_named_gpio(np,"amp-en", 0);
if (!gpio_is_valid(amp_en))
{
return -ENODEV;
}
gpio_request(amp_en, "amp-en");
gpio_direction_output(amp_en, 0);
//申请节点,后面需要改为1 不然 没有/sys/class/gpio/gpio114/ 的 direction 目录
gpio_export(amp_en, 1);
msleep(1);
gpio_set_value(amp_en, 1);
msleep(1);
// 对应的dts可以参考我之前写的,只是多了一个添加节点的工具罢了
// https://blog.csdn.net/weixin_51178981/article/details/125097672?spm=1001.2014.3001.5501
边栏推荐
- 捷码赋能案例:专业培训、技术支撑,多措并举推动毕业生搭建智慧校园毕设系统
- ue5 小知识点 开启lumen的设置
- Certbot failed to update certificate solution
- P3500 [POI2010]TES-Intelligence Test(二分&离线)
- . Net interprocess communication
- Canal synchronizes MySQL data changes to Kafka (CentOS deployment)
- 程序员在互联网行业的地位 | 每日趣闻
- [Chongqing Guangdong education] engineering fluid mechanics reference materials of southwestjiaotonguniversity
- MIT CMS. 300 session 8 – immersion / immersion
- [network] channel attention network and spatial attention network
猜你喜欢
![[FreeRTOS interrupt experiment]](/img/8f/54422d346bb54d23fab824be2f17a3.jpg)
[FreeRTOS interrupt experiment]

How to estimate the population with samples? (mean, variance, standard deviation)

RTP GB28181 文件测试工具

Understanding of processes, threads, coroutines, synchronization, asynchrony, blocking, non blocking, concurrency, parallelism, and serialization

捷码赋能案例:专业培训、技术支撑,多措并举推动毕业生搭建智慧校园毕设系统

Visio draw fan

The implementation of the maize negotiable digital warehouse receipt standard will speed up the asset digitization process of the industry

Certbot failed to update certificate solution

How do programmers teach their bosses to do things in one sentence? "I'm off duty first. You have to work harder."

Fuzzy -- basic application method of AFL
随机推荐
Lambda expression learning
最高法院,离婚案件判决标准
Ue5 small knowledge freezerendering view rendered objects in the cone
How does vs change the project type?
Crawler notes: improve data collection efficiency! Use of proxy pool and thread pool
也算是学习中的小总结
JVM garbage collector concept
Easyrecovery靠谱不收费的数据恢复电脑软件
Data processing methods - smote series and adasyn
SharedPreferences 源码分析
Embedded development program framework
MySQL reported an error datetime (0) null
After learning classes and objects, I wrote a date class
One question per day (Mathematics)
[network] channel attention network and spatial attention network
2328. Number of incremental paths in the grid graph (memory search)
The ECU of 21 Audi q5l 45tfsi brushes is upgraded to master special adjustment, and the horsepower is safely and stably increased to 305 horsepower
[Chongqing Guangdong education] engineering fluid mechanics reference materials of southwestjiaotonguniversity
Unity screen coordinates ugui coordinates world coordinates conversion between three coordinate systems
[tomato assistant installation]