• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
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 "modules/audio_processing/agc/utility.h"
12 
13 #include <math.h>
14 
15 namespace webrtc {
16 
17 static const double kLog10 = 2.30258509299;
18 static const double kLinear2DbScale = 20.0 / kLog10;
19 static const double kLinear2LoudnessScale = 13.4 / kLog10;
20 
Loudness2Db(double loudness)21 double Loudness2Db(double loudness) {
22   return loudness * kLinear2DbScale / kLinear2LoudnessScale;
23 }
24 
Linear2Loudness(double rms)25 double Linear2Loudness(double rms) {
26   if (rms == 0)
27     return -15;
28   return kLinear2LoudnessScale * log(rms);
29 }
30 
Db2Loudness(double db)31 double Db2Loudness(double db) {
32   return db * kLinear2LoudnessScale / kLinear2DbScale;
33 }
34 
Dbfs2Loudness(double dbfs)35 double Dbfs2Loudness(double dbfs) {
36   return Db2Loudness(90 + dbfs);
37 }
38 
39 }  // namespace webrtc
40