1
0
mirror of https://github.com/qTox/qTox.git synced 2024-03-22 14:00:36 +08:00

Merge branch 'filter_audio' of https://github.com/mwuttke97/qTox into filter_audio

Added some `#ifdef QTOX_FILTER_AUDIO`s.
Conflicts:
	qtox.pro

Conflicts:
	src/coreav.cpp
This commit is contained in:
Maximilian Wuttke 2014-12-14 09:50:18 +01:00
parent e7cad9b942
commit e0cb122abe
11 changed files with 213 additions and 4 deletions

31
install_libfilteraudio.sh Normal file
View File

@ -0,0 +1,31 @@
#!/bin/sh
CURRENT_DIR=$DIRSTACK
SOURCE_DIR="filter_audio/"
SOURCE_PATH="./../"
LIB_DIR="/usr/local/lib/"
INCLUDE_DIR="/usr/local/include/"
echo "Clone filter_audio from GitHub.com"
cd $SOURCE_PATH
git clone --quiet https://github.com/irungentoo/filter_audio.git $SOURCE_DIR
echo "Compile filter_audio"
cd $SOURCE_DIR
gcc -c -fPIC filter_audio.c aec/*.c agc/*.c ns/*.c other/*.c -lm -lpthread
echo "Create shared object file"
gcc *.o -shared -o libfilteraudio.so
echo "Clean up"
rm *.o
echo "Install libfilteraudio.so"
sudo cp libfilteraudio.so $LIB_DIR
echo "Install include files"
sudo cp *.h $INCLUDE_DIR
echo "Finished."
cd $CURRENT_DIR
exit 1

View File

@ -234,6 +234,12 @@ SOURCES += \
src/widget/form/settings/advancedform.cpp \
src/audio.cpp
contains(DEFINES, QTOX_FILTER_AUDIO) {
HEADERS += src/audiofilterer.h
SOURCES += src/audiofilterer.cpp
unix|win32: LIBS += -lfilteraudio
}
contains(DEFINES, QTOX_PLATFORM_EXT) {
HEADERS += src/platform/timer.h
SOURCES += src/platform/timer_osx.cpp \

52
src/audiofilterer.cpp Normal file
View File

@ -0,0 +1,52 @@
/*
Copyright (C) 2014 by Project Tox <https://tox.im>
This file is part of qTox, a Qt-based graphical interface for Tox.
This program is libre 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
(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 COPYING file for more details.
*/
#ifdef QTOX_FILTER_AUDIO
#include "audiofilterer.h"
extern "C"{
#include <filter_audio.h>
}
void AudioFilterer::startFilter(unsigned int fs)
{
closeFilter();
filter = new_filter_audio(fs);
}
void AudioFilterer::closeFilter()
{
if (filter)
kill_filter_audio(filter);
}
void AudioFilterer::filterAudio(int16_t* data, int framesize)
{
if (!filter)
return;
filter_audio(filter, (int16_t*) data, framesize);
}
AudioFilterer::~AudioFilterer()
{
closeFilter();
}
#endif // QTOX_FILTER_AUDIO

41
src/audiofilterer.h Normal file
View File

@ -0,0 +1,41 @@
/*
Copyright (C) 2014 by Project Tox <https://tox.im>
This file is part of qTox, a Qt-based graphical interface for Tox.
This program is libre 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
(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 COPYING file for more details.
*/
#ifdef QTOX_FILTER_AUDIO
#ifndef AUDIOFILTERER_H
#define AUDIOFILTERER_H
#include <cstdint>
#ifndef _FILTER_AUDIO
typedef struct Filter_Audio Filter_Audio;
#endif
class AudioFilterer
{
public:
explicit AudioFilterer() = default;
~AudioFilterer();
void startFilter(unsigned int fs);
void filterAudio(int16_t* data, int framesize);
void closeFilter();
private:
struct Filter_Audio* filter{nullptr};
};
#endif // AUDIOFILTERER_H
#endif // QTOX_FILTER_AUDIO

View File

@ -33,6 +33,9 @@ class QTimer;
class QString;
class CString;
class VideoSource;
#ifdef QTOX_FILTER_AUDIO
class AudioFilterer;
#endif
class Core : public QObject
{
@ -283,6 +286,9 @@ private:
int dhtServerId;
static QList<ToxFile> fileSendQueue, fileRecvQueue;
static ToxCall calls[TOXAV_MAX_CALLS];
#ifdef QTOX_FILTER_AUDIO
static AudioFilterer * filterer[TOXAV_MAX_CALLS];
#endif
static QHash<int, ToxGroupCall> groupCalls; // Maps group IDs to ToxGroupCalls
QMutex fileSendMutex, messageSendMutex;
bool ready;

View File

@ -17,10 +17,17 @@
#include "core.h"
#include "video/camera.h"
#include "audio.h"
#ifdef QTOX_FILTER_AUDIO
#include "audiofilterer.h"
#endif
#include "misc/settings.h"
#include <QDebug>
#include <QTimer>
ToxCall Core::calls[TOXAV_MAX_CALLS];
#ifdef QTOX_FILTER_AUDIO
AudioFilterer * Core::filterer[TOXAV_MAX_CALLS] { nullptr};
#endif
const int Core::videobufsize{TOXAV_MAX_VIDEO_WIDTH * TOXAV_MAX_VIDEO_HEIGHT * 4};
uint8_t* Core::videobuf;
@ -65,6 +72,20 @@ void Core::prepareCall(int friendId, int callId, ToxAv* toxav, bool videoEnabled
calls[callId].sendVideoTimer->start();
Camera::getInstance()->subscribe();
}
#ifdef QTOX_FILTER_AUDIO
if (Settings::getInstance().getFilterAudio())
{
Core::filterer[callId] = new AudioFilterer();
filterer[callId]->startFilter(48000);
}
else
{
if (filterer[callId])
delete filterer[callId];
filterer[callId] = nullptr;
}
#endif
}
void Core::onAvMediaChange(void* toxav, int32_t callId, void* core)
@ -246,8 +267,16 @@ void Core::sendCallAudio(int callId, ToxAv* toxav)
return;
}
#ifdef QTOX_FILTER_AUDIO
if (filterer[callId])
{
filterer[callId]->filterAudio((int16_t*) buf, framesize);
}
#endif
if ((r = toxav_send_audio(toxav, callId, dest, r)) < 0)
{
qDebug() << "Core: toxav_send_audio error";
}
}
calls[callId].sendAudioTimer->start();
}
@ -294,14 +323,16 @@ void Core::sendCallVideo(int callId)
void Core::micMuteToggle(int callId)
{
if (calls[callId].active) {
if (calls[callId].active)
{
calls[callId].muteMic = !calls[callId].muteMic;
}
}
void Core::volMuteToggle(int callId)
{
if (calls[callId].active) {
if (calls[callId].active)
{
calls[callId].muteVol = !calls[callId].muteVol;
alSourcef(calls[callId].alSource, AL_GAIN, calls[callId].muteVol ? 0.f : 1.f);
}
@ -321,6 +352,15 @@ void Core::onAvCancel(void* _toxav, int32_t callId, void* core)
calls[callId].active = false;
#ifdef QTOX_FILTER_AUDIO
if (filterer[callId])
{
filterer[callId]->closeFilter();
delete filterer[callId];
filterer[callId] = nullptr;
}
#endif
emit static_cast<Core*>(core)->avCancel(friendId, callId);
}

View File

@ -198,6 +198,7 @@ void Settings::load()
s.beginGroup("Audio");
inDev = s.value("inDev", "").toString();
outDev = s.value("outDev", "").toString();
filterAudio = s.value("filterAudio", false).toBool();
s.endGroup();
// Read the embedded DHT bootsrap nodes list if needed
@ -340,6 +341,7 @@ void Settings::save(QString path, bool writeFriends)
s.beginGroup("Audio");
s.setValue("inDev", inDev);
s.setValue("outDev", outDev);
s.setValue("filterAudio", filterAudio);
s.endGroup();
if (!writeFriends || currentProfile.isEmpty()) // Core::switchConfiguration
@ -898,6 +900,14 @@ void Settings::setOutDev(const QString& deviceSpecifier)
outDev = deviceSpecifier;
}
bool Settings::getFilterAudio() const{
return filterAudio;
}
void Settings::setFilterAudio(bool newValue){
filterAudio = newValue;
}
QString Settings::getFriendAdress(const QString &publicKey) const
{
QString key = ToxID::fromString(publicKey).publicKey;

View File

@ -128,6 +128,9 @@ public:
QString getOutDev() const;
void setOutDev(const QString& deviceSpecifier);
bool getFilterAudio() const;
void setFilterAudio(bool newValue);
// Assume all widgets have unique names
// Don't use it to save every single thing you want to save, use it
// for some general purpose widgets, such as MainWindows or Splitters,
@ -298,6 +301,7 @@ private:
// Audio
QString inDev;
QString outDev;
bool filterAudio;
struct friendProp
{

View File

@ -33,12 +33,19 @@ AVForm::AVForm() :
bodyUI = new Ui::AVSettings;
bodyUI->setupUi(this);
#ifdef QTOX_FILTER_AUDIO
bodyUI->filterAudio->setChecked(Settings::getInstance().getFilterAudio());
#else
bodyUI->filterAudio->setDisabled(true);
#endif
connect(Camera::getInstance(), &Camera::propProbingFinished, this, &AVForm::onPropProbingFinished);
connect(Camera::getInstance(), &Camera::resolutionProbingFinished, this, &AVForm::onResProbingFinished);
auto qcomboboxIndexChanged = (void(QComboBox::*)(const QString&)) &QComboBox::currentIndexChanged;
connect(bodyUI->inDevCombobox, qcomboboxIndexChanged, this, &AVForm::onInDevChanged);
connect(bodyUI->outDevCombobox, qcomboboxIndexChanged, this, &AVForm::onOutDevChanged);
connect(bodyUI->filterAudio, SIGNAL(toggled(bool)), this, SLOT(onFilterAudioToggled(bool)));
connect(bodyUI->rescanButton, &QPushButton::clicked, this, [=](){getAudioInDevices(); getAudioOutDevices();});
}
@ -189,3 +196,7 @@ void AVForm::onOutDevChanged(const QString& deviceDescriptor)
Settings::getInstance().setOutDev(deviceDescriptor);
Audio::openOutput(deviceDescriptor);
}
void AVForm::onFilterAudioToggled(bool filterAudio){
Settings::getInstance().setFilterAudio(filterAudio);
}

View File

@ -52,6 +52,7 @@ private slots:
// audio
void onInDevChanged(const QString& deviceDescriptor);
void onOutDevChanged(const QString& deviceDescriptor);
void onFilterAudioToggled(bool filterAudio);
// camera
void onPropProbingFinished(Camera::Prop prop, double val);

View File

@ -30,8 +30,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>810</width>
<height>496</height>
<width>808</width>
<height>618</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_5">
@ -96,6 +96,13 @@
</property>
</widget>
</item>
<item row="8" column="0">
<widget class="QCheckBox" name="filterAudio">
<property name="text">
<string>Filter audio</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>