Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
savoirfairelinux
jami-daemon
Commits
644cbad3
Commit
644cbad3
authored
Sep 20, 2011
by
Rafaël Carré
Browse files
Simplify ToneList
parent
0b4c0216
Changes
7
Show whitespace changes
Inline
Side-by-side
daemon/src/audio/audioloop.cpp
View file @
644cbad3
...
...
@@ -35,6 +35,7 @@
#include
"audioloop.h"
#include
<math.h>
#include
<cstring>
#include
<cassert>
AudioLoop
::
AudioLoop
()
:
_buffer
(
0
),
_size
(
0
),
_pos
(
0
),
_sampleRate
(
0
)
{
...
...
@@ -46,9 +47,11 @@ AudioLoop::~AudioLoop()
}
void
AudioLoop
::
getNext
(
SFLDataFormat
*
output
,
in
t
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
)
{
_error
(
"AudioLoop: Error: Audio loop size is 0"
);
...
...
@@ -56,7 +59,7 @@ AudioLoop::getNext (SFLDataFormat* output, int total_samples, short volume)
}
while
(
total_samples
)
{
in
t
samples
=
total_samples
;
size_
t
samples
=
total_samples
;
if
(
samples
>
(
_size
-
pos
))
{
samples
=
_size
-
pos
;
...
...
@@ -65,7 +68,7 @@ AudioLoop::getNext (SFLDataFormat* output, int total_samples, short volume)
memcpy
(
output
,
_buffer
+
pos
,
samples
*
sizeof
(
SFLDataFormat
));
// short>char conversion
if
(
volume
!=
100
)
{
for
(
in
t
i
=
0
;
i
<
samples
;
i
++
)
{
for
(
size_
t
i
=
0
;
i
<
samples
;
i
++
)
{
*
output
=
(
*
output
*
volume
)
/
100
;
output
++
;
}
...
...
@@ -73,7 +76,6 @@ AudioLoop::getNext (SFLDataFormat* output, int total_samples, short volume)
output
+=
samples
;
// this is the destination...
}
// should adjust sound here, in output???
pos
=
(
pos
+
samples
)
%
_size
;
total_samples
-=
samples
;
...
...
daemon/src/audio/audioloop.h
View file @
644cbad3
...
...
@@ -61,7 +61,7 @@ class AudioLoop
* @param nb of int16 to send
* @param volume The volume
*/
void
getNext
(
SFLDataFormat
*
output
,
in
t
samples
,
short
volume
=
100
);
void
getNext
(
SFLDataFormat
*
output
,
size_
t
samples
,
short
volume
=
100
);
/**
* Reset the pointer position
...
...
@@ -74,7 +74,7 @@ class AudioLoop
* Accessor to the size of the buffer
* @return unsigned int The size
*/
unsigned
in
t
getSize
()
{
size_
t
getSize
()
{
return
_size
;
}
...
...
@@ -84,10 +84,10 @@ class AudioLoop
SFLDataFormat
*
_buffer
;
/** Number of samples inside the buffer */
in
t
_size
;
size_
t
_size
;
/** current position, set to 0, when initialize */
in
t
_pos
;
size_
t
_pos
;
/** Sample rate */
unsigned
int
_sampleRate
;
...
...
daemon/src/audio/sound/tone.h
View file @
644cbad3
...
...
@@ -36,9 +36,6 @@
#include
<string>
#include
"audio/audioloop.h"
#define TONE_NBTONE 4
#define TONE_NBCOUNTRY 7
#define TABLE_LENGTH 4096
/**
...
...
daemon/src/audio/sound/tonelist.cpp
View file @
644cbad3
...
...
@@ -32,120 +32,87 @@
*/
#include
"tonelist.h"
ToneList
::
ToneList
()
:
_nbTone
(
TONE_NBTONE
)
,
_nbCountry
(
TONE_NBCOUNTRY
),
_defaultCountryId
(
ZID_NORTH_AMERICA
)
{
initToneDefinition
();
}
ToneList
::~
ToneList
()
{
}
void
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
""
;
static
const
char
*
toneZone
[
TelephoneTone
::
ZID_COUNTRIES
][
Tone
::
TONE_NULL
]
=
{
{
// 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"
,
}
};
return
_toneZone
[
countryId
][
toneId
];
}
T
oneList
::
COUNTRYID
T
oneList
::
getCountryId
(
const
std
::
string
&
countryName
)
T
elephoneTone
::
COUNTRYID
T
elephoneTone
::
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
}
if
(
countryName
==
"North America"
)
return
ZID_NORTH_AMERICA
;
if
(
countryName
==
"France"
)
return
ZID_FRANCE
;
if
(
countryName
==
"Australia"
)
return
ZID_AUSTRALIA
;
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
;
return
ZID_NORTH_AMERICA
;
// default
}
TelephoneTone
::
TelephoneTone
(
const
std
::
string
&
countryName
,
unsigned
int
sampleRate
)
:
_currentTone
(
Tone
::
TONE_NULL
),
_toneList
()
_currentTone
(
Tone
::
TONE_NULL
)
{
_debug
(
"TelephoneTone: Generate new telephone tones at %u Hz"
,
sampleRate
);
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
);
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
);
}
TelephoneTone
::~
TelephoneTone
()
{
for
(
in
t
i
=
0
;
i
<
_toneList
.
getNbTone
()
;
i
++
)
{
for
(
size_
t
i
=
0
;
i
<
Tone
::
TONE_NULL
;
i
++
)
delete
_tone
[
i
];
_tone
[
i
]
=
0
;
}
}
void
TelephoneTone
::
setCurrentTone
(
Tone
::
TONEID
toneId
)
{
if
(
toneId
!=
Tone
::
TONE_NULL
&&
_currentTone
!=
toneId
)
{
if
(
toneId
!=
Tone
::
TONE_NULL
&&
_currentTone
!=
toneId
)
_tone
[
toneId
]
->
reset
();
}
_currentTone
=
toneId
;
}
...
...
@@ -153,17 +120,8 @@ TelephoneTone::setCurrentTone (Tone::TONEID toneId)
Tone
*
TelephoneTone
::
getCurrentTone
()
{
if
(
_currentTone
==
Tone
::
TONE_NULL
)
{
return
0
;
}
if
(
_currentTone
==
Tone
::
TONE_NULL
)
return
NULL
;
return
_tone
[
_currentTone
];
}
bool
TelephoneTone
::
shouldPlay
()
{
return
(
(
_currentTone
!=
Tone
::
TONE_NULL
)
?
true
:
false
);
}
daemon/src/audio/sound/tonelist.h
View file @
644cbad3
...
...
@@ -5,6 +5,7 @@
* Inspired by tonegenerator of
* Laurielle Lea <laurielle.lea@savoirfairelinux.com> (2004)
*
*
* 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
* the Free Software Foundation; either version 3 of the License, or
...
...
@@ -36,23 +37,9 @@
#include
"tone.h"
/**
* @file tonelist.h
* @brief Manages the different kind of tones according to the country
*/
class
ToneList
class
TelephoneTone
{
public:
/**
* Constructor
*/
ToneList
();
/**
* Destructor
*/
~
ToneList
();
/** Countries */
enum
COUNTRYID
{
...
...
@@ -62,70 +49,16 @@ class ToneList
ZID_UNITED_KINGDOM
,
ZID_SPAIN
,
ZID_ITALY
,
ZID_JAPAN
ZID_JAPAN
,
ZID_COUNTRIES
,
};
/**
* 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
();
std
::
string
_toneZone
[
TONE_NBCOUNTRY
][
TONE_NBTONE
];
int
_nbTone
;
int
_nbCountry
;
COUNTRYID
_defaultCountryId
;
};
/**
* @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
();
/** send TONE::ZT_TONE_NULL to stop the playing */
void
setCurrentTone
(
Tone
::
TONEID
toneId
);
/**
* @return the currentTone after setting it with setCurrentTone
* 0 if the current tone is null
*/
Tone
*
getCurrentTone
();
/** @return true if you should play the tone (CurrentTone is not NULL) */
bool
shouldPlay
();
private:
// Copy Constructor
TelephoneTone
(
const
TelephoneTone
&
rh
);
...
...
@@ -133,9 +66,10 @@ class TelephoneTone
// Assignment Operator
TelephoneTone
&
operator
=
(
const
TelephoneTone
&
rh
);
Tone
*
_tone
[
TONE_NBTONE
];
static
COUNTRYID
getCountryId
(
const
std
::
string
&
countryName
);
Tone
*
_tone
[
Tone
::
TONE_NULL
];
Tone
::
TONEID
_currentTone
;
ToneList
_toneList
;
};
#endif
daemon/src/managerimpl.cpp
View file @
644cbad3
...
...
@@ -211,7 +211,8 @@ bool ManagerImpl::outgoingCall (const std::string& account_id,
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
);
// 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
// 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
,
Call
::
CallConfiguration
config
)
{
...
...
daemon/src/managerimpl.h
View file @
644cbad3
...
...
@@ -1224,11 +1224,6 @@ class ManagerImpl
*/
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
;
};
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment