LCOV - code coverage report
Current view: top level - src/media/audio/sound - tonelist.cpp (source / functions) Coverage Total Hit
Test: jami-coverage-filtered.info Lines: 63.8 % 47 30
Test Date: 2026-06-13 09:18:46 Functions: 83.3 % 6 5

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

Generated by: LCOV version 2.0-1