summaryrefslogtreecommitdiff
path: root/voice_engine/dtmf_inband.h
blob: eb045c925d5872b164814711ba9a0f8681b3d5f8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
/*
 *  Copyright (c) 2011 The WebRTC project authors. All Rights Reserved.
 *
 *  Use of this source code is governed by a BSD-style license
 *  that can be found in the LICENSE file in the root of the source
 *  tree. An additional intellectual property rights grant can be found
 *  in the file PATENTS.  All contributing project authors may
 *  be found in the AUTHORS file in the root of the source tree.
 */

#ifndef WEBRTC_VOICE_ENGINE_DTMF_INBAND_H_
#define WEBRTC_VOICE_ENGINE_DTMF_INBAND_H_

#include "webrtc/typedefs.h"
#include "webrtc/voice_engine/voice_engine_defines.h"

namespace webrtc {
class CriticalSectionWrapper;

class DtmfInband
{
public:
    DtmfInband(int32_t id);

    virtual ~DtmfInband();

    void Init();

    int SetSampleRate(uint16_t frequency);

    int GetSampleRate(uint16_t& frequency);

    int AddTone(uint8_t eventCode,
                int32_t lengthMs,
                int32_t attenuationDb);

    int ResetTone();
    int StartTone(uint8_t eventCode, int32_t attenuationDb);

    int StopTone();

    bool IsAddingTone();

    int Get10msTone(int16_t output[320], uint16_t& outputSizeInSamples);

    uint32_t DelaySinceLastTone() const;

    void UpdateDelaySinceLastTone();

private:
    void ReInit();
    int16_t DtmfFix_generate(int16_t* decoded,
                             int16_t value,
                             int16_t volume,
                             int16_t frameLen,
                             int16_t fs);

private:
    enum {kDtmfFrameSizeMs = 10};
    enum {kDtmfAmpHigh = 32768};
    enum {kDtmfAmpLow  = 23171};	// 3 dB lower than the high frequency

    int16_t DtmfFix_generateSignal(int16_t a1_times2,
                                   int16_t a2_times2,
                                   int16_t volume,
                                   int16_t* signal,
                                   int16_t length);

private:
    CriticalSectionWrapper& _critSect;
    int32_t _id;
    uint16_t _outputFrequencyHz;  // {8000, 16000, 32000}
    int16_t _oldOutputLow[2];     // Data needed for oscillator model
    int16_t _oldOutputHigh[2];    // Data needed for oscillator model
    int16_t _frameLengthSamples;  // {80, 160, 320}
    int32_t _remainingSamples;
    int16_t _eventCode;           // [0, 15]
    int16_t _attenuationDb;       // [0, 36]
    int32_t _lengthMs;
    bool _reinit;  // 'true' if the oscillator should be reinit for next event
    bool _playing;
    uint32_t _delaySinceLastToneMS; // time since last generated tone [ms]
};

}  // namespace webrtc

#endif // #ifndef WEBRTC_VOICE_ENGINE_DTMF_INBAND_H_