LCOV - code coverage report
Current view: top level - src/media/audio/sound - tonelist.cpp (source / functions) Hit Total Coverage
Test: jami-coverage-filtered.info Lines: 31 48 64.6 %
Date: 2024-12-21 08:56:24 Functions: 5 6 83.3 %

          Line data    Source code
       1             : /*
       2             :  *  Copyright (C) 2004-2024 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             : 
      24             : namespace jami {
      25             : 
      26             : TelephoneTone::CountryId
      27          33 : TelephoneTone::getCountryId(const std::string& countryName)
      28             : {
      29          33 :     if (countryName == "North America")
      30          33 :         return CountryId::ZID_NORTH_AMERICA;
      31           0 :     else if (countryName == "France")
      32           0 :         return CountryId::ZID_FRANCE;
      33           0 :     else if (countryName == "Australia")
      34           0 :         return CountryId::ZID_AUSTRALIA;
      35           0 :     else if (countryName == "United Kingdom")
      36           0 :         return CountryId::ZID_UNITED_KINGDOM;
      37           0 :     else if (countryName == "Spain")
      38           0 :         return CountryId::ZID_SPAIN;
      39           0 :     else if (countryName == "Italy")
      40           0 :         return CountryId::ZID_ITALY;
      41           0 :     else if (countryName == "Japan")
      42           0 :         return CountryId::ZID_JAPAN;
      43             :     else
      44           0 :         return CountryId::ZID_NORTH_AMERICA; // default
      45             : }
      46             : 
      47          33 : TelephoneTone::TelephoneTone(const std::string& countryName, unsigned int sampleRate, AVSampleFormat sampleFormat)
      48          33 :     : countryId_(getCountryId(countryName))
      49          33 :     , currentTone_(Tone::ToneId::TONE_NULL)
      50             : {
      51          33 :     buildTones(sampleRate, sampleFormat);
      52          33 : }
      53             : 
      54             : void
      55         670 : TelephoneTone::setCurrentTone(Tone::ToneId toneId)
      56             : {
      57         670 :     if (toneId != Tone::ToneId::TONE_NULL && currentTone_ != toneId)
      58          72 :         tones_[(size_t) toneId]->reset();
      59             : 
      60         670 :     currentTone_ = toneId;
      61         670 : }
      62             : 
      63             : void
      64          58 : TelephoneTone::setSampleRate(unsigned int sampleRate, AVSampleFormat sampleFormat)
      65             : {
      66          58 :     buildTones(sampleRate, sampleFormat);
      67          58 : }
      68             : 
      69             : std::shared_ptr<Tone>
      70           0 : TelephoneTone::getCurrentTone()
      71             : {
      72           0 :     if (currentTone_ < Tone::ToneId::DIALTONE or currentTone_ >= Tone::ToneId::TONE_NULL)
      73           0 :         return nullptr;
      74             : 
      75           0 :     return tones_[(size_t) currentTone_];
      76             : }
      77             : 
      78             : void
      79          91 : TelephoneTone::buildTones(unsigned int sampleRate, AVSampleFormat sampleFormat)
      80             : {
      81          91 :     const char* toneZone[(size_t) TelephoneTone::CountryId::ZID_COUNTRIES]
      82             :                         [(size_t) Tone::ToneId::TONE_NULL]
      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             :            }};
     132          91 :     tones_[(size_t) Tone::ToneId::DIALTONE]
     133         182 :         = std::make_shared<Tone>(toneZone[(size_t) countryId_][(size_t) Tone::ToneId::DIALTONE],
     134          91 :                                  sampleRate, sampleFormat);
     135          91 :     tones_[(size_t) Tone::ToneId::BUSY]
     136         182 :         = std::make_shared<Tone>(toneZone[(size_t) countryId_][(size_t) Tone::ToneId::BUSY],
     137          91 :                                  sampleRate, sampleFormat);
     138          91 :     tones_[(size_t) Tone::ToneId::RINGTONE]
     139         182 :         = std::make_shared<Tone>(toneZone[(size_t) countryId_][(size_t) Tone::ToneId::RINGTONE],
     140          91 :                                  sampleRate, sampleFormat);
     141          91 :     tones_[(size_t) Tone::ToneId::CONGESTION]
     142         182 :         = std::make_shared<Tone>(toneZone[(size_t) countryId_][(size_t) Tone::ToneId::CONGESTION],
     143          91 :                                  sampleRate, sampleFormat);
     144          91 : }
     145             : 
     146             : } // namespace jami

Generated by: LCOV version 1.14