blob: 48458adfb51dfe6019f5f1bfea73ec67f69f5f36 [file] [log] [blame]
pbos@webrtc.org788acd12014-12-15 09:41:24 +00001/*
2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
3 *
4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
9 */
10
11#include "webrtc/modules/audio_processing/agc/utility.h"
12
13#include <math.h>
14
15static const double kLog10 = 2.30258509299;
16static const double kLinear2DbScale = 20.0 / kLog10;
17static const double kLinear2LoudnessScale = 13.4 / kLog10;
18
19double Loudness2Db(double loudness) {
20 return loudness * kLinear2DbScale / kLinear2LoudnessScale;
21}
22
23double Linear2Loudness(double rms) {
24 if (rms == 0)
25 return -15;
26 return kLinear2LoudnessScale * log(rms);
27}
28
29double Db2Loudness(double db) {
30 return db * kLinear2LoudnessScale / kLinear2DbScale;
31}
32
33double Dbfs2Loudness(double dbfs) {
34 return Db2Loudness(90 + dbfs);
35}