Ring Daemon 16.0.0
Loading...
Searching...
No Matches
dtmf.cpp
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
18#include "dtmf.h"
19
20namespace jami {
21
22DTMF::DTMF(unsigned int sampleRate, AVSampleFormat sampleFormat)
23 : currentTone_(0)
24 , newTone_(0)
25 , dtmfgenerator_(sampleRate, sampleFormat)
26{}
27
28void
30{
31 newTone_ = code;
32}
33
34bool
36{
37 try {
38 if (currentTone_ != 0) {
39 // Currently generating a DTMF tone
40 if (currentTone_ == newTone_) {
41 // Continue generating the same tone
42 dtmfgenerator_.getNextSamples(buffer);
43 return true;
44 } else if (newTone_ != 0) {
45 // New tone requested
46 dtmfgenerator_.getSamples(buffer, newTone_);
47 currentTone_ = newTone_;
48 return true;
49 } else {
50 // Stop requested
51 currentTone_ = newTone_;
52 return false;
53 }
54 } else {
55 // Not generating any DTMF tone
56 if (newTone_) {
57 // Requested to generate a DTMF tone
58 dtmfgenerator_.getSamples(buffer, newTone_);
59 currentTone_ = newTone_;
60 return true;
61 } else
62 return false;
63 }
64 } catch (const DTMFException& e) {
65 // invalid key
66 return false;
67 }
68}
69
70} // namespace jami
void getNextSamples(AVFrame *frame)
void getSamples(AVFrame *frame, unsigned char code)
void startTone(char code)
Start the done for th given dtmf.
Definition dtmf.cpp:29
DTMF(unsigned int sampleRate, AVSampleFormat sampleFormat)
Create a new DTMF.
Definition dtmf.cpp:22
bool generateDTMF(AVFrame *frame)
Copy the sound inside the sampling* buffer.
Definition dtmf.cpp:35
DMTF library to generate a dtmf sample.
void emitSignal(Args... args)
Definition ring_signal.h:64