Commit 1e4bd1b2 authored by llea's avatar llea

Add volume control for speaker and micro

parent f7dafc63
...@@ -57,6 +57,8 @@ OBJS = \ ...@@ -57,6 +57,8 @@ OBJS = \
jpushbutton.o jpushbutton.moc.o \ jpushbutton.o jpushbutton.moc.o \
numerickeypad.o numerickeypad.moc.o \ numerickeypad.o numerickeypad.moc.o \
qtGUImainwindow.o qtGUImainwindow.moc.o \ qtGUImainwindow.o qtGUImainwindow.moc.o \
vector.o \
volumecontrol.o volumecontrol.moc.o \
stun.o udp.o stun.o udp.o
start: check prereq all start: check prereq all
......
...@@ -50,11 +50,11 @@ void AudioBuffer::resize (size_t newsize) ...@@ -50,11 +50,11 @@ void AudioBuffer::resize (size_t newsize)
} }
void void
AudioBuffer::setData (short *buf) { AudioBuffer::setData (short *buf, int vol) {
short *databuf = data; short *databuf = data;
for (int i = 0; i < (int)size; i++) { for (int i = 0; i < (int)size; i++) {
databuf[i] = buf[i]; databuf[i] = buf[i]*vol;
} }
} }
...@@ -62,7 +62,7 @@ public: ...@@ -62,7 +62,7 @@ public:
*/ */
void resize (size_t newsize); void resize (size_t newsize);
void setData (short *buf); void setData (short *buf, int);
void *data; void *data;
private: private:
......
...@@ -296,7 +296,6 @@ AudioDriversOSS::writeBuffer (void) { ...@@ -296,7 +296,6 @@ AudioDriversOSS::writeBuffer (void) {
size_t count = audio_buf.getSize(); size_t count = audio_buf.getSize();
short *buf = (short*)audio_buf.getData(); short *buf = (short*)audio_buf.getData();
audio_buf_info info; audio_buf_info info;
if (ioctl(audio_fd, SNDCTL_DSP_GETOSPACE, &info) == 0 ) { if (ioctl(audio_fd, SNDCTL_DSP_GETOSPACE, &info) == 0 ) {
......
...@@ -47,7 +47,7 @@ AudioRtp::AudioRtp (SIP *sip, Manager *manager) { ...@@ -47,7 +47,7 @@ AudioRtp::AudioRtp (SIP *sip, Manager *manager) {
this->manager = manager; this->manager = manager;
RTXThread = NULL; RTXThread = NULL;
if (!manager->useStun()) { if (!manager->useStun()) {
if (Config::gets("Signalisations", "SIP.sipproxy") == NULL) { if (Config::gets("Signalisations", "SIP.sipproxy") == "") {
svr = Config::gets("Signalisations", "SIP.sipproxy"); svr = Config::gets("Signalisations", "SIP.sipproxy");
} }
} else { } else {
...@@ -142,6 +142,7 @@ AudioRtpRTX::run (void) { ...@@ -142,6 +142,7 @@ AudioRtpRTX::run (void) {
unsigned char *data_to_send; unsigned char *data_to_send;
short *data_mute; short *data_mute;
short *data_from_mic; short *data_from_mic;
short *data_from_mic_tmp;
int i, int i,
compSize, compSize,
timestamp; timestamp;
...@@ -150,6 +151,7 @@ AudioRtpRTX::run (void) { ...@@ -150,6 +151,7 @@ AudioRtpRTX::run (void) {
data_for_speakers = new short[2048]; data_for_speakers = new short[2048];
data_from_mic = new short[1024]; data_from_mic = new short[1024];
data_from_mic_tmp = new short[1024];
data_to_send = new unsigned char[1024]; data_to_send = new unsigned char[1024];
data_mute = new short[1024]; data_mute = new short[1024];
...@@ -245,7 +247,7 @@ AudioRtpRTX::run (void) { ...@@ -245,7 +247,7 @@ AudioRtpRTX::run (void) {
if (!manager->mute) { if (!manager->mute) {
// i = audioDevice->readBuffer (320); // i = audioDevice->readBuffer (320);
// data_from_mic = (short*)manager->audiodriver->audio_buf.getData(); // data_from_mic = (short*)manager->audiodriver->audio_buf.getData();
// qDebug("audiortp data_from_mic 0x%d", data_from_mic); // qDebug("audiortp data_from_mic 0x%d", data_from_mic);
i = audioDevice->readBuffer (data_from_mic, 320); i = audioDevice->readBuffer (data_from_mic, 320);
} else { } else {
// When IP-phone user click on mute button, we read buffer of a // When IP-phone user click on mute button, we read buffer of a
...@@ -253,11 +255,14 @@ AudioRtpRTX::run (void) { ...@@ -253,11 +255,14 @@ AudioRtpRTX::run (void) {
i = audioDevice->readBuffer (data_mute, 320); i = audioDevice->readBuffer (data_mute, 320);
} }
for (int j = 0; j < i; j++)
data_from_mic_tmp[j] = data_from_mic[j]*manager->getMicVolume()/10;
// Encode acquired audio sample // Encode acquired audio sample
compSize = AudioCodec::codecEncode ( compSize = AudioCodec::codecEncode (
ac.handleCodecs[0], ac.handleCodecs[0],
data_to_send, data_to_send,
data_from_mic, i); data_from_mic_tmp, i);
// Send encoded audio sample // Send encoded audio sample
if (!sym) { if (!sym) {
...@@ -290,7 +295,8 @@ AudioRtpRTX::run (void) { ...@@ -290,7 +295,8 @@ AudioRtpRTX::run (void) {
// Write decoded data to sound device // Write decoded data to sound device
manager->audiodriver->audio_buf.resize(expandedSize); manager->audiodriver->audio_buf.resize(expandedSize);
manager->audiodriver->audio_buf.setData (data_for_speakers); manager->audiodriver->audio_buf.setData (data_for_speakers,
manager->getSpkrVolume()/10);
// i = audioDevice->writeBuffer (data_for_speakers, expandedSize); // i = audioDevice->writeBuffer (data_for_speakers, expandedSize);
i = audioDevice->writeBuffer (); i = audioDevice->writeBuffer ();
delete adu; delete adu;
...@@ -303,6 +309,7 @@ AudioRtpRTX::run (void) { ...@@ -303,6 +309,7 @@ AudioRtpRTX::run (void) {
delete[] data_for_speakers; delete[] data_for_speakers;
delete[] data_from_mic; delete[] data_from_mic;
delete[] data_from_mic_tmp;
delete[] data_mute; delete[] data_mute;
delete[] data_to_send; delete[] data_to_send;
this->exit(); this->exit();
......
This diff is collapsed.
...@@ -49,20 +49,18 @@ void ConfigurationPanel::init() ...@@ -49,20 +49,18 @@ void ConfigurationPanel::init()
sipproxy->setText(QString(Config::getchar("Signalisations", "SIP.sipproxy", ""))); sipproxy->setText(QString(Config::getchar("Signalisations", "SIP.sipproxy", "")));
playTones->setChecked(Config::get("Signalisations", "DTMF.playTones", (int)true)); playTones->setChecked(Config::get("Signalisations", "DTMF.playTones", (int)true));
pulseLength->setValue(Config::get("Signalisations", "DTMF.pulseLength", 250)); pulseLength->setValue(Config::get("Signalisations", "DTMF.pulseLength", 250));
sendDTMFas->setCurrentItem(Config::get("Signalisations", "DTMF.sendDTMFas",1)); sendDTMFas->setCurrentItem(Config::get("Signalisations", "DTMF.sendDTMFas",0));
STUNserver->setText(Config::get("Signalisations", "STUN.STUNserver", STUNserver->setText(Config::get("Signalisations", "STUN.STUNserver",
"stun.fwdnet.net:3478")); "stun.fwdnet.net:3478"));
useStunYes->setChecked(Config::get("Signalisations", "STUN.useStunYes", (int)false)); ((QRadioButton*)stunButtonGroup->find(Config::get("Signalisations", "STUN.useStun", 1)))->setChecked(true);
useStunNo->setChecked(Config::get("Signalisations", "STUN.useStunNo", (int)true));
// For audio tab // For audio tab
ossButton->setChecked(Config::get("Audio", "Drivers.driverOSS", (int)true)); ossButton->setChecked(Config::get("Audio", "Drivers.driverOSS", (int)true));
alsaButton->setChecked(Config::get("Audio", "Drivers.driverALSA", (int)false)); alsaButton->setChecked(Config::get("Audio", "Drivers.driverALSA", (int)false));
codec1->setCurrentText(QString(Config::getchar("Audio", "Codecs.codec1", "G711u"))); codec1->setCurrentText(QString(Config::getchar("Audio", "Codecs.codec1", "G711u")));
codec2->setCurrentText(QString(Config::getchar("Audio", "Codecs.codec2", "G711a"))); codec2->setCurrentText(QString(Config::getchar("Audio", "Codecs.codec2", "G711u")));
codec3->setCurrentText(QString(Config::getchar("Audio", "Codecs.codec3", "GSM"))); codec3->setCurrentText(QString(Config::getchar("Audio", "Codecs.codec3", "G711u")));
codec4->setCurrentText(QString(Config::getchar("Audio", "Codecs.codec4", "iLBC"))); codec4->setCurrentText(QString(Config::getchar("Audio", "Codecs.codec4", "G711u")));
codec5->setCurrentText(QString(Config::getchar("Audio", "Codecs.codec5", "SPEEX"))); codec5->setCurrentText(QString(Config::getchar("Audio", "Codecs.codec5", "G711u")));
// For preferences tab // For preferences tab
SkinChoice->setCurrentText(QString(Config::getchar( SkinChoice->setCurrentText(QString(Config::getchar(
...@@ -118,8 +116,6 @@ void ConfigurationPanel::saveSlot() ...@@ -118,8 +116,6 @@ void ConfigurationPanel::saveSlot()
Config::set("Signalisations", "DTMF.playTones", playTones->isChecked()); Config::set("Signalisations", "DTMF.playTones", playTones->isChecked());
Config::set("Signalisations", "DTMF.sendDTMFas" , sendDTMFas->currentItem()); Config::set("Signalisations", "DTMF.sendDTMFas" , sendDTMFas->currentItem());
Config::set("Signalisations", "STUN.STUNserver", STUNserver->text()); Config::set("Signalisations", "STUN.STUNserver", STUNserver->text());
Config::set("Signalisations", "STUN.useStunYes", useStunYes->isChecked());
Config::set("Signalisations", "STUN.useStunNo", useStunNo->isChecked());
Config::set("Audio", "Drivers.driverOSS", ossButton->isChecked()); Config::set("Audio", "Drivers.driverOSS", ossButton->isChecked());
Config::set("Audio", "Drivers.driverALSA", alsaButton->isChecked()); Config::set("Audio", "Drivers.driverALSA", alsaButton->isChecked());
...@@ -209,6 +205,7 @@ void ConfigurationPanel::changeTabSlot() ...@@ -209,6 +205,7 @@ void ConfigurationPanel::changeTabSlot()
} }
void ConfigurationPanel::useStunSlot(int id)
{
Config::set("Signalisations", "STUN.useStun", id);
}
This diff is collapsed.
/**************************************************************************** /****************************************************************************
** Form interface generated from reading ui file 'configurationpanel.ui' ** Form interface generated from reading ui file 'configurationpanel.ui'
** **
** Created: Wed Jan 26 14:28:43 2005 ** Created: Fri Jan 28 18:58:55 2005
** by: The User Interface Compiler ($Id$) ** by: The User Interface Compiler ($Id$)
** **
** WARNING! All changes made in this file will be lost! ** WARNING! All changes made in this file will be lost!
...@@ -64,12 +64,12 @@ public: ...@@ -64,12 +64,12 @@ public:
QLabel* textLabel1_3; QLabel* textLabel1_3;
QLabel* textLabel3_2; QLabel* textLabel3_2;
QWidget* STUNPage; QWidget* STUNPage;
QButtonGroup* buttonGroup3;
QRadioButton* useStunYes;
QRadioButton* useStunNo;
QGroupBox* groupBox3; QGroupBox* groupBox3;
QLabel* textLabel1_5; QLabel* textLabel1_5;
QLineEdit* STUNserver; QLineEdit* STUNserver;
QButtonGroup* stunButtonGroup;
QRadioButton* useStunYes;
QRadioButton* useStunNo;
QWidget* DTMFPage; QWidget* DTMFPage;
QGroupBox* SettingsDTMF; QGroupBox* SettingsDTMF;
QCheckBox* playTones; QCheckBox* playTones;
...@@ -121,15 +121,16 @@ public: ...@@ -121,15 +121,16 @@ public:
public slots: public slots:
virtual void saveSlot(); virtual void saveSlot();
virtual void changeTabSlot(); virtual void changeTabSlot();
virtual void useStunSlot( int id );
protected: protected:
QGridLayout* ConfigurationPanelLayout; QGridLayout* ConfigurationPanelLayout;
QVBoxLayout* layout8; QVBoxLayout* layout8;
QHBoxLayout* layout7; QHBoxLayout* layout7;
QSpacerItem* Horizontal_Spacing2; QSpacerItem* Horizontal_Spacing2;
QVBoxLayout* layout14; QVBoxLayout* layout17;
QGridLayout* groupBox1Layout; QGridLayout* groupBox1Layout;
QVBoxLayout* buttonGroup3Layout; QVBoxLayout* stunButtonGroupLayout;
QGridLayout* SettingsDTMFLayout; QGridLayout* SettingsDTMFLayout;
QVBoxLayout* layout11; QVBoxLayout* layout11;
QHBoxLayout* layout10; QHBoxLayout* layout10;
...@@ -143,7 +144,7 @@ protected: ...@@ -143,7 +144,7 @@ protected:
QHBoxLayout* layout11_2; QHBoxLayout* layout11_2;
QVBoxLayout* layout9; QVBoxLayout* layout9;
QVBoxLayout* layout10_2; QVBoxLayout* layout10_2;
QVBoxLayout* layout17; QVBoxLayout* layout17_2;
QHBoxLayout* layout16; QHBoxLayout* layout16;
QSpacerItem* spacer5; QSpacerItem* spacer5;
QHBoxLayout* layout16_2; QHBoxLayout* layout16_2;
......
...@@ -84,6 +84,9 @@ Manager::Manager (QString *Dc = NULL) { ...@@ -84,6 +84,9 @@ Manager::Manager (QString *Dc = NULL) {
// show configuration panel // show configuration panel
gui()->configuration(); gui()->configuration();
} }
spkr_volume = 10;
mic_volume = 10;
} }
Manager::~Manager (void) { Manager::~Manager (void) {
...@@ -132,7 +135,7 @@ void ...@@ -132,7 +135,7 @@ void
Manager::selectAudioDriver (void) { Manager::selectAudioDriver (void) {
this->audiodriver = new AudioDriversOSS (); this->audiodriver = new AudioDriversOSS ();
// TODO remplacer par ce qui suit ad ALSA sera implement // TODO remplacer par ce qui suit qd ALSA sera implement
#if 0 #if 0
if (Config::getb("Audio", "Drivers.driverOSS")) { if (Config::getb("Audio", "Drivers.driverOSS")) {
this->audiodriver = new AudioDriversOSS (); this->audiodriver = new AudioDriversOSS ();
...@@ -525,3 +528,13 @@ Manager::nameDisplay (char *name) { ...@@ -525,3 +528,13 @@ Manager::nameDisplay (char *name) {
gui()->lcd->clearBuffer(); gui()->lcd->clearBuffer();
gui()->lcd->appendText(name); gui()->lcd->appendText(name);
} }
void
Manager::spkrSoundVolume (int val) {
spkr_volume = val;
}
void
Manager::micSoundVolume (int val) {
mic_volume = val;
}
...@@ -20,7 +20,6 @@ ...@@ -20,7 +20,6 @@
#ifndef __MANAGER_H__ #ifndef __MANAGER_H__
#define __MANAGER_H__ #define __MANAGER_H__
#include "audiodrivers.h" #include "audiodrivers.h"
#include "phoneline.h" #include "phoneline.h"
#include "../stund/stun.h" #include "../stund/stun.h"
...@@ -91,6 +90,10 @@ public: ...@@ -91,6 +90,10 @@ public:
void congestion (bool); void congestion (bool);
void errorDisplay (char*); void errorDisplay (char*);
void nameDisplay (char*); void nameDisplay (char*);
void spkrSoundVolume (int);
void micSoundVolume (int);
inline int getSpkrVolume (void) { return spkr_volume; }
inline int getMicVolume (void) { return mic_volume; }
private: private:
bool b_ringing; bool b_ringing;
...@@ -98,6 +101,8 @@ private: ...@@ -98,6 +101,8 @@ private:
bool b_congestion; bool b_congestion;
int firewallPort; int firewallPort;
QString firewallAddr; QString firewallAddr;
int spkr_volume;
int mic_volume;
void sip_init (void); void sip_init (void);
bool createSettingsPath (void); bool createSettingsPath (void);
......
/**************************************************************************** /****************************************************************************
** Form implementation generated from reading ui file 'phonebook.ui' ** Form implementation generated from reading ui file 'phonebook.ui'
** **
** Created: Wed Jan 26 14:28:43 2005 ** Created: Fri Jan 28 18:58:54 2005
** by: The User Interface Compiler ($Id$) ** by: The User Interface Compiler ($Id$)
** **
** WARNING! All changes made in this file will be lost! ** WARNING! All changes made in this file will be lost!
......
/**************************************************************************** /****************************************************************************
** Form interface generated from reading ui file 'phonebook.ui' ** Form interface generated from reading ui file 'phonebook.ui'
** **
** Created: Wed Jan 26 14:28:43 2005 ** Created: Fri Jan 28 18:58:54 2005
** by: The User Interface Compiler ($Id$) ** by: The User Interface Compiler ($Id$)
** **
** WARNING! All changes made in this file will be lost! ** WARNING! All changes made in this file will be lost!
......
...@@ -32,7 +32,32 @@ Point::Point (const char* filename) { ...@@ -32,7 +32,32 @@ Point::Point (const char* filename) {
} }
Point::~Point (void) { Point::~Point (void) {
delete skinConfigTree; if (skinConfigTree != NULL) {
delete skinConfigTree;
skinConfigTree = NULL;
}
}
/**
* Extract the substring before the comma
*/
string
Point::getSubstrX (const char* key) {
char * value = skinConfigTree->getValue(NULL, key);
string tmp(value);
int index = tmp.find(',');
return tmp.substr(0, index);
}
/**
* Extract the substring after the comma
*/
string
Point::getSubstrY (const char* key) {
char * value = skinConfigTree->getValue(NULL, key);
string tmp(value);
int index = tmp.find(',');
return tmp.substr(index + 1, tmp.length() - index);
} }
/** /**
...@@ -40,11 +65,22 @@ Point::~Point (void) { ...@@ -40,11 +65,22 @@ Point::~Point (void) {
*/ */
int int
Point::getX (const char* key) { Point::getX (const char* key) {
/*
char * value = skinConfigTree->getValue(NULL, key); char * value = skinConfigTree->getValue(NULL, key);
string tmp(value); string tmp(value);
int index = tmp.find(','); int index = tmp.find(',');
int toto = atoi((tmp.substr(0, index)).data()); return atoi((tmp.substr(0, index)).data());
return toto; */
int index;
string tmp = getSubstrX(key);
if (getDirection(key) == HORIZONTAL) {
index = tmp.find('-');
return atoi((tmp.substr(0, tmp.length() - index)).data());
} else {
return atoi(tmp.data());
}
} }
/** /**
...@@ -52,6 +88,7 @@ Point::getX (const char* key) { ...@@ -52,6 +88,7 @@ Point::getX (const char* key) {
*/ */
int int
Point::getY (const char* key) { Point::getY (const char* key) {
/*
char * value = skinConfigTree->getValue(NULL, key); char * value = skinConfigTree->getValue(NULL, key);
string tmp(value); string tmp(value);
int index1, index2; int index1, index2;
...@@ -65,6 +102,16 @@ Point::getY (const char* key) { ...@@ -65,6 +102,16 @@ Point::getY (const char* key) {
index2 = tmp.find('-'); index2 = tmp.find('-');
return atoi((tmp.substr(index1 + 1, index2 - index1)).data()); return atoi((tmp.substr(index1 + 1, index2 - index1)).data());
} }
*/
int index;
string tmp = getSubstrY(key);
if (getDirection(key) == VERTICAL) {
index = tmp.find('-');
return atoi((tmp.substr(0, tmp.length() - index)).data());
} else {
return atoi(tmp.data());
}
} }
/** /**
...@@ -72,8 +119,38 @@ Point::getY (const char* key) { ...@@ -72,8 +119,38 @@ Point::getY (const char* key) {
*/ */
int int
Point::getVariation (const char* key) { Point::getVariation (const char* key) {
/*
char * value = skinConfigTree->getValue(NULL, key); char * value = skinConfigTree->getValue(NULL, key);
string tmp(value); string tmp(value);
int index = tmp.find('-'); int index = tmp.find('-');
return atoi((tmp.substr(index + 1, tmp.length() - index)).data()); return atoi((tmp.substr(index + 1, tmp.length() - index)).data());
*/
int index;
string str;
if (getDirection(key) == HORIZONTAL) {
str = getSubstrX(key);
} else if (getDirection(key) == VERTICAL) {
str = getSubstrY(key);
}
index = str.find('-');
return atoi((str.substr(index + 1, str.length() - index)).data());
}
/**
* Get the direction of the variation for 'key'
*
* @return 1 -> horizontal or 2 -> vertical
* (0 if no variation)
*/
int
Point::getDirection (const char* key) {
if (getSubstrX(key).find('-') != string::npos) {
return HORIZONTAL;
} else if (getSubstrY(key).find('-') != string::npos) {
return VERTICAL;
} else {
return NO_DIRECTION;
}
} }
...@@ -20,6 +20,13 @@ ...@@ -20,6 +20,13 @@
#ifndef __POINT_H__ #ifndef __POINT_H__
#define __POINT_H__ #define __POINT_H__
#include <string>
using namespace std;
#define NO_DIRECTION 0
#define HORIZONTAL 1
#define VERTICAL 2
class ConfigurationTree; class ConfigurationTree;
class Point { class Point {
...@@ -30,9 +37,12 @@ public: ...@@ -30,9 +37,12 @@ public:
int getX (const char*); int getX (const char*);
int getY (const char*); int getY (const char*);
int getVariation (const char*); int getVariation (const char*);
int getDirection (const char*);
private: private:
ConfigurationTree* skinConfigTree; ConfigurationTree* skinConfigTree;
string getSubstrX (const char*);
string getSubstrY (const char*);
}; };
#endif // __POINT_H__ #endif // __POINT_H__
...@@ -49,6 +49,8 @@ ...@@ -49,6 +49,8 @@
#include "point.h" #include "point.h"
#include "skin.h" #include "skin.h"
#include "qtGUImainwindow.h" #include "qtGUImainwindow.h"
#include "vector.h"