Bug 1291715 - Add support for 44100 and 48000 Hz sample rates to DtmfInband; r=jesup draft
authorDan Minor <dminor@mozilla.com>
Wed, 14 Sep 2016 16:07:46 -0400
changeset 421560 edbde6e8c8b6cfd1c44c808022849c688364745b
parent 421559 6b4153e6bddb939a89b58961abcec4b1741a68d3
child 421561 c9eb56f65858ee43f9defa63d11ad9a049b629a8
push id31551
push userdminor@mozilla.com
push dateThu, 06 Oct 2016 13:12:16 +0000
reviewersjesup
bugs1291715, 44100, 48000, 32000, 32768, 16383, 16000, 44800
milestone52.0a1
Bug 1291715 - Add support for 44100 and 48000 Hz sample rates to DtmfInband; r=jesup The DtmfInband class does not support sample rates above 32000. This adds support for 44100 and 48000. The 'a' coefficients were calculated in python as: int(round(32768*math.cos(2*math.pi*f/fs))) The 'ym2' coefficients were calculated in python as: int(round(16383*math.sin(2*math.pi*f/fs))) where f was in: [697, 770, 852, 941, 1209, 1336, 1477, 1633] and fs was in: [8000, 16000, 32000, 44100, 44800]. The calculated values were slightly off the existing values at 8000 Hz, but agreed at 16000 and 32000 Hz. MozReview-Commit-ID: GIzyUSyecR4
media/webrtc/trunk/webrtc/voice_engine/dtmf_inband.cc
media/webrtc/trunk/webrtc/voice_engine/output_mixer.cc
--- a/media/webrtc/trunk/webrtc/voice_engine/dtmf_inband.cc
+++ b/media/webrtc/trunk/webrtc/voice_engine/dtmf_inband.cc
@@ -29,16 +29,26 @@ const int16_t Dtmf_a_times2Tab16Khz[8]=
 	29144, 28361, 27409, 26258
 };
 
 const int16_t Dtmf_a_times2Tab32Khz[8]=
 {
 	32462,32394, 32311, 32210, 31849, 31647, 31400, 31098
 };
 
+const int16_t Dtmf_a_times2Tab44_1Khz[8]=
+{
+  32607, 32571, 32527, 32474, 32283, 32176, 32045, 31885
+};
+
+const int16_t Dtmf_a_times2Tab48Khz[8]=
+{
+  32612, 32577, 32534, 32483, 32298, 32194, 32067, 31912
+};
+
 // Second table is sin(2*pi*f/fs) in Q14
 
 const int16_t Dtmf_ym2Tab8Khz[8]=
 {
 	8527, 9315, 10163, 11036,
 	13322, 14206, 15021, 15708
 };
 
@@ -48,16 +58,26 @@ const int16_t Dtmf_ym2Tab16Khz[8]=
 	7490, 8207, 8979, 9801
 };
 
 const int16_t Dtmf_ym2Tab32Khz[8]=
 {
 	2235, 2468, 2728, 3010, 3853, 4249, 4685, 5164
 };
 
+const int16_t Dtmf_ym2Tab44_1Khz[8]=
+{
+  1624, 1794, 1984, 2190, 2808, 3100, 3422, 3777
+};
+
+const int16_t Dtmf_ym2Tab48Khz[8]=
+{
+  1599, 1766, 1953, 2156, 2765, 3052, 3369, 3719
+};
+
 const int16_t Dtmf_dBm0kHz[37]=
 {
        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,
@@ -87,17 +107,19 @@ DtmfInband::~DtmfInband()
 	delete &_critSect;
 }
 
 int
 DtmfInband::SetSampleRate(uint16_t frequency)
 {
     if (frequency != 8000 &&
             frequency != 16000 &&
-            frequency != 32000)
+            frequency != 32000 &&
+            frequency != 44100 &&
+            frequency != 48000)
     {
         // invalid sample rate
         assert(false);
         return -1;
     }
     _outputFrequencyHz = frequency;
     return 0;
 }
@@ -277,16 +299,22 @@ DtmfInband::DtmfFix_generate(int16_t *de
         a_times2Tbl=Dtmf_a_times2Tab8Khz;
         y2_Table=Dtmf_ym2Tab8Khz;
     } else if (fs==16000) {
         a_times2Tbl=Dtmf_a_times2Tab16Khz;
         y2_Table=Dtmf_ym2Tab16Khz;
     } else if (fs==32000) {
         a_times2Tbl=Dtmf_a_times2Tab32Khz;
         y2_Table=Dtmf_ym2Tab32Khz;
+    } else if (fs==44100) {
+        a_times2Tbl=Dtmf_a_times2Tab44_1Khz;
+        y2_Table=Dtmf_ym2Tab44_1Khz;
+    } else if (fs==48000) {
+        a_times2Tbl=Dtmf_a_times2Tab48Khz;
+        y2_Table=Dtmf_ym2Tab48Khz;
     } else {
         return(-1);
     }
 
     if ((value==1)||(value==2)||(value==3)||(value==12)) {
         a1_times2=a_times2Tbl[0];
         if (_reinit) {
             _oldOutputLow[0]=y2_Table[0];
--- a/media/webrtc/trunk/webrtc/voice_engine/output_mixer.cc
+++ b/media/webrtc/trunk/webrtc/voice_engine/output_mixer.cc
@@ -594,16 +594,32 @@ void OutputMixer::APMAnalyzeReverseStrea
 //                             Private methods
 // ----------------------------------------------------------------------------
 
 int
 OutputMixer::InsertInbandDtmfTone()
 {
     uint16_t sampleRate(0);
     _dtmfGenerator.GetSampleRate(sampleRate);
+
+    // We're not using a supported sample rate for the DtmfInband generator, so
+    // we won't be able to generate feedback tones.
+    if (!(_audioFrame.sample_rate_hz_ == 8000 ||
+          _audioFrame.sample_rate_hz_ == 16000 ||
+          _audioFrame.sample_rate_hz_ == 32000 ||
+          _audioFrame.sample_rate_hz_ == 44100 ||
+          _audioFrame.sample_rate_hz_ == 48000)) {
+
+        WEBRTC_TRACE(kTraceError, kTraceVoice, VoEId(_instanceId, -1),
+                     "OutputMixer::InsertInbandDtmfTone() Sample rate"
+                     "not supported");
+
+        return -1;
+    }
+
     if (sampleRate != _audioFrame.sample_rate_hz_)
     {
         // Update sample rate of Dtmf tone since the mixing frequency changed.
         _dtmfGenerator.SetSampleRate(
             (uint16_t)(_audioFrame.sample_rate_hz_));
         // Reset the tone to be added taking the new sample rate into account.
         _dtmfGenerator.ResetTone();
     }