From 82e1644d6716a6f5a851b120fb6afb1ef10ee573 Mon Sep 17 00:00:00 2001 From: Nils Fenner Date: Tue, 20 Oct 2015 23:14:07 +0200 Subject: [PATCH] cleanup Audio::openOutput --- src/audio/audio.cpp | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/src/audio/audio.cpp b/src/audio/audio.cpp index 3489f1a5e..e04a6c9ff 100644 --- a/src/audio/audio.cpp +++ b/src/audio/audio.cpp @@ -231,7 +231,9 @@ Open an output device */ bool Audio::openOutput(const QString &outDevDescr) { + qDebug() << "Opening audio output " + outDevDescr; QMutexLocker lock(&audioOutLock); + auto* tmp = alOutDev; alOutDev = nullptr; if (outDevDescr.isEmpty()) @@ -239,12 +241,7 @@ bool Audio::openOutput(const QString &outDevDescr) else alOutDev = alcOpenDevice(outDevDescr.toStdString().c_str()); - if (!alOutDev) - { - qWarning() << "Cannot open output audio device " + outDevDescr; - return false; - } - else + if (alOutDev) { if (alContext && alcMakeContextCurrent(nullptr) == ALC_TRUE) alcDestroyContext(alContext); @@ -252,19 +249,22 @@ bool Audio::openOutput(const QString &outDevDescr) if (tmp) alcCloseDevice(tmp); - alContext = alcCreateContext(alOutDev,nullptr); - if (!alcMakeContextCurrent(alContext)) + alContext = alcCreateContext(alOutDev, nullptr); + if (alcMakeContextCurrent(alContext)) + { + alGenSources(1, &alMainSource); + } + else { qWarning() << "Cannot create output audio context"; alcCloseDevice(alOutDev); return false; } - else - { - alGenSources(1, &alMainSource); - } - - qDebug() << "Opening audio output " + outDevDescr; + } + else + { + qWarning() << "Cannot open output audio device " + outDevDescr; + return false; } Core* core = Core::getInstance(); @@ -405,7 +405,7 @@ void Audio::playGroupAudio(int group, int peer, const int16_t* data, qreal volume = 0.; int bufsize = samples * 2 * channels; for (int i = 0; i < bufsize; ++i) - volume += abs(data[i]);//std::max(volume, data[i]); + volume += abs(data[i]); emit groupAudioPlayed(group, peer, volume / bufsize);