mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-22 21:35:40 +08:00
Use nested namespaces (C++17 feature)
This commit is contained in:
@@ -24,153 +24,147 @@
|
||||
#include <QDateTime>
|
||||
#include <QSharedPointer>
|
||||
|
||||
namespace BlackCore
|
||||
namespace BlackCore::Afv::Audio
|
||||
{
|
||||
namespace Afv
|
||||
//! Input buffer
|
||||
class CAudioInputBuffer : public QIODevice
|
||||
{
|
||||
namespace Audio
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
//! Inout buffer
|
||||
CAudioInputBuffer(QObject *parent);
|
||||
|
||||
//! Start
|
||||
void start(const QAudioFormat &format);
|
||||
|
||||
//! Stop
|
||||
void stop();
|
||||
|
||||
//! \copydoc QIODevice::readData
|
||||
virtual qint64 readData(char *data, qint64 maxlen) override;
|
||||
|
||||
//! \copydoc QIODevice::writeData
|
||||
virtual qint64 writeData(const char *data, qint64 len) override;
|
||||
|
||||
signals:
|
||||
//! Frame is available
|
||||
void frameAvailable(const QByteArray &frame);
|
||||
|
||||
private:
|
||||
static constexpr qint64 frameSize = 960;
|
||||
QByteArray m_buffer;
|
||||
QAudioFormat m_format;
|
||||
};
|
||||
|
||||
//! Opus data arguments
|
||||
struct OpusDataAvailableArgs
|
||||
{
|
||||
uint sequenceCounter = 0; //!< sequence counter
|
||||
QByteArray audio; //!< audio data
|
||||
};
|
||||
|
||||
//! Input volume stream arguments
|
||||
struct InputVolumeStreamArgs
|
||||
{
|
||||
//! Peak volume raw
|
||||
double PeakRaw = 0.0;
|
||||
|
||||
//! Peak volume in dB
|
||||
double PeakDB = -1.0 * std::numeric_limits<double>::infinity();
|
||||
|
||||
//! Peak volume in VU
|
||||
double PeakVU = 0.0;
|
||||
};
|
||||
|
||||
//! Input
|
||||
class CInput : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
//! Ctor
|
||||
CInput(int sampleRate, QObject *parent = nullptr);
|
||||
|
||||
//! Dtor
|
||||
virtual ~CInput() override
|
||||
{
|
||||
//! Input buffer
|
||||
class CAudioInputBuffer : public QIODevice
|
||||
{
|
||||
Q_OBJECT
|
||||
this->stop();
|
||||
}
|
||||
|
||||
public:
|
||||
//! Inout buffer
|
||||
CAudioInputBuffer(QObject *parent);
|
||||
//! Number of encoded bytes
|
||||
//! @{
|
||||
int opusBytesEncoded() const { return m_opusBytesEncoded; }
|
||||
void setOpusBytesEncoded(int opusBytesEncoded) { m_opusBytesEncoded = opusBytesEncoded; }
|
||||
//! @}
|
||||
|
||||
//! Start
|
||||
void start(const QAudioFormat &format);
|
||||
//! Gain ratio, value a amplitude need to be multiplied with
|
||||
//! \see http://www.sengpielaudio.com/calculator-amplification.htm
|
||||
//! \remark gain ratio is voltage ratio/or amplitude ratio, something between 0.001-7.95 for -60dB to 80dB
|
||||
//! @{
|
||||
double getGainRatio() const { return m_gainRatio; }
|
||||
bool setGainRatio(double gainRatio);
|
||||
//! @}
|
||||
// those used to be the original function names
|
||||
// double volume() const { return m_volume; }
|
||||
// bool setVolume(double volume);
|
||||
|
||||
//! Stop
|
||||
void stop();
|
||||
/* disabled as not needed
|
||||
//! The device's volume 0..1
|
||||
//! @{
|
||||
double getDeviceInputVolume() const;
|
||||
bool setDeviceInputVolume(double volume);
|
||||
//! @}
|
||||
*/
|
||||
|
||||
//! \copydoc QIODevice::readData
|
||||
virtual qint64 readData(char *data, qint64 maxlen) override;
|
||||
//! Started?
|
||||
bool started() const { return m_started; }
|
||||
|
||||
//! \copydoc QIODevice::writeData
|
||||
virtual qint64 writeData(const char *data, qint64 len) override;
|
||||
//! Start
|
||||
void start(const BlackMisc::Audio::CAudioDeviceInfo &inputDevice);
|
||||
|
||||
signals:
|
||||
//! Frame is available
|
||||
void frameAvailable(const QByteArray &frame);
|
||||
//! Stop
|
||||
void stop();
|
||||
|
||||
private:
|
||||
static constexpr qint64 frameSize = 960;
|
||||
QByteArray m_buffer;
|
||||
QAudioFormat m_format;
|
||||
};
|
||||
//! Corresponding device
|
||||
const BlackMisc::Audio::CAudioDeviceInfo &device() const { return m_device; }
|
||||
|
||||
//! Opus data arguments
|
||||
struct OpusDataAvailableArgs
|
||||
{
|
||||
uint sequenceCounter = 0; //!< sequence counter
|
||||
QByteArray audio; //!< audio data
|
||||
};
|
||||
signals:
|
||||
//! Volume stream data
|
||||
void inputVolumeStream(const InputVolumeStreamArgs &args);
|
||||
|
||||
//! Input volume stream arguments
|
||||
struct InputVolumeStreamArgs
|
||||
{
|
||||
//! Peak volume raw
|
||||
double PeakRaw = 0.0;
|
||||
//! OPUS data
|
||||
void opusDataAvailable(const OpusDataAvailableArgs &args);
|
||||
|
||||
//! Peak volume in dB
|
||||
double PeakDB = -1.0 * std::numeric_limits<double>::infinity();
|
||||
private:
|
||||
void audioInDataAvailable(const QByteArray &frame);
|
||||
|
||||
//! Peak volume in VU
|
||||
double PeakVU = 0.0;
|
||||
};
|
||||
static constexpr qint64 c_frameSize = 960;
|
||||
int m_sampleRate = 0;
|
||||
|
||||
//! Input
|
||||
class CInput : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
BlackSound::Codecs::COpusEncoder m_encoder;
|
||||
QScopedPointer<QAudioInput> m_audioInput;
|
||||
BlackMisc::Audio::CAudioDeviceInfo m_device;
|
||||
QAudioFormat m_inputFormat;
|
||||
|
||||
public:
|
||||
//! Ctor
|
||||
CInput(int sampleRate, QObject *parent = nullptr);
|
||||
bool m_started = false;
|
||||
int m_opusBytesEncoded = 0;
|
||||
int m_sampleCount = 0;
|
||||
double m_gainRatio = 1.0;
|
||||
qint16 m_maxSampleInput = 0.0;
|
||||
|
||||
//! Dtor
|
||||
virtual ~CInput() override
|
||||
{
|
||||
this->stop();
|
||||
}
|
||||
const int SampleCountPerEvent = 4800;
|
||||
const double maxDb = 0;
|
||||
const double minDb = -40;
|
||||
|
||||
//! Number of encoded bytes
|
||||
//! @{
|
||||
int opusBytesEncoded() const { return m_opusBytesEncoded; }
|
||||
void setOpusBytesEncoded(int opusBytesEncoded) { m_opusBytesEncoded = opusBytesEncoded; }
|
||||
//! @}
|
||||
|
||||
//! Gain ratio, value a amplitude need to be multiplied with
|
||||
//! \see http://www.sengpielaudio.com/calculator-amplification.htm
|
||||
//! \remark gain ratio is voltage ratio/or amplitude ratio, something between 0.001-7.95 for -60dB to 80dB
|
||||
//! @{
|
||||
double getGainRatio() const { return m_gainRatio; }
|
||||
bool setGainRatio(double gainRatio);
|
||||
//! @}
|
||||
// those used to be the original function names
|
||||
// double volume() const { return m_volume; }
|
||||
// bool setVolume(double volume);
|
||||
|
||||
/* disabled as not needed
|
||||
//! The device's volume 0..1
|
||||
//! @{
|
||||
double getDeviceInputVolume() const;
|
||||
bool setDeviceInputVolume(double volume);
|
||||
//! @}
|
||||
*/
|
||||
|
||||
//! Started?
|
||||
bool started() const { return m_started; }
|
||||
|
||||
//! Start
|
||||
void start(const BlackMisc::Audio::CAudioDeviceInfo &inputDevice);
|
||||
|
||||
//! Stop
|
||||
void stop();
|
||||
|
||||
//! Corresponding device
|
||||
const BlackMisc::Audio::CAudioDeviceInfo &device() const { return m_device; }
|
||||
|
||||
signals:
|
||||
//! Volume stream data
|
||||
void inputVolumeStream(const InputVolumeStreamArgs &args);
|
||||
|
||||
//! OPUS data
|
||||
void opusDataAvailable(const OpusDataAvailableArgs &args);
|
||||
|
||||
private:
|
||||
void audioInDataAvailable(const QByteArray &frame);
|
||||
|
||||
static constexpr qint64 c_frameSize = 960;
|
||||
int m_sampleRate = 0;
|
||||
|
||||
BlackSound::Codecs::COpusEncoder m_encoder;
|
||||
QScopedPointer<QAudioInput> m_audioInput;
|
||||
BlackMisc::Audio::CAudioDeviceInfo m_device;
|
||||
QAudioFormat m_inputFormat;
|
||||
|
||||
bool m_started = false;
|
||||
int m_opusBytesEncoded = 0;
|
||||
int m_sampleCount = 0;
|
||||
double m_gainRatio = 1.0;
|
||||
qint16 m_maxSampleInput = 0.0;
|
||||
|
||||
const int SampleCountPerEvent = 4800;
|
||||
const double maxDb = 0;
|
||||
const double minDb = -40;
|
||||
|
||||
uint m_audioSequenceCounter = 0;
|
||||
CAudioInputBuffer *m_audioInputBuffer = nullptr;
|
||||
uint m_audioSequenceCounter = 0;
|
||||
CAudioInputBuffer *m_audioInputBuffer = nullptr;
|
||||
|
||||
#ifdef Q_OS_MAC
|
||||
BlackMisc::CMacOSMicrophoneAccess m_micAccess;
|
||||
void delayedInitMicrophone();
|
||||
BlackMisc::CMacOSMicrophoneAccess m_micAccess;
|
||||
void delayedInitMicrophone();
|
||||
#endif
|
||||
};
|
||||
} // ns
|
||||
} // ns
|
||||
};
|
||||
} // ns
|
||||
|
||||
#endif // guard
|
||||
|
||||
Reference in New Issue
Block a user