Commit 1e4bd1b2 authored by llea's avatar llea

Add volume control for speaker and micro

parent f7dafc63
......@@ -57,6 +57,8 @@ OBJS = \
jpushbutton.o jpushbutton.moc.o \
numerickeypad.o numerickeypad.moc.o \
qtGUImainwindow.o qtGUImainwindow.moc.o \
vector.o \
volumecontrol.o volumecontrol.moc.o \
stun.o udp.o
start: check prereq all
......
......@@ -50,11 +50,11 @@ void AudioBuffer::resize (size_t newsize)
}
void
AudioBuffer::setData (short *buf) {
AudioBuffer::setData (short *buf, int vol) {
short *databuf = data;
for (int i = 0; i < (int)size; i++) {
databuf[i] = buf[i];
databuf[i] = buf[i]*vol;
}
}
......@@ -62,7 +62,7 @@ public:
*/
void resize (size_t newsize);
void setData (short *buf);
void setData (short *buf, int);
void *data;
private:
......
......@@ -297,7 +297,6 @@ AudioDriversOSS::writeBuffer (void) {
size_t count = audio_buf.getSize();
short *buf = (short*)audio_buf.getData();
audio_buf_info info;
if (ioctl(audio_fd, SNDCTL_DSP_GETOSPACE, &info) == 0 ) {
if (info.fragstotal - info.fragments > 15) {
......
......@@ -47,7 +47,7 @@ AudioRtp::AudioRtp (SIP *sip, Manager *manager) {
this->manager = manager;
RTXThread = NULL;
if (!manager->useStun()) {
if (Config::gets("Signalisations", "SIP.sipproxy") == NULL) {
if (Config::gets("Signalisations", "SIP.sipproxy") == "") {
svr = Config::gets("Signalisations", "SIP.sipproxy");
}
} else {
......@@ -142,6 +142,7 @@ AudioRtpRTX::run (void) {
unsigned char *data_to_send;
short *data_mute;
short *data_from_mic;
short *data_from_mic_tmp;
int i,
compSize,
timestamp;
......@@ -150,6 +151,7 @@ AudioRtpRTX::run (void) {
data_for_speakers = new short[2048];
data_from_mic = new short[1024];
data_from_mic_tmp = new short[1024];
data_to_send = new unsigned char[1024];
data_mute = new short[1024];
......@@ -253,11 +255,14 @@ AudioRtpRTX::run (void) {
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
compSize = AudioCodec::codecEncode (
ac.handleCodecs[0],
data_to_send,
data_from_mic, i);
data_from_mic_tmp, i);
// Send encoded audio sample
if (!sym) {
......@@ -290,7 +295,8 @@ AudioRtpRTX::run (void) {
// Write decoded data to sound device
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 ();
delete adu;
......@@ -303,6 +309,7 @@ AudioRtpRTX::run (void) {
delete[] data_for_speakers;
delete[] data_from_mic;
delete[] data_from_mic_tmp;
delete[] data_mute;
delete[] data_to_send;
this->exit();
......
This diff is collapsed.
......@@ -49,20 +49,18 @@ void ConfigurationPanel::init()
sipproxy->setText(QString(Config::getchar("Signalisations", "SIP.sipproxy", "")));
playTones->setChecked(Config::get("Signalisations", "DTMF.playTones", (int)true));
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",
"stun.fwdnet.net:3478"));
useStunYes->setChecked(Config::get("Signalisations", "STUN.useStunYes", (int)false));
useStunNo->setChecked(Config::get("Signalisations", "STUN.useStunNo", (int)true));
((QRadioButton*)stunButtonGroup->find(Config::get("Signalisations", "STUN.useStun", 1)))->setChecked(true);
// For audio tab
ossButton->setChecked(Config::get("Audio", "Drivers.driverOSS", (int)true));
alsaButton->setChecked(Config::get("Audio", "Drivers.driverALSA", (int)false));
codec1->setCurrentText(QString(Config::getchar("Audio", "Codecs.codec1", "G711u")));
codec2->setCurrentText(QString(Config::getchar("Audio", "Codecs.codec2", "G711a")));
codec3->setCurrentText(QString(Config::getchar("Audio", "Codecs.codec3", "GSM")));
codec4->setCurrentText(QString(Config::getchar("Audio", "Codecs.codec4", "iLBC")));
codec5->setCurrentText(QString(Config::getchar("Audio", "Codecs.codec5", "SPEEX")));
codec2->setCurrentText(QString(Config::getchar("Audio", "Codecs.codec2", "G711u")));
codec3->setCurrentText(QString(Config::getchar("Audio", "Codecs.codec3", "G711u")));
codec4->setCurrentText(QString(Config::getchar("Audio", "Codecs.codec4", "G711u")));
codec5->setCurrentText(QString(Config::getchar("Audio", "Codecs.codec5", "G711u")));
// For preferences tab
SkinChoice->setCurrentText(QString(Config::getchar(
......@@ -118,8 +116,6 @@ void ConfigurationPanel::saveSlot()
Config::set("Signalisations", "DTMF.playTones", playTones->isChecked());
Config::set("Signalisations", "DTMF.sendDTMFas" , sendDTMFas->currentItem());
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.driverALSA", alsaButton->isChecked());
......@@ -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'
**
** Created: Wed Jan 26 14:28:43 2005
** Created: Fri Jan 28 18:58:55 2005
** by: The User Interface Compiler ($Id$)
**
** WARNING! All changes made in this file will be lost!
......@@ -64,12 +64,12 @@ public:
QLabel* textLabel1_3;
QLabel* textLabel3_2;
QWidget* STUNPage;
QButtonGroup* buttonGroup3;
QRadioButton* useStunYes;
QRadioButton* useStunNo;
QGroupBox* groupBox3;
QLabel* textLabel1_5;
QLineEdit* STUNserver;
QButtonGroup* stunButtonGroup;
QRadioButton* useStunYes;
QRadioButton* useStunNo;
QWidget* DTMFPage;
QGroupBox* SettingsDTMF;
QCheckBox* playTones;
......@@ -121,15 +121,16 @@ public:
public slots:
virtual void saveSlot();
virtual void changeTabSlot();
virtual void useStunSlot( int id );
protected:
QGridLayout* ConfigurationPanelLayout;
QVBoxLayout* layout8;
QHBoxLayout* layout7;
QSpacerItem* Horizontal_Spacing2;
QVBoxLayout* layout14;
QVBoxLayout* layout17;
QGridLayout* groupBox1Layout;
QVBoxLayout* buttonGroup3Layout;
QVBoxLayout* stunButtonGroupLayout;
QGridLayout* SettingsDTMFLayout;
QVBoxLayout* layout11;
QHBoxLayout* layout10;
......@@ -143,7 +144,7 @@ protected:
QHBoxLayout* layout11_2;
QVBoxLayout* layout9;
QVBoxLayout* layout10_2;
QVBoxLayout* layout17;
QVBoxLayout* layout17_2;
QHBoxLayout* layout16;
QSpacerItem* spacer5;
QHBoxLayout* layout16_2;
......
......@@ -84,6 +84,9 @@ Manager::Manager (QString *Dc = NULL) {
// show configuration panel
gui()->configuration();
}
spkr_volume = 10;
mic_volume = 10;
}
Manager::~Manager (void) {
......@@ -132,7 +135,7 @@ void
Manager::selectAudioDriver (void) {
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 (Config::getb("Audio", "Drivers.driverOSS")) {
this->audiodriver = new AudioDriversOSS ();
......@@ -525,3 +528,13 @@ Manager::nameDisplay (char *name) {
gui()->lcd->clearBuffer();
gui()->lcd->appendText(name);
}
void
Manager::spkrSoundVolume (int val) {
spkr_volume = val;
}
void
Manager::micSoundVolume (int val) {
mic_volume = val;
}
......@@ -20,7 +20,6 @@
#ifndef __MANAGER_H__
#define __MANAGER_H__
#include "audiodrivers.h"
#include "phoneline.h"
#include "../stund/stun.h"
......@@ -91,6 +90,10 @@ public:
void congestion (bool);
void errorDisplay (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:
bool b_ringing;
......@@ -98,6 +101,8 @@ private:
bool b_congestion;
int firewallPort;
QString firewallAddr;
int spkr_volume;
int mic_volume;
void sip_init (void);
bool createSettingsPath (void);
......
/****************************************************************************
** 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$)
**
** WARNING! All changes made in this file will be lost!
......
/****************************************************************************
** 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$)
**
** WARNING! All changes made in this file will be lost!
......
......@@ -32,7 +32,32 @@ Point::Point (const char* filename) {
}
Point::~Point (void) {
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) {
*/
int
Point::getX (const char* key) {
/*
char * value = skinConfigTree->getValue(NULL, key);
string tmp(value);
int index = tmp.find(',');
int toto = atoi((tmp.substr(0, index)).data());
return toto;
return atoi((tmp.substr(0, index)).data());
*/
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) {
*/
int
Point::getY (const char* key) {
/*
char * value = skinConfigTree->getValue(NULL, key);
string tmp(value);
int index1, index2;
......@@ -65,6 +102,16 @@ Point::getY (const char* key) {
index2 = tmp.find('-');
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) {
*/
int
Point::getVariation (const char* key) {
/*
char * value = skinConfigTree->getValue(NULL, key);
string tmp(value);
int index = tmp.find('-');
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 @@
#ifndef __POINT_H__
#define __POINT_H__
#include <string>
using namespace std;
#define NO_DIRECTION 0
#define HORIZONTAL 1
#define VERTICAL 2
class ConfigurationTree;
class Point {
......@@ -30,9 +37,12 @@ public:
int getX (const char*);
int getY (const char*);
int getVariation (const char*);
int getDirection (const char*);
private:
ConfigurationTree* skinConfigTree;
string getSubstrX (const char*);
string getSubstrY (const char*);
};
#endif // __POINT_H__
......@@ -49,6 +49,8 @@
#include "point.h"
#include "skin.h"
#include "qtGUImainwindow.h"
#include "vector.h"
#include "volumecontrol.h"
#define QCHAR_TO_STRIP "-"
#define REG_EXPR "(-|\\(|\\)| )"
......@@ -274,7 +276,18 @@ QtGUIMainWindow::QtGUIMainWindow (QWidget *parent, const char *name, WFlags f,
NULL, mypop, parent, name);
trayicon->show();
connect(trayicon, SIGNAL(clickedLeft()), this, SLOT(clickHandle()));
connect(vol_spkr, SIGNAL(setVolumeValue(int)), this, SLOT(volumeSpkrChanged(int)));
connect(vol_mic, SIGNAL(setVolumeValue(int)), this, SLOT(volumeMicChanged(int)));
}
void
QtGUIMainWindow::volumeSpkrChanged(int val) {
callmanager->spkrSoundVolume(val);
}
void
QtGUIMainWindow::volumeMicChanged(int val) {
callmanager->micSoundVolume(val);
}
/**
......@@ -298,6 +311,8 @@ QtGUIMainWindow::~QtGUIMainWindow(void) {
delete dtmf_button;
delete vol_mic;
delete vol_spkr;
delete micVolVector;
delete spkrVolVector;
delete panel;
delete blinkTimer;
delete keypad;
......@@ -392,9 +407,12 @@ QtGUIMainWindow::initButtons (void) {
callmanager->phLines[j]->button()->move (pt->getX(lnum),pt->getY(lnum));
}
// Set pixmaps volume TODO:change to thing like slider
vol_mic = new JPushButton(this, NULL, VOLUME);
vol_spkr = new JPushButton(this, NULL, VOLUME);
// Set pixmaps volume
micVolVector = new Vector(this, VOL_MIC, pt);
spkrVolVector = new Vector(this, VOL_SPKR, pt);
vol_mic = new VolumeControl(this, NULL, VOLUME, micVolVector);
vol_spkr = new VolumeControl(this, NULL, VOLUME, spkrVolVector);
vol_mic->move(pt->getX(VOL_MIC), pt->getY(VOL_MIC));
vol_spkr->move(pt->getX(VOL_SPKR), pt->getY(VOL_SPKR));
}
......@@ -1017,7 +1035,7 @@ QtGUIMainWindow::pressedKeySlot (int id) {
key->startTone(code);
key->generateDTMF(buf, SAMPLING_RATE);
callmanager->audiodriver->audio_buf.resize(SAMPLING_RATE);
callmanager->audiodriver->audio_buf.setData (buf);
callmanager->audiodriver->audio_buf.setData (buf, callmanager->getSpkrVolume()/10);
pulselen = Config::get("Signalisations", "DTMF.pulseLength", 250);
callmanager->audiodriver->audio_buf.resize(pulselen * (OCTETS/1000));
// a = callmanager->audiodriver->writeBuffer(buf, pulselen * (OCTETS/1000));
......
......@@ -45,6 +45,7 @@
#include "transqwidget.h"
#include "trayicon.h"
#include "url_inputui.h"
#include "volumecontrol.h"
#define MAIN_INITIAL_POSITION 20
#define TEXT_MODE 0
......@@ -105,8 +106,8 @@ public:
JPushButton *dial_button;
JPushButton *mute_button;
JPushButton *dtmf_button;
JPushButton *vol_mic;
JPushButton *vol_spkr;
VolumeControl *vol_mic;
VolumeControl *vol_spkr;
int currentLineNumber;
int busyNum;
......@@ -181,6 +182,9 @@ public slots:
void pressedKeyStar (void);
void pressedKeyHash (void);
void volumeSpkrChanged (int);
void volumeMicChanged (int);
protected:
// To handle the key pressed event
void keyPressEvent (QKeyEvent *);
......@@ -188,6 +192,8 @@ protected:
private:
// Configuration skin file
Point *pt;
Vector *micVolVector;
Vector *spkrVolVector;
// To construct ring rect pixmap
QImage imageRing;
......
......@@ -52,6 +52,10 @@ EventThread::EventThread (SIP *sip) : Thread () {
this->sipthread = sip;
}
EventThread::~EventThread (void) {
this->terminate();
}
/**
* Reimplementation of run() to update widget
*/
......
......@@ -62,6 +62,7 @@ using namespace ost;
class EventThread : public Thread {
public:
EventThread (SIP *);
~EventThread (void);
virtual void run ();
private:
SIP * sipthread;
......
......@@ -30,6 +30,7 @@ extern "C" {
#define PIXMAP_KEYPAD "dtmf_main.png"
#define PIXMAP_SCREEN "screen_main.png"
#define PIXMAP_OVERSCREEN "overscreen.png"
#define PIXMAP_VOLUME "volume.png"
#define PIXMAP_IS_RINGING "ring.png"
#define PIXMAP_NO_RINGING "no_ring.png"
......
......@@ -44,6 +44,7 @@ ToneThread::~ToneThread (void) {
void
ToneThread::run (void) {
while (mngr->tonezone) {
mngr->audiodriver->audio_buf.setData (buf, mngr->getSpkrVolume()/10);
mngr->audiodriver->writeBuffer();
//mngr->audiodriver->writeBuffer(buf, totalbytes);
}
......@@ -231,7 +232,7 @@ ToneGenerator::toneHandle (int idr) {
if (tonethread == NULL) {
tonethread = new ToneThread (manager, buf, totalbytes);
manager->audiodriver->audio_buf.resize(totalbytes);
manager->audiodriver->audio_buf.setData (buf);
// manager->audiodriver->audio_buf.setData (buf);
tonethread->start();
}
......
......@@ -79,3 +79,4 @@ TransQWidget::mousePressEvent (QMouseEvent *e) {
mouse_x = e->x();
mouse_y = e->y();
}
/****************************************************************************
** Form implementation generated from reading ui file 'url_input.ui'
**
** Created: Wed Jan 26 14:28:43 2005
** Created: Fri Jan 28 18:58:54 2005
** by: The User Interface Compiler ($Id$)
**
** WARNING! All changes made in this file will be lost!
......
/****************************************************************************
** Form interface generated from reading ui file 'url_input.ui'
**
** Created: Wed Jan 26 14:28:43 2005
** Created: Fri Jan 28 18:58:54 2005
** by: The User Interface Compiler ($Id$)
**
** WARNING! All changes made in this file will be lost!
......
/**
* Copyright (C) 2004-2005 Savoir-Faire Linux inc.
* Author: Laurielle Lea <laurielle.lea@savoirfairelinux.com>
*
* 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 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include "vector.h"
#include "point.h"
#include "transqwidget.h"
Vector::Vector (QtGUIMainWindow* gui, const char* name, Point* pt) {
this->x = pt->getX (name);