Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(50)

Unified Diff: webrtc/modules/audio_coding/neteq/dtmf_tone_generator.cc

Issue 2404183003: Fix bug in DTMF generation where events with level > 36 would be ignored. (Closed)
Patch Set: reviewer comments Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: webrtc/modules/audio_coding/neteq/dtmf_tone_generator.cc
diff --git a/webrtc/modules/audio_coding/neteq/dtmf_tone_generator.cc b/webrtc/modules/audio_coding/neteq/dtmf_tone_generator.cc
index f4d5190c615ab2c0ecd3eddd007b6c1301522ce8..8b4b9d3f4f661d8422ebba9e706fc9de1fe93c77 100644
--- a/webrtc/modules/audio_coding/neteq/dtmf_tone_generator.cc
+++ b/webrtc/modules/audio_coding/neteq/dtmf_tone_generator.cc
@@ -30,7 +30,8 @@
#include "webrtc/modules/audio_coding/neteq/dtmf_tone_generator.h"
-#include <assert.h>
+#include "webrtc/base/arraysize.h"
+#include "webrtc/base/checks.h"
namespace webrtc {
@@ -86,12 +87,16 @@ const int DtmfToneGenerator::kInitValue2[4][16] = {
{ 2851, 2582, 2851, 3148, 2582, 2851, 3148, 2582, 2851, 3148, 2582, 3148,
3476, 3476, 3476, 3476} };
-// Amplitude multipliers for volume values 0 through 36, corresponding to
-// 0 dBm0 through -36 dBm0. Values are in Q14.
-const int DtmfToneGenerator::kAmplitude[37] = {
+// Amplitude multipliers for volume values 0 through 63, corresponding to
+// 0 dBm0 through -63 dBm0. Values are in Q14.
+// for a in range(0, 64):
+// print round(16141.0 * 10**(-float(a)/20))
+const int DtmfToneGenerator::kAmplitude[64] = {
16141, 14386, 12821, 11427, 10184, 9077, 8090, 7210, 6426, 5727, 5104, 4549,
4054, 3614, 3221, 2870, 2558, 2280, 2032, 1811, 1614, 1439, 1282, 1143,
- 1018, 908, 809, 721, 643, 573, 510, 455, 405, 361, 322, 287, 256 };
+ 1018, 908, 809, 721, 643, 573, 510, 455, 405, 361, 322, 287, 256, 228, 203,
+ 181, 161, 144, 128, 114, 102, 91, 81, 72, 64, 57, 51, 45, 41, 36, 32, 29,
+ 26, 23, 20, 18, 16, 14, 13, 11 };
// Constructor.
DtmfToneGenerator::DtmfToneGenerator()
@@ -106,7 +111,7 @@ DtmfToneGenerator::DtmfToneGenerator()
// Returns 0 on success, otherwise an error code.
int DtmfToneGenerator::Init(int fs, int event, int attenuation) {
initialized_ = false;
- int fs_index;
+ size_t fs_index;
if (fs == 8000) {
fs_index = 0;
} else if (fs == 16000) {
@@ -116,7 +121,7 @@ int DtmfToneGenerator::Init(int fs, int event, int attenuation) {
} else if (fs == 48000) {
fs_index = 3;
} else {
- assert(false);
+ RTC_NOTREACHED();
fs_index = 1; // Default to 8000 Hz.
}
@@ -124,16 +129,32 @@ int DtmfToneGenerator::Init(int fs, int event, int attenuation) {
return kParameterError; // Invalid event number.
}
- if (attenuation < 0 || attenuation > 36) {
+ if (attenuation < 0 || attenuation > 63) {
return kParameterError; // Invalid attenuation.
}
// Look up oscillator coefficient for low and high frequencies.
+ RTC_DCHECK_LE(0u, fs_index);
+ RTC_DCHECK_GT(arraysize(kCoeff1), fs_index);
+ RTC_DCHECK_GT(arraysize(kCoeff2), fs_index);
+ RTC_DCHECK_LE(0, event);
+ RTC_DCHECK_GT(arraysize(kCoeff1[fs_index]), static_cast<size_t>(event));
+ RTC_DCHECK_GT(arraysize(kCoeff2[fs_index]), static_cast<size_t>(event));
coeff1_ = kCoeff1[fs_index][event];
coeff2_ = kCoeff2[fs_index][event];
+
// Look up amplitude multiplier.
+ RTC_DCHECK_LE(0, attenuation);
+ RTC_DCHECK_GT(arraysize(kAmplitude), static_cast<size_t>(attenuation));
amplitude_ = kAmplitude[attenuation];
+
// Initialize sample history.
+ RTC_DCHECK_LE(0u, fs_index);
+ RTC_DCHECK_GT(arraysize(kInitValue1), fs_index);
+ RTC_DCHECK_GT(arraysize(kInitValue2), fs_index);
+ RTC_DCHECK_LE(0, event);
+ RTC_DCHECK_GT(arraysize(kInitValue1[fs_index]), static_cast<size_t>(event));
+ RTC_DCHECK_GT(arraysize(kInitValue2[fs_index]), static_cast<size_t>(event));
sample_history1_[0] = kInitValue1[fs_index][event];
sample_history1_[1] = 0;
sample_history2_[0] = kInitValue2[fs_index][event];

Powered by Google App Engine
This is Rietveld 408576698