mirror of
https://github.com/qTox/qTox.git
synced 2024-03-22 14:00:36 +08:00
cleanup OpenAL compatibility code in audio class
This commit is contained in:
parent
a1b87194b8
commit
08c43d0b83
|
@ -48,6 +48,15 @@
|
||||||
#include <AL/alc.h>
|
#include <AL/alc.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifndef ALC_ALL_DEVICES_SPECIFIER
|
||||||
|
// compatibility with older versions of OpenAL
|
||||||
|
#include <AL/alext.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef QTOX_FILTER_AUDIO
|
||||||
|
#include "audiofilterer.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
Audio* Audio::instance{nullptr};
|
Audio* Audio::instance{nullptr};
|
||||||
|
|
||||||
class AudioPrivate
|
class AudioPrivate
|
||||||
|
@ -77,7 +86,6 @@ public:
|
||||||
ALCdevice* alOutDev;
|
ALCdevice* alOutDev;
|
||||||
ALCcontext* alContext;
|
ALCcontext* alContext;
|
||||||
|
|
||||||
// predefined sources
|
|
||||||
ALuint alMainSource;
|
ALuint alMainSource;
|
||||||
|
|
||||||
qreal inputVolume;
|
qreal inputVolume;
|
||||||
|
@ -792,7 +800,7 @@ bool Audio::tryCaptureSamples(int16_t* buf, int samples)
|
||||||
if (!(d->alInDev && d->inputInitialized))
|
if (!(d->alInDev && d->inputInitialized))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
ALint curSamples=0;
|
ALint curSamples = 0;
|
||||||
alcGetIntegerv(d->alInDev, ALC_CAPTURE_SAMPLES, sizeof(curSamples), &curSamples);
|
alcGetIntegerv(d->alInDev, ALC_CAPTURE_SAMPLES, sizeof(curSamples), &curSamples);
|
||||||
if (curSamples < samples)
|
if (curSamples < samples)
|
||||||
return false;
|
return false;
|
||||||
|
@ -814,29 +822,19 @@ bool Audio::tryCaptureSamples(int16_t* buf, int samples)
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef QTOX_FILTER_AUDIO
|
#if defined(QTOX_FILTER_AUDIO) && defined(ALC_LOOPBACK_CAPTURE_SAMPLES)
|
||||||
#include "audiofilterer.h"
|
void Audio::getEchoesToFilter(AudioFilterer* filterer, int samples)
|
||||||
|
|
||||||
/* include for compatibility with older versions of OpenAL */
|
|
||||||
#ifndef ALC_ALL_DEVICES_SPECIFIER
|
|
||||||
#include <AL/alext.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
void Audio::getEchoesToFilter(AudioFilterer* filterer, int framesize)
|
|
||||||
{
|
{
|
||||||
#ifdef ALC_LOOPBACK_CAPTURE_SAMPLES
|
QMutexLocker locker(&d->audioLock);
|
||||||
|
|
||||||
ALint samples;
|
ALint samples;
|
||||||
alcGetIntegerv(Audio::getInstance().alOutDev, ALC_LOOPBACK_CAPTURE_SAMPLES, sizeof(samples), &samples);
|
alcGetIntegerv(&d->alOutDev, ALC_LOOPBACK_CAPTURE_SAMPLES, sizeof(samples), &samples);
|
||||||
if (samples >= framesize)
|
if (samples >= samples)
|
||||||
{
|
{
|
||||||
int16_t buf[framesize];
|
int16_t buf[samples];
|
||||||
alcCaptureSamplesLoopback(Audio::getInstance().alOutDev, buf, framesize);
|
alcCaptureSamplesLoopback(&d->alOutDev, buf, samples);
|
||||||
filterer->passAudioOutput(buf, framesize);
|
filterer->passAudioOutput(buf, samples);
|
||||||
filterer->setEchoDelayMs(5); // This 5ms is configurable I believe
|
filterer->setEchoDelayMs(5); // This 5ms is configurable I believe
|
||||||
}
|
}
|
||||||
#else
|
|
||||||
Q_UNUSED(filterer);
|
|
||||||
Q_UNUSED(framesize);
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -82,9 +82,8 @@ public:
|
||||||
static void playGroupAudioQueued(void *, int group, int peer, const int16_t* data,
|
static void playGroupAudioQueued(void *, int group, int peer, const int16_t* data,
|
||||||
unsigned samples, uint8_t channels, unsigned sample_rate, void*);
|
unsigned samples, uint8_t channels, unsigned sample_rate, void*);
|
||||||
|
|
||||||
#ifdef QTOX_FILTER_AUDIO
|
#if defined(QTOX_FILTER_AUDIO) && defined(ALC_LOOPBACK_CAPTURE_SAMPLES)
|
||||||
static void getEchoesToFilter(AudioFilterer* filter, int framesize);
|
void getEchoesToFilter(AudioFilterer* filter, int samples);
|
||||||
// is a null op #ifndef ALC_LOOPBACK_CAPTURE_SAMPLES
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
|
|
|
@ -263,9 +263,11 @@ bool CoreAV::sendCallAudio(uint32_t callId)
|
||||||
call.filterer = new AudioFilterer();
|
call.filterer = new AudioFilterer();
|
||||||
call.filterer->startFilter(AUDIO_SAMPLE_RATE);
|
call.filterer->startFilter(AUDIO_SAMPLE_RATE);
|
||||||
}
|
}
|
||||||
// is a null op #ifndef ALC_LOOPBACK_CAPTURE_SAMPLES
|
|
||||||
Audio::getEchoesToFilter(call.filterer, AUDIO_FRAME_SAMPLE_COUNT * AUDIO_CHANNELS);
|
|
||||||
|
|
||||||
|
#ifdef ALC_LOOPBACK_CAPTURE_SAMPLES
|
||||||
|
// compatibility with older versions of OpenAL
|
||||||
|
Audio::getInstance().getEchoesToFilter(call.filterer, AUDIO_FRAME_SAMPLE_COUNT * AUDIO_CHANNELS);
|
||||||
|
#endif
|
||||||
call.filterer->filterAudio(buf, AUDIO_FRAME_SAMPLE_COUNT * AUDIO_CHANNELS);
|
call.filterer->filterAudio(buf, AUDIO_FRAME_SAMPLE_COUNT * AUDIO_CHANNELS);
|
||||||
}
|
}
|
||||||
else if (call.filterer)
|
else if (call.filterer)
|
||||||
|
@ -413,10 +415,10 @@ bool CoreAV::sendGroupCallAudio(int groupId)
|
||||||
call.filterer = new AudioFilterer();
|
call.filterer = new AudioFilterer();
|
||||||
call.filterer->startFilter(AUDIO_SAMPLE_RATE);
|
call.filterer->startFilter(AUDIO_SAMPLE_RATE);
|
||||||
}
|
}
|
||||||
// is a null op #ifndef ALC_LOOPBACK_CAPTURE_SAMPLES
|
|
||||||
Audio::getEchoesToFilter(call.filterer, AUDIO_FRAME_SAMPLE_COUNT);
|
|
||||||
|
|
||||||
call.filterer->filterAudio(buf, AUDIO_FRAME_SAMPLE_COUNT * AUDIO_CHANNELS);
|
#ifdef ALC_LOOPBACK_CAPTURE_SAMPLES
|
||||||
|
Audio::getInstance().getEchoesToFilter(call.filterer, AUDIO_FRAME_SAMPLE_COUNT);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
else if (call.filterer)
|
else if (call.filterer)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue
Block a user