mirror of
https://git.jami.net/savoirfairelinux/jami-daemon.git
synced 2025-08-12 22:09:25 +08:00
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
This commit is contained in:

committed by
Adrien Béraud

parent
69fa351120
commit
adf9c5c4a5
@ -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;
|
||||
|
Reference in New Issue
Block a user