How to detect max dB Swift

徘徊边缘 提交于 2019-12-03 21:08:53

i was currently building my app about movie making,and learned something about how to metering sound level in dB.

the origin data of recorder.averagePowerForChannel is not really dB level of the sound,it's provide a level range which is -160 - 0,so we need some modification to make this data more reasonable

so i was finding some thing that makes this data(value) convert to dB level data.

(Sorry about forgot where i was found it!)

here is the code

/**
 Format dBFS to dB

 - author: RÅGE_Devil_Jåmeson
 - date: (2016-07-13) 20:07:03

 - parameter dBFSValue: raw value of averagePowerOfChannel

 - returns: formatted value
 */
func dBFS_convertTo_dB (dBFSValue: Float) -> Float
{
var level:Float = 0.0
let peak_bottom:Float = -60.0 // dBFS -> -160..0   so it can be -80 or -60

if dBFSValue < peak_bottom
{
    level = 0.0
}
else if dBFSValue >= 0.0
{
    level = 1.0
}
else
{
    let root:Float              =   2.0
    let minAmp:Float            =   powf(10.0, 0.05 * peak_bottom)
    let inverseAmpRange:Float   =   1.0 / (1.0 - minAmp)
    let amp:Float               =   powf(10.0, 0.05 * dBFSValue)
    let adjAmp:Float            =   (amp - minAmp) * inverseAmpRange

    level = powf(adjAmp, 1.0 / root)
}
return level
}

i was noticed that you are recording whit 2 channels so it will be little different with my code;

wish could help you out or give you some ideas :D

LAST UPDATE

Change coding language to swift

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!