Skip to content
Snippets Groups Projects
Commit 8b402ee6 authored by Alexandre Savard's avatar Alexandre Savard
Browse files
parents f0c23e62 f196d54e
Branches
Tags
No related merge requests found
...@@ -26,9 +26,4 @@ EXTRA_DIST = README.gentoo \ ...@@ -26,9 +26,4 @@ EXTRA_DIST = README.gentoo \
m4/lt~obsolete.m4 \ m4/lt~obsolete.m4 \
m4/ltoptions.m4 \ m4/ltoptions.m4 \
m4/ltsugar.m4 \ m4/ltsugar.m4 \
m4/ltversion.m4 \ m4/ltversion.m4
images/logo_ico.png \
images/sfl-logo.png \
images/sflphone_logo.png \
images/sflphone.png \
images/tray-icon.png
...@@ -33,13 +33,13 @@ ...@@ -33,13 +33,13 @@
*/ */
#include "audioloop.h" #include "audioloop.h"
#include <math.h> #include <cmath>
#include <numeric>
#include <cstring> #include <cstring>
#include <cassert> #include <cassert>
AudioLoop::AudioLoop() : buffer_(0), size_(0), pos_(0), sampleRate_(0) AudioLoop::AudioLoop() : buffer_(0), size_(0), pos_(0), sampleRate_(0)
{ {}
}
AudioLoop::~AudioLoop() AudioLoop::~AudioLoop()
{ {
...@@ -54,9 +54,12 @@ AudioLoop::getNext(SFLDataFormat* output, size_t total_samples, short volume) ...@@ -54,9 +54,12 @@ AudioLoop::getNext(SFLDataFormat* output, size_t total_samples, short volume)
if (size_ == 0) { if (size_ == 0) {
ERROR("AudioLoop: Error: Audio loop size is 0"); ERROR("AudioLoop: Error: Audio loop size is 0");
return; return;
} else if (pos >= size_) {
ERROR("AudioLoop: Error: Invalid loop position %d", pos);
return;
} }
while (total_samples) { while (total_samples > 0) {
size_t samples = total_samples; size_t samples = total_samples;
if (samples > (size_ - pos)) if (samples > (size_ - pos))
...@@ -65,13 +68,12 @@ AudioLoop::getNext(SFLDataFormat* output, size_t total_samples, short volume) ...@@ -65,13 +68,12 @@ AudioLoop::getNext(SFLDataFormat* output, size_t total_samples, short volume)
// short->char conversion // short->char conversion
memcpy(output, buffer_ + pos, samples * sizeof(SFLDataFormat)); memcpy(output, buffer_ + pos, samples * sizeof(SFLDataFormat));
// Scaling needed
if (volume != 100) { if (volume != 100) {
double gain = volume * 0.01; const double gain = volume * 0.01;
for (size_t i = 0; i < samples; i++) { for (size_t i = 0; i < samples; ++i, ++output)
*output *= gain; *output *= gain;
output++;
}
} else } else
output += samples; // this is the destination... output += samples; // this is the destination...
......
...@@ -62,18 +62,17 @@ SamplerateConverter::Short2FloatArray(const short *in, float *out, int len) ...@@ -62,18 +62,17 @@ SamplerateConverter::Short2FloatArray(const short *in, float *out, int len)
out[len] = (float) in[len] * .000030517578125f; out[len] = (float) in[len] * .000030517578125f;
} }
void SamplerateConverter::resample(SFLDataFormat* dataIn , SFLDataFormat* dataOut , int inputFreq , int outputFreq , int nbSamples) void SamplerateConverter::resample(SFLDataFormat *dataIn,
SFLDataFormat *dataOut, int inputFreq,
int outputFreq, int nbSamples)
{ {
double sampleFactor = (double) outputFreq / inputFreq; double sampleFactor = (double) outputFreq / inputFreq;
if (sampleFactor == 1.0) if (sampleFactor == 1.0)
return; return;
unsigned int outSamples = nbSamples * sampleFactor; const int outSamples = nbSamples * sampleFactor;
unsigned int maxSamples = outSamples; const unsigned int maxSamples = std::max(outSamples, nbSamples);
if (maxSamples < (unsigned int)nbSamples)
maxSamples = nbSamples;
if (maxSamples > samples_) { if (maxSamples > samples_) {
/* grow buffer if needed */ /* grow buffer if needed */
......
...@@ -58,7 +58,7 @@ class SamplerateConverter { ...@@ -58,7 +58,7 @@ class SamplerateConverter {
* @param SamplerateConverter2 The desired sample rate * @param SamplerateConverter2 The desired sample rate
* @param nbSamples The number of samples to process * @param nbSamples The number of samples to process
*/ */
void resample(SFLDataFormat* dataIn , SFLDataFormat* dataOut , int samplerate1 , int samplerate2 , int nbSamples); void resample(SFLDataFormat* dataIn , SFLDataFormat* dataOut , int oldrate, int newrate, int nbSamples);
/** /**
* Convert short table to floats for audio processing * Convert short table to floats for audio processing
......
...@@ -66,11 +66,11 @@ RawFile::RawFile(const std::string& name, sfl::AudioCodec* codec, unsigned int s ...@@ -66,11 +66,11 @@ RawFile::RawFile(const std::string& name, sfl::AudioCodec* codec, unsigned int s
file.read(fileBuffer,length); file.read(fileBuffer,length);
file.close(); file.close();
unsigned int frameSize = audioCodec_->getFrameSize(); const unsigned int frameSize = audioCodec_->getFrameSize();
unsigned int bitrate = audioCodec_->getBitRate() * 1000 / 8; const unsigned int bitrate = audioCodec_->getBitRate() * 1000 / 8;
unsigned int audioRate = audioCodec_->getClockRate(); const unsigned int audioRate = audioCodec_->getClockRate();
unsigned int encFrameSize = frameSize * bitrate / audioRate; const unsigned int encFrameSize = frameSize * bitrate / audioRate;
unsigned int decodedSize = length * (frameSize / encFrameSize); const unsigned int decodedSize = length * (frameSize / encFrameSize);
SFLDataFormat *monoBuffer = new SFLDataFormat[decodedSize]; SFLDataFormat *monoBuffer = new SFLDataFormat[decodedSize];
SFLDataFormat *bufpos = monoBuffer; SFLDataFormat *bufpos = monoBuffer;
...@@ -115,9 +115,9 @@ RawFile::RawFile(const std::string& name, sfl::AudioCodec* codec, unsigned int s ...@@ -115,9 +115,9 @@ RawFile::RawFile(const std::string& name, sfl::AudioCodec* codec, unsigned int s
} }
WaveFile::WaveFile(const std::string& fileName, unsigned int audioSamplingRate) WaveFile::WaveFile(const std::string& fileName, int newRate)
{ {
std::fstream fs(fileName.c_str(), std::ios_base::in); const std::fstream fs(fileName.c_str(), std::ios_base::in);
if (!fs) if (!fs)
throw AudioFileException("File " + fileName + " doesn't exist"); throw AudioFileException("File " + fileName + " doesn't exist");
...@@ -127,49 +127,48 @@ WaveFile::WaveFile(const std::string& fileName, unsigned int audioSamplingRate) ...@@ -127,49 +127,48 @@ WaveFile::WaveFile(const std::string& fileName, unsigned int audioSamplingRate)
fileStream.open(fileName.c_str(), std::ios::in | std::ios::binary); fileStream.open(fileName.c_str(), std::ios::in | std::ios::binary);
char riff[4] = { 0, 0, 0, 0 }; char riff[4] = { 0, 0, 0, 0 };
fileStream.read(riff, 4); fileStream.read(riff, sizeof riff / sizeof riff[0]);
if (strncmp("RIFF", riff, 4) != 0) if (strncmp("RIFF", riff, sizeof riff / sizeof riff[0]) != 0)
throw AudioFileException("File is not of RIFF format"); throw AudioFileException("File is not of RIFF format");
char fmt[4] = { 0, 0, 0, 0 }; char fmt[4] = { 0, 0, 0, 0 };
int maxIteration = 10; int maxIteration = 10;
while (maxIteration-- && strncmp("fmt ", fmt, 4)) while (maxIteration-- and strncmp("fmt ", fmt, sizeof fmt / sizeof fmt[0]))
fileStream.read(fmt, 4); fileStream.read(fmt, sizeof fmt / sizeof fmt[0]);
if (maxIteration == 0) if (maxIteration == 0)
throw AudioFileException("Could not find \"fmt \" chunk"); throw AudioFileException("Could not find \"fmt \" chunk");
SINT32 chunk_size; // fmt chunk size SINT32 chunkSize; // fmt chunk size
fileStream.read(reinterpret_cast<char *>(&chunkSize), sizeof chunkSize); // Read fmt chunk size.
unsigned short formatTag; // data compression tag unsigned short formatTag; // data compression tag
fileStream.read(reinterpret_cast<char *>(&formatTag), sizeof formatTag);
fileStream.read(reinterpret_cast<char*>(&chunk_size), 4); // Read fmt chunk size.
fileStream.read(reinterpret_cast<char*>(&formatTag), 2);
if (formatTag != 1) // PCM = 1, FLOAT = 3 if (formatTag != 1) // PCM = 1, FLOAT = 3
throw AudioFileException("File contains an unsupported data format type"); throw AudioFileException("File contains an unsupported data format type");
// Get number of channels from the header. // Get number of channels from the header.
SINT16 chan; SINT16 chan;
fileStream.read((char*) &chan, 2); fileStream.read(reinterpret_cast<char *>(&chan), sizeof chan);
if (chan > 2) if (chan > 2)
throw AudioFileException("WaveFile: unsupported number of channels"); throw AudioFileException("WaveFile: unsupported number of channels");
// Get file sample rate from the header. // Get file sample rate from the header.
SINT32 srate; SINT32 fileRate;
fileStream.read((char*) &srate, 4); fileStream.read(reinterpret_cast<char *>(&fileRate), sizeof fileRate);
SINT32 avgb; SINT32 avgb;
fileStream.read((char*) &avgb, 4); fileStream.read(reinterpret_cast<char *>(&avgb), sizeof avgb);
SINT16 blockal; SINT16 blockal;
fileStream.read((char*) &blockal, 2); fileStream.read(reinterpret_cast<char *>(&blockal), sizeof blockal);
// Determine the data type // Determine the data type
SINT16 dt; SINT16 dt;
fileStream.read((char*) &dt, 2); fileStream.read(reinterpret_cast<char *>(&dt), sizeof dt);
if (dt != 8 && dt != 16 && dt != 32) if (dt != 8 && dt != 16 && dt != 32)
throw AudioFileException("File's bits per sample with is not supported"); throw AudioFileException("File's bits per sample with is not supported");
...@@ -178,46 +177,45 @@ WaveFile::WaveFile(const std::string& fileName, unsigned int audioSamplingRate) ...@@ -178,46 +177,45 @@ WaveFile::WaveFile(const std::string& fileName, unsigned int audioSamplingRate)
char data[4] = { 0, 0, 0, 0 }; char data[4] = { 0, 0, 0, 0 };
maxIteration = 10; maxIteration = 10;
while (maxIteration-- && strncmp("data", data, 4)) while (maxIteration-- && strncmp("data", data, sizeof data / sizeof data[0]))
fileStream.read(data, 4); fileStream.read(data, sizeof data / sizeof data[0]);
// Samplerate converter initialized with 88200 sample long // Samplerate converter initialized with 88200 sample long
int converterSamples = ((unsigned int)srate > audioSamplingRate) ? srate : audioSamplingRate; SamplerateConverter converter(std::max(fileRate, newRate));
SamplerateConverter converter_(converterSamples);
// Get length of data from the header. // Get length of data from the header.
SINT32 bytes; SINT32 bytes;
fileStream.read((char*) &bytes, 4); fileStream.read(reinterpret_cast<char *>(&bytes), sizeof bytes);
unsigned long nbSamples = 8 * bytes / dt / chan; // sample frames
DEBUG("WaveFile: frame size %ld, data size %d align %d rate %d avgbyte %d chunk size %d dt %d", // sample frames, should not be longer than a minute
nbSamples, bytes, blockal, srate, avgb, chunk_size, dt); int nbSamples = std::min(60 * fileRate, 8 * bytes / dt / chan);
// Should not be longer than a minute DEBUG("WaveFile: frame size %ld, data size %d align %d rate %d avgbyte %d "
if (nbSamples > static_cast<unsigned int>(60 * srate)) "chunk size %d dt %d", nbSamples, bytes, blockal, fileRate, avgb,
nbSamples = 60 * srate; chunkSize, dt);
SFLDataFormat *tempBuffer = new SFLDataFormat[nbSamples]; size_ = nbSamples;
SFLDataFormat *tempBuffer = new SFLDataFormat[size_];
fileStream.read(reinterpret_cast<char *>(tempBuffer), nbSamples * sizeof(SFLDataFormat)); fileStream.read(reinterpret_cast<char *>(tempBuffer),
nbSamples * sizeof(SFLDataFormat));
// mix two channels together if stereo // mix two channels together if stereo
if (chan == 2) { if (chan == 2) {
for (unsigned int i = 0; i < nbSamples - 1; i += 2) for (int i = 0, j = 0; i < nbSamples - 1; i += 2, ++j)
tempBuffer[static_cast<size_t>(i * 0.5)] = (tempBuffer[i] + tempBuffer[i + 1]) * 0.5; tempBuffer[j] = (tempBuffer[i] + tempBuffer[i + 1]) * 0.5;
nbSamples *= 0.5; nbSamples *= 0.5;
} }
if ((unsigned int) srate != audioSamplingRate) { if (fileRate != newRate) {
int outSamples = ((float) nbSamples * ((float) audioSamplingRate / (float) srate)); const float ratio = newRate / (float) fileRate;
buffer_ = new SFLDataFormat[outSamples]; const int outSamples = ceil(nbSamples * ratio);
converter_.resample(tempBuffer, buffer_, srate, audioSamplingRate, nbSamples); size_ = outSamples;
buffer_ = new SFLDataFormat[size_];
converter.resample(tempBuffer, buffer_, fileRate, newRate, nbSamples);
delete [] tempBuffer; delete [] tempBuffer;
} else } else
buffer_ = tempBuffer; buffer_ = tempBuffer;
size_ = nbSamples; sampleRate_ = newRate;
sampleRate_ = audioSamplingRate;
} }
...@@ -83,7 +83,7 @@ class WaveFile : public AudioFile { ...@@ -83,7 +83,7 @@ class WaveFile : public AudioFile {
* @param filename The absolute path to the file * @param filename The absolute path to the file
* @param sampleRate The sample rate to read it * @param sampleRate The sample rate to read it
*/ */
WaveFile(const std::string&, unsigned int); WaveFile(const std::string&, int);
}; };
#endif // __AUDIOFILE_H__ #endif // __AUDIOFILE_H__
...@@ -36,6 +36,7 @@ noinst_HEADERS = \ ...@@ -36,6 +36,7 @@ noinst_HEADERS = \
dbusmanager.h \ dbusmanager.h \
networkmanager_proxy.h \ networkmanager_proxy.h \
networkmanager.h \ networkmanager.h \
dbus_cpp.h \
$(BUILT_SOURCES) $(BUILT_SOURCES)
# Dbus service file # Dbus service file
......
...@@ -1548,7 +1548,7 @@ int SIPSessionReinvite(SIPCall *call) ...@@ -1548,7 +1548,7 @@ int SIPSessionReinvite(SIPCall *call)
void invite_session_state_changed_cb(pjsip_inv_session *inv, pjsip_event *e) void invite_session_state_changed_cb(pjsip_inv_session *inv, pjsip_event *e)
{ {
SIPCall *call = reinterpret_cast<SIPCall*>(inv->mod_data[mod_ua_.id]); SIPCall *call = static_cast<SIPCall*>(inv->mod_data[mod_ua_.id]);
if (call == NULL) if (call == NULL)
return; return;
...@@ -1620,7 +1620,7 @@ void sdp_request_offer_cb(pjsip_inv_session *inv, const pjmedia_sdp_session *off ...@@ -1620,7 +1620,7 @@ void sdp_request_offer_cb(pjsip_inv_session *inv, const pjmedia_sdp_session *off
void sdp_create_offer_cb(pjsip_inv_session *inv, pjmedia_sdp_session **p_offer) void sdp_create_offer_cb(pjsip_inv_session *inv, pjmedia_sdp_session **p_offer)
{ {
SIPCall *call = reinterpret_cast<SIPCall*>(inv->mod_data[mod_ua_.id]); SIPCall *call = static_cast<SIPCall*>(inv->mod_data[mod_ua_.id]);
std::string accountid(Manager::instance().getAccountFromCall(call->getCallId())); std::string accountid(Manager::instance().getAccountFromCall(call->getCallId()));
SIPAccount *account = dynamic_cast<SIPAccount *>(Manager::instance().getAccount(accountid)); SIPAccount *account = dynamic_cast<SIPAccount *>(Manager::instance().getAccount(accountid));
...@@ -1648,7 +1648,7 @@ void sdp_media_update_cb(pjsip_inv_session *inv, pj_status_t status) ...@@ -1648,7 +1648,7 @@ void sdp_media_update_cb(pjsip_inv_session *inv, pj_status_t status)
const pjmedia_sdp_session *remote_sdp; const pjmedia_sdp_session *remote_sdp;
const pjmedia_sdp_session *local_sdp; const pjmedia_sdp_session *local_sdp;
SIPCall *call = reinterpret_cast<SIPCall *>(inv->mod_data[mod_ua_.id]); SIPCall *call = static_cast<SIPCall *>(inv->mod_data[mod_ua_.id]);
if (call == NULL) { if (call == NULL) {
DEBUG("UserAgent: Call declined by peer, SDP negotiation stopped"); DEBUG("UserAgent: Call declined by peer, SDP negotiation stopped");
...@@ -1805,7 +1805,7 @@ void transaction_state_changed_cb(pjsip_inv_session *inv UNUSED, pjsip_transacti ...@@ -1805,7 +1805,7 @@ void transaction_state_changed_cb(pjsip_inv_session *inv UNUSED, pjsip_transacti
std::string formatedMessage = (char*) r_data->msg_info.msg->body->data; std::string formatedMessage = (char*) r_data->msg_info.msg->body->data;
// Try to determine who is the recipient of the message // Try to determine who is the recipient of the message
SIPCall *call = reinterpret_cast<SIPCall *>(inv->mod_data[mod_ua_.id]); SIPCall *call = static_cast<SIPCall *>(inv->mod_data[mod_ua_.id]);
if (!call) if (!call)
return; return;
...@@ -1844,7 +1844,7 @@ void transaction_state_changed_cb(pjsip_inv_session *inv UNUSED, pjsip_transacti ...@@ -1844,7 +1844,7 @@ void transaction_state_changed_cb(pjsip_inv_session *inv UNUSED, pjsip_transacti
} }
} }
void update_contact_header(struct pjsip_regc_cbparam *param, SIPAccount *account) void update_contact_header(pjsip_regc_cbparam *param, SIPAccount *account)
{ {
SIPVoIPLink *siplink = dynamic_cast<SIPVoIPLink *>(account->getVoIPLink()); SIPVoIPLink *siplink = dynamic_cast<SIPVoIPLink *>(account->getVoIPLink());
...@@ -1908,7 +1908,7 @@ void update_contact_header(struct pjsip_regc_cbparam *param, SIPAccount *account ...@@ -1908,7 +1908,7 @@ void update_contact_header(struct pjsip_regc_cbparam *param, SIPAccount *account
pj_pool_release(pool); pj_pool_release(pool);
} }
void registration_cb(struct pjsip_regc_cbparam *param) void registration_cb(pjsip_regc_cbparam *param)
{ {
SIPAccount *account = static_cast<SIPAccount *>(param->token); SIPAccount *account = static_cast<SIPAccount *>(param->token);
...@@ -1990,7 +1990,7 @@ void registration_cb(struct pjsip_regc_cbparam *param) ...@@ -1990,7 +1990,7 @@ void registration_cb(struct pjsip_regc_cbparam *param)
void onCallTransfered(pjsip_inv_session *inv, pjsip_rx_data *rdata) void onCallTransfered(pjsip_inv_session *inv, pjsip_rx_data *rdata)
{ {
SIPCall *currentCall = reinterpret_cast<SIPCall *>(inv->mod_data[mod_ua_.id]); SIPCall *currentCall = static_cast<SIPCall *>(inv->mod_data[mod_ua_.id]);
if (currentCall == NULL) if (currentCall == NULL)
return; return;
...@@ -2020,8 +2020,7 @@ void transfer_client_cb(pjsip_evsub *sub, pjsip_event *event) ...@@ -2020,8 +2020,7 @@ void transfer_client_cb(pjsip_evsub *sub, pjsip_event *event)
break; break;
case PJSIP_EVSUB_STATE_ACTIVE: { case PJSIP_EVSUB_STATE_ACTIVE: {
SIPVoIPLink *link = static_cast<SIPVoIPLink *>(pjsip_evsub_get_mod_data(sub, mod_ua_.id));
SIPVoIPLink *link = reinterpret_cast<SIPVoIPLink *>(pjsip_evsub_get_mod_data(sub, mod_ua_.id));
if (!link or !event) if (!link or !event)
return; return;
...@@ -2093,7 +2092,7 @@ std::string fetchHeaderValue(pjsip_msg *msg, const std::string &field) ...@@ -2093,7 +2092,7 @@ std::string fetchHeaderValue(pjsip_msg *msg, const std::string &field)
{ {
pj_str_t name = pj_str((char*) field.c_str()); pj_str_t name = pj_str((char*) field.c_str());
pjsip_generic_string_hdr *hdr = (pjsip_generic_string_hdr*) pjsip_msg_find_hdr_by_name(msg, &name, NULL); pjsip_generic_string_hdr *hdr = static_cast<pjsip_generic_string_hdr*>(pjsip_msg_find_hdr_by_name(msg, &name, NULL));
if (!hdr) if (!hdr)
return ""; return "";
...@@ -2124,7 +2123,7 @@ std::vector<std::string> SIPVoIPLink::getAllIpInterfaceByName() ...@@ -2124,7 +2123,7 @@ std::vector<std::string> SIPVoIPLink::getAllIpInterfaceByName()
if (sock >= 0) { if (sock >= 0) {
if (ioctl(sock, SIOCGIFCONF, &ifconf) >= 0) if (ioctl(sock, SIOCGIFCONF, &ifconf) >= 0)
for (unsigned i = 0; i < ifconf.ifc_len/sizeof(struct ifreq); i++) for (unsigned i = 0; i < ifconf.ifc_len / sizeof(ifreq); ++i)
ifaceList.push_back(std::string(ifreqs[i].ifr_name)); ifaceList.push_back(std::string(ifreqs[i].ifr_name));
close(sock); close(sock);
...@@ -2150,7 +2149,7 @@ std::string SIPVoIPLink::getInterfaceAddrFromName(const std::string &ifaceName) ...@@ -2150,7 +2149,7 @@ std::string SIPVoIPLink::getInterfaceAddrFromName(const std::string &ifaceName)
ioctl(fd, SIOCGIFADDR, &ifr); ioctl(fd, SIOCGIFADDR, &ifr);
close(fd); close(fd);
sockaddr_in *saddr_in = (struct sockaddr_in *) &ifr.ifr_addr; sockaddr_in *saddr_in = (sockaddr_in *) &ifr.ifr_addr;
return inet_ntoa(saddr_in->sin_addr); return inet_ntoa(saddr_in->sin_addr);
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment