From 06e722ae77004fdb9f20004ccc0cddc1e4af31dd Mon Sep 17 00:00:00 2001 From: "niklas.enbom@webrtc.org" Date: Wed, 4 Apr 2012 07:44:27 +0000 Subject: [PATCH] Adding parameter setting for typing detection Review URL: https://webrtc-codereview.appspot.com/476001 git-svn-id: http://webrtc.googlecode.com/svn/trunk@1984 4adac7df-926f-26a2-2b94-8c16560cd09d --- .../main/interface/voe_audio_processing.h | 8 +++++ .../main/source/transmit_mixer.cc | 31 ++++++++++++++++--- src/voice_engine/main/source/transmit_mixer.h | 11 +++++++ .../main/source/voe_audio_processing_impl.cc | 29 +++++++++++++++++ .../main/source/voe_audio_processing_impl.h | 5 +++ 5 files changed, 80 insertions(+), 4 deletions(-) diff --git a/src/voice_engine/main/interface/voe_audio_processing.h b/src/voice_engine/main/interface/voe_audio_processing.h index 0d21f622b5..4cedb77e32 100644 --- a/src/voice_engine/main/interface/voe_audio_processing.h +++ b/src/voice_engine/main/interface/voe_audio_processing.h @@ -193,6 +193,14 @@ public: // Returns error if typing detection is disabled. virtual int TimeSinceLastTyping(int &seconds) = 0; + // Optional setting of typing detection parameters + // Parameter with value == 0 will be ignored + // and left with default config. + virtual int SetTypingDetectionParameters(int timeWindow, + int costPerTyping, + int reportingThreshold, + int penaltyDecay) = 0; + protected: VoEAudioProcessing() {} virtual ~VoEAudioProcessing() {} diff --git a/src/voice_engine/main/source/transmit_mixer.cc b/src/voice_engine/main/source/transmit_mixer.cc index 9fc9f4fff4..ecceb8b47b 100644 --- a/src/voice_engine/main/source/transmit_mixer.cc +++ b/src/voice_engine/main/source/transmit_mixer.cc @@ -186,6 +186,10 @@ TransmitMixer::TransmitMixer(const WebRtc_UWord32 instanceId) : _timeSinceLastTyping(0), _penaltyCounter(0), _typingNoiseWarning(0), + _timeWindow(10), // 10ms slots accepted to count as a hit + _costPerTyping(100), // Penalty added for a typing + activity coincide + _reportingThreshold(300), // Threshold for _penaltyCounter + _penaltyDecay(1), // how much we reduce _penaltyCounter every 10 ms. #endif _saturationWarning(0), _noiseWarning(0), @@ -1396,10 +1400,10 @@ int TransmitMixer::TypingDetection() } if (keyPressed && (_audioFrame._vadActivity == AudioFrame::kVadActive) - && (_timeActive < 10)) + && (_timeActive < _timeWindow)) { - _penaltyCounter += 100; - if (_penaltyCounter > 300) + _penaltyCounter += _costPerTyping; + if (_penaltyCounter > _reportingThreshold) { if (_typingNoiseWarning == 1) { @@ -1418,7 +1422,7 @@ int TransmitMixer::TypingDetection() } if (_penaltyCounter > 0) - _penaltyCounter--; + _penaltyCounter-=_penaltyDecay; return (0); } @@ -1442,6 +1446,25 @@ int TransmitMixer::TimeSinceLastTyping(int &seconds) } #endif +#ifdef WEBRTC_VOICE_ENGINE_TYPING_DETECTION +int TransmitMixer::SetTypingDetectionParameters(int timeWindow, + int costPerTyping, + int reportingThreshold, + int penaltyDecay) +{ + if(timeWindow != 0) + _timeWindow = timeWindow; + if(costPerTyping != 0) + _costPerTyping = costPerTyping; + if(reportingThreshold != 0) + _reportingThreshold = reportingThreshold; + if(penaltyDecay != 0) + _penaltyDecay = penaltyDecay; + + return(0); +} +#endif + } // namespace voe } // namespace webrtc diff --git a/src/voice_engine/main/source/transmit_mixer.h b/src/voice_engine/main/source/transmit_mixer.h index 271686d4ca..77697c11d4 100644 --- a/src/voice_engine/main/source/transmit_mixer.h +++ b/src/voice_engine/main/source/transmit_mixer.h @@ -151,6 +151,10 @@ public: // FileCallback #ifdef WEBRTC_VOICE_ENGINE_TYPING_DETECTION public: // Typing detection int TimeSinceLastTyping(int &seconds); + int SetTypingDetectionParameters(int timeWindow, + int costPerTyping, + int reportingThreshold, + int penaltyDecay); #endif private: @@ -205,6 +209,13 @@ private: // owns WebRtc_Word32 _timeSinceLastTyping; WebRtc_Word32 _penaltyCounter; WebRtc_UWord32 _typingNoiseWarning; + + // Tunable treshold values + int _timeWindow; // nr of10ms slots accepted to count as a hit. + int _costPerTyping; // Penalty added for a typing + activity coincide. + int _reportingThreshold; // Threshold for _penaltyCounter. + int _penaltyDecay; // How much we reduce _penaltyCounter every 10 ms. + #endif WebRtc_UWord32 _saturationWarning; WebRtc_UWord32 _noiseWarning; diff --git a/src/voice_engine/main/source/voe_audio_processing_impl.cc b/src/voice_engine/main/source/voe_audio_processing_impl.cc index eddc23ecbc..1b19932adb 100644 --- a/src/voice_engine/main/source/voe_audio_processing_impl.cc +++ b/src/voice_engine/main/source/voe_audio_processing_impl.cc @@ -1065,6 +1065,35 @@ int VoEAudioProcessingImpl::TimeSinceLastTyping(int &seconds) { } +int VoEAudioProcessingImpl::SetTypingDetectionParameters(int timeWindow, + int costPerTyping, + int reportingThreshold, + int penaltyDecay) { + + WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_instanceId, -1), + "SetTypingDetectionParameters()"); + ANDROID_NOT_SUPPORTED(_engineStatistics); + IPHONE_NOT_SUPPORTED(); + +#ifdef WEBRTC_VOICE_ENGINE_TYPING_DETECTION + if (!_engineStatistics.Initialized()) { + _engineStatistics.SetLastError(VE_NOT_INITED, kTraceError); + return -1; + } + return (_transmitMixerPtr->SetTypingDetectionParameters(timeWindow, + costPerTyping, + reportingThreshold, + penaltyDecay)); + +#else + _engineStatistics.SetLastError(VE_FUNC_NOT_SUPPORTED, kTraceError, + "SetTypingDetectionParameters is not supported"); + return -1; +#endif + +} + + #endif // #ifdef WEBRTC_VOICE_ENGINE_AUDIO_PROCESSING_API diff --git a/src/voice_engine/main/source/voe_audio_processing_impl.h b/src/voice_engine/main/source/voe_audio_processing_impl.h index 9598da40bd..6140eec72d 100644 --- a/src/voice_engine/main/source/voe_audio_processing_impl.h +++ b/src/voice_engine/main/source/voe_audio_processing_impl.h @@ -91,6 +91,11 @@ class VoEAudioProcessingImpl virtual int TimeSinceLastTyping(int &seconds); + virtual int SetTypingDetectionParameters(int timeWindow, + int costPerTyping, + int reportingThreshold, + int penaltyDecay); + protected: VoEAudioProcessingImpl(); virtual ~VoEAudioProcessingImpl();