Skip to content
Snippets Groups Projects
Commit b6771a0c authored by Anthony Léonard's avatar Anthony Léonard Committed by Guillaume Roguez
Browse files

audio: TelephoneTone isn't recreated entirely anymore


A new instance of TelephoneTone was created every time the
sample rate was changed. Consequently, the selected tone
was lost each time it happened and the ALSA backend was
trying to read an empty buffer in an infinite loop when the
contact wasn't answering the call.
The precise changes are :
 * A setSampleRate was added as a method in tonelist[.cpp|.h]
 * A buildTones method was also created to prevent code
   redundancy.
 * setSampleRate is used instead of recreating the object in
   tonecontrol.cpp

Change-Id: I44a86345953068848d0304516d502de5c37bb113
Tuleap: #168
Reviewed-by: default avatarGuillaume Roguez <guillaume.roguez@savoirfairelinux.com>
parent e69626aa
Branches
No related tags found
No related merge requests found
......@@ -91,14 +91,9 @@ TelephoneTone::getCountryId(const std::string& countryName)
}
TelephoneTone::TelephoneTone(const std::string& countryName, unsigned int sampleRate) :
currentTone_(Tone::TONE_NULL)
currentTone_(Tone::TONE_NULL), countryId_(getCountryId(countryName))
{
TelephoneTone::COUNTRYID countryId = getCountryId(countryName);
tone_[Tone::TONE_DIALTONE] = new Tone(toneZone[countryId][Tone::TONE_DIALTONE], sampleRate);
tone_[Tone::TONE_BUSY] = new Tone(toneZone[countryId][Tone::TONE_BUSY], sampleRate);
tone_[Tone::TONE_RINGTONE] = new Tone(toneZone[countryId][Tone::TONE_RINGTONE], sampleRate);
tone_[Tone::TONE_CONGESTION] = new Tone(toneZone[countryId][Tone::TONE_CONGESTION], sampleRate);
buildTones(sampleRate);
}
TelephoneTone::~TelephoneTone()
......@@ -116,6 +111,14 @@ TelephoneTone::setCurrentTone(Tone::TONEID toneId)
currentTone_ = toneId;
}
void
TelephoneTone::setSampleRate(unsigned int sampleRate)
{
for (size_t i=0; i < Tone::TONE_NULL; i++)
delete tone_[i];
buildTones(sampleRate);
}
Tone*
TelephoneTone::getCurrentTone()
{
......@@ -125,4 +128,13 @@ TelephoneTone::getCurrentTone()
return tone_[currentTone_];
}
void
TelephoneTone::buildTones(unsigned int sampleRate)
{
tone_[Tone::TONE_DIALTONE] = new Tone(toneZone[countryId_][Tone::TONE_DIALTONE], sampleRate);
tone_[Tone::TONE_BUSY] = new Tone(toneZone[countryId_][Tone::TONE_BUSY], sampleRate);
tone_[Tone::TONE_RINGTONE] = new Tone(toneZone[countryId_][Tone::TONE_RINGTONE], sampleRate);
tone_[Tone::TONE_CONGESTION] = new Tone(toneZone[countryId_][Tone::TONE_CONGESTION], sampleRate);
}
} // namespace ring
......@@ -46,6 +46,7 @@ class TelephoneTone {
~TelephoneTone();
void setCurrentTone(Tone::TONEID toneId);
void setSampleRate(unsigned int sampleRate);
Tone* getCurrentTone();
private:
......@@ -53,6 +54,8 @@ class TelephoneTone {
static COUNTRYID getCountryId(const std::string& countryName);
void buildTones(unsigned int sampleRate);
COUNTRYID countryId_;
Tone* tone_[Tone::TONE_NULL];
Tone::TONEID currentTone_;
};
......
......@@ -44,7 +44,10 @@ ToneControl::setSampleRate(unsigned rate)
{
std::lock_guard<std::mutex> lk(mutex_);
sampleRate_ = rate;
telephoneTone_.reset(new TelephoneTone(prefs_.getZoneToneChoice(), rate));
if (!telephoneTone_)
telephoneTone_.reset(new TelephoneTone(prefs_.getZoneToneChoice(), rate));
else
telephoneTone_->setSampleRate(rate);
}
AudioLoop*
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment