utility.cc (1086B)
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 <cmath> 14 #include <numbers> 15 16 namespace webrtc { 17 18 static const double kLog10 = std::numbers::ln10; 19 static const double kLinear2DbScale = 20.0 / kLog10; 20 static const double kLinear2LoudnessScale = 13.4 / kLog10; 21 22 double Loudness2Db(double loudness) { 23 return loudness * kLinear2DbScale / kLinear2LoudnessScale; 24 } 25 26 double Linear2Loudness(double rms) { 27 if (rms == 0) 28 return -15; 29 return kLinear2LoudnessScale * log(rms); 30 } 31 32 double Db2Loudness(double db) { 33 return db * kLinear2LoudnessScale / kLinear2DbScale; 34 } 35 36 double Dbfs2Loudness(double dbfs) { 37 return Db2Loudness(90 + dbfs); 38 } 39 40 } // namespace webrtc