Skip to content
Snippets Groups Projects
Commit c3b68020 authored by Adrien Béraud's avatar Adrien Béraud Committed by Kateryna Kostiuk
Browse files

tone list: cleanup

Change-Id: I0bbcdd7e5d496ce79f31ed2c172c9b530c73f160
parent 9214fe3b
No related branches found
No related tags found
No related merge requests found
...@@ -288,7 +288,7 @@ struct Manager::ManagerPimpl ...@@ -288,7 +288,7 @@ struct Manager::ManagerPimpl
* Play one tone * Play one tone
* @return false if the driver is uninitialize * @return false if the driver is uninitialize
*/ */
void playATone(Tone::TONEID toneId); void playATone(Tone::ToneId toneId);
int getCurrentDeviceIndex(DeviceType type); int getCurrentDeviceIndex(DeviceType type);
...@@ -467,7 +467,7 @@ Manager::ManagerPimpl::parseConfiguration() ...@@ -467,7 +467,7 @@ Manager::ManagerPimpl::parseConfiguration()
* Multi Thread * Multi Thread
*/ */
void void
Manager::ManagerPimpl::playATone(Tone::TONEID toneId) Manager::ManagerPimpl::playATone(Tone::ToneId toneId)
{ {
if (not base_.voipPreferences.getPlayTones()) if (not base_.voipPreferences.getPlayTones())
return; return;
...@@ -2021,7 +2021,7 @@ Manager::stopTone() ...@@ -2021,7 +2021,7 @@ Manager::stopTone()
void void
Manager::playTone() Manager::playTone()
{ {
pimpl_->playATone(Tone::TONE_DIALTONE); pimpl_->playATone(Tone::ToneId::DIALTONE);
} }
/** /**
...@@ -2030,7 +2030,7 @@ Manager::playTone() ...@@ -2030,7 +2030,7 @@ Manager::playTone()
void void
Manager::playToneWithMessage() Manager::playToneWithMessage()
{ {
pimpl_->playATone(Tone::TONE_CONGESTION); pimpl_->playATone(Tone::ToneId::CONGESTION);
} }
/** /**
...@@ -2039,7 +2039,7 @@ Manager::playToneWithMessage() ...@@ -2039,7 +2039,7 @@ Manager::playToneWithMessage()
void void
Manager::congestion() Manager::congestion()
{ {
pimpl_->playATone(Tone::TONE_CONGESTION); pimpl_->playATone(Tone::ToneId::CONGESTION);
} }
/** /**
...@@ -2048,7 +2048,7 @@ Manager::congestion() ...@@ -2048,7 +2048,7 @@ Manager::congestion()
void void
Manager::ringback() Manager::ringback()
{ {
pimpl_->playATone(Tone::TONE_RINGTONE); pimpl_->playATone(Tone::ToneId::RINGTONE);
} }
/** /**
......
...@@ -45,11 +45,11 @@ class Tone : public AudioLoop { ...@@ -45,11 +45,11 @@ class Tone : public AudioLoop {
Tone(const std::string& definition, unsigned int sampleRate); Tone(const std::string& definition, unsigned int sampleRate);
/** The different kind of tones */ /** The different kind of tones */
enum TONEID { enum class ToneId {
TONE_DIALTONE = 0, DIALTONE = 0,
TONE_BUSY, BUSY,
TONE_RINGTONE, RINGTONE,
TONE_CONGESTION, CONGESTION,
TONE_NULL TONE_NULL
}; };
......
...@@ -26,7 +26,54 @@ ...@@ -26,7 +26,54 @@
namespace jami { namespace jami {
static const char *toneZone[TelephoneTone::ZID_COUNTRIES][Tone::TONE_NULL] = { TelephoneTone::CountryId
TelephoneTone::getCountryId(const std::string& countryName)
{
if (countryName == "North America") return CountryId::ZID_NORTH_AMERICA;
else if (countryName == "France") return CountryId::ZID_FRANCE;
else if (countryName == "Australia") return CountryId::ZID_AUSTRALIA;
else if (countryName == "United Kingdom") return CountryId::ZID_UNITED_KINGDOM;
else if (countryName == "Spain") return CountryId::ZID_SPAIN;
else if (countryName == "Italy") return CountryId::ZID_ITALY;
else if (countryName == "Japan") return CountryId::ZID_JAPAN;
else return CountryId::ZID_NORTH_AMERICA; // default
}
TelephoneTone::TelephoneTone(const std::string& countryName, unsigned int sampleRate)
: countryId_(getCountryId(countryName))
, currentTone_(Tone::ToneId::TONE_NULL)
{
buildTones(sampleRate);
}
void
TelephoneTone::setCurrentTone(Tone::ToneId toneId)
{
if (toneId != Tone::ToneId::TONE_NULL && currentTone_ != toneId)
tones_[(size_t)toneId]->reset();
currentTone_ = toneId;
}
void
TelephoneTone::setSampleRate(unsigned int sampleRate)
{
buildTones(sampleRate);
}
std::shared_ptr<Tone>
TelephoneTone::getCurrentTone()
{
if (currentTone_ < Tone::ToneId::DIALTONE or currentTone_ >= Tone::ToneId::TONE_NULL)
return nullptr;
return tones_[(size_t)currentTone_];
}
void
TelephoneTone::buildTones(unsigned int sampleRate)
{
const char* toneZone[(size_t)TelephoneTone::CountryId::ZID_COUNTRIES][(size_t)Tone::ToneId::TONE_NULL] = {
{ {
// ZID_NORTH_AMERICA // ZID_NORTH_AMERICA
"350+440", // Tone::TONE_DIALTONE "350+440", // Tone::TONE_DIALTONE
...@@ -77,59 +124,10 @@ static const char *toneZone[TelephoneTone::ZID_COUNTRIES][Tone::TONE_NULL] = { ...@@ -77,59 +124,10 @@ static const char *toneZone[TelephoneTone::ZID_COUNTRIES][Tone::TONE_NULL] = {
"400/500,0/500", "400/500,0/500",
} }
}; };
tones_[(size_t)Tone::ToneId::DIALTONE] = std::make_shared<Tone>(toneZone[(size_t)countryId_][(size_t)Tone::ToneId::DIALTONE], sampleRate);
tones_[(size_t)Tone::ToneId::BUSY] = std::make_shared<Tone>(toneZone[(size_t)countryId_][(size_t)Tone::ToneId::BUSY], sampleRate);
TelephoneTone::COUNTRYID tones_[(size_t)Tone::ToneId::RINGTONE] = std::make_shared<Tone>(toneZone[(size_t)countryId_][(size_t)Tone::ToneId::RINGTONE], sampleRate);
TelephoneTone::getCountryId(const std::string& countryName) tones_[(size_t)Tone::ToneId::CONGESTION] = std::make_shared<Tone>(toneZone[(size_t)countryId_][(size_t)Tone::ToneId::CONGESTION], sampleRate);
{
if (countryName == "North America") return ZID_NORTH_AMERICA;
else if (countryName == "France") return ZID_FRANCE;
else if (countryName == "Australia") return ZID_AUSTRALIA;
else if (countryName == "United Kingdom") return ZID_UNITED_KINGDOM;
else if (countryName == "Spain") return ZID_SPAIN;
else if (countryName == "Italy") return ZID_ITALY;
else if (countryName == "Japan") return ZID_JAPAN;
else return ZID_NORTH_AMERICA; // default
}
TelephoneTone::TelephoneTone(const std::string& countryName, unsigned int sampleRate)
: countryId_(getCountryId(countryName))
, currentTone_(Tone::TONE_NULL)
{
buildTones(sampleRate);
}
void
TelephoneTone::setCurrentTone(Tone::TONEID toneId)
{
if (toneId != Tone::TONE_NULL && currentTone_ != toneId)
tones_[toneId]->reset();
currentTone_ = toneId;
}
void
TelephoneTone::setSampleRate(unsigned int sampleRate)
{
buildTones(sampleRate);
}
std::shared_ptr<Tone>
TelephoneTone::getCurrentTone()
{
if (currentTone_ < Tone::TONE_DIALTONE or currentTone_ >= Tone::TONE_NULL)
return nullptr;
return tones_[currentTone_];
}
void
TelephoneTone::buildTones(unsigned int sampleRate)
{
tones_[Tone::TONE_DIALTONE] = std::make_shared<Tone>(toneZone[countryId_][Tone::TONE_DIALTONE], sampleRate);
tones_[Tone::TONE_BUSY] = std::make_shared<Tone>(toneZone[countryId_][Tone::TONE_BUSY], sampleRate);
tones_[Tone::TONE_RINGTONE] = std::make_shared<Tone>(toneZone[countryId_][Tone::TONE_RINGTONE], sampleRate);
tones_[Tone::TONE_CONGESTION] = std::make_shared<Tone>(toneZone[countryId_][Tone::TONE_CONGESTION], sampleRate);
} }
} // namespace jami } // namespace jami
...@@ -34,7 +34,7 @@ namespace jami { ...@@ -34,7 +34,7 @@ namespace jami {
class TelephoneTone { class TelephoneTone {
public: public:
/** Countries */ /** Countries */
enum COUNTRYID { enum class CountryId {
ZID_NORTH_AMERICA = 0, ZID_NORTH_AMERICA = 0,
ZID_FRANCE, ZID_FRANCE,
ZID_AUSTRALIA, ZID_AUSTRALIA,
...@@ -47,20 +47,20 @@ class TelephoneTone { ...@@ -47,20 +47,20 @@ class TelephoneTone {
TelephoneTone(const std::string& countryName, unsigned int sampleRate); TelephoneTone(const std::string& countryName, unsigned int sampleRate);
void setCurrentTone(Tone::TONEID toneId); void setCurrentTone(Tone::ToneId toneId);
void setSampleRate(unsigned int sampleRate); void setSampleRate(unsigned int sampleRate);
std::shared_ptr<Tone> getCurrentTone(); std::shared_ptr<Tone> getCurrentTone();
private: private:
NON_COPYABLE(TelephoneTone); NON_COPYABLE(TelephoneTone);
static COUNTRYID getCountryId(const std::string& countryName); static CountryId getCountryId(const std::string& countryName);
void buildTones(unsigned int sampleRate); void buildTones(unsigned int sampleRate);
COUNTRYID countryId_; CountryId countryId_;
std::array<std::shared_ptr<Tone>, Tone::TONE_NULL> tones_; std::array<std::shared_ptr<Tone>, (size_t)Tone::ToneId::TONE_NULL> tones_;
Tone::TONEID currentTone_; Tone::ToneId currentTone_;
}; };
} // namespace jami } // namespace jami
...@@ -103,7 +103,7 @@ ToneControl::stop() ...@@ -103,7 +103,7 @@ ToneControl::stop()
std::lock_guard<std::mutex> lk(mutex_); std::lock_guard<std::mutex> lk(mutex_);
if (telephoneTone_) if (telephoneTone_)
telephoneTone_->setCurrentTone(Tone::TONE_NULL); telephoneTone_->setCurrentTone(Tone::ToneId::TONE_NULL);
if (audioFile_) { if (audioFile_) {
emitSignal<DRing::CallSignal::RecordPlaybackStopped>(audioFile_->getFilePath()); emitSignal<DRing::CallSignal::RecordPlaybackStopped>(audioFile_->getFilePath());
...@@ -112,7 +112,7 @@ ToneControl::stop() ...@@ -112,7 +112,7 @@ ToneControl::stop()
} }
void void
ToneControl::play(Tone::TONEID toneId) ToneControl::play(Tone::ToneId toneId)
{ {
std::lock_guard<std::mutex> lk(mutex_); std::lock_guard<std::mutex> lk(mutex_);
......
...@@ -49,7 +49,7 @@ class ToneControl { ...@@ -49,7 +49,7 @@ class ToneControl {
bool setAudioFile(const std::string& file); bool setAudioFile(const std::string& file);
void stopAudioFile(); void stopAudioFile();
void stop(); void stop();
void play(Tone::TONEID toneId); void play(Tone::ToneId toneId);
void seek(double value); void seek(double value);
private: private:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment