行业知识
Android audio 音量曲线
index 转化为 db的流程
首先android 根据不同的流类型定义不同的曲线,曲线文件存放在/vendor/etc/audio_policy_volumes.xml
()或者audio_policy_volumes_drc.xml下面 要看audio_policy_configuration.xml所引用的xml。
1,-3400 33,-2400 66,-1500 100,-600
曲线的定义如上。
()是定义了几个区间。point的两个值分别为index 和db。 定义的index范围是1到100, 而db的范围为-3400 到-600.
外部的index范围不一定是1,100 比如外部index范围为0,39.
-
ui的index寻找在曲线index位置
那么第一步先将传递进去的index,转换为1,100等比例的位置。 假设传递是x, 要求等比例的y。
x/(39 -0) = y / (100 -1)。 假设传递的18 ,求出来y = 46.
-
寻找曲线index对应的分贝。
首先46是处在【33,66】的这个区间内,这个区间对应的db区间是【-2400,-1500】。
先求这个区间一个index对应多少db 将总的index(66 -33)除于总的db(-1500 - (-2400)) 为单位index对应的db。
那46对应的有多少index,46对应为 46 -33。 将这两者相乘就是46对应在这个区间内的db值, 加上起始的-2400就是最终的db。
db就在这个区间里面算。 所求的db = -2400 + (((- 1500 - (-2400))/(66 -33) x(46 -33)) = 2045.
也等比例计算的一个方式。 相对于一个个区间是独立。起始点是最靠近的上一个区间的index,然后计算区间内一个index对应多少db。
传递进去的index相对于起始index的值。
- db转为amplit
//exp是以e为底的指数函数,常数 e 的值约为 2.718282;是由分贝算式推导过来的db = 20* ln(P1/P0);P0是基本功率 aml = exp( db * 0.115129f); // exp( dB * ln(10) / 20 )
- 相应的代码位置
status_t AudioPolicyManager::checkAndSetVolume(IVolumeCurves &curves,VolumeSource volumeSource,int index,const sp& outputDesc,DeviceTypeSet deviceTypes,int delayMs,bool force)float volumeDb = computeVolume(curves, volumeSource, index, deviceTypes);float AudioPolicyManager::computeVolume(IVolumeCurves &curves, VolumeSource volumeSource, int index, const DeviceTypeSet& deviceTypes){ float volumeDb = curves.volIndexToDb(Volume::getDeviceCategory(deviceTypes), index);} virtual float volIndexToDb(device_category deviceCat, int indexInUi) const { sp vc = getCurvesFor(deviceCat); if (vc != 0) { return vc->volIndexToDb(indexInUi, mIndexMin, mIndexMax); } else { ALOGE("Invalid device category %d for Volume Curve", deviceCat); return 0.0f; } }
上一篇:怎么下载客户服务器软件?
下一篇:gprs怎么发送到服务器?