Ring Daemon 16.0.0
Loading...
Searching...
No Matches
dtmfgenerator.h
Go to the documentation of this file.
1/*
2 * Copyright (C) 2004-2025 Savoir-faire Linux Inc.
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <https://www.gnu.org/licenses/>.
16 */
17#pragma once
18
19#include <stdexcept>
20#include <string>
21#include <vector>
22#include "noncopyable.h"
23#include "tone.h"
24
25#define NUM_TONES 16
26
27/*
28 * @file dtmfgenerator.h
29 * @brief DMTF Generator Exception
30 */
31
32namespace jami {
33
34class DTMFException : public std::runtime_error
35{
36public:
37 DTMFException(const std::string& str)
38 : std::runtime_error(str) {};
39};
40
41/*
42 * @file dtmfgenerator.h
43 * @brief DTMF Tone Generator
44 */
46{
47private:
49 struct DTMFTone
50 {
51 unsigned char code;
52 unsigned lower;
53 unsigned higher;
54 };
55
57 struct DTMFState
58 {
59 unsigned int offset;
60 AVFrame* sample;
61 };
62
64 DTMFState state;
65
67 static const DTMFTone tones_[NUM_TONES];
68
70 std::array<libjami::FrameBuffer, NUM_TONES> toneBuffers_;
71
73 unsigned sampleRate_;
74
76 Tone tone_;
77
78public:
84 DTMFGenerator(unsigned int sampleRate, AVSampleFormat sampleFormat);
85
87
89
90 /*
91 * Get n samples of the signal of code code
92 * @param frame the output AVFrame to fill
93 * @param code dtmf code to get sound
94 */
95 void getSamples(AVFrame* frame, unsigned char code);
96
97 /*
98 * Get next n samples (continues where previous call to
99 * genSample or genNextSamples stopped
100 * @param buffer a AudioSample vector
101 */
103
104private:
110 libjami::FrameBuffer fillToneBuffer(int index);
111};
112
113} // namespace jami
DTMFException(const std::string &str)
NON_COPYABLE(DTMFGenerator)
void getNextSamples(AVFrame *frame)
void getSamples(AVFrame *frame, unsigned char code)
#define NUM_TONES
void emitSignal(Args... args)
Definition ring_signal.h:64
std::unique_ptr< AVFrame, AVFrame_deleter > FrameBuffer
Simple macro to hide class' copy constructor and assignment operator.
Tone sample (dial, busy, ring, congestion)