1 /* 2 * Copyright (c) 2011 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 #ifndef WEBRTC_VOICE_ENGINE_DTMF_INBAND_H_ 12 #define WEBRTC_VOICE_ENGINE_DTMF_INBAND_H_ 13 14 #include "webrtc/typedefs.h" 15 #include "webrtc/voice_engine/voice_engine_defines.h" 16 17 #define MAX_DTMF_SAMPLERATE 48000 18 19 namespace webrtc { 20 class CriticalSectionWrapper; 21 22 class DtmfInband 23 { 24 public: 25 DtmfInband(int32_t id); 26 27 virtual ~DtmfInband(); 28 29 void Init(); 30 31 int SetSampleRate(uint16_t frequency); 32 33 int GetSampleRate(uint16_t& frequency); 34 35 int AddTone(uint8_t eventCode, 36 int32_t lengthMs, 37 int32_t attenuationDb); 38 39 int ResetTone(); 40 int StartTone(uint8_t eventCode, int32_t attenuationDb); 41 42 int StopTone(); 43 44 bool IsAddingTone(); 45 46 int Get10msTone(int16_t output[MAX_DTMF_SAMPLERATE/100], uint16_t& outputSizeInSamples); 47 48 uint32_t DelaySinceLastTone() const; 49 50 void UpdateDelaySinceLastTone(); 51 52 private: 53 void ReInit(); 54 int16_t DtmfFix_generate(int16_t* decoded, 55 int16_t value, 56 int16_t volume, 57 int16_t frameLen, 58 uint16_t fs); 59 60 private: 61 enum {kDtmfFrameSizeMs = 10}; 62 enum {kDtmfAmpHigh = 32768}; 63 enum {kDtmfAmpLow = 23171}; // 3 dB lower than the high frequency 64 65 int16_t DtmfFix_generateSignal(int16_t a1_times2, 66 int16_t a2_times2, 67 int16_t volume, 68 int16_t* signal, 69 int16_t length); 70 71 private: 72 CriticalSectionWrapper& _critSect; 73 int32_t _id; 74 uint16_t _outputFrequencyHz; // {8000, 16000, 32000, 44100, 48000} 75 int16_t _oldOutputLow[2]; // Data needed for oscillator model 76 int16_t _oldOutputHigh[2]; // Data needed for oscillator model 77 int16_t _frameLengthSamples; // {80, 160, 320, 441, 480} 78 int32_t _remainingSamples; 79 int16_t _eventCode; // [0, 15] 80 int16_t _attenuationDb; // [0, 36] 81 int32_t _lengthMs; 82 bool _reinit; // 'true' if the oscillator should be reinit for next event 83 bool _playing; 84 uint32_t _delaySinceLastToneMS; // time since last generated tone [ms] 85 }; 86 87 } // namespace webrtc 88 89 #endif // #ifndef WEBRTC_VOICE_ENGINE_DTMF_INBAND_H_ 90