2014-11-17 03:49:20 +08:00
|
|
|
/*
|
2017-04-13 05:27:48 +08:00
|
|
|
Copyright © 2014-2017 by The qTox Project Contributors
|
2015-06-06 09:40:08 +08:00
|
|
|
|
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
|
|
|
|
|
|
|
|
#include <atomic>
|
2015-10-22 13:57:46 +08:00
|
|
|
#include <cmath>
|
2015-12-10 13:48:28 +08:00
|
|
|
|
2016-01-21 23:43:13 +08:00
|
|
|
#include <QMutex>
|
2017-02-26 19:52:45 +08:00
|
|
|
#include <QObject>
|
2016-01-22 03:17:18 +08:00
|
|
|
#include <QTimer>
|
2016-01-21 23:43:13 +08:00
|
|
|
|
2016-09-28 11:25:44 +08:00
|
|
|
#include <cassert>
|
|
|
|
|
2015-08-19 01:40:11 +08:00
|
|
|
class Audio : public QObject
|
2014-11-17 02:04:45 +08:00
|
|
|
{
|
2016-01-21 23:43:13 +08:00
|
|
|
Q_OBJECT
|
2015-11-15 04:02:29 +08:00
|
|
|
|
2014-11-17 02:04:45 +08:00
|
|
|
public:
|
2017-02-26 19:52:45 +08:00
|
|
|
enum class Sound
|
|
|
|
{
|
|
|
|
NewMessage,
|
|
|
|
Test,
|
2017-06-13 12:27:29 +08:00
|
|
|
IncomingCall,
|
|
|
|
OutgoingCall
|
2017-02-26 19:52:45 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
inline static QString getSound(Sound s)
|
|
|
|
{
|
|
|
|
switch (s) {
|
2016-09-28 11:25:44 +08:00
|
|
|
case Sound::Test:
|
|
|
|
return QStringLiteral(":/audio/notification.pcm");
|
|
|
|
case Sound::NewMessage:
|
|
|
|
return QStringLiteral(":/audio/notification.pcm");
|
|
|
|
case Sound::IncomingCall:
|
|
|
|
return QStringLiteral(":/audio/ToxIncomingCall.pcm");
|
2017-06-13 12:27:29 +08:00
|
|
|
case Sound::OutgoingCall:
|
|
|
|
return QStringLiteral(":/audio/ToxOutgoingCall.pcm");
|
2016-09-28 11:25:44 +08:00
|
|
|
}
|
|
|
|
assert(false);
|
|
|
|
return QString();
|
|
|
|
}
|
2015-10-18 21:51:38 +08:00
|
|
|
static Audio& getInstance();
|
2014-11-20 05:26:04 +08:00
|
|
|
|
2017-04-13 05:27:48 +08:00
|
|
|
virtual qreal outputVolume() const = 0;
|
|
|
|
virtual void setOutputVolume(qreal volume) = 0;
|
2015-10-20 09:46:44 +08:00
|
|
|
|
2017-04-13 05:27:48 +08:00
|
|
|
virtual qreal minInputGain() const = 0;
|
|
|
|
virtual void setMinInputGain(qreal dB) = 0;
|
2016-07-07 17:58:28 +08:00
|
|
|
|
2017-04-13 05:27:48 +08:00
|
|
|
virtual qreal maxInputGain() const = 0;
|
|
|
|
virtual void setMaxInputGain(qreal dB) = 0;
|
2016-07-07 17:58:28 +08:00
|
|
|
|
2017-04-13 05:27:48 +08:00
|
|
|
virtual qreal inputGain() const = 0;
|
|
|
|
virtual void setInputGain(qreal dB) = 0;
|
2015-10-20 09:46:44 +08:00
|
|
|
|
2017-04-13 05:27:48 +08:00
|
|
|
virtual void reinitInput(const QString& inDevDesc) = 0;
|
|
|
|
virtual bool reinitOutput(const QString& outDevDesc) = 0;
|
2015-11-09 04:09:38 +08:00
|
|
|
|
2017-04-13 05:27:48 +08:00
|
|
|
virtual bool isOutputReady() const = 0;
|
2015-10-20 09:46:44 +08:00
|
|
|
|
2017-04-13 05:27:48 +08:00
|
|
|
virtual QStringList outDeviceNames() = 0;
|
|
|
|
virtual QStringList inDeviceNames() = 0;
|
2016-07-07 17:58:28 +08:00
|
|
|
|
2017-04-13 05:27:48 +08:00
|
|
|
virtual void subscribeOutput(uint& sourceId) = 0;
|
|
|
|
virtual void unsubscribeOutput(uint& sourceId) = 0;
|
2016-07-07 17:58:28 +08:00
|
|
|
|
2017-04-13 05:27:48 +08:00
|
|
|
virtual void subscribeInput() = 0;
|
|
|
|
virtual void unsubscribeInput() = 0;
|
2015-10-05 08:36:50 +08:00
|
|
|
|
2017-04-13 05:27:48 +08:00
|
|
|
virtual void startLoop() = 0;
|
|
|
|
virtual void stopLoop() = 0;
|
|
|
|
virtual void playMono16Sound(const QByteArray& data) = 0;
|
|
|
|
virtual void playMono16Sound(const QString& path) = 0;
|
2014-11-17 02:04:45 +08:00
|
|
|
|
2017-04-13 05:27:48 +08:00
|
|
|
virtual void playAudioBuffer(uint sourceId, const int16_t* data, int samples, unsigned channels,
|
2017-06-01 15:50:59 +08:00
|
|
|
int sampleRate) = 0;
|
2015-09-28 03:34:14 +08:00
|
|
|
|
2016-07-27 06:18:57 +08:00
|
|
|
public:
|
|
|
|
// Public default audio settings
|
|
|
|
static constexpr uint32_t AUDIO_SAMPLE_RATE = 48000;
|
|
|
|
static constexpr uint32_t AUDIO_FRAME_DURATION = 20;
|
2017-06-01 15:50:59 +08:00
|
|
|
static constexpr uint32_t AUDIO_FRAME_SAMPLE_COUNT =
|
|
|
|
AUDIO_FRAME_DURATION * AUDIO_SAMPLE_RATE / 1000;
|
2017-04-27 06:06:26 +08:00
|
|
|
static constexpr uint32_t AUDIO_CHANNELS = 1;
|
2016-07-27 06:18:57 +08:00
|
|
|
|
2015-08-19 01:40:11 +08:00
|
|
|
signals:
|
2017-02-26 19:52:45 +08:00
|
|
|
void frameAvailable(const int16_t* pcm, size_t sample_count, uint8_t channels,
|
|
|
|
uint32_t sampling_rate);
|
2014-11-17 02:04:45 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // AUDIO_H
|