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