Ring Daemon 16.0.0
Loading...
Searching...
No Matches
tonelist.cpp
Go to the documentation of this file.
1/*
2 * Copyright (C) 2004-2025 Savoir-faire Linux Inc.
3 *
4 * Inspired by tonegenerator of
5 * Laurielle Lea <laurielle.lea@savoirfairelinux.com> (2004)
6 *
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <https://www.gnu.org/licenses/>.
19 */
20#include "tonelist.h"
21
22#include <ciso646> // fix windows compiler bug
23
24namespace jami {
25
27TelephoneTone::getCountryId(const std::string& countryName)
28{
29 if (countryName == "North America")
31 else if (countryName == "France")
33 else if (countryName == "Australia")
35 else if (countryName == "United Kingdom")
37 else if (countryName == "Spain")
39 else if (countryName == "Italy")
41 else if (countryName == "Japan")
43 else
44 return CountryId::ZID_NORTH_AMERICA; // default
45}
46
47TelephoneTone::TelephoneTone(const std::string& countryName, unsigned int sampleRate, AVSampleFormat sampleFormat)
48 : countryId_(getCountryId(countryName))
49 , currentTone_(Tone::ToneId::TONE_NULL)
50{
51 buildTones(sampleRate, sampleFormat);
52}
53
54void
56{
57 if (toneId != Tone::ToneId::TONE_NULL && currentTone_ != toneId)
58 tones_[(size_t) toneId]->reset();
59
60 currentTone_ = toneId;
61}
62
63void
64TelephoneTone::setSampleRate(unsigned int sampleRate, AVSampleFormat sampleFormat)
65{
66 buildTones(sampleRate, sampleFormat);
67}
68
69std::shared_ptr<Tone>
71{
73 return nullptr;
74
75 return tones_[(size_t) currentTone_];
76}
77
78void
79TelephoneTone::buildTones(unsigned int sampleRate, AVSampleFormat sampleFormat)
80{
83 = {{
84 // ZID_NORTH_AMERICA
85 "350+440", // Tone::TONE_DIALTONE
86 "480+620/500,0/500", // Tone::TONE_BUSY
87 "440+480/2000,0/4000", // Tone::TONE_RINGTONE
88 "480+620/250,0/250", // Tone::TONE_CONGESTION
89 },
90 {
91 // ZID_FRANCE
92 "440",
93 "440/500,0/500",
94 "440/1500,0/3500",
95 "440/250,0/250",
96 },
97 {
98 // ZID_AUSTRALIA
99 "413+438",
100 "425/375,0/375",
101 "413+438/400,0/200,413+438/400,0/2000",
102 "425/375,0/375,420/375,8/375",
103 },
104 {
105 // ZID_UNITED_KINGDOM
106 "350+440",
107 "400/375,0/375",
108 "400+450/400,0/200,400+450/400,0/2000",
109 "400/400,0/350,400/225,0/525",
110 },
111 {
112 // ZID_SPAIN
113 "425",
114 "425/200,0/200",
115 "425/1500,0/3000",
116 "425/200,0/200,425/200,0/200,425/200,0/600",
117 },
118 {
119 // ZID_ITALY
120 "425/600,0/1000,425/200,0/200",
121 "425/500,0/500",
122 "425/1000,0/4000",
123 "425/200,0/200",
124 },
125 {
126 // ZID_JAPAN
127 "400",
128 "400/500,0/500",
129 "400+15/1000,0/2000",
130 "400/500,0/500",
131 }};
133 = std::make_shared<Tone>(toneZone[(size_t) countryId_][(size_t) Tone::ToneId::DIALTONE],
134 sampleRate, sampleFormat);
135 tones_[(size_t) Tone::ToneId::BUSY]
136 = std::make_shared<Tone>(toneZone[(size_t) countryId_][(size_t) Tone::ToneId::BUSY],
137 sampleRate, sampleFormat);
139 = std::make_shared<Tone>(toneZone[(size_t) countryId_][(size_t) Tone::ToneId::RINGTONE],
140 sampleRate, sampleFormat);
142 = std::make_shared<Tone>(toneZone[(size_t) countryId_][(size_t) Tone::ToneId::CONGESTION],
143 sampleRate, sampleFormat);
144}
145
146} // namespace jami
CountryId
Countries.
Definition tonelist.h:34
void setCurrentTone(Tone::ToneId toneId)
Definition tonelist.cpp:55
std::shared_ptr< Tone > getCurrentTone()
Definition tonelist.cpp:70
void setSampleRate(unsigned int sampleRate, AVSampleFormat sampleFormat)
Definition tonelist.cpp:64
TelephoneTone(const std::string &countryName, unsigned int sampleRate, AVSampleFormat sampleFormat)
Definition tonelist.cpp:47
ToneId
The different kind of tones.
Definition tone.h:43
void emitSignal(Args... args)
Definition ring_signal.h:64