1
0
mirror of https://github.com/qTox/qTox.git synced 2024-03-22 14:00:36 +08:00
qTox/src/audio/audio.h

107 lines
2.8 KiB
C
Raw Normal View History

2014-11-17 03:49:20 +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.
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.
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
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
2014-11-17 03:49:20 +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
*/
#ifndef AUDIO_H
#define AUDIO_H
#include <QObject>
#include <QMutexLocker>
#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 QTimer;
struct Tox;
class AudioFilterer;
2015-08-19 01:40:11 +08:00
class Audio : public QObject
{
Q_OBJECT
public:
2015-10-18 21:51:38 +08:00
static Audio& getInstance();
public:
void startAudioThread();
2015-10-20 09:46:44 +08:00
qreal getOutputVolume();
void setOutputVolume(qreal volume);
void setInputVolume(qreal volume);
void subscribeInput();
void unsubscribeInput();
void openInput(const QString& inDevDescr);
bool openOutput(const QString& outDevDescr);
bool isInputReady();
bool isOutputClosed();
void playMono16Sound(const QByteArray& data);
bool tryCaptureSamples(uint8_t* buf, int framesize);
static void playGroupAudioQueued(Tox*, int group, int peer, const int16_t* data,
unsigned samples, uint8_t channels, unsigned sample_rate, void*);
#ifdef QTOX_FILTER_AUDIO
static void getEchoesToFilter(AudioFilterer* filter, int framesize);
// is a null op #ifndef ALC_LOOPBACK_CAPTURE_SAMPLES
#endif
public slots:
2015-10-20 09:46:44 +08:00
void closeInput();
void closeOutput();
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);
private:
Audio();
2015-01-24 22:31:11 +08:00
~Audio();
void playAudioBuffer(ALuint alSource, const int16_t *data, int samples, unsigned channels, int sampleRate);
private:
static Audio* instance;
2015-10-18 21:51:38 +08:00
private:
QThread* audioThread;
QMutex audioInLock;
QMutex audioOutLock;
std::atomic<int> inputSubscriptions;
ALCdevice* alOutDev;
ALCdevice* alInDev;
qreal outputVolume;
qreal inputVolume;
ALuint alMainSource;
ALCcontext* alContext;
QTimer* timer;
};
#endif // AUDIO_H