Ring Daemon
Loading...
Searching...
No Matches
dtmfgenerator.h
Go to the documentation of this file.
1/*
2 * Copyright (C) 2004-2026 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 <array>
20#include <stdexcept>
21#include <string>
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 DTMFState
50 {
51 unsigned int offset;
52 AVFrame* sample;
53 };
54
56 DTMFState state;
57
59 std::array<libjami::FrameBuffer, NUM_TONES> toneBuffers_;
60
62 unsigned sampleRate_;
63
65 Tone tone_;
66
67public:
73 DTMFGenerator(unsigned int sampleRate, AVSampleFormat sampleFormat);
74
76
78
79 /*
80 * Get n samples of the signal of code code
81 * @param frame the output AVFrame to fill
82 * @param code dtmf code to get sound
83 */
84 void getSamples(AVFrame* frame, unsigned char code);
85
86 /*
87 * Get next n samples (continues where previous call to
88 * genSample or genNextSamples stopped
89 * @param buffer a AudioSample vector
90 */
92
93private:
99 libjami::FrameBuffer fillToneBuffer(unsigned index);
100};
101
102} // namespace jami
DTMFException(const std::string &str)
NON_COPYABLE(DTMFGenerator)
void getNextSamples(AVFrame *frame)
void getSamples(AVFrame *frame, unsigned char code)
void emitSignal(Args... args)
Definition jami_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)