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