andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 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 | |
pbos@webrtc.org | 50a4d9f | 2013-05-29 13:19:09 +0000 | [diff] [blame] | 11 | #ifndef WEBRTC_VOICE_ENGINE_DTMF_INBAND_H_ |
| 12 | #define WEBRTC_VOICE_ENGINE_DTMF_INBAND_H_ |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 13 | |
pbos@webrtc.org | 471ae72 | 2013-05-21 13:52:32 +0000 | [diff] [blame] | 14 | #include "webrtc/typedefs.h" |
| 15 | #include "webrtc/voice_engine/voice_engine_defines.h" |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 16 | |
| 17 | namespace webrtc { |
| 18 | class CriticalSectionWrapper; |
| 19 | |
| 20 | class DtmfInband |
| 21 | { |
| 22 | public: |
pbos@webrtc.org | ca7a9a2 | 2013-05-14 08:31:39 +0000 | [diff] [blame] | 23 | DtmfInband(int32_t id); |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 24 | |
| 25 | virtual ~DtmfInband(); |
| 26 | |
| 27 | void Init(); |
| 28 | |
pbos@webrtc.org | ca7a9a2 | 2013-05-14 08:31:39 +0000 | [diff] [blame] | 29 | int SetSampleRate(uint16_t frequency); |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 30 | |
pbos@webrtc.org | 54f03bc | 2013-04-09 10:09:10 +0000 | [diff] [blame] | 31 | int GetSampleRate(uint16_t& frequency); |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 32 | |
pbos@webrtc.org | ca7a9a2 | 2013-05-14 08:31:39 +0000 | [diff] [blame] | 33 | int AddTone(uint8_t eventCode, |
pbos@webrtc.org | 54f03bc | 2013-04-09 10:09:10 +0000 | [diff] [blame] | 34 | int32_t lengthMs, |
| 35 | int32_t attenuationDb); |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 36 | |
| 37 | int ResetTone(); |
pbos@webrtc.org | ca7a9a2 | 2013-05-14 08:31:39 +0000 | [diff] [blame] | 38 | int StartTone(uint8_t eventCode, int32_t attenuationDb); |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 39 | |
| 40 | int StopTone(); |
| 41 | |
| 42 | bool IsAddingTone(); |
| 43 | |
pbos@webrtc.org | 54f03bc | 2013-04-09 10:09:10 +0000 | [diff] [blame] | 44 | int Get10msTone(int16_t output[320], uint16_t& outputSizeInSamples); |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 45 | |
pbos@webrtc.org | 54f03bc | 2013-04-09 10:09:10 +0000 | [diff] [blame] | 46 | uint32_t DelaySinceLastTone() const; |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 47 | |
| 48 | void UpdateDelaySinceLastTone(); |
| 49 | |
| 50 | private: |
| 51 | void ReInit(); |
pbos@webrtc.org | 54f03bc | 2013-04-09 10:09:10 +0000 | [diff] [blame] | 52 | int16_t DtmfFix_generate(int16_t* decoded, |
pbos@webrtc.org | ca7a9a2 | 2013-05-14 08:31:39 +0000 | [diff] [blame] | 53 | int16_t value, |
| 54 | int16_t volume, |
| 55 | int16_t frameLen, |
| 56 | int16_t fs); |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 57 | |
| 58 | private: |
| 59 | enum {kDtmfFrameSizeMs = 10}; |
| 60 | enum {kDtmfAmpHigh = 32768}; |
| 61 | enum {kDtmfAmpLow = 23171}; // 3 dB lower than the high frequency |
| 62 | |
pbos@webrtc.org | ca7a9a2 | 2013-05-14 08:31:39 +0000 | [diff] [blame] | 63 | int16_t DtmfFix_generateSignal(int16_t a1_times2, |
| 64 | int16_t a2_times2, |
| 65 | int16_t volume, |
pbos@webrtc.org | 54f03bc | 2013-04-09 10:09:10 +0000 | [diff] [blame] | 66 | int16_t* signal, |
pbos@webrtc.org | ca7a9a2 | 2013-05-14 08:31:39 +0000 | [diff] [blame] | 67 | int16_t length); |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 68 | |
| 69 | private: |
| 70 | CriticalSectionWrapper& _critSect; |
pbos@webrtc.org | 54f03bc | 2013-04-09 10:09:10 +0000 | [diff] [blame] | 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; |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 80 | bool _reinit; // 'true' if the oscillator should be reinit for next event |
| 81 | bool _playing; |
pbos@webrtc.org | 54f03bc | 2013-04-09 10:09:10 +0000 | [diff] [blame] | 82 | uint32_t _delaySinceLastToneMS; // time since last generated tone [ms] |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 83 | }; |
| 84 | |
pbos@webrtc.org | 3b89e10 | 2013-07-03 15:12:26 +0000 | [diff] [blame] | 85 | } // namespace webrtc |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 86 | |
pbos@webrtc.org | 50a4d9f | 2013-05-29 13:19:09 +0000 | [diff] [blame] | 87 | #endif // #ifndef WEBRTC_VOICE_ENGINE_DTMF_INBAND_H_ |