Commit 644cbad3 authored by Rafaël Carré's avatar Rafaël Carré
Browse files

Simplify ToneList

parent 0b4c0216
...@@ -35,6 +35,7 @@ ...@@ -35,6 +35,7 @@
#include "audioloop.h" #include "audioloop.h"
#include <math.h> #include <math.h>
#include <cstring> #include <cstring>
#include <cassert>
AudioLoop::AudioLoop() :_buffer (0), _size (0), _pos (0), _sampleRate (0) AudioLoop::AudioLoop() :_buffer (0), _size (0), _pos (0), _sampleRate (0)
{ {
...@@ -46,9 +47,11 @@ AudioLoop::~AudioLoop() ...@@ -46,9 +47,11 @@ AudioLoop::~AudioLoop()
} }
void void
AudioLoop::getNext (SFLDataFormat* output, int total_samples, short volume) AudioLoop::getNext (SFLDataFormat* output, size_t total_samples, short volume)
{ {
int pos = _pos; size_t pos = _pos;
assert(_size);
if(_size == 0) { if(_size == 0) {
_error("AudioLoop: Error: Audio loop size is 0"); _error("AudioLoop: Error: Audio loop size is 0");
...@@ -56,7 +59,7 @@ AudioLoop::getNext (SFLDataFormat* output, int total_samples, short volume) ...@@ -56,7 +59,7 @@ AudioLoop::getNext (SFLDataFormat* output, int total_samples, short volume)
} }
while (total_samples) { while (total_samples) {
int samples = total_samples; size_t samples = total_samples;
if (samples > (_size-pos)) { if (samples > (_size-pos)) {
samples = _size-pos; samples = _size-pos;
...@@ -65,7 +68,7 @@ AudioLoop::getNext (SFLDataFormat* output, int total_samples, short volume) ...@@ -65,7 +68,7 @@ AudioLoop::getNext (SFLDataFormat* output, int total_samples, short volume)
memcpy(output, _buffer+pos, samples*sizeof (SFLDataFormat)); // short>char conversion memcpy(output, _buffer+pos, samples*sizeof (SFLDataFormat)); // short>char conversion
if (volume!=100) { if (volume!=100) {
for (int i=0; i<samples; i++) { for (size_t i=0; i<samples; i++) {
*output = (*output * volume) /100; *output = (*output * volume) /100;
output++; output++;
} }
...@@ -73,7 +76,6 @@ AudioLoop::getNext (SFLDataFormat* output, int total_samples, short volume) ...@@ -73,7 +76,6 @@ AudioLoop::getNext (SFLDataFormat* output, int total_samples, short volume)
output += samples; // this is the destination... output += samples; // this is the destination...
} }
// should adjust sound here, in output???
pos = (pos + samples) % _size; pos = (pos + samples) % _size;
total_samples -= samples; total_samples -= samples;
......
...@@ -61,7 +61,7 @@ class AudioLoop ...@@ -61,7 +61,7 @@ class AudioLoop
* @param nb of int16 to send * @param nb of int16 to send
* @param volume The volume * @param volume The volume
*/ */
void getNext (SFLDataFormat* output, int samples, short volume=100); void getNext (SFLDataFormat* output, size_t samples, short volume=100);
/** /**
* Reset the pointer position * Reset the pointer position
...@@ -74,7 +74,7 @@ class AudioLoop ...@@ -74,7 +74,7 @@ class AudioLoop
* Accessor to the size of the buffer * Accessor to the size of the buffer
* @return unsigned int The size * @return unsigned int The size
*/ */
unsigned int getSize() { size_t getSize() {
return _size; return _size;
} }
...@@ -84,10 +84,10 @@ class AudioLoop ...@@ -84,10 +84,10 @@ class AudioLoop
SFLDataFormat* _buffer; SFLDataFormat* _buffer;
/** Number of samples inside the buffer */ /** Number of samples inside the buffer */
int _size; size_t _size;
/** current position, set to 0, when initialize */ /** current position, set to 0, when initialize */
int _pos; size_t _pos;
/** Sample rate */ /** Sample rate */
unsigned int _sampleRate; unsigned int _sampleRate;
......
...@@ -36,9 +36,6 @@ ...@@ -36,9 +36,6 @@
#include <string> #include <string>
#include "audio/audioloop.h" #include "audio/audioloop.h"
#define TONE_NBTONE 4
#define TONE_NBCOUNTRY 7
#define TABLE_LENGTH 4096 #define TABLE_LENGTH 4096
/** /**
......
...@@ -32,120 +32,87 @@ ...@@ -32,120 +32,87 @@
*/ */
#include "tonelist.h" #include "tonelist.h"
ToneList::ToneList() : _nbTone (TONE_NBTONE) , static const char *toneZone[TelephoneTone::ZID_COUNTRIES][Tone::TONE_NULL] = {
_nbCountry (TONE_NBCOUNTRY), { // ZID_NORTH_AMERICA
_defaultCountryId (ZID_NORTH_AMERICA) "350+440", //Tone::TONE_DIALTONE
"480+620/500,0/500", //Tone::TONE_BUSY
"440+480/2000,0/4000", //Tone::TONE_RINGTONE
"480+620/250,0/250", //Tone::TONE_CONGESTION
},
{ //ZID_FRANCE
"440",
"440/500,0/500",
"440/1500,0/3500",
"440/250,0/250",
},
{ //ZID_AUSTRALIA
"413+438",
"425/375,0/375",
"413+438/400,0/200,413+438/400,0/2000",
"425/375,0/375,420/375,8/375",
},
{ //ZID_UNITED_KINGDOM
"350+440",
"400/375,0/375",
"400+450/400,0/200,400+450/400,0/2000",
"400/400,0/350,400/225,0/525",
},
{ //ZID_SPAIN
"425",
"425/200,0/200",
"425/1500,0/3000",
"425/200,0/200,425/200,0/200,425/200,0/600",
},
{ //ZID_ITALY
"425/600,0/1000,425/200,0/200",
"425/500,0/500",
"425/1000,0/4000",
"425/200,0/200",
},
{ //ZID_JAPAN
"400",
"400/500,0/500",
"400+15/1000,0/2000",
"400/500,0/500",
}
};
TelephoneTone::COUNTRYID
TelephoneTone::getCountryId (const std::string& countryName)
{ {
initToneDefinition(); if (countryName == "North America") return ZID_NORTH_AMERICA;
} if (countryName == "France") return ZID_FRANCE;
if (countryName == "Australia") return ZID_AUSTRALIA;
ToneList::~ToneList() if (countryName == "United Kingdom") return ZID_UNITED_KINGDOM;
{ if (countryName == "Spain") return ZID_SPAIN;
} if (countryName == "Italy") return ZID_ITALY;
if (countryName == "Japan") return ZID_JAPAN;
void return ZID_NORTH_AMERICA; // default
ToneList::initToneDefinition()
{
_toneZone[ZID_NORTH_AMERICA][Tone::TONE_DIALTONE] = "350+440";
_toneZone[ZID_NORTH_AMERICA][Tone::TONE_BUSY] = "480+620/500,0/500";
_toneZone[ZID_NORTH_AMERICA][Tone::TONE_RINGTONE] = "440+480/2000,0/4000";
_toneZone[ZID_NORTH_AMERICA][Tone::TONE_CONGESTION] = "480+620/250,0/250";
_toneZone[ZID_FRANCE][Tone::TONE_DIALTONE] = "440";
_toneZone[ZID_FRANCE][Tone::TONE_BUSY] = "440/500,0/500";
_toneZone[ZID_FRANCE][Tone::TONE_RINGTONE] = "440/1500,0/3500";
_toneZone[ZID_FRANCE][Tone::TONE_CONGESTION] = "440/250,0/250";
_toneZone[ZID_AUSTRALIA][Tone::TONE_DIALTONE] = "413+438";
_toneZone[ZID_AUSTRALIA][Tone::TONE_BUSY] = "425/375,0/375";
_toneZone[ZID_AUSTRALIA][Tone::TONE_RINGTONE] =
"413+438/400,0/200,413+438/400,0/2000";
_toneZone[ZID_AUSTRALIA][Tone::TONE_CONGESTION] = "425/375,0/375,420/375,8/375";
_toneZone[ZID_UNITED_KINGDOM][Tone::TONE_DIALTONE] = "350+440";
_toneZone[ZID_UNITED_KINGDOM][Tone::TONE_BUSY] = "400/375,0/375";
_toneZone[ZID_UNITED_KINGDOM][Tone::TONE_RINGTONE] =
"400+450/400,0/200,400+450/400,0/2000";
_toneZone[ZID_UNITED_KINGDOM][Tone::TONE_CONGESTION] =
"400/400,0/350,400/225,0/525";
_toneZone[ZID_SPAIN][Tone::TONE_DIALTONE] = "425";
_toneZone[ZID_SPAIN][Tone::TONE_BUSY] = "425/200,0/200";
_toneZone[ZID_SPAIN][Tone::TONE_RINGTONE] = "425/1500,0/3000";
_toneZone[ZID_SPAIN][Tone::TONE_CONGESTION] =
"425/200,0/200,425/200,0/200,425/200,0/600";
_toneZone[ZID_ITALY][Tone::TONE_DIALTONE] = "425/600,0/1000,425/200,0/200";
_toneZone[ZID_ITALY][Tone::TONE_BUSY] = "425/500,0/500";
_toneZone[ZID_ITALY][Tone::TONE_RINGTONE] = "425/1000,0/4000";
_toneZone[ZID_ITALY][Tone::TONE_CONGESTION] = "425/200,0/200";
_toneZone[ZID_JAPAN][Tone::TONE_DIALTONE] = "400";
_toneZone[ZID_JAPAN][Tone::TONE_BUSY] = "400/500,0/500";
_toneZone[ZID_JAPAN][Tone::TONE_RINGTONE] = "400+15/1000,0/2000";
_toneZone[ZID_JAPAN][Tone::TONE_CONGESTION] = "400/500,0/500";
}
std::string
ToneList::getDefinition (COUNTRYID countryId, Tone::TONEID toneId)
{
if (toneId == Tone::TONE_NULL) {
return "";
}
return _toneZone[countryId][toneId];
}
ToneList::COUNTRYID
ToneList::getCountryId (const std::string& countryName)
{
if (countryName.compare ("North America") == 0) {
return ZID_NORTH_AMERICA;
} else if (countryName.compare ("France") == 0) {
return ZID_FRANCE;
} else if (countryName.compare ("Australia") == 0) {
return ZID_AUSTRALIA;
} else if (countryName.compare ("United Kingdom") == 0) {
return ZID_UNITED_KINGDOM;
} else if (countryName.compare ("Spain") == 0) {
return ZID_SPAIN;
} else if (countryName.compare ("Italy") == 0) {
return ZID_ITALY;
} else if (countryName.compare ("Japan") == 0) {
return ZID_JAPAN;
} else {
return _defaultCountryId; // default, we don't want segmentation fault
}
} }
TelephoneTone::TelephoneTone (const std::string& countryName, unsigned int sampleRate) : TelephoneTone::TelephoneTone (const std::string& countryName, unsigned int sampleRate) :
_currentTone (Tone::TONE_NULL), _currentTone (Tone::TONE_NULL)
_toneList()
{ {
_debug ("TelephoneTone: Generate new telephone tones at %u Hz", sampleRate); TelephoneTone::COUNTRYID countryId = getCountryId (countryName);
ToneList::COUNTRYID countryId = _toneList.getCountryId (countryName);
_tone[Tone::TONE_DIALTONE] = new Tone (_toneList.getDefinition (countryId, Tone::TONE_DIALTONE), sampleRate);
_tone[Tone::TONE_BUSY] = new Tone (_toneList.getDefinition (countryId, Tone::TONE_BUSY), sampleRate);
_tone[Tone::TONE_RINGTONE] = new Tone (_toneList.getDefinition (countryId, Tone::TONE_RINGTONE), sampleRate);
_tone[Tone::TONE_CONGESTION] = new Tone (_toneList.getDefinition (countryId, Tone::TONE_CONGESTION), 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);
} }
TelephoneTone::~TelephoneTone() TelephoneTone::~TelephoneTone()
{ {
for (int i=0; i<_toneList.getNbTone(); i++) { for (size_t i=0; i < Tone::TONE_NULL; i++)
delete _tone[i]; delete _tone[i];
_tone[i] = 0;
}
} }
void void
TelephoneTone::setCurrentTone (Tone::TONEID toneId) TelephoneTone::setCurrentTone (Tone::TONEID toneId)
{ {
if (toneId != Tone::TONE_NULL && _currentTone != toneId) { if (toneId != Tone::TONE_NULL && _currentTone != toneId)
_tone[toneId]->reset(); _tone[toneId]->reset();
}
_currentTone = toneId; _currentTone = toneId;
} }
...@@ -153,17 +120,8 @@ TelephoneTone::setCurrentTone (Tone::TONEID toneId) ...@@ -153,17 +120,8 @@ TelephoneTone::setCurrentTone (Tone::TONEID toneId)
Tone* Tone*
TelephoneTone::getCurrentTone() TelephoneTone::getCurrentTone()
{ {
if (_currentTone == Tone::TONE_NULL) { if (_currentTone == Tone::TONE_NULL)
return 0; return NULL;
}
return _tone[_currentTone]; return _tone[_currentTone];
} }
bool
TelephoneTone::shouldPlay()
{
return ( (_currentTone != Tone::TONE_NULL) ? true : false);
}
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
* Inspired by tonegenerator of * Inspired by tonegenerator of
* Laurielle Lea <laurielle.lea@savoirfairelinux.com> (2004) * Laurielle Lea <laurielle.lea@savoirfairelinux.com> (2004)
* *
*
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or * the Free Software Foundation; either version 3 of the License, or
...@@ -36,96 +37,28 @@ ...@@ -36,96 +37,28 @@
#include "tone.h" #include "tone.h"
/** class TelephoneTone
* @file tonelist.h
* @brief Manages the different kind of tones according to the country
*/
class ToneList
{ {
public: public:
/**
* Constructor
*/
ToneList();
/**
* Destructor
*/
~ToneList();
/** Countries */
enum COUNTRYID {
ZID_NORTH_AMERICA = 0,
ZID_FRANCE,
ZID_AUSTRALIA,
ZID_UNITED_KINGDOM,
ZID_SPAIN,
ZID_ITALY,
ZID_JAPAN
};
/**
* Get the string definition of a tone
* return the default country or default tone if id are invalid
* @param countryId The country Id, see ToneList constructor for the list
* @param toneId The toneId
* @return std::string A string definition of the tone
*/
std::string getDefinition (COUNTRYID countryId, Tone::TONEID toneId);
/**
* Get the country id associate to a country name
* return the default country id if not found
* The default tone/country are set inside the ToneList constructor
* @param countryName countryName, see the ToneList constructor list
* @return COUNTRYID Country Id or default Id
*/
COUNTRYID getCountryId (const std::string& countryName);
/** @return int The number of tones */
int getNbTone() {
return _nbTone;
}
private:
// Copy Constructor
ToneList (const ToneList& rh);
// Assignment Operator
ToneList& operator= (const ToneList& rh);
void initToneDefinition(); /** Countries */
std::string _toneZone[TONE_NBCOUNTRY][TONE_NBTONE]; enum COUNTRYID {
int _nbTone; ZID_NORTH_AMERICA = 0,
int _nbCountry; ZID_FRANCE,
COUNTRYID _defaultCountryId; ZID_AUSTRALIA,
}; ZID_UNITED_KINGDOM,
ZID_SPAIN,
ZID_ITALY,
ZID_JAPAN,
ZID_COUNTRIES,
};
/**
* @author Yan Morin <yan.morin@savoirfairelinux.com>
*/
class TelephoneTone
{
public:
/** Initialize the toneList and set the current tone to null */
TelephoneTone (const std::string& countryName, unsigned int sampleRate); TelephoneTone (const std::string& countryName, unsigned int sampleRate);
~TelephoneTone(); ~TelephoneTone();
/** send TONE::ZT_TONE_NULL to stop the playing */
void setCurrentTone (Tone::TONEID toneId); void setCurrentTone (Tone::TONEID toneId);
/**
* @return the currentTone after setting it with setCurrentTone
* 0 if the current tone is null
*/
Tone* getCurrentTone(); Tone* getCurrentTone();
/** @return true if you should play the tone (CurrentTone is not NULL) */
bool shouldPlay();
private: private:
// Copy Constructor // Copy Constructor
TelephoneTone (const TelephoneTone& rh); TelephoneTone (const TelephoneTone& rh);
...@@ -133,9 +66,10 @@ class TelephoneTone ...@@ -133,9 +66,10 @@ class TelephoneTone
// Assignment Operator // Assignment Operator
TelephoneTone& operator= (const TelephoneTone& rh); TelephoneTone& operator= (const TelephoneTone& rh);
Tone* _tone[TONE_NBTONE]; static COUNTRYID getCountryId (const std::string& countryName);
Tone* _tone[Tone::TONE_NULL];
Tone::TONEID _currentTone; Tone::TONEID _currentTone;
ToneList _toneList;
}; };
#endif #endif
...@@ -211,7 +211,8 @@ bool ManagerImpl::outgoingCall (const std::string& account_id, ...@@ -211,7 +211,8 @@ bool ManagerImpl::outgoingCall (const std::string& account_id,
std::string to_cleaned(NumberCleaner::clean(to, prefix)); std::string to_cleaned(NumberCleaner::clean(to, prefix));
Call::CallConfiguration callConfig = checkCallConfiguration (call_id, to_cleaned); Call::CallConfiguration callConfig = (to_cleaned.find (SIP_SCHEME) == 0 or to_cleaned.find (SIPS_SCHEME) == 0) ? Call::IPtoIP : Call::Classic;
associateConfigToCall(call_id, callConfig); associateConfigToCall(call_id, callConfig);
// in any cases we have to detach from current communication // in any cases we have to detach from current communication
...@@ -2905,11 +2906,6 @@ void ManagerImpl::setHookSettings (const std::map<std::string, std::string>& set ...@@ -2905,11 +2906,6 @@ void ManagerImpl::setHookSettings (const std::map<std::string, std::string>& set
// saveConfig(); // saveConfig();
} }
Call::CallConfiguration ManagerImpl::checkCallConfiguration (const std::string& id, const std::string &to)
{
return (to.find (SIP_SCHEME) == 0 or to.find (SIPS_SCHEME) == 0) ? Call::IPtoIP : Call::Classic;
}
bool ManagerImpl::associateConfigToCall (const std::string& callID, bool ManagerImpl::associateConfigToCall (const std::string& callID,
Call::CallConfiguration config) Call::CallConfiguration config)
{ {
......
...@@ -1224,11 +1224,6 @@ class ManagerImpl ...@@ -1224,11 +1224,6 @@ class ManagerImpl
*/ */
sfl::InstantMessaging *_imModule; sfl::InstantMessaging *_imModule;
/**
* Check if the call is a classic call or a direct IP-to-IP call
*/
Call::CallConfiguration checkCallConfiguration (const std::string& id, const std::string& to);
Conf::YamlEmitter *emitter; Conf::YamlEmitter *emitter;
}; };
......
Supports Markdown
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