博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Android 录音getMaxAmplitude()
阅读量:7172 次
发布时间:2019-06-29

本文共 1428 字,大约阅读时间需要 4 分钟。

这个方法是用来获取在前一次调用此方法之后录音中出现的最大振幅,文档解释如下:

Returns the maximum absolute amplitude that was sampled since the last call to this method. Call this only after the setAudioSource().

很多人遇到问题,说是返回值为0,文档中解释如下:the maximum absolute amplitude measured since the last call, or 0 when called for the first time。

 

所以这个方法是需要间隔一段时间调用一次的,也就是说,需要放在线程里面调用的。第一次调用会返回0。

 

最近需要使用这个方法获取音量的变化,对其返回值很好奇,查了一些资料(from stackoverflow),解释如下:

 

The MediaRecorder.getMaxAmplitude() function returns unsigned 16-bit integer values (0-32767). Which is probably just the abs() of the CD-quality sample values that range from -32768 to 32767. This means that they probably represent a 16-bit digitalization of the electrical output from 0-100% maximum voltage range of the microphone build into that mobile phone. Since even in one brand of mobile these microphones sometimes vary in their precise range not even to similar phones will necessarily return the same value given the same distance to the same sound source.This value however correlates to sound pressure in Pascal since it's also a linear quantisation of the solund pressure, in the area where sound can be measured with the given microphone (which will not cover the entire sprectrum due to the limitations of the phone).

 

然后看了一下小米录音机的源码,它其中就有一段代码是用来反映录音音量大小的,关键代码如下:

 

int vuSize = MAX_VU_SIZE * mRecorder.getMaxAmplitude() / 32768;

 

其中MAX_VU_SIZE是小米将音量分的等级数,然后可以将获得的振幅处以32768(关于这个数字,前面一段资料里面有解释),这样子就能获得音量所处的等级。

 

转载地址:http://tvbzm.baihongyu.com/

你可能感兴趣的文章
linux下查看文件编码及修改编码
查看>>
VC中的延时
查看>>
算法与数据结构知识点
查看>>
在单位成功实验的PIX配置
查看>>
centos6.x使用dd命令制作u盘启动
查看>>
如何使用Wireshark抓包
查看>>
mysql 时间函数用法 集合
查看>>
技术宅男既要提升编程技术也要加强沟通能力
查看>>
开源计划--格瓦拉梦想(GUEVARA‘S DREAM)
查看>>
show full columns 和 checking privileges的说明
查看>>
电信网络拓扑图自动布局之总线
查看>>
数据库启动时报ORA-00845错误解决方法
查看>>
查询阿里云存储文件并导出excle 保存到本地
查看>>
WebService-—调用第三方提供的webService服务
查看>>
LVM报错:resize2fs: Bad magic number in super-block
查看>>
从开发到部署会用到的 Docker 命令
查看>>
access数据库转mysql数据库
查看>>
CISCO服务器配置RAID步骤
查看>>
利用makefile文件编译c++源文件
查看>>
VS 0xC0000005 运行错误分析
查看>>