mirror of
https://github.com/qTox/qTox.git
synced 2024-03-22 14:00:36 +08:00
cleanup Audio::openOutput
This commit is contained in:
parent
3eb7b48d1c
commit
82e1644d67
|
@ -231,7 +231,9 @@ Open an output device
|
||||||
*/
|
*/
|
||||||
bool Audio::openOutput(const QString &outDevDescr)
|
bool Audio::openOutput(const QString &outDevDescr)
|
||||||
{
|
{
|
||||||
|
qDebug() << "Opening audio output " + outDevDescr;
|
||||||
QMutexLocker lock(&audioOutLock);
|
QMutexLocker lock(&audioOutLock);
|
||||||
|
|
||||||
auto* tmp = alOutDev;
|
auto* tmp = alOutDev;
|
||||||
alOutDev = nullptr;
|
alOutDev = nullptr;
|
||||||
if (outDevDescr.isEmpty())
|
if (outDevDescr.isEmpty())
|
||||||
|
@ -239,12 +241,7 @@ bool Audio::openOutput(const QString &outDevDescr)
|
||||||
else
|
else
|
||||||
alOutDev = alcOpenDevice(outDevDescr.toStdString().c_str());
|
alOutDev = alcOpenDevice(outDevDescr.toStdString().c_str());
|
||||||
|
|
||||||
if (!alOutDev)
|
if (alOutDev)
|
||||||
{
|
|
||||||
qWarning() << "Cannot open output audio device " + outDevDescr;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
{
|
||||||
if (alContext && alcMakeContextCurrent(nullptr) == ALC_TRUE)
|
if (alContext && alcMakeContextCurrent(nullptr) == ALC_TRUE)
|
||||||
alcDestroyContext(alContext);
|
alcDestroyContext(alContext);
|
||||||
|
@ -252,19 +249,22 @@ bool Audio::openOutput(const QString &outDevDescr)
|
||||||
if (tmp)
|
if (tmp)
|
||||||
alcCloseDevice(tmp);
|
alcCloseDevice(tmp);
|
||||||
|
|
||||||
alContext = alcCreateContext(alOutDev,nullptr);
|
alContext = alcCreateContext(alOutDev, nullptr);
|
||||||
if (!alcMakeContextCurrent(alContext))
|
if (alcMakeContextCurrent(alContext))
|
||||||
|
{
|
||||||
|
alGenSources(1, &alMainSource);
|
||||||
|
}
|
||||||
|
else
|
||||||
{
|
{
|
||||||
qWarning() << "Cannot create output audio context";
|
qWarning() << "Cannot create output audio context";
|
||||||
alcCloseDevice(alOutDev);
|
alcCloseDevice(alOutDev);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
else
|
}
|
||||||
{
|
else
|
||||||
alGenSources(1, &alMainSource);
|
{
|
||||||
}
|
qWarning() << "Cannot open output audio device " + outDevDescr;
|
||||||
|
return false;
|
||||||
qDebug() << "Opening audio output " + outDevDescr;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Core* core = Core::getInstance();
|
Core* core = Core::getInstance();
|
||||||
|
@ -405,7 +405,7 @@ void Audio::playGroupAudio(int group, int peer, const int16_t* data,
|
||||||
qreal volume = 0.;
|
qreal volume = 0.;
|
||||||
int bufsize = samples * 2 * channels;
|
int bufsize = samples * 2 * channels;
|
||||||
for (int i = 0; i < bufsize; ++i)
|
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);
|
emit groupAudioPlayed(group, peer, volume / bufsize);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user