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

111 lines
3.2 KiB
C
Raw Normal View History

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