2022-05-12 00:46:20 +00:00
|
|
|
#ifndef rtHandler_H
|
|
|
|
#define rtHandler_H
|
|
|
|
|
|
|
|
#include <QObject>
|
|
|
|
#include <QByteArray>
|
|
|
|
#include <QThread>
|
2022-05-12 19:30:51 +00:00
|
|
|
#include <QMutex>
|
2022-05-12 00:46:20 +00:00
|
|
|
|
2022-05-14 14:05:48 +00:00
|
|
|
#ifndef Q_OS_LINUX
|
2022-05-12 00:46:20 +00:00
|
|
|
#include "RtAudio.h"
|
|
|
|
#else
|
|
|
|
#include "rtaudio/RtAudio.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
#include <QAudioFormat>
|
|
|
|
#include <QTime>
|
|
|
|
#include <QMap>
|
2022-05-14 00:27:44 +00:00
|
|
|
#include <QTimer>
|
2022-05-12 00:46:20 +00:00
|
|
|
|
|
|
|
|
|
|
|
/* wfview Packet types */
|
|
|
|
#include "packettypes.h"
|
|
|
|
|
|
|
|
/* Logarithmic taper for volume control */
|
|
|
|
#include "audiotaper.h"
|
|
|
|
|
2022-05-14 12:45:56 +00:00
|
|
|
#include "audiohandler.h"
|
2022-05-12 00:46:20 +00:00
|
|
|
/* Audio converter class*/
|
|
|
|
#include "audioconverter.h"
|
|
|
|
|
|
|
|
#include <QDebug>
|
|
|
|
|
|
|
|
|
2022-05-14 12:45:56 +00:00
|
|
|
class rtHandler : public audioHandler
|
2022-05-12 00:46:20 +00:00
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
public:
|
|
|
|
rtHandler(QObject* parent = 0);
|
|
|
|
~rtHandler();
|
|
|
|
|
|
|
|
int getLatency();
|
|
|
|
|
|
|
|
|
|
|
|
void getNextAudioChunk(QByteArray& data);
|
|
|
|
quint16 getAmplitude();
|
|
|
|
|
|
|
|
public slots:
|
|
|
|
bool init(audioSetup setup);
|
|
|
|
void changeLatency(const quint16 newSize);
|
|
|
|
void setVolume(unsigned char volume);
|
|
|
|
void convertedInput(audioPacket audio);
|
|
|
|
void convertedOutput(audioPacket audio);
|
|
|
|
void incomingAudio(const audioPacket data);
|
|
|
|
|
|
|
|
|
|
|
|
private slots:
|
|
|
|
|
|
|
|
signals:
|
|
|
|
void audioMessage(QString message);
|
|
|
|
void sendLatency(quint16 newSize);
|
|
|
|
void haveAudioData(const audioPacket& data);
|
2022-08-24 22:02:00 +00:00
|
|
|
void haveLevels(quint16 amplitudePeak, quint16 amplitudeRMS, quint16 latency, quint16 current, bool under, bool over);
|
2022-05-12 00:46:20 +00:00
|
|
|
void setupConverter(QAudioFormat in, QAudioFormat out, quint8 opus, quint8 resamp);
|
|
|
|
void sendToConverter(audioPacket audio);
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
|
|
|
|
|
|
|
int readData(void* outputBuffer, void* inputBuffer, unsigned int nFrames, double streamTime, RtAudioStreamStatus status);
|
|
|
|
|
|
|
|
static int staticRead(void* outputBuffer, void* inputBuffer, unsigned int nFrames, double streamTime, RtAudioStreamStatus status, void* userData) {
|
|
|
|
return static_cast<rtHandler*>(userData)->readData(outputBuffer, inputBuffer, nFrames, streamTime, status);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int writeData(void* outputBuffer, void* inputBuffer, unsigned int nFrames, double streamTime, RtAudioStreamStatus status);
|
|
|
|
|
|
|
|
static int staticWrite(void* outputBuffer, void* inputBuffer, unsigned int nFrames, double streamTime, RtAudioStreamStatus status, void* userData) {
|
|
|
|
return static_cast<rtHandler*>(userData)->writeData(outputBuffer, inputBuffer, nFrames, streamTime, status);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool isInitialized = false;
|
|
|
|
|
|
|
|
RtAudio* audio = Q_NULLPTR;
|
|
|
|
int audioDevice = 0;
|
|
|
|
RtAudio::StreamParameters aParams;
|
|
|
|
RtAudio::StreamOptions options;
|
|
|
|
RtAudio::DeviceInfo info;
|
|
|
|
|
|
|
|
quint16 audioLatency;
|
|
|
|
unsigned int chunkSize;
|
|
|
|
|
|
|
|
quint32 lastSeq;
|
|
|
|
quint32 lastSentSeq = 0;
|
|
|
|
|
|
|
|
quint16 currentLatency;
|
2022-05-14 00:11:00 +00:00
|
|
|
float amplitude = 0.0;
|
2022-05-12 00:46:20 +00:00
|
|
|
qreal volume = 1.0;
|
|
|
|
|
|
|
|
audioSetup setup;
|
|
|
|
QAudioFormat inFormat;
|
|
|
|
QAudioFormat outFormat;
|
|
|
|
audioConverter* converter = Q_NULLPTR;
|
|
|
|
QThread* converterThread = Q_NULLPTR;
|
|
|
|
QByteArray arrayBuffer;
|
|
|
|
bool isUnderrun = false;
|
2022-05-13 15:09:26 +00:00
|
|
|
bool isOverrun = false;
|
2022-05-12 19:30:51 +00:00
|
|
|
QMutex audioMutex;
|
2022-05-14 00:27:44 +00:00
|
|
|
int retryConnectCount = 0;
|
2022-05-12 00:46:20 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // rtHandler_H
|