pbos@webrtc.org | 788acd1 | 2014-12-15 09:41:24 +0000 | [diff] [blame] | 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 "webrtc/modules/audio_processing/agc/utility.h" |
| 12 | |
| 13 | #include <math.h> |
| 14 | |
| 15 | static const double kLog10 = 2.30258509299; |
| 16 | static const double kLinear2DbScale = 20.0 / kLog10; |
| 17 | static const double kLinear2LoudnessScale = 13.4 / kLog10; |
| 18 | |
| 19 | double Loudness2Db(double loudness) { |
| 20 | return loudness * kLinear2DbScale / kLinear2LoudnessScale; |
| 21 | } |
| 22 | |
| 23 | double Linear2Loudness(double rms) { |
| 24 | if (rms == 0) |
| 25 | return -15; |
| 26 | return kLinear2LoudnessScale * log(rms); |
| 27 | } |
| 28 | |
| 29 | double Db2Loudness(double db) { |
| 30 | return db * kLinear2LoudnessScale / kLinear2DbScale; |
| 31 | } |
| 32 | |
| 33 | double Dbfs2Loudness(double dbfs) { |
| 34 | return Db2Loudness(90 + dbfs); |
| 35 | } |