2014-11-17 03:49:20 +08:00
|
|
|
/*
|
2015-06-06 09:40:08 +08:00
|
|
|
Copyright © 2014-2015 by The qTox Project
|
|
|
|
|
2014-11-17 03:49:20 +08:00
|
|
|
This file is part of qTox, a Qt-based graphical interface for Tox.
|
|
|
|
|
2015-06-06 09:40:08 +08:00
|
|
|
qTox is libre software: you can redistribute it and/or modify
|
2014-11-17 03:49:20 +08:00
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
2015-06-06 09:40:08 +08:00
|
|
|
|
|
|
|
qTox is distributed in the hope that it will be useful,
|
2014-11-17 03:49:20 +08:00
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
2015-06-06 09:40:08 +08:00
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
2014-11-17 03:49:20 +08:00
|
|
|
|
2015-06-06 09:40:08 +08:00
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with qTox. If not, see <http://www.gnu.org/licenses/>.
|
2014-11-17 03:49:20 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
2014-11-17 02:04:45 +08:00
|
|
|
#ifndef AUDIO_H
|
|
|
|
#define AUDIO_H
|
|
|
|
|
2014-11-20 05:26:04 +08:00
|
|
|
#include <QObject>
|
|
|
|
#include <QHash>
|
2015-10-18 21:23:33 +08:00
|
|
|
#include <QMutexLocker>
|
2014-11-17 02:04:45 +08:00
|
|
|
#include <atomic>
|
|
|
|
|
|
|
|
#if defined(__APPLE__) && defined(__MACH__)
|
|
|
|
#include <OpenAL/al.h>
|
|
|
|
#include <OpenAL/alc.h>
|
|
|
|
#else
|
|
|
|
#include <AL/al.h>
|
|
|
|
#include <AL/alc.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
class QString;
|
|
|
|
class QByteArray;
|
2014-11-20 05:26:04 +08:00
|
|
|
class QTimer;
|
|
|
|
class QThread;
|
2015-01-05 00:55:39 +08:00
|
|
|
class QMutex;
|
2014-11-20 05:26:04 +08:00
|
|
|
struct Tox;
|
2015-02-18 14:25:25 +08:00
|
|
|
class AudioFilterer;
|
2014-11-17 02:04:45 +08:00
|
|
|
|
2015-08-19 01:40:11 +08:00
|
|
|
class Audio : public QObject
|
2014-11-17 02:04:45 +08:00
|
|
|
{
|
2014-11-20 05:26:04 +08:00
|
|
|
Q_OBJECT
|
|
|
|
|
2014-11-17 02:04:45 +08:00
|
|
|
public:
|
2015-10-18 21:51:38 +08:00
|
|
|
static Audio& getInstance();
|
2014-11-20 05:26:04 +08:00
|
|
|
|
2015-10-18 21:23:33 +08:00
|
|
|
public:
|
|
|
|
void startAudioThread();
|
|
|
|
|
2015-10-18 21:51:38 +08:00
|
|
|
static float getOutputVolume();
|
2015-10-18 21:23:33 +08:00
|
|
|
qreal GetOutputVolume();
|
2015-10-18 21:51:38 +08:00
|
|
|
static void setOutputVolume(float volume);
|
2015-10-18 21:23:33 +08:00
|
|
|
void SetOutputVolume(qreal volume);
|
|
|
|
|
2015-10-18 21:51:38 +08:00
|
|
|
static void setInputVolume(float volume);
|
2015-10-18 21:23:33 +08:00
|
|
|
void SetInputVolume(qreal volume);
|
2015-05-12 07:27:32 +08:00
|
|
|
|
2015-10-18 21:51:38 +08:00
|
|
|
static void suscribeInput();
|
2015-10-18 21:23:33 +08:00
|
|
|
void SubscribeInput();
|
2015-10-18 21:51:38 +08:00
|
|
|
static void unsuscribeInput();
|
2015-10-19 03:20:39 +08:00
|
|
|
void UnsubscribeInput();
|
2014-11-17 02:04:45 +08:00
|
|
|
|
2015-10-18 21:51:38 +08:00
|
|
|
static void openInput(const QString& inDevDescr);
|
2015-10-18 21:23:33 +08:00
|
|
|
void OpenInput(const QString& inDevDescr);
|
2015-10-18 21:51:38 +08:00
|
|
|
static bool openOutput(const QString& outDevDescr);
|
2015-10-18 21:23:33 +08:00
|
|
|
bool OpenOutput(const QString& outDevDescr);
|
|
|
|
static void closeInput();
|
|
|
|
void CloseInput();
|
2015-10-18 21:51:38 +08:00
|
|
|
static void closeOutput();
|
2015-10-18 21:23:33 +08:00
|
|
|
void CloseOutput();
|
2014-11-17 02:04:45 +08:00
|
|
|
|
2015-10-18 21:51:38 +08:00
|
|
|
static bool isInputReady();
|
2015-10-18 21:23:33 +08:00
|
|
|
bool IsInputReady();
|
2015-10-18 21:51:38 +08:00
|
|
|
static bool isOutputClosed();
|
2015-10-18 21:23:33 +08:00
|
|
|
bool IsOutputClosed();
|
2015-01-05 00:55:39 +08:00
|
|
|
|
2015-10-18 21:51:38 +08:00
|
|
|
static void playMono16Sound(const QByteArray& data);
|
2015-10-18 21:23:33 +08:00
|
|
|
void PlayMono16Sound(const QByteArray& data);
|
2015-10-18 21:51:38 +08:00
|
|
|
static bool tryCaptureSamples(uint8_t* buf, int framesize);
|
2015-10-18 21:23:33 +08:00
|
|
|
bool TryCaptureSamples(uint8_t* buf, int framesize);
|
2014-11-17 02:04:45 +08:00
|
|
|
|
2014-11-20 05:26:04 +08:00
|
|
|
static void playGroupAudioQueued(Tox*, int group, int peer, const int16_t* data,
|
|
|
|
unsigned samples, uint8_t channels, unsigned sample_rate, void*);
|
2015-10-18 21:23:33 +08:00
|
|
|
void PlayGroupAudio(int group, int peer, const int16_t* data,
|
|
|
|
unsigned samples, uint8_t channels, unsigned sample_rate);
|
2014-11-20 05:26:04 +08:00
|
|
|
|
2015-02-18 14:25:25 +08:00
|
|
|
#ifdef QTOX_FILTER_AUDIO
|
|
|
|
static void getEchoesToFilter(AudioFilterer* filter, int framesize);
|
|
|
|
// is a null op #ifndef ALC_LOOPBACK_CAPTURE_SAMPLES
|
|
|
|
#endif
|
|
|
|
|
2014-11-20 05:26:04 +08:00
|
|
|
public slots:
|
|
|
|
void playGroupAudio(int group, int peer, const int16_t* data,
|
|
|
|
unsigned samples, uint8_t channels, unsigned sample_rate);
|
|
|
|
|
2015-08-19 01:40:11 +08:00
|
|
|
signals:
|
|
|
|
void groupAudioPlayed(int group, int peer, unsigned short volume);
|
|
|
|
|
2014-11-17 02:04:45 +08:00
|
|
|
private:
|
2015-10-18 21:23:33 +08:00
|
|
|
Audio();
|
2015-01-24 22:31:11 +08:00
|
|
|
~Audio();
|
2015-10-18 21:23:33 +08:00
|
|
|
|
|
|
|
void playAudioBuffer(ALuint alSource, const int16_t *data, int samples, unsigned channels, int sampleRate);
|
2014-11-17 02:04:45 +08:00
|
|
|
|
|
|
|
private:
|
2014-11-20 05:26:04 +08:00
|
|
|
static Audio* instance;
|
2015-10-18 21:23:33 +08:00
|
|
|
|
2015-10-18 21:51:38 +08:00
|
|
|
private:
|
2015-10-18 21:23:33 +08:00
|
|
|
QThread* audioThread;
|
|
|
|
QMutex audioInLock;
|
|
|
|
QMutex audioOutLock;
|
2015-10-19 03:19:33 +08:00
|
|
|
std::atomic<int> inputSubscriptions;
|
2015-10-18 21:23:33 +08:00
|
|
|
ALCdevice* alOutDev;
|
|
|
|
ALCdevice* alInDev;
|
|
|
|
qreal outputVolume;
|
|
|
|
qreal inputVolume;
|
|
|
|
ALuint alMainSource;
|
|
|
|
ALCcontext* alContext;
|
|
|
|
QTimer* timer;
|
2014-11-17 02:04:45 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // AUDIO_H
|