1.WebRTC中音频能量计算
WebRTC中实现获取音频能量计算的方法是:获取音频数据最大的振幅(即绝对值最大)(范围是0-32767),然后再除以1000,得到0-32之间的数值。从数组中获取相应索引所对应的能量level等级。
我们看下webRTC中level_indicator.cc中对音频level判断的处理。
namespace webrtc {
namespace voe {
// Number of bars on the indicator.
// Note that the number of elements is specified because we are indexing it
// in the range of 0-32
const int8_t permutation[33] =
{0,1,2,3,4,4,5,5,5,5,6,6,6,6,6,7,7,7,7,8,8,8,9,9,9,9,9,9,9,9,9,9,9};
AudioLevel::AudioLevel() :
_absMax(0),
_count(0),
_currentLevel(0),
_currentLevelFullRange(0) {
}
AudioLevel::~AudioLevel() {
}
void AudioLevel::Clear()
{
rtc::CritScope cs(&_critSect);
_absMax = 0;
_count = 0;
_currentLevel = 0;
_currentLevelFullRange = 0;
}
void AudioLevel::ComputeLevel(const AudioFrame& audioFrame)
{
int16_t absValue(0);
//获取最大值
// Check speech level (works for 2