diff --git a/src/media/audio/audioloop.h b/src/media/audio/audioloop.h index 12f8895aeb9eed8ad16aa314a3be43da49bb8f9b..628610b07cc11d8350672561fa9906282c939340 100644 --- a/src/media/audio/audioloop.h +++ b/src/media/audio/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 __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__ diff --git a/src/media/audio/sound/tone.h b/src/media/audio/sound/tone.h index 109d41461b7e36bab8ab8c915f507f3f01547b5c..96240ba862f2c9dd34e662952afc5cf2297aeb2c 100644 --- a/src/media/audio/sound/tone.h +++ b/src/media/audio/sound/tone.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__ diff --git a/src/media/audio/sound/tonelist.cpp b/src/media/audio/sound/tonelist.cpp index 9e52dbd6c16d58c9cd12a3c5b52ff73f0842eec3..f25284e96ca1e101ae6833197d098dfb3ba2983f 100644 --- a/src/media/audio/sound/tonelist.cpp +++ b/src/media/audio/sound/tonelist.cpp @@ -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 diff --git a/src/media/audio/sound/tonelist.h b/src/media/audio/sound/tonelist.h index d1614c9f68317f0f7ea19b8aaae5e3d82dbceb08..564d6751daab7f26f21f1f81964002c41d0bf343 100644 --- a/src/media/audio/sound/tonelist.h +++ b/src/media/audio/sound/tonelist.h @@ -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 diff --git a/src/media/audio/tonecontrol.cpp b/src/media/audio/tonecontrol.cpp index a4a3ba16e56f5898091d1389a894da1865597bc5..2f682d5d94c09dc35dc22f47b850899a7675e1a7 100644 --- a/src/media/audio/tonecontrol.cpp +++ b/src/media/audio/tonecontrol.cpp @@ -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 diff --git a/src/media/audio/tonecontrol.h b/src/media/audio/tonecontrol.h index 61c1cd9c123afe02cf828e766b7dc639fa916da4..4bc67b7312192b9c548b7a1672954491a06f1eb8 100644 --- a/src/media/audio/tonecontrol.h +++ b/src/media/audio/tonecontrol.h @@ -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;