blob: 2a87e5ce74ccef19ee0c930c125a227a1158c4a5 [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
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020011#include "modules/audio_processing/agc/utility.h"
pbos@webrtc.org788acd12014-12-15 09:41:24 +000012
13#include <math.h>
14
Per Åhgrene7175c92020-03-20 16:43:34 +010015namespace webrtc {
16
pbos@webrtc.org788acd12014-12-15 09:41:24 +000017static const double kLog10 = 2.30258509299;
18static const double kLinear2DbScale = 20.0 / kLog10;
19static const double kLinear2LoudnessScale = 13.4 / kLog10;
20
21double Loudness2Db(double loudness) {
22 return loudness * kLinear2DbScale / kLinear2LoudnessScale;
23}
24
25double Linear2Loudness(double rms) {
26 if (rms == 0)
27 return -15;
28 return kLinear2LoudnessScale * log(rms);
29}
30
31double Db2Loudness(double db) {
32 return db * kLinear2LoudnessScale / kLinear2DbScale;
33}
34
35double Dbfs2Loudness(double dbfs) {
36 return Db2Loudness(90 + dbfs);
37}
Per Åhgrene7175c92020-03-20 16:43:34 +010038
39} // namespace webrtc