Browse Source

refactor: run formatting script

reviewable/pr5606/r3
sudden6 6 years ago
parent
commit
47402fae90
No known key found for this signature in database
GPG Key ID: 279509B499E032B9
  1. 3
      src/audio/backend/alsink.cpp
  2. 5
      src/audio/backend/alsink.h
  3. 25
      src/audio/backend/openal.cpp
  4. 10
      src/audio/backend/openal.h
  5. 9
      src/audio/backend/openal2.cpp
  6. 3
      src/audio/backend/openal2.h
  7. 26
      src/core/toxcall.cpp
  8. 1
      src/core/toxcall.h
  9. 4
      src/widget/form/settings/avform.h

3
src/audio/backend/alsink.cpp

@ -83,8 +83,7 @@ AlSink::AlSink(OpenAL& al, uint sourceId)
: audio{al} : audio{al}
, sourceId{sourceId} , sourceId{sourceId}
, killLock{QMutex::Recursive} , killLock{QMutex::Recursive}
{ {}
}
AlSink::operator bool() const AlSink::operator bool() const
{ {

5
src/audio/backend/alsink.h

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

25
src/audio/backend/openal.cpp

@ -37,12 +37,12 @@ namespace {
{ {
for (quint32 i = 0; i < bufferSize; ++i) { for (quint32 i = 0; i < bufferSize; ++i) {
// gain amplification with clipping to 16-bit boundaries // gain amplification with clipping to 16-bit boundaries
buffer[i] = qBound<int16_t>(std::numeric_limits<int16_t>::min(), buffer[i] =
qRound(buffer[i] * gainFactor), qBound<int16_t>(std::numeric_limits<int16_t>::min(), qRound(buffer[i] * gainFactor),
std::numeric_limits<int16_t>::max()); std::numeric_limits<int16_t>::max());
} }
} }
} } // namespace
/** /**
* @class OpenAL * @class OpenAL
@ -82,13 +82,15 @@ OpenAL::OpenAL()
captureTimer.setSingleShot(false); captureTimer.setSingleShot(false);
captureTimer.moveToThread(audioThread); captureTimer.moveToThread(audioThread);
// TODO for Qt 5.6+: use qOverload // 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.setInterval(1000);
cleanupTimer.setSingleShot(false); cleanupTimer.setSingleShot(false);
connect(&cleanupTimer, &QTimer::timeout, this, &OpenAL::cleanupSound); connect(&cleanupTimer, &QTimer::timeout, this, &OpenAL::cleanupSound);
// TODO for Qt 5.6+: use qOverload // 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(); audioThread->start();
} }
@ -332,8 +334,7 @@ void OpenAL::unsubscribeInput()
return; return;
inSubscriptions--; inSubscriptions--;
qDebug() << "Unsubscribed from audio input device [" << inSubscriptions qDebug() << "Unsubscribed from audio input device [" << inSubscriptions << "subscriptions left ]";
<< "subscriptions left ]";
if (!inSubscriptions) if (!inSubscriptions)
cleanupInput(); cleanupInput();
@ -377,8 +378,8 @@ bool OpenAL::initInput(const QString& deviceName, uint32_t channels)
this->channels = channels; this->channels = channels;
int stereoFlag = channels == 1 ? AL_FORMAT_MONO16 : AL_FORMAT_STEREO16; int stereoFlag = channels == 1 ? AL_FORMAT_MONO16 : AL_FORMAT_STEREO16;
const int bytesPerSample = 2; const int bytesPerSample = 2;
const int safetyFactor = 2; // internal OpenAL ring buffer. must be larger than our inputBuffer to avoid the ring const int safetyFactor = 2; // internal OpenAL ring buffer. must be larger than our inputBuffer
// from overwriting itself between captures. // to avoid the ring from overwriting itself between captures.
AUDIO_FRAME_SAMPLE_COUNT_TOTAL = AUDIO_FRAME_SAMPLE_COUNT_PER_CHANNEL * channels; AUDIO_FRAME_SAMPLE_COUNT_TOTAL = AUDIO_FRAME_SAMPLE_COUNT_PER_CHANNEL * channels;
const ALCsizei ringBufSize = AUDIO_FRAME_SAMPLE_COUNT_TOTAL * bytesPerSample * safetyFactor; const ALCsizei ringBufSize = AUDIO_FRAME_SAMPLE_COUNT_TOTAL * bytesPerSample * safetyFactor;
@ -650,7 +651,8 @@ void OpenAL::doInput()
return; 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() void OpenAL::doOutput()
@ -725,7 +727,8 @@ QStringList OpenAL::inDeviceNames()
* @brief Free all buffers that finished playing on a source * @brief Free all buffers that finished playing on a source
* @param sourceId where to remove the buffers from * @param sourceId where to remove the buffers from
*/ */
void OpenAL::cleanupBuffers(uint sourceId) { void OpenAL::cleanupBuffers(uint sourceId)
{
// unqueue all buffers from the source // unqueue all buffers from the source
ALint processed = 0; ALint processed = 0;
alGetSourcei(sourceId, AL_BUFFERS_PROCESSED, &processed); alGetSourcei(sourceId, AL_BUFFERS_PROCESSED, &processed);

10
src/audio/backend/openal.h

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

9
src/audio/backend/openal2.cpp

@ -32,7 +32,8 @@
#include <cassert> #include <cassert>
extern "C" { extern "C"
{
#include <filter_audio.h> #include <filter_audio.h>
} }
@ -80,8 +81,7 @@ OpenAL2::OpenAL2()
, alProxyContext{nullptr} , alProxyContext{nullptr}
, alProxySource{0} , alProxySource{0}
, alProxyBuffer{0} , alProxyBuffer{0}
{ {}
}
bool OpenAL2::initInput(const QString& deviceName) bool OpenAL2::initInput(const QString& deviceName)
{ {
@ -324,7 +324,8 @@ void OpenAL2::doOutput()
alcMakeContextCurrent(alOutContext); 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); alSourceQueueBuffers(alProxySource, 1, bufids);

3
src/audio/backend/openal2.h

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

26
src/core/toxcall.cpp

@ -31,8 +31,7 @@
ToxCall::ToxCall(bool VideoEnabled, CoreAV& av) ToxCall::ToxCall(bool VideoEnabled, CoreAV& av)
: av{&av} : av{&av}
, videoEnabled{VideoEnabled} , videoEnabled{VideoEnabled}
{ {}
}
ToxCall::~ToxCall() ToxCall::~ToxCall()
{ {
@ -110,8 +109,8 @@ ToxFriendCall::ToxFriendCall(uint32_t FriendNum, bool VideoEnabled, CoreAV& av)
Audio& audio = Audio::getInstance(); Audio& audio = Audio::getInstance();
audio.subscribeInput(); audio.subscribeInput();
audioInConn = QObject::connect(&Audio::getInstance(), &Audio::frameAvailable, audioInConn = QObject::connect(&Audio::getInstance(), &Audio::frameAvailable,
[&av, FriendNum](const int16_t* pcm, size_t samples, uint8_t chans, [&av, FriendNum](const int16_t* pcm, size_t samples,
uint32_t rate) { uint8_t chans, uint32_t rate) {
av.sendCallAudio(FriendNum, pcm, samples, chans, rate); av.sendCallAudio(FriendNum, pcm, samples, chans, rate);
}); });
@ -120,9 +119,7 @@ ToxFriendCall::ToxFriendCall(uint32_t FriendNum, bool VideoEnabled, CoreAV& av)
} }
audioSinkInvalid = QObject::connect(sink.get(), &IAudioSink::invalidated, audioSinkInvalid = QObject::connect(sink.get(), &IAudioSink::invalidated,
[this]() { [this]() { this->onAudioSinkInvalidated(); });
this->onAudioSinkInvalidated();
});
// register video // register video
@ -154,9 +151,7 @@ void ToxFriendCall::onAudioSinkInvalidated()
const auto newSink = Audio::getInstance().makeSink(); const auto newSink = Audio::getInstance().makeSink();
audioSinkInvalid = QObject::connect(newSink, &IAudioSink::invalidated, audioSinkInvalid = QObject::connect(newSink, &IAudioSink::invalidated,
[this]() { [this]() { this->onAudioSinkInvalidated(); });
this->onAudioSinkInvalidated();
});
sink.reset(newSink); sink.reset(newSink);
} }
@ -206,8 +201,8 @@ ToxGroupCall::ToxGroupCall(int GroupNum, CoreAV& av)
Audio& audio = Audio::getInstance(); Audio& audio = Audio::getInstance();
audio.subscribeInput(); audio.subscribeInput();
audioInConn = QObject::connect(&Audio::getInstance(), &Audio::frameAvailable, audioInConn = QObject::connect(&Audio::getInstance(), &Audio::frameAvailable,
[&av, GroupNum](const int16_t* pcm, size_t samples, uint8_t chans, [&av, GroupNum](const int16_t* pcm, size_t samples,
uint32_t rate) { uint8_t chans, uint32_t rate) {
av.sendGroupCallAudio(GroupNum, pcm, samples, chans, rate); av.sendGroupCallAudio(GroupNum, pcm, samples, chans, rate);
}); });
@ -247,10 +242,9 @@ void ToxGroupCall::addPeer(ToxPk peerId)
IAudioSink* newSink = audio.makeSink(); IAudioSink* newSink = audio.makeSink();
peers.emplace(peerId, std::unique_ptr<IAudioSink>(newSink)); peers.emplace(peerId, std::unique_ptr<IAudioSink>(newSink));
QMetaObject::Connection con = QObject::connect(newSink, &IAudioSink::invalidated, QMetaObject::Connection con =
[this, peerId]() { QObject::connect(newSink, &IAudioSink::invalidated,
this->onAudioSinkInvalidated(peerId); [this, peerId]() { this->onAudioSinkInvalidated(peerId); });
});
sinkInvalid.insert({peerId, con}); sinkInvalid.insert({peerId, con});
} }

1
src/core/toxcall.h

@ -110,6 +110,7 @@ public:
void clearPeers(); void clearPeers();
const std::unique_ptr<IAudioSink>& getAudioSink(ToxPk peer); const std::unique_ptr<IAudioSink>& getAudioSink(ToxPk peer);
private: private:
std::map<ToxPk, std::unique_ptr<IAudioSink>> peers; std::map<ToxPk, std::unique_ptr<IAudioSink>> peers;
std::map<ToxPk, QMetaObject::Connection> sinkInvalid; std::map<ToxPk, QMetaObject::Connection> sinkInvalid;

4
src/widget/form/settings/avform.h

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

Loading…
Cancel
Save