mirror of
https://github.com/qTox/qTox.git
synced 2024-03-22 14:00:36 +08:00
move docs to cpp
This commit is contained in:
parent
1c205b7c16
commit
59ca97e9b6
|
@ -38,6 +38,9 @@
|
||||||
|
|
||||||
Audio* Audio::instance{nullptr};
|
Audio* Audio::instance{nullptr};
|
||||||
|
|
||||||
|
/**
|
||||||
|
Returns the singleton's instance. Will construct on first call.
|
||||||
|
*/
|
||||||
Audio& Audio::getInstance()
|
Audio& Audio::getInstance()
|
||||||
{
|
{
|
||||||
if (!instance)
|
if (!instance)
|
||||||
|
@ -89,6 +92,9 @@ float Audio::getOutputVolume()
|
||||||
return getInstance().GetOutputVolume();
|
return getInstance().GetOutputVolume();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
Returns the current output volume, between 0 and 1
|
||||||
|
*/
|
||||||
qreal Audio::GetOutputVolume()
|
qreal Audio::GetOutputVolume()
|
||||||
{
|
{
|
||||||
QMutexLocker locker(&audioOutLock);
|
QMutexLocker locker(&audioOutLock);
|
||||||
|
@ -100,6 +106,9 @@ void Audio::setOutputVolume(float volume)
|
||||||
getInstance().SetOutputVolume(volume);
|
getInstance().SetOutputVolume(volume);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
The volume must be between 0 and 1
|
||||||
|
*/
|
||||||
void Audio::SetOutputVolume(qreal volume)
|
void Audio::SetOutputVolume(qreal volume)
|
||||||
{
|
{
|
||||||
QMutexLocker locker(&audioOutLock);
|
QMutexLocker locker(&audioOutLock);
|
||||||
|
@ -122,6 +131,9 @@ void Audio::SetOutputVolume(qreal volume)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
The volume must be between 0 and 2
|
||||||
|
*/
|
||||||
void Audio::setInputVolume(float volume)
|
void Audio::setInputVolume(float volume)
|
||||||
{
|
{
|
||||||
getInstance().SetInputVolume(volume);
|
getInstance().SetInputVolume(volume);
|
||||||
|
@ -139,6 +151,9 @@ void Audio::suscribeInput()
|
||||||
inst.SubscribeInput();
|
inst.SubscribeInput();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
Call when you need to capture sound from the open input device.
|
||||||
|
*/
|
||||||
void Audio::SubscribeInput()
|
void Audio::SubscribeInput()
|
||||||
{
|
{
|
||||||
assert(userCount >= 0);
|
assert(userCount >= 0);
|
||||||
|
@ -170,6 +185,9 @@ void Audio::unsuscribeInput()
|
||||||
inst.UnSubscribeInput();
|
inst.UnSubscribeInput();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
Call once you don't need to capture on the open input device anymore.
|
||||||
|
*/
|
||||||
void Audio::UnSubscribeInput()
|
void Audio::UnSubscribeInput()
|
||||||
{
|
{
|
||||||
assert(userCount > 0);
|
assert(userCount > 0);
|
||||||
|
@ -194,6 +212,9 @@ void Audio::openInput(const QString& inDevDescr)
|
||||||
getInstance().OpenInput(inDevDescr);
|
getInstance().OpenInput(inDevDescr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
Open an input device, use before suscribing
|
||||||
|
*/
|
||||||
void Audio::OpenInput(const QString& inDevDescr)
|
void Audio::OpenInput(const QString& inDevDescr)
|
||||||
{
|
{
|
||||||
QMutexLocker lock(&audioInLock);
|
QMutexLocker lock(&audioInLock);
|
||||||
|
@ -238,6 +259,9 @@ bool Audio::openOutput(const QString& outDevDescr)
|
||||||
return getInstance().OpenOutput(outDevDescr);
|
return getInstance().OpenOutput(outDevDescr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
Open an output device
|
||||||
|
*/
|
||||||
bool Audio::OpenOutput(const QString &outDevDescr)
|
bool Audio::OpenOutput(const QString &outDevDescr)
|
||||||
{
|
{
|
||||||
QMutexLocker lock(&audioOutLock);
|
QMutexLocker lock(&audioOutLock);
|
||||||
|
@ -288,6 +312,9 @@ void Audio::closeInput()
|
||||||
getInstance().CloseInput();
|
getInstance().CloseInput();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
Close an input device, please don't use unless everyone's unsuscribed
|
||||||
|
*/
|
||||||
void Audio::CloseInput()
|
void Audio::CloseInput()
|
||||||
{
|
{
|
||||||
qDebug() << "Closing input";
|
qDebug() << "Closing input";
|
||||||
|
@ -311,6 +338,9 @@ void Audio::closeOutput()
|
||||||
getInstance().CloseOutput();
|
getInstance().CloseOutput();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
Close an output device
|
||||||
|
*/
|
||||||
void Audio::CloseOutput()
|
void Audio::CloseOutput()
|
||||||
{
|
{
|
||||||
qDebug() << "Closing output";
|
qDebug() << "Closing output";
|
||||||
|
@ -339,6 +369,9 @@ void Audio::playMono16Sound(const QByteArray& data)
|
||||||
getInstance().PlayMono16Sound(data);
|
getInstance().PlayMono16Sound(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
Play a 44100Hz mono 16bit PCM sound
|
||||||
|
*/
|
||||||
void Audio::PlayMono16Sound(const QByteArray& data)
|
void Audio::PlayMono16Sound(const QByteArray& data)
|
||||||
{
|
{
|
||||||
QMutexLocker lock(&audioOutLock);
|
QMutexLocker lock(&audioOutLock);
|
||||||
|
@ -377,6 +410,11 @@ void Audio::PlayMono16Sound(const QByteArray& data)
|
||||||
alDeleteBuffers(1, &buffer);
|
alDeleteBuffers(1, &buffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
@brief May be called from any thread, will always queue a call to playGroupAudio.
|
||||||
|
|
||||||
|
The first and last argument are ignored, but allow direct compatibility with toxcore.
|
||||||
|
*/
|
||||||
void Audio::playGroupAudioQueued(Tox*,int group, int peer, const int16_t* data,
|
void Audio::playGroupAudioQueued(Tox*,int group, int peer, const int16_t* data,
|
||||||
unsigned samples, uint8_t channels, unsigned sample_rate, void* core)
|
unsigned samples, uint8_t channels, unsigned sample_rate, void* core)
|
||||||
{
|
{
|
||||||
|
@ -392,6 +430,9 @@ void Audio::playGroupAudio(int group, int peer, const int16_t* data,
|
||||||
getInstance().PlayGroupAudio(group, peer, data, samples, channels, sample_rate);
|
getInstance().PlayGroupAudio(group, peer, data, samples, channels, sample_rate);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
Must be called from the audio thread, plays a group call's received audio
|
||||||
|
*/
|
||||||
void Audio::PlayGroupAudio(int group, int peer, const int16_t* data,
|
void Audio::PlayGroupAudio(int group, int peer, const int16_t* data,
|
||||||
unsigned samples, uint8_t channels, unsigned sample_rate)
|
unsigned samples, uint8_t channels, unsigned sample_rate)
|
||||||
{
|
{
|
||||||
|
@ -465,6 +506,9 @@ bool Audio::isInputReady()
|
||||||
return getInstance().IsInputReady();
|
return getInstance().IsInputReady();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
Returns true if the input device is open and suscribed to
|
||||||
|
*/
|
||||||
bool Audio::IsInputReady()
|
bool Audio::IsInputReady()
|
||||||
{
|
{
|
||||||
QMutexLocker locker(&audioInLock);
|
QMutexLocker locker(&audioInLock);
|
||||||
|
@ -476,6 +520,9 @@ bool Audio::isOutputClosed()
|
||||||
return getInstance().IsOutputClosed();
|
return getInstance().IsOutputClosed();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
Returns true if the output device is open
|
||||||
|
*/
|
||||||
bool Audio::IsOutputClosed()
|
bool Audio::IsOutputClosed()
|
||||||
{
|
{
|
||||||
QMutexLocker locker(&audioOutLock);
|
QMutexLocker locker(&audioOutLock);
|
||||||
|
@ -487,6 +534,9 @@ bool Audio::tryCaptureSamples(uint8_t* buf, int framesize)
|
||||||
return getInstance().TryCaptureSamples(buf, framesize);
|
return getInstance().TryCaptureSamples(buf, framesize);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
Does nothing and return false on failure
|
||||||
|
*/
|
||||||
bool Audio::TryCaptureSamples(uint8_t* buf, int framesize)
|
bool Audio::TryCaptureSamples(uint8_t* buf, int framesize)
|
||||||
{
|
{
|
||||||
QMutexLocker lock(&audioInLock);
|
QMutexLocker lock(&audioInLock);
|
||||||
|
|
|
@ -47,45 +47,43 @@ class Audio : public QObject
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
static Audio& getInstance(); ///< Returns the singleton's instance. Will construct on first call.
|
static Audio& getInstance();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
void startAudioThread();
|
void startAudioThread();
|
||||||
|
|
||||||
static float getOutputVolume(); ///< Returns the current output volume, between 0 and 1
|
static float getOutputVolume();
|
||||||
qreal GetOutputVolume();
|
qreal GetOutputVolume();
|
||||||
static void setOutputVolume(float volume); ///< The volume must be between 0 and 1
|
static void setOutputVolume(float volume);
|
||||||
void SetOutputVolume(qreal volume);
|
void SetOutputVolume(qreal volume);
|
||||||
|
|
||||||
static void setInputVolume(float volume); ///< The volume must be between 0 and 2
|
static void setInputVolume(float volume);
|
||||||
void SetInputVolume(qreal volume);
|
void SetInputVolume(qreal volume);
|
||||||
|
|
||||||
static void suscribeInput(); ///< Call when you need to capture sound from the open input device.
|
static void suscribeInput();
|
||||||
void SubscribeInput();
|
void SubscribeInput();
|
||||||
static void unsuscribeInput(); ///< Call once you don't need to capture on the open input device anymore.
|
static void unsuscribeInput();
|
||||||
void UnSubscribeInput();
|
void UnSubscribeInput();
|
||||||
|
|
||||||
static void openInput(const QString& inDevDescr); ///< Open an input device, use before suscribing
|
static void openInput(const QString& inDevDescr);
|
||||||
void OpenInput(const QString& inDevDescr);
|
void OpenInput(const QString& inDevDescr);
|
||||||
static bool openOutput(const QString& outDevDescr); ///< Open an output device
|
static bool openOutput(const QString& outDevDescr);
|
||||||
bool OpenOutput(const QString& outDevDescr);
|
bool OpenOutput(const QString& outDevDescr);
|
||||||
static void closeInput();
|
static void closeInput();
|
||||||
void CloseInput();
|
void CloseInput();
|
||||||
static void closeOutput(); ///< Close an output device
|
static void closeOutput();
|
||||||
void CloseOutput();
|
void CloseOutput();
|
||||||
|
|
||||||
static bool isInputReady(); ///< Returns true if the input device is open and suscribed to
|
static bool isInputReady();
|
||||||
bool IsInputReady();
|
bool IsInputReady();
|
||||||
static bool isOutputClosed(); ///< Returns true if the output device is open
|
static bool isOutputClosed();
|
||||||
bool IsOutputClosed();
|
bool IsOutputClosed();
|
||||||
|
|
||||||
static void playMono16Sound(const QByteArray& data); ///< Play a 44100Hz mono 16bit PCM sound
|
static void playMono16Sound(const QByteArray& data);
|
||||||
void PlayMono16Sound(const QByteArray& data);
|
void PlayMono16Sound(const QByteArray& data);
|
||||||
static bool tryCaptureSamples(uint8_t* buf, int framesize); ///< Does nothing and return false on failure
|
static bool tryCaptureSamples(uint8_t* buf, int framesize);
|
||||||
bool TryCaptureSamples(uint8_t* buf, int framesize);
|
bool TryCaptureSamples(uint8_t* buf, int framesize);
|
||||||
|
|
||||||
/// May be called from any thread, will always queue a call to playGroupAudio
|
|
||||||
/// The first and last argument are ignored, but allow direct compatibility with toxcore
|
|
||||||
static void playGroupAudioQueued(Tox*, int group, int peer, const int16_t* data,
|
static void playGroupAudioQueued(Tox*, 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*);
|
||||||
void PlayGroupAudio(int group, int peer, const int16_t* data,
|
void PlayGroupAudio(int group, int peer, const int16_t* data,
|
||||||
|
@ -97,7 +95,6 @@ public:
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
/// Must be called from the audio thread, plays a group call's received audio
|
|
||||||
void playGroupAudio(int group, int peer, const int16_t* data,
|
void playGroupAudio(int group, int peer, const int16_t* data,
|
||||||
unsigned samples, uint8_t channels, unsigned sample_rate);
|
unsigned samples, uint8_t channels, unsigned sample_rate);
|
||||||
static void pauseOutput();
|
static void pauseOutput();
|
||||||
|
@ -115,6 +112,7 @@ private:
|
||||||
private:
|
private:
|
||||||
static Audio* instance;
|
static Audio* instance;
|
||||||
|
|
||||||
|
private:
|
||||||
QThread* audioThread;
|
QThread* audioThread;
|
||||||
QMutex audioInLock;
|
QMutex audioInLock;
|
||||||
QMutex audioOutLock;
|
QMutex audioOutLock;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user