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

refactor: run formatting script

This commit is contained in:
sudden6 2019-04-23 23:05:49 +02:00
parent 5b908184fc
commit 47402fae90
No known key found for this signature in database
GPG Key ID: 279509B499E032B9
11 changed files with 83 additions and 79 deletions

View File

@ -14,28 +14,28 @@ AlSink::~AlSink()
QMutexLocker{&killLock};
// unsubscribe only if not already killed
if(!killed) {
if (!killed) {
audio.destroySink(*this);
killed = true;
}
}
void AlSink::playAudioBuffer(const int16_t *data, int samples, unsigned channels, int sampleRate) const
void AlSink::playAudioBuffer(const int16_t* data, int samples, unsigned channels, int sampleRate) const
{
QMutexLocker{&killLock};
if(killed) {
if (killed) {
qCritical() << "Trying to play audio on an invalid sink";
} else {
audio.playAudioBuffer(sourceId, data, samples, channels, sampleRate);
}
}
void AlSink::playMono16Sound(const IAudioSink::Sound &sound)
void AlSink::playMono16Sound(const IAudioSink::Sound& sound)
{
QMutexLocker{&killLock};
if(killed) {
if (killed) {
qCritical() << "Trying to play sound on an invalid sink";
} else {
audio.playMono16Sound(*this, sound);
@ -46,7 +46,7 @@ void AlSink::startLoop()
{
QMutexLocker{&killLock};
if(killed) {
if (killed) {
qCritical() << "Trying to start loop on an invalid sink";
} else {
audio.startLoop(sourceId);
@ -57,7 +57,7 @@ void AlSink::stopLoop()
{
QMutexLocker{&killLock};
if(killed) {
if (killed) {
qCritical() << "Trying to stop loop on an invalid sink";
} else {
audio.stopLoop(sourceId);
@ -83,8 +83,7 @@ AlSink::AlSink(OpenAL& al, uint sourceId)
: audio{al}
, sourceId{sourceId}
, killLock{QMutex::Recursive}
{
}
{}
AlSink::operator bool() const
{

View File

@ -1,8 +1,8 @@
#ifndef ALSINK_H
#define ALSINK_H
#include <QObject>
#include <QMutex>
#include <QObject>
#include "src/audio/iaudiosink.h"
@ -12,15 +12,14 @@ class AlSink : public IAudioSink
{
Q_OBJECT
public:
AlSink(OpenAL &al, uint sourceId);
AlSink(const AlSink &src) = delete;
AlSink & operator=(const AlSink&) = delete;
AlSink(OpenAL& al, uint sourceId);
AlSink(const AlSink& src) = delete;
AlSink& operator=(const AlSink&) = delete;
AlSink(AlSink&& other) = delete;
AlSink & operator=(AlSink&& other) = delete;
AlSink& operator=(AlSink&& other) = delete;
~AlSink();
void playAudioBuffer(const int16_t* data, int samples, unsigned channels,
int sampleRate) const;
void playAudioBuffer(const int16_t* data, int samples, unsigned channels, int sampleRate) const;
void playMono16Sound(const IAudioSink::Sound& sound);
void startLoop();
void stopLoop();

View File

@ -33,16 +33,16 @@
#include <cassert>
namespace {
void applyGain(int16_t* buffer, uint32_t bufferSize, qreal gainFactor)
{
for (quint32 i = 0; i < bufferSize; ++i) {
// gain amplification with clipping to 16-bit boundaries
buffer[i] = qBound<int16_t>(std::numeric_limits<int16_t>::min(),
qRound(buffer[i] * gainFactor),
std::numeric_limits<int16_t>::max());
}
void applyGain(int16_t* buffer, uint32_t bufferSize, qreal gainFactor)
{
for (quint32 i = 0; i < bufferSize; ++i) {
// gain amplification with clipping to 16-bit boundaries
buffer[i] =
qBound<int16_t>(std::numeric_limits<int16_t>::min(), qRound(buffer[i] * gainFactor),
std::numeric_limits<int16_t>::max());
}
}
} // namespace
/**
* @class OpenAL
@ -82,13 +82,15 @@ OpenAL::OpenAL()
captureTimer.setSingleShot(false);
captureTimer.moveToThread(audioThread);
// TODO for Qt 5.6+: use qOverload
connect(audioThread, &QThread::started, &captureTimer, static_cast<void (QTimer::*)(void)>(&QTimer::start));
connect(audioThread, &QThread::started, &captureTimer,
static_cast<void (QTimer::*)(void)>(&QTimer::start));
cleanupTimer.setInterval(1000);
cleanupTimer.setSingleShot(false);
connect(&cleanupTimer, &QTimer::timeout, this, &OpenAL::cleanupSound);
// TODO for Qt 5.6+: use qOverload
connect(audioThread, &QThread::started, &cleanupTimer, static_cast<void (QTimer::*)(void)>(&QTimer::start));
connect(audioThread, &QThread::started, &cleanupTimer,
static_cast<void (QTimer::*)(void)>(&QTimer::start));
audioThread->start();
}
@ -245,7 +247,7 @@ bool OpenAL::reinitOutput(const QString& outDevDesc)
* @brief Allocates ressources for a new audio output
* @return AudioSink on success, nullptr on failure
*/
IAudioSink *OpenAL::makeSink()
IAudioSink* OpenAL::makeSink()
{
QMutexLocker locker(&audioLock);
@ -332,8 +334,7 @@ void OpenAL::unsubscribeInput()
return;
inSubscriptions--;
qDebug() << "Unsubscribed from audio input device [" << inSubscriptions
<< "subscriptions left ]";
qDebug() << "Unsubscribed from audio input device [" << inSubscriptions << "subscriptions left ]";
if (!inSubscriptions)
cleanupInput();
@ -377,8 +378,8 @@ bool OpenAL::initInput(const QString& deviceName, uint32_t channels)
this->channels = channels;
int stereoFlag = channels == 1 ? AL_FORMAT_MONO16 : AL_FORMAT_STEREO16;
const int bytesPerSample = 2;
const int safetyFactor = 2; // internal OpenAL ring buffer. must be larger than our inputBuffer to avoid the ring
// from overwriting itself between captures.
const int safetyFactor = 2; // internal OpenAL ring buffer. must be larger than our inputBuffer
// to avoid the ring from overwriting itself between captures.
AUDIO_FRAME_SAMPLE_COUNT_TOTAL = AUDIO_FRAME_SAMPLE_COUNT_PER_CHANNEL * channels;
const ALCsizei ringBufSize = AUDIO_FRAME_SAMPLE_COUNT_TOTAL * bytesPerSample * safetyFactor;
@ -446,18 +447,18 @@ bool OpenAL::initOutput(const QString& deviceName)
/**
* @brief Play a 48kHz mono 16bit PCM sound
*/
void OpenAL::playMono16Sound(AlSink& sink, const IAudioSink::Sound &sound)
void OpenAL::playMono16Sound(AlSink& sink, const IAudioSink::Sound& sound)
{
const uint sourceId = sink.getSourceId();
QFile sndFile(IAudioSink::getSound(sound));
if(!sndFile.exists()) {
if (!sndFile.exists()) {
qDebug() << "Trying to open non existent sound file";
return;
}
sndFile.open(QIODevice::ReadOnly);
const QByteArray data{sndFile.readAll()};
if(data.isEmpty()) {
if (data.isEmpty()) {
qDebug() << "Sound file contained no data";
return;
}
@ -606,9 +607,9 @@ float OpenAL::getVolume()
float sumOfSquares = 0;
for (quint32 i = 0; i < samples; i++) {
float sample = static_cast<float>(inputBuffer[i]) / std::numeric_limits<int16_t>::max();
sumOfSquares += std::pow(sample , 2);
sumOfSquares += std::pow(sample, 2);
}
const float rms = std::sqrt(sumOfSquares/samples);
const float rms = std::sqrt(sumOfSquares / samples);
// our calculated normalized volume could possibly be above 1 because our RMS assumes a sinusoidal wave
const float normalizedVolume = std::min(rms * rootTwo, 1.0f);
return normalizedVolume;
@ -650,7 +651,8 @@ void OpenAL::doInput()
return;
}
emit Audio::frameAvailable(inputBuffer, AUDIO_FRAME_SAMPLE_COUNT_PER_CHANNEL, channels, AUDIO_SAMPLE_RATE);
emit Audio::frameAvailable(inputBuffer, AUDIO_FRAME_SAMPLE_COUNT_PER_CHANNEL, channels,
AUDIO_SAMPLE_RATE);
}
void OpenAL::doOutput()
@ -725,7 +727,8 @@ QStringList OpenAL::inDeviceNames()
* @brief Free all buffers that finished playing on a source
* @param sourceId where to remove the buffers from
*/
void OpenAL::cleanupBuffers(uint sourceId) {
void OpenAL::cleanupBuffers(uint sourceId)
{
// unqueue all buffers from the source
ALint processed = 0;
alGetSourcei(sourceId, AL_BUFFERS_PROCESSED, &processed);

View File

@ -52,8 +52,14 @@ public:
OpenAL();
virtual ~OpenAL();
qreal maxOutputVolume() const { return 1; }
qreal minOutputVolume() const { return 0; }
qreal maxOutputVolume() const
{
return 1;
}
qreal minOutputVolume() const
{
return 0;
}
qreal outputVolume() const;
void setOutputVolume(qreal volume);

View File

@ -32,7 +32,8 @@
#include <cassert>
extern "C" {
extern "C"
{
#include <filter_audio.h>
}
@ -80,8 +81,7 @@ OpenAL2::OpenAL2()
, alProxyContext{nullptr}
, alProxySource{0}
, alProxyBuffer{0}
{
}
{}
bool OpenAL2::initInput(const QString& deviceName)
{
@ -324,7 +324,8 @@ void OpenAL2::doOutput()
alcMakeContextCurrent(alOutContext);
}
alBufferData(bufids[0], AL_FORMAT_MONO16, outBuf, AUDIO_FRAME_SAMPLE_COUNT_PER_CHANNEL * 2, AUDIO_SAMPLE_RATE);
alBufferData(bufids[0], AL_FORMAT_MONO16, outBuf, AUDIO_FRAME_SAMPLE_COUNT_PER_CHANNEL * 2,
AUDIO_SAMPLE_RATE);
alSourceQueueBuffers(alProxySource, 1, bufids);

View File

@ -37,7 +37,8 @@
#include <AL/alc.h>
#include <AL/alext.h>
extern "C" {
extern "C"
{
#include <filter_audio.h>
}

View File

@ -79,7 +79,7 @@ public:
virtual ~IAudioSink() {}
virtual void playAudioBuffer(const int16_t* data, int samples, unsigned channels,
int sampleRate) const = 0;
int sampleRate) const = 0;
virtual void playMono16Sound(const Sound& sound) = 0;
virtual void startLoop() = 0;
virtual void stopLoop() = 0;

View File

@ -31,8 +31,7 @@
ToxCall::ToxCall(bool VideoEnabled, CoreAV& av)
: av{&av}
, videoEnabled{VideoEnabled}
{
}
{}
ToxCall::~ToxCall()
{
@ -110,19 +109,17 @@ ToxFriendCall::ToxFriendCall(uint32_t FriendNum, bool VideoEnabled, CoreAV& av)
Audio& audio = Audio::getInstance();
audio.subscribeInput();
audioInConn = QObject::connect(&Audio::getInstance(), &Audio::frameAvailable,
[&av, FriendNum](const int16_t* pcm, size_t samples, uint8_t chans,
uint32_t rate) {
av.sendCallAudio(FriendNum, pcm, samples, chans, rate);
});
[&av, FriendNum](const int16_t* pcm, size_t samples,
uint8_t chans, uint32_t rate) {
av.sendCallAudio(FriendNum, pcm, samples, chans, rate);
});
if (!audioInConn) {
qDebug() << "Audio input connection not working";
qDebug() << "Audio input connection not working";
}
audioSinkInvalid = QObject::connect(sink.get(), &IAudioSink::invalidated,
[this]() {
this->onAudioSinkInvalidated();
});
[this]() { this->onAudioSinkInvalidated(); });
// register video
@ -154,9 +151,7 @@ void ToxFriendCall::onAudioSinkInvalidated()
const auto newSink = Audio::getInstance().makeSink();
audioSinkInvalid = QObject::connect(newSink, &IAudioSink::invalidated,
[this]() {
this->onAudioSinkInvalidated();
});
[this]() { this->onAudioSinkInvalidated(); });
sink.reset(newSink);
}
@ -193,7 +188,7 @@ void ToxFriendCall::setState(const TOXAV_FRIEND_CALL_STATE& value)
state = value;
}
const std::unique_ptr<IAudioSink> &ToxFriendCall::getAudioSink() const
const std::unique_ptr<IAudioSink>& ToxFriendCall::getAudioSink() const
{
return sink;
}
@ -206,13 +201,13 @@ ToxGroupCall::ToxGroupCall(int GroupNum, CoreAV& av)
Audio& audio = Audio::getInstance();
audio.subscribeInput();
audioInConn = QObject::connect(&Audio::getInstance(), &Audio::frameAvailable,
[&av, GroupNum](const int16_t* pcm, size_t samples, uint8_t chans,
uint32_t rate) {
av.sendGroupCallAudio(GroupNum, pcm, samples, chans, rate);
});
[&av, GroupNum](const int16_t* pcm, size_t samples,
uint8_t chans, uint32_t rate) {
av.sendGroupCallAudio(GroupNum, pcm, samples, chans, rate);
});
if (!audioInConn) {
qDebug() << "Audio input connection not working";
qDebug() << "Audio input connection not working";
}
}
@ -231,7 +226,7 @@ void ToxGroupCall::onAudioSinkInvalidated(ToxPk peerId)
void ToxGroupCall::removePeer(ToxPk peerId)
{
const auto& source = peers.find(peerId);
if(source == peers.cend()) {
if (source == peers.cend()) {
qDebug() << "Peer:" << peerId.toString() << "does not have a source, can't remove";
return;
}
@ -247,10 +242,9 @@ void ToxGroupCall::addPeer(ToxPk peerId)
IAudioSink* newSink = audio.makeSink();
peers.emplace(peerId, std::unique_ptr<IAudioSink>(newSink));
QMetaObject::Connection con = QObject::connect(newSink, &IAudioSink::invalidated,
[this, peerId]() {
this->onAudioSinkInvalidated(peerId);
});
QMetaObject::Connection con =
QObject::connect(newSink, &IAudioSink::invalidated,
[this, peerId]() { this->onAudioSinkInvalidated(peerId); });
sinkInvalid.insert({peerId, con});
}
@ -264,16 +258,16 @@ bool ToxGroupCall::havePeer(ToxPk peerId)
void ToxGroupCall::clearPeers()
{
peers.clear();
for(auto con : sinkInvalid) {
for (auto con : sinkInvalid) {
QObject::disconnect(con.second);
}
sinkInvalid.clear();
}
const std::unique_ptr<IAudioSink> &ToxGroupCall::getAudioSink(ToxPk peer)
const std::unique_ptr<IAudioSink>& ToxGroupCall::getAudioSink(ToxPk peer)
{
if(!havePeer(peer)) {
if (!havePeer(peer)) {
addPeer(peer);
}
const auto& source = peers.find(peer);

View File

@ -77,7 +77,7 @@ public:
TOXAV_FRIEND_CALL_STATE getState() const;
void setState(const TOXAV_FRIEND_CALL_STATE& value);
const std::unique_ptr<IAudioSink> &getAudioSink() const;
const std::unique_ptr<IAudioSink>& getAudioSink() const;
protected:
std::unique_ptr<QTimer> timeoutTimer;
@ -109,7 +109,8 @@ public:
bool havePeer(ToxPk peerId);
void clearPeers();
const std::unique_ptr<IAudioSink> &getAudioSink(ToxPk peer);
const std::unique_ptr<IAudioSink>& getAudioSink(ToxPk peer);
private:
std::map<ToxPk, std::unique_ptr<IAudioSink>> peers;
std::map<ToxPk, QMetaObject::Connection> sinkInvalid;

View File

@ -150,7 +150,7 @@ void AVForm::showEvent(QShowEvent* event)
subscribedToAudioIn = true;
}
if(audioSink == nullptr) {
if (audioSink == nullptr) {
audioSink.reset(audio->makeSink());
}
@ -571,7 +571,7 @@ void AVForm::on_outDevCombobox_currentIndexChanged(int deviceIndex)
const QString oldName = audioSettings->getOutDev();
if(oldName != deviceName) {
if (oldName != deviceName) {
audioSettings->setOutDev(deviceName);
audio->reinitOutput(deviceName);
audioSink.reset(Audio::getInstance().makeSink());

View File

@ -41,8 +41,8 @@ class AVForm : public GenericForm, private Ui::AVForm
{
Q_OBJECT
public:
AVForm(Audio* audio, CoreAV* coreAV, CameraSource& camera,
IAudioSettings* audioSettings, IVideoSettings* videoSettings);
AVForm(Audio* audio, CoreAV* coreAV, CameraSource& camera, IAudioSettings* audioSettings,
IVideoSettings* videoSettings);
~AVForm() override;
QString getFormName() final override
{