blob: eb045c925d5872b164814711ba9a0f8681b3d5f8 [file] [log] [blame]
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +00001/*
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.org50a4d9f2013-05-29 13:19:09 +000011#ifndef WEBRTC_VOICE_ENGINE_DTMF_INBAND_H_
12#define WEBRTC_VOICE_ENGINE_DTMF_INBAND_H_
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +000013
pbos@webrtc.org471ae722013-05-21 13:52:32 +000014#include "webrtc/typedefs.h"
15#include "webrtc/voice_engine/voice_engine_defines.h"
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +000016
17namespace webrtc {
18class CriticalSectionWrapper;
19
20class DtmfInband
21{
22public:
pbos@webrtc.orgca7a9a22013-05-14 08:31:39 +000023 DtmfInband(int32_t id);
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +000024
25 virtual ~DtmfInband();
26
27 void Init();
28
pbos@webrtc.orgca7a9a22013-05-14 08:31:39 +000029 int SetSampleRate(uint16_t frequency);
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +000030
pbos@webrtc.org54f03bc2013-04-09 10:09:10 +000031 int GetSampleRate(uint16_t& frequency);
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +000032
pbos@webrtc.orgca7a9a22013-05-14 08:31:39 +000033 int AddTone(uint8_t eventCode,
pbos@webrtc.org54f03bc2013-04-09 10:09:10 +000034 int32_t lengthMs,
35 int32_t attenuationDb);
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +000036
37 int ResetTone();
pbos@webrtc.orgca7a9a22013-05-14 08:31:39 +000038 int StartTone(uint8_t eventCode, int32_t attenuationDb);
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +000039
40 int StopTone();
41
42 bool IsAddingTone();
43
pbos@webrtc.org54f03bc2013-04-09 10:09:10 +000044 int Get10msTone(int16_t output[320], uint16_t& outputSizeInSamples);
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +000045
pbos@webrtc.org54f03bc2013-04-09 10:09:10 +000046 uint32_t DelaySinceLastTone() const;
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +000047
48 void UpdateDelaySinceLastTone();
49
50private:
51 void ReInit();
pbos@webrtc.org54f03bc2013-04-09 10:09:10 +000052 int16_t DtmfFix_generate(int16_t* decoded,
pbos@webrtc.orgca7a9a22013-05-14 08:31:39 +000053 int16_t value,
54 int16_t volume,
55 int16_t frameLen,
56 int16_t fs);
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +000057
58private:
59 enum {kDtmfFrameSizeMs = 10};
60 enum {kDtmfAmpHigh = 32768};
61 enum {kDtmfAmpLow = 23171}; // 3 dB lower than the high frequency
62
pbos@webrtc.orgca7a9a22013-05-14 08:31:39 +000063 int16_t DtmfFix_generateSignal(int16_t a1_times2,
64 int16_t a2_times2,
65 int16_t volume,
pbos@webrtc.org54f03bc2013-04-09 10:09:10 +000066 int16_t* signal,
pbos@webrtc.orgca7a9a22013-05-14 08:31:39 +000067 int16_t length);
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +000068
69private:
70 CriticalSectionWrapper& _critSect;
pbos@webrtc.org54f03bc2013-04-09 10:09:10 +000071 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.orgb015cbe2012-10-22 18:19:23 +000080 bool _reinit; // 'true' if the oscillator should be reinit for next event
81 bool _playing;
pbos@webrtc.org54f03bc2013-04-09 10:09:10 +000082 uint32_t _delaySinceLastToneMS; // time since last generated tone [ms]
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +000083};
84
pbos@webrtc.org3b89e102013-07-03 15:12:26 +000085} // namespace webrtc
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +000086
pbos@webrtc.org50a4d9f2013-05-29 13:19:09 +000087#endif // #ifndef WEBRTC_VOICE_ENGINE_DTMF_INBAND_H_