Ring Daemon
Loading...
Searching...
No Matches
tonelist.cpp
Go to the documentation of this file.
1/*
2 * Copyright (C) 2004-2026 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
22namespace jami {
23
25TelephoneTone::getCountryId(const std::string& countryName)
26{
27 if (countryName == "North America")
29 else if (countryName == "France")
31 else if (countryName == "Australia")
33 else if (countryName == "United Kingdom")
35 else if (countryName == "Spain")
37 else if (countryName == "Italy")
39 else if (countryName == "Japan")
41 else
42 return CountryId::ZID_NORTH_AMERICA; // default
43}
44
45TelephoneTone::TelephoneTone(const std::string& countryName, unsigned int sampleRate, AVSampleFormat sampleFormat)
46 : countryId_(getCountryId(countryName))
47 , currentTone_(Tone::ToneId::TONE_NULL)
48{
49 buildTones(sampleRate, sampleFormat);
50}
51
52void
54{
55 if (toneId != Tone::ToneId::TONE_NULL && currentTone_ != toneId)
56 tones_[(size_t) toneId]->reset();
57
58 currentTone_ = toneId;
59}
60
61void
62TelephoneTone::setSampleRate(unsigned int sampleRate, AVSampleFormat sampleFormat)
63{
64 buildTones(sampleRate, sampleFormat);
65}
66
67std::shared_ptr<Tone>
69{
71 return nullptr;
72
73 return tones_[(size_t) currentTone_];
74}
75
76void
77TelephoneTone::buildTones(unsigned int sampleRate, AVSampleFormat sampleFormat)
78{
80 = {{
81 // ZID_NORTH_AMERICA
82 "350+440", // Tone::TONE_DIALTONE
83 "480+620/500,0/500", // Tone::TONE_BUSY
84 "440+480/2000,0/4000", // Tone::TONE_RINGTONE
85 "480+620/250,0/250", // Tone::TONE_CONGESTION
86 },
87 {
88 // ZID_FRANCE
89 "440",
90 "440/500,0/500",
91 "440/1500,0/3500",
92 "440/250,0/250",
93 },
94 {
95 // ZID_AUSTRALIA
96 "413+438",
97 "425/375,0/375",
98 "413+438/400,0/200,413+438/400,0/2000",
99 "425/375,0/375,420/375,8/375",
100 },
101 {
102 // ZID_UNITED_KINGDOM
103 "350+440",
104 "400/375,0/375",
105 "400+450/400,0/200,400+450/400,0/2000",
106 "400/400,0/350,400/225,0/525",
107 },
108 {
109 // ZID_SPAIN
110 "425",
111 "425/200,0/200",
112 "425/1500,0/3000",
113 "425/200,0/200,425/200,0/200,425/200,0/600",
114 },
115 {
116 // ZID_ITALY
117 "425/600,0/1000,425/200,0/200",
118 "425/500,0/500",
119 "425/1000,0/4000",
120 "425/200,0/200",
121 },
122 {
123 // ZID_JAPAN
124 "400",
125 "400/500,0/500",
126 "400+15/1000,0/2000",
127 "400/500,0/500",
128 }};
130 = std::make_shared<Tone>(toneZone[(size_t) countryId_][(size_t) Tone::ToneId::DIALTONE],
131 sampleRate,
132 sampleFormat);
133 tones_[(size_t) Tone::ToneId::BUSY]
134 = std::make_shared<Tone>(toneZone[(size_t) countryId_][(size_t) Tone::ToneId::BUSY], sampleRate, sampleFormat);
136 = std::make_shared<Tone>(toneZone[(size_t) countryId_][(size_t) Tone::ToneId::RINGTONE],
137 sampleRate,
138 sampleFormat);
140 = std::make_shared<Tone>(toneZone[(size_t) countryId_][(size_t) Tone::ToneId::CONGESTION],
141 sampleRate,
142 sampleFormat);
143}
144
145} // namespace jami
CountryId
Countries.
Definition tonelist.h:34
void setCurrentTone(Tone::ToneId toneId)
Definition tonelist.cpp:53
std::shared_ptr< Tone > getCurrentTone()
Definition tonelist.cpp:68
void setSampleRate(unsigned int sampleRate, AVSampleFormat sampleFormat)
Definition tonelist.cpp:62
TelephoneTone(const std::string &countryName, unsigned int sampleRate, AVSampleFormat sampleFormat)
Definition tonelist.cpp:45
ToneId
The different kind of tones.
Definition tone.h:43
void emitSignal(Args... args)
Definition jami_signal.h:64