From e50872be1389b5e5e9967ee530a355d6ff5ea293 Mon Sep 17 00:00:00 2001 From: solenberg Date: Mon, 14 Mar 2016 15:32:50 -0700 Subject: [PATCH] Remove unused method OutputMixer::PlayDtmfTone() and infrastructure. BUG=webrtc:4690 Review URL: https://codereview.webrtc.org/1796183002 Cr-Commit-Position: refs/heads/master@{#11990} --- webrtc/voice_engine/BUILD.gn | 2 - webrtc/voice_engine/dtmf_inband.cc | 389 ----------------------- webrtc/voice_engine/dtmf_inband.h | 90 ------ webrtc/voice_engine/include/voe_errors.h | 2 +- webrtc/voice_engine/output_mixer.cc | 73 ----- webrtc/voice_engine/output_mixer.h | 6 - webrtc/voice_engine/voice_engine.gyp | 2 - 7 files changed, 1 insertion(+), 563 deletions(-) delete mode 100644 webrtc/voice_engine/dtmf_inband.cc delete mode 100644 webrtc/voice_engine/dtmf_inband.h diff --git a/webrtc/voice_engine/BUILD.gn b/webrtc/voice_engine/BUILD.gn index 899b7333b2..31b1d5b430 100644 --- a/webrtc/voice_engine/BUILD.gn +++ b/webrtc/voice_engine/BUILD.gn @@ -16,8 +16,6 @@ source_set("voice_engine") { "channel_manager.h", "channel_proxy.cc", "channel_proxy.h", - "dtmf_inband.cc", - "dtmf_inband.h", "include/voe_audio_processing.h", "include/voe_base.h", "include/voe_codec.h", diff --git a/webrtc/voice_engine/dtmf_inband.cc b/webrtc/voice_engine/dtmf_inband.cc deleted file mode 100644 index a6d0905711..0000000000 --- a/webrtc/voice_engine/dtmf_inband.cc +++ /dev/null @@ -1,389 +0,0 @@ -/* - * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. - * - * Use of this source code is governed by a BSD-style license - * that can be found in the LICENSE file in the root of the source - * tree. An additional intellectual property rights grant can be found - * in the file PATENTS. All contributing project authors may - * be found in the AUTHORS file in the root of the source tree. - */ - -#include "webrtc/voice_engine/dtmf_inband.h" - -#include - -#include "webrtc/system_wrappers/include/trace.h" - -namespace webrtc { - -const int16_t Dtmf_a_times2Tab8Khz[8]= -{ - 27978, 26956, 25701, 24219, - 19073, 16325, 13085, 9314 -}; - -const int16_t Dtmf_a_times2Tab16Khz[8]= -{ - 31548, 31281, 30951, 30556, - 29144, 28361, 27409, 26258 -}; - -const int16_t Dtmf_a_times2Tab32Khz[8]= -{ - 32462,32394, 32311, 32210, 31849, 31647, 31400, 31098 -}; - -// Second table is sin(2*pi*f/fs) in Q14 - -const int16_t Dtmf_ym2Tab8Khz[8]= -{ - 8527, 9315, 10163, 11036, - 13322, 14206, 15021, 15708 -}; - -const int16_t Dtmf_ym2Tab16Khz[8]= -{ - 4429, 4879, 5380, 5918, - 7490, 8207, 8979, 9801 -}; - -const int16_t Dtmf_ym2Tab32Khz[8]= -{ - 2235, 2468, 2728, 3010, 3853, 4249, 4685, 5164 -}; - -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, - 256 -}; - - -DtmfInband::DtmfInband(int32_t id) : - _id(id), - _outputFrequencyHz(8000), - _frameLengthSamples(0), - _remainingSamples(0), - _eventCode(0), - _attenuationDb(0), - _lengthMs(0), - _reinit(true), - _playing(false), - _delaySinceLastToneMS(1000) -{ - memset(_oldOutputLow, 0, sizeof(_oldOutputLow)); - memset(_oldOutputHigh, 0, sizeof(_oldOutputHigh)); -} - -DtmfInband::~DtmfInband() -{ -} - -int -DtmfInband::SetSampleRate(uint16_t frequency) -{ - if (frequency != 8000 && - frequency != 16000 && - frequency != 32000) - { - // invalid sample rate - assert(false); - return -1; - } - _outputFrequencyHz = frequency; - return 0; -} - -int -DtmfInband::GetSampleRate(uint16_t& frequency) -{ - frequency = _outputFrequencyHz; - return 0; -} - -void -DtmfInband::Init() -{ - _remainingSamples = 0; - _frameLengthSamples = 0; - _eventCode = 0; - _attenuationDb = 0; - _lengthMs = 0; - _reinit = true; - _oldOutputLow[0] = 0; - _oldOutputLow[1] = 0; - _oldOutputHigh[0] = 0; - _oldOutputHigh[1] = 0; - _delaySinceLastToneMS = 1000; -} - -int -DtmfInband::AddTone(uint8_t eventCode, - int32_t lengthMs, - int32_t attenuationDb) -{ - rtc::CritScope lock(&_critSect); - - if (attenuationDb > 36 || eventCode > 15) - { - assert(false); - return -1; - } - - if (IsAddingTone()) - { - WEBRTC_TRACE(kTraceWarning, kTraceVoice, VoEId(_id,-1), - "DtmfInband::AddTone() new tone interrupts ongoing tone"); - } - - ReInit(); - - _frameLengthSamples = static_cast (_outputFrequencyHz / 100); - _eventCode = static_cast (eventCode); - _attenuationDb = static_cast (attenuationDb); - _remainingSamples = static_cast - (lengthMs * (_outputFrequencyHz / 1000)); - _lengthMs = lengthMs; - - return 0; -} - -int -DtmfInband::ResetTone() -{ - rtc::CritScope lock(&_critSect); - - ReInit(); - - _frameLengthSamples = static_cast (_outputFrequencyHz / 100); - _remainingSamples = static_cast - (_lengthMs * (_outputFrequencyHz / 1000)); - - return 0; -} - -int -DtmfInband::StartTone(uint8_t eventCode, - int32_t attenuationDb) -{ - rtc::CritScope lock(&_critSect); - - if (attenuationDb > 36 || eventCode > 15) - { - assert(false); - return -1; - } - - if (IsAddingTone()) - { - return -1; - } - - ReInit(); - - _frameLengthSamples = static_cast (_outputFrequencyHz / 100); - _eventCode = static_cast (eventCode); - _attenuationDb = static_cast (attenuationDb); - _playing = true; - - return 0; -} - -int -DtmfInband::StopTone() -{ - rtc::CritScope lock(&_critSect); - - if (!_playing) - { - return 0; - } - - _playing = false; - - return 0; -} - -// Shall be called between tones -void -DtmfInband::ReInit() -{ - _reinit = true; -} - -bool -DtmfInband::IsAddingTone() -{ - rtc::CritScope lock(&_critSect); - return (_remainingSamples > 0 || _playing); -} - -int -DtmfInband::Get10msTone(int16_t output[320], - uint16_t& outputSizeInSamples) -{ - rtc::CritScope lock(&_critSect); - if (DtmfFix_generate(output, - _eventCode, - _attenuationDb, - _frameLengthSamples, - _outputFrequencyHz) == -1) - { - return -1; - } - _remainingSamples -= _frameLengthSamples; - outputSizeInSamples = _frameLengthSamples; - _delaySinceLastToneMS = 0; - return 0; -} - -void -DtmfInband::UpdateDelaySinceLastTone() -{ - rtc::CritScope lock(&_critSect); - _delaySinceLastToneMS += kDtmfFrameSizeMs; - // avoid wraparound - if (_delaySinceLastToneMS > (1<<30)) - { - _delaySinceLastToneMS = 1000; - } -} - -uint32_t -DtmfInband::DelaySinceLastTone() const -{ - rtc::CritScope lock(&_critSect); - return _delaySinceLastToneMS; -} - -int16_t -DtmfInband::DtmfFix_generate(int16_t *decoded, - int16_t value, - int16_t volume, - int16_t frameLen, - int16_t fs) -{ - const int16_t *a_times2Tbl; - const int16_t *y2_Table; - int16_t a1_times2 = 0, a2_times2 = 0; - - if (fs==8000) { - 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 { - return(-1); - } - - if ((value==1)||(value==2)||(value==3)||(value==12)) { - a1_times2=a_times2Tbl[0]; - if (_reinit) { - _oldOutputLow[0]=y2_Table[0]; - _oldOutputLow[1]=0; - } - } else if ((value==4)||(value==5)||(value==6)||(value==13)) { - a1_times2=a_times2Tbl[1]; - if (_reinit) { - _oldOutputLow[0]=y2_Table[1]; - _oldOutputLow[1]=0; - } - } else if ((value==7)||(value==8)||(value==9)||(value==14)) { - a1_times2=a_times2Tbl[2]; - if (_reinit) { - _oldOutputLow[0]=y2_Table[2]; - _oldOutputLow[1]=0; - } - } else if ((value==10)||(value==0)||(value==11)||(value==15)) { - a1_times2=a_times2Tbl[3]; - if (_reinit) { - _oldOutputLow[0]=y2_Table[3]; - _oldOutputLow[1]=0; - } - } - if ((value==1)||(value==4)||(value==7)||(value==10)) { - a2_times2=a_times2Tbl[4]; - if (_reinit) { - _oldOutputHigh[0]=y2_Table[4]; - _oldOutputHigh[1]=0; - _reinit=false; - } - } else if ((value==2)||(value==5)||(value==8)||(value==0)) { - a2_times2=a_times2Tbl[5]; - if (_reinit) { - _oldOutputHigh[0]=y2_Table[5]; - _oldOutputHigh[1]=0; - _reinit=false; - } - } else if ((value==3)||(value==6)||(value==9)||(value==11)) { - a2_times2=a_times2Tbl[6]; - if (_reinit) { - _oldOutputHigh[0]=y2_Table[6]; - _oldOutputHigh[1]=0; - _reinit=false; - } - } else if ((value==12)||(value==13)||(value==14)||(value==15)) { - a2_times2=a_times2Tbl[7]; - if (_reinit) { - _oldOutputHigh[0]=y2_Table[7]; - _oldOutputHigh[1]=0; - _reinit=false; - } - } - - return (DtmfFix_generateSignal(a1_times2, - a2_times2, - volume, - decoded, - frameLen)); -} - -int16_t -DtmfInband::DtmfFix_generateSignal(int16_t a1_times2, - int16_t a2_times2, - int16_t volume, - int16_t *signal, - int16_t length) -{ - int i; - - /* Generate Signal */ - for (i=0;i> 14) - _oldOutputLow[0]); - tempValHigh = (int16_t)(((( (int32_t)(a2_times2 * - _oldOutputHigh[1])) + 8192) >> 14) - _oldOutputHigh[0]); - - /* Update memory */ - _oldOutputLow[0]=_oldOutputLow[1]; - _oldOutputLow[1]=tempValLow; - _oldOutputHigh[0]=_oldOutputHigh[1]; - _oldOutputHigh[1]=tempValHigh; - - tempVal = (int32_t)(kDtmfAmpLow * tempValLow) + - (int32_t)(kDtmfAmpHigh * tempValHigh); - - /* Norm the signal to Q14 */ - tempVal=(tempVal+16384)>>15; - - /* Scale the signal to correct dbM0 value */ - signal[i]=(int16_t)((tempVal*Dtmf_dBm0kHz[volume]+8192)>>14); - } - - return(0); -} - -} // namespace webrtc diff --git a/webrtc/voice_engine/dtmf_inband.h b/webrtc/voice_engine/dtmf_inband.h deleted file mode 100644 index 795c5ce8fc..0000000000 --- a/webrtc/voice_engine/dtmf_inband.h +++ /dev/null @@ -1,90 +0,0 @@ -/* - * Copyright (c) 2011 The WebRTC project authors. All Rights Reserved. - * - * Use of this source code is governed by a BSD-style license - * that can be found in the LICENSE file in the root of the source - * tree. An additional intellectual property rights grant can be found - * in the file PATENTS. All contributing project authors may - * be found in the AUTHORS file in the root of the source tree. - */ - -#ifndef WEBRTC_VOICE_ENGINE_DTMF_INBAND_H_ -#define WEBRTC_VOICE_ENGINE_DTMF_INBAND_H_ - -#include "webrtc/typedefs.h" -#include "webrtc/voice_engine/voice_engine_defines.h" -#include "webrtc/base/criticalsection.h" - -namespace webrtc { - -// TODO(solenberg): Used as a DTMF tone generator in voe::OutputMixer. Pull out -// the one in NetEq and use that instead? We don't need several -// implemenations of this. -class DtmfInband -{ -public: - DtmfInband(int32_t id); - - virtual ~DtmfInband(); - - void Init(); - - int SetSampleRate(uint16_t frequency); - - int GetSampleRate(uint16_t& frequency); - - int AddTone(uint8_t eventCode, - int32_t lengthMs, - int32_t attenuationDb); - - int ResetTone(); - int StartTone(uint8_t eventCode, int32_t attenuationDb); - - int StopTone(); - - bool IsAddingTone(); - - int Get10msTone(int16_t output[320], uint16_t& outputSizeInSamples); - - uint32_t DelaySinceLastTone() const; - - void UpdateDelaySinceLastTone(); - -private: - void ReInit(); - int16_t DtmfFix_generate(int16_t* decoded, - int16_t value, - int16_t volume, - int16_t frameLen, - int16_t fs); - -private: - enum {kDtmfFrameSizeMs = 10}; - enum {kDtmfAmpHigh = 32768}; - enum {kDtmfAmpLow = 23171}; // 3 dB lower than the high frequency - - int16_t DtmfFix_generateSignal(int16_t a1_times2, - int16_t a2_times2, - int16_t volume, - int16_t* signal, - int16_t length); - -private: - rtc::CriticalSection _critSect; - int32_t _id; - uint16_t _outputFrequencyHz; // {8000, 16000, 32000} - int16_t _oldOutputLow[2]; // Data needed for oscillator model - int16_t _oldOutputHigh[2]; // Data needed for oscillator model - int16_t _frameLengthSamples; // {80, 160, 320} - int32_t _remainingSamples; - int16_t _eventCode; // [0, 15] - int16_t _attenuationDb; // [0, 36] - int32_t _lengthMs; - bool _reinit; // 'true' if the oscillator should be reinit for next event - bool _playing; - uint32_t _delaySinceLastToneMS; // time since last generated tone [ms] -}; - -} // namespace webrtc - -#endif // #ifndef WEBRTC_VOICE_ENGINE_DTMF_INBAND_H_ diff --git a/webrtc/voice_engine/include/voe_errors.h b/webrtc/voice_engine/include/voe_errors.h index 572fc922ed..04f02be934 100644 --- a/webrtc/voice_engine/include/voe_errors.h +++ b/webrtc/voice_engine/include/voe_errors.h @@ -47,7 +47,7 @@ #define VE_NO_GQOS 8033 #define VE_INVALID_TIMESTAMP 8034 #define VE_RECEIVE_PACKET_TIMEOUT 8035 -#define VE_STILL_PLAYING_PREV_DTMF 8036 +// 8036 is not used #define VE_INIT_FAILED_WRONG_EXPIRY 8037 #define VE_SENDING 8038 #define VE_ENABLE_IPV6_FAILED 8039 diff --git a/webrtc/voice_engine/output_mixer.cc b/webrtc/voice_engine/output_mixer.cc index 1c9525a1ab..9316229b07 100644 --- a/webrtc/voice_engine/output_mixer.cc +++ b/webrtc/voice_engine/output_mixer.cc @@ -93,7 +93,6 @@ OutputMixer::Create(OutputMixer*& mixer, uint32_t instanceId) OutputMixer::OutputMixer(uint32_t instanceId) : _mixerModule(*AudioConferenceMixer::Create(instanceId)), _audioLevel(), - _dtmfGenerator(instanceId), _instanceId(instanceId), _externalMediaCallbackPtr(NULL), _externalMedia(false), @@ -112,8 +111,6 @@ OutputMixer::OutputMixer(uint32_t instanceId) : "OutputMixer::OutputMixer() failed to register mixer" "callbacks"); } - - _dtmfGenerator.Init(); } void @@ -192,21 +189,6 @@ int OutputMixer::DeRegisterExternalMediaProcessing() return 0; } -int OutputMixer::PlayDtmfTone(uint8_t eventCode, int lengthMs, - int attenuationDb) -{ - WEBRTC_TRACE(kTraceInfo, kTraceVoice, VoEId(_instanceId, -1), - "OutputMixer::PlayDtmfTone()"); - if (_dtmfGenerator.AddTone(eventCode, lengthMs, attenuationDb) != 0) - { - _engineStatisticsPtr->SetLastError(VE_STILL_PLAYING_PREV_DTMF, - kTraceError, - "OutputMixer::PlayDtmfTone()"); - return -1; - } - return 0; -} - int32_t OutputMixer::SetMixabilityStatus(MixerParticipant& participant, bool mixable) @@ -492,12 +474,6 @@ OutputMixer::DoOperationsOnCombinedSignal(bool feed_data_to_apm) _mixingFrequencyHz = _audioFrame.sample_rate_hz_; } - // --- Insert inband Dtmf tone - if (_dtmfGenerator.IsAddingTone()) - { - InsertInbandDtmfTone(); - } - // Scale left and/or right channel(s) if balance is active if (_panLeft != 1.0 || _panRight != 1.0) { @@ -554,54 +530,5 @@ OutputMixer::DoOperationsOnCombinedSignal(bool feed_data_to_apm) return 0; } - -// ---------------------------------------------------------------------------- -// Private methods -// ---------------------------------------------------------------------------- - -int -OutputMixer::InsertInbandDtmfTone() -{ - uint16_t sampleRate(0); - _dtmfGenerator.GetSampleRate(sampleRate); - 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(); - } - - int16_t toneBuffer[320]; - uint16_t toneSamples(0); - if (_dtmfGenerator.Get10msTone(toneBuffer, toneSamples) == -1) - { - WEBRTC_TRACE(kTraceWarning, kTraceVoice, VoEId(_instanceId, -1), - "OutputMixer::InsertInbandDtmfTone() inserting Dtmf" - "tone failed"); - return -1; - } - - // replace mixed audio with Dtmf tone - if (_audioFrame.num_channels_ == 1) - { - // mono - memcpy(_audioFrame.data_, toneBuffer, sizeof(int16_t) - * toneSamples); - } else - { - // stereo - for (size_t i = 0; i < _audioFrame.samples_per_channel_; i++) - { - _audioFrame.data_[2 * i] = toneBuffer[i]; - _audioFrame.data_[2 * i + 1] = 0; - } - } - assert(_audioFrame.samples_per_channel_ == toneSamples); - - return 0; -} - } // namespace voe } // namespace webrtc diff --git a/webrtc/voice_engine/output_mixer.h b/webrtc/voice_engine/output_mixer.h index 3287860f7f..ae2f53fdb9 100644 --- a/webrtc/voice_engine/output_mixer.h +++ b/webrtc/voice_engine/output_mixer.h @@ -17,7 +17,6 @@ #include "webrtc/modules/audio_conference_mixer/include/audio_conference_mixer.h" #include "webrtc/modules/audio_conference_mixer/include/audio_conference_mixer_defines.h" #include "webrtc/modules/utility/include/file_recorder.h" -#include "webrtc/voice_engine/dtmf_inband.h" #include "webrtc/voice_engine/level_indicator.h" #include "webrtc/voice_engine/voice_engine_defines.h" @@ -50,9 +49,6 @@ public: int DeRegisterExternalMediaProcessing(); - // VoEDtmf - int PlayDtmfTone(uint8_t eventCode, int lengthMs, int attenuationDb); - int32_t MixActiveChannels(); int32_t DoOperationsOnCombinedSignal(bool feed_data_to_apm); @@ -102,7 +98,6 @@ public: private: OutputMixer(uint32_t instanceId); - int InsertInbandDtmfTone(); // uses Statistics* _engineStatisticsPtr; @@ -118,7 +113,6 @@ private: // Converts mixed audio to the audio processing rate. PushResampler audioproc_resampler_; AudioLevel _audioLevel; // measures audio level for the combined signal - DtmfInband _dtmfGenerator; int _instanceId; VoEMediaProcess* _externalMediaCallbackPtr; bool _externalMedia; diff --git a/webrtc/voice_engine/voice_engine.gyp b/webrtc/voice_engine/voice_engine.gyp index a848d6c668..b93c903d71 100644 --- a/webrtc/voice_engine/voice_engine.gyp +++ b/webrtc/voice_engine/voice_engine.gyp @@ -52,8 +52,6 @@ 'channel_manager.h', 'channel_proxy.cc', 'channel_proxy.h', - 'dtmf_inband.cc', - 'dtmf_inband.h', 'level_indicator.cc', 'level_indicator.h', 'monitor_module.cc',