Skip to content
This repository has been archived by the owner on Feb 12, 2023. It is now read-only.

Commit

Permalink
style: reformat current C++ codebase using clang-format
Browse files Browse the repository at this point in the history
  • Loading branch information
zetok committed Feb 26, 2017
1 parent 4367dc6 commit 80f5de3
Show file tree
Hide file tree
Showing 259 changed files with 5,892 additions and 7,750 deletions.
126 changes: 49 additions & 77 deletions src/audio/audio.cpp
Expand Up @@ -27,8 +27,8 @@
#include <QMutexLocker>
#include <QPointer>
#include <QThread>
#include <QtMath>
#include <QWaitCondition>
#include <QtMath>

#include <cassert>

Expand Down Expand Up @@ -56,8 +56,8 @@ class Audio::Private
static const ALchar* outDeviceNames()
{
return (alcIsExtensionPresent(NULL, "ALC_ENUMERATE_ALL_EXT") != AL_FALSE)
? alcGetString(NULL, ALC_ALL_DEVICES_SPECIFIER)
: alcGetString(NULL, ALC_DEVICE_SPECIFIER);
? alcGetString(NULL, ALC_ALL_DEVICES_SPECIFIER)
: alcGetString(NULL, ALC_DEVICE_SPECIFIER);
}

qreal inputGain() const
Expand All @@ -77,12 +77,12 @@ class Audio::Private
}

public:
qreal minInputGain;
qreal maxInputGain;
qreal minInputGain;
qreal maxInputGain;

private:
qreal gain;
qreal gainFactor;
qreal gain;
qreal gainFactor;
};

/**
Expand All @@ -102,7 +102,8 @@ class Audio::Private
* @param s Name of the sound to get the path of.
* @return The path of the requested sound.
*
* @fn void Audio::frameAvailable(const int16_t *pcm, size_t sample_count, uint8_t channels, uint32_t sampling_rate);
* @fn void Audio::frameAvailable(const int16_t *pcm, size_t sample_count, uint8_t channels,
* uint32_t sampling_rate);
*
* When there are input subscribers, we regularly emit captured audio frames with this signal
* Always connect with a blocking queued connection lambda, else the behaviour is undefined
Expand Down Expand Up @@ -150,7 +151,7 @@ Audio::Audio()
moveToThread(audioThread);

connect(&captureTimer, &QTimer::timeout, this, &Audio::doCapture);
captureTimer.setInterval(AUDIO_FRAME_DURATION/2);
captureTimer.setInterval(AUDIO_FRAME_DURATION / 2);
captureTimer.setSingleShot(false);
captureTimer.start();
connect(&playMono16Timer, &QTimer::timeout, this, &Audio::playMono16SoundCleanup);
Expand All @@ -175,7 +176,7 @@ void Audio::checkAlError() noexcept
qWarning("OpenAL error: %d", al_err);
}

void Audio::checkAlcError(ALCdevice *device) noexcept
void Audio::checkAlcError(ALCdevice* device) noexcept
{
const ALCenum alc_err = alcGetError(device);
if (alc_err)
Expand All @@ -191,8 +192,7 @@ qreal Audio::outputVolume() const

ALfloat volume = 0.0;

if (alOutDev)
{
if (alOutDev) {
alGetListenerf(AL_GAIN, &volume);
checkAlError();
}
Expand Down Expand Up @@ -302,8 +302,7 @@ void Audio::subscribeInput()
{
QMutexLocker locker(&audioLock);

if (!autoInitInput())
{
if (!autoInitInput()) {
qWarning("Failed to subscribe to audio input device.");
return;
}
Expand All @@ -325,7 +324,8 @@ void Audio::unsubscribeInput()
return;

inSubscriptions--;
qDebug() << "Unsubscribed from audio input device [" << inSubscriptions << "subscriptions left ]";
qDebug() << "Unsubscribed from audio input device [" << inSubscriptions
<< "subscriptions left ]";

if (!inSubscriptions)
cleanupInput();
Expand Down Expand Up @@ -367,14 +367,11 @@ bool Audio::initInput(const QString& deviceName)
const ALCsizei bufSize = (frameDuration * sampleRate * 4) / 1000 * chnls;

const QByteArray qDevName = deviceName.toUtf8();
const ALchar* tmpDevName = qDevName.isEmpty()
? nullptr
: qDevName.constData();
const ALchar* tmpDevName = qDevName.isEmpty() ? nullptr : qDevName.constData();
alInDev = alcCaptureOpenDevice(tmpDevName, sampleRate, stereoFlag, bufSize);

// Restart the capture if necessary
if (!alInDev)
{
if (!alInDev) {
qWarning() << "Failed to initialize audio input device:" << deviceName;
return false;
}
Expand Down Expand Up @@ -402,13 +399,10 @@ bool Audio::initOutput(const QString& deviceName)
assert(!alOutDev);

const QByteArray qDevName = deviceName.toUtf8();
const ALchar* tmpDevName = qDevName.isEmpty()
? nullptr
: qDevName.constData();
const ALchar* tmpDevName = qDevName.isEmpty() ? nullptr : qDevName.constData();
alOutDev = alcOpenDevice(tmpDevName);

if (!alOutDev)
{
if (!alOutDev) {
qWarning() << "Cannot open output audio device" << deviceName;
return false;
}
Expand All @@ -417,8 +411,7 @@ bool Audio::initOutput(const QString& deviceName)
alOutContext = alcCreateContext(alOutDev, nullptr);
checkAlcError(alOutDev);

if (!alcMakeContextCurrent(alOutContext))
{
if (!alcMakeContextCurrent(alOutContext)) {
qWarning() << "Cannot create output audio context";
return false;
}
Expand All @@ -431,8 +424,7 @@ bool Audio::initOutput(const QString& deviceName)
checkAlError();

Core* core = Core::getInstance();
if (core)
{
if (core) {
// reset each call's audio source
core->getAv()->invalidateCallSources();
}
Expand Down Expand Up @@ -466,8 +458,7 @@ void Audio::playMono16Sound(const QByteArray& data)

ALint state;
alGetSourcei(alMainSource, AL_SOURCE_STATE, &state);
if (state == AL_PLAYING)
{
if (state == AL_PLAYING) {
alSourceStop(alMainSource);
alSourcei(alMainSource, AL_BUFFER, AL_NONE);
}
Expand All @@ -480,7 +471,8 @@ void Audio::playMono16Sound(const QByteArray& data)
playMono16Timer.start(durationMs + 50);
}

void Audio::playAudioBuffer(ALuint alSource, const int16_t *data, int samples, unsigned channels, int sampleRate)
void Audio::playAudioBuffer(ALuint alSource, const int16_t* data, int samples, unsigned channels,
int sampleRate)
{
assert(channels == 1 || channels == 2);
QMutexLocker locker(&audioLock);
Expand All @@ -494,24 +486,19 @@ void Audio::playAudioBuffer(ALuint alSource, const int16_t *data, int samples, u
alGetSourcei(alSource, AL_BUFFERS_QUEUED, &queued);
alSourcei(alSource, AL_LOOPING, AL_FALSE);

if (processed)
{
if (processed) {
ALuint bufids[processed];
alSourceUnqueueBuffers(alSource, processed, bufids);
alDeleteBuffers(processed - 1, bufids + 1);
bufid = bufids[0];
}
else if (queued < 16)
{
} else if (queued < 16) {
alGenBuffers(1, &bufid);
}
else
{
} else {
return;
}

alBufferData(bufid, (channels == 1) ? AL_FORMAT_MONO16 : AL_FORMAT_STEREO16, data,
samples * 2 * channels, sampleRate);
samples * 2 * channels, sampleRate);
alSourceQueueBuffers(alSource, 1, &bufid);

ALint state;
Expand Down Expand Up @@ -543,14 +530,12 @@ void Audio::cleanupOutput()
{
outputInitialized = false;

if (alOutDev)
{
if (alOutDev) {
alSourcei(alMainSource, AL_LOOPING, AL_FALSE);
alSourceStop(alMainSource);
alDeleteSources(1, &alMainSource);

if (alMainBuffer)
{
if (alMainBuffer) {
alDeleteBuffers(1, &alMainBuffer);
alMainBuffer = 0;
}
Expand Down Expand Up @@ -578,8 +563,7 @@ void Audio::playMono16SoundCleanup()

ALint state;
alGetSourcei(alMainSource, AL_SOURCE_STATE, &state);
if (state == AL_STOPPED)
{
if (state == AL_STOPPED) {
alSourcei(alMainSource, AL_BUFFER, AL_NONE);
alDeleteBuffers(1, &alMainBuffer);
alMainBuffer = 0;
Expand All @@ -604,12 +588,11 @@ void Audio::doCapture()
int16_t buf[AUDIO_FRAME_SAMPLE_COUNT * AUDIO_CHANNELS];
alcCaptureSamples(alInDev, buf, AUDIO_FRAME_SAMPLE_COUNT);

for (quint32 i = 0; i < AUDIO_FRAME_SAMPLE_COUNT * AUDIO_CHANNELS; ++i)
{
for (quint32 i = 0; i < AUDIO_FRAME_SAMPLE_COUNT * AUDIO_CHANNELS; ++i) {
// gain amplification with clipping to 16-bit boundaries
int ampPCM = qBound<int>(std::numeric_limits<int16_t>::min(),
qRound(buf[i] * d->inputGainFactor()),
std::numeric_limits<int16_t>::max());
int ampPCM =
qBound<int>(std::numeric_limits<int16_t>::min(), qRound(buf[i] * d->inputGainFactor()),
std::numeric_limits<int16_t>::max());

buf[i] = static_cast<int16_t>(ampPCM);
}
Expand All @@ -631,13 +614,11 @@ QStringList Audio::outDeviceNames()
QStringList list;
const ALchar* pDeviceList = Private::outDeviceNames();

if (pDeviceList)
{
while (*pDeviceList)
{
if (pDeviceList) {
while (*pDeviceList) {
int len = static_cast<int>(strlen(pDeviceList));
list << QString::fromUtf8(pDeviceList, len);
pDeviceList += len+1;
pDeviceList += len + 1;
}
}

Expand All @@ -649,13 +630,11 @@ QStringList Audio::inDeviceNames()
QStringList list;
const ALchar* pDeviceList = Private::inDeviceNames();

if (pDeviceList)
{
while (*pDeviceList)
{
if (pDeviceList) {
while (*pDeviceList) {
int len = static_cast<int>(strlen(pDeviceList));
list << QString::fromUtf8(pDeviceList, len);
pDeviceList += len+1;
pDeviceList += len + 1;
}
}

Expand All @@ -666,14 +645,12 @@ void Audio::subscribeOutput(ALuint& sid)
{
QMutexLocker locker(&audioLock);

if (!autoInitOutput())
{
if (!autoInitOutput()) {
qWarning("Failed to subscribe to audio output device.");
return;
}

if (!alcMakeContextCurrent(alOutContext))
{
if (!alcMakeContextCurrent(alOutContext)) {
qWarning("Failed to activate output context.");
return;
}
Expand All @@ -682,23 +659,19 @@ void Audio::subscribeOutput(ALuint& sid)
assert(sid);
outSources << sid;

qDebug() << "Audio source" << sid << "created. Sources active:"
<< outSources.size();
qDebug() << "Audio source" << sid << "created. Sources active:" << outSources.size();
}

void Audio::unsubscribeOutput(ALuint &sid)
void Audio::unsubscribeOutput(ALuint& sid)
{
QMutexLocker locker(&audioLock);

outSources.removeAll(sid);

if (sid)
{
if (alIsSource(sid))
{
if (sid) {
if (alIsSource(sid)) {
alDeleteSources(1, &sid);
qDebug() << "Audio source" << sid << "deleted. Sources active:"
<< outSources.size();
qDebug() << "Audio source" << sid << "deleted. Sources active:" << outSources.size();
} else {
qWarning() << "Trying to delete invalid audio source" << sid;
}
Expand All @@ -724,8 +697,7 @@ void Audio::stopLoop()

ALint state;
alGetSourcei(alMainSource, AL_SOURCE_STATE, &state);
if (state == AL_STOPPED)
{
if (state == AL_STOPPED) {
alSourcei(alMainSource, AL_BUFFER, AL_NONE);
alDeleteBuffers(1, &alMainBuffer);
alMainBuffer = 0;
Expand Down

0 comments on commit 80f5de3

Please sign in to comment.