Commit adf9c5c4 authored by Guillaume Roguez's avatar Guillaume Roguez Committed by Adrien Béraud

audio: modern C++ refactoring in tone/audioloop

This patch refactors some audio classes and its implementation
in respect of daemon coding rules and modernize its
implementation by using modern C++ facilities.

Change-Id: Ia45e33bfe43b2a60997ece7c2810054405210e26
parent 69fa3511
......@@ -20,8 +20,8 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#ifndef __AUDIOLOOP_H__
#define __AUDIOLOOP_H__
#pragma once
#include "ring_types.h"
#include "noncopyable.h"
......@@ -36,8 +36,16 @@ namespace ring {
class AudioLoop {
public:
AudioLoop() {}
AudioLoop(unsigned int sampleRate);
AudioLoop& operator=(AudioLoop&& o) noexcept {
std::swap(buffer_, o.buffer_);
std::swap(pos_, o.pos_);
return *this;
}
virtual ~AudioLoop();
/**
......@@ -70,10 +78,10 @@ class AudioLoop {
}
protected:
/** The data buffer */
AudioBuffer * buffer_;
AudioBuffer * buffer_ {nullptr};
/** current position, set to 0, when initialize */
size_t pos_;
size_t pos_ {0};
private:
NON_COPYABLE(AudioLoop);
......@@ -82,4 +90,3 @@ class AudioLoop {
} // namespace ring
#endif // __AUDIOLOOP_H__
......@@ -20,8 +20,8 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#ifndef __TONE_H__
#define __TONE_H__
#pragma once
#include <string>
#include "audio/audioloop.h"
......@@ -35,6 +35,8 @@ namespace ring {
class Tone : public AudioLoop {
public:
Tone() : AudioLoop() {}
/**
* Constructor
* @param definition String that contain frequency/time of the tone
......@@ -70,5 +72,3 @@ class Tone : public AudioLoop {
};
} // namespace ring
#endif // __TONE_H__
......@@ -90,23 +90,18 @@ TelephoneTone::getCountryId(const std::string& countryName)
else return ZID_NORTH_AMERICA; // default
}
TelephoneTone::TelephoneTone(const std::string& countryName, unsigned int sampleRate) :
currentTone_(Tone::TONE_NULL), countryId_(getCountryId(countryName))
TelephoneTone::TelephoneTone(const std::string& countryName, unsigned int sampleRate)
: countryId_(getCountryId(countryName))
, currentTone_(Tone::TONE_NULL)
{
buildTones(sampleRate);
}
TelephoneTone::~TelephoneTone()
{
for (size_t i=0; i < Tone::TONE_NULL; i++)
delete tone_[i];
}
void
TelephoneTone::setCurrentTone(Tone::TONEID toneId)
{
if (toneId != Tone::TONE_NULL && currentTone_ != toneId)
tone_[toneId]->reset();
tones_[toneId].reset();
currentTone_ = toneId;
}
......@@ -114,8 +109,6 @@ TelephoneTone::setCurrentTone(Tone::TONEID toneId)
void
TelephoneTone::setSampleRate(unsigned int sampleRate)
{
for (size_t i=0; i < Tone::TONE_NULL; i++)
delete tone_[i];
buildTones(sampleRate);
}
......@@ -123,18 +116,18 @@ Tone*
TelephoneTone::getCurrentTone()
{
if (currentTone_ < Tone::TONE_DIALTONE or currentTone_ >= Tone::TONE_NULL)
return NULL;
return nullptr;
return tone_[currentTone_];
return &tones_[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);
tones_[Tone::TONE_DIALTONE] = Tone(toneZone[countryId_][Tone::TONE_DIALTONE], sampleRate);
tones_[Tone::TONE_BUSY] = Tone(toneZone[countryId_][Tone::TONE_BUSY], sampleRate);
tones_[Tone::TONE_RINGTONE] = Tone(toneZone[countryId_][Tone::TONE_RINGTONE], sampleRate);
tones_[Tone::TONE_CONGESTION] = Tone(toneZone[countryId_][Tone::TONE_CONGESTION], sampleRate);
}
} // namespace ring
......@@ -21,11 +21,14 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#ifndef __TONELIST_H__
#define __TONELIST_H__
#pragma once
#include "tone.h"
#include <string>
#include <array>
#include <memory>
namespace ring {
class TelephoneTone {
......@@ -43,7 +46,6 @@ class TelephoneTone {
};
TelephoneTone(const std::string& countryName, unsigned int sampleRate);
~TelephoneTone();
void setCurrentTone(Tone::TONEID toneId);
void setSampleRate(unsigned int sampleRate);
......@@ -55,11 +57,10 @@ class TelephoneTone {
static COUNTRYID getCountryId(const std::string& countryName);
void buildTones(unsigned int sampleRate);
COUNTRYID countryId_;
Tone* tone_[Tone::TONE_NULL];
std::array<Tone, Tone::TONE_NULL> tones_;
Tone::TONEID currentTone_;
};
} // namespace ring
#endif
......@@ -23,6 +23,7 @@
#endif
#include "audio/tonecontrol.h"
#include "sound/tonelist.h"
#include "client/ring_signal.h"
#include "dring/callmanager_interface.h" // for CallSignal
......
......@@ -22,7 +22,6 @@
#include "preferences.h"
#include "audio/sound/tone.h" // for Tone::TONEID declaration
#include "audio/sound/tonelist.h"
#include "audio/sound/audiofile.h"
#include <mutex>
......@@ -36,6 +35,8 @@ namespace ring {
* complexes interactions occuring in a multi-call context.
*/
class TelephoneTone;
class ToneControl {
public:
ToneControl() = delete;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment