Test tx audio sending (again)

merge-requests/2/head
Phil Taylor 2021-02-12 20:42:56 +00:00
rodzic 5a55d5fd3d
commit f83f40bee8
4 zmienionych plików z 46 dodań i 6 usunięć

Wyświetl plik

@ -177,8 +177,11 @@ void audioHandler::reinit()
audioInput = Q_NULLPTR;
audioInput = new QAudioInput(deviceInfo, format, this);
audioInput->setBufferSize(audioBuffer);
audioInput->setNotifyInterval(20);
connect(audioInput, SIGNAL(notify()), SLOT(notified()));
connect(audioInput, SIGNAL(stateChanged(QAudio::State)), SLOT(stateChanged(QAudio::State)));
}
else {
// (Re)initialize audio output
@ -303,6 +306,15 @@ qint64 audioHandler::readData(char* data, qint64 maxlen)
qint64 audioHandler::writeData(const char* data, qint64 len)
{
QMutexLocker locker(&mutex);
if (buffer.length() > bufferSize)
{
qWarning() << "writeData() Buffer overflow";
buffer.clear();
}
int chunkSize = 960; // Assume 8bit or uLaw.
if (isUlaw) {
for (int f = 0; f < len / 2; f++)
@ -324,11 +336,14 @@ qint64 audioHandler::writeData(const char* data, qint64 len)
qWarning() << "Unsupported number of bits! :" << radioSampleBits;
}
while (buffer.length() >= chunkSize)
if (buffer.length() >= chunkSize)
{
qDebug() << "Sending haveAudioData() with " << chunkSize << " bytes " << " rxlen: " << len;
emit haveAudioData(buffer.mid(0, chunkSize));
buffer.remove(0, chunkSize);
}
return (len); // Always return the same number as we received
}
@ -397,5 +412,17 @@ void audioHandler::getBufferSize()
emit sendBufferSize(audioOutput->bufferSize());
}
void audioHandler::getNextAudioChunk()
{
QMutexLocker locker(&mutex);
quint16 numSamples = radioSampleBits * 120;
if (buffer.size() >= numSamples) {
emit haveAudioData(buffer.mid(0, numSamples));
buffer.remove(0, numSamples);
}
return;
}

Wyświetl plik

@ -13,6 +13,7 @@
#include <QAudioInput>
#include <QIODevice>
#include <QThread>
#include <QTimer>
#include <QDebug>
@ -48,12 +49,14 @@ public slots:
private slots:
void notified();
void stateChanged(QAudio::State state);
void getNextAudioChunk(void);
signals:
void audioMessage(QString message);
void sendBufferSize(quint16 newSize);
void haveAudioData(const QByteArray& data);
private:
void reinit();
@ -72,6 +75,8 @@ private:
QAudioDeviceInfo deviceInfo;
quint16 radioSampleRate;
quint8 radioSampleBits;
QTimer* txAudioTimer = Q_NULLPTR; // Send pkt0 packets every 1000ms.
};

Wyświetl plik

@ -498,7 +498,7 @@ void udpSerial::DataReceived()
pkt7Timer->start(3000); // send pkt7 idle packets every 3 seconds
pkt0Timer = new QTimer(this);
connect(pkt0Timer, &QTimer::timeout, this, std::bind(&udpBase::SendPkt0Idle,this,true,0));
connect(pkt0Timer, &QTimer::timeout, this, std::bind(&udpBase::SendPkt0Idle, this, true, 0));
pkt0Timer->start(100);
periodicRunning = true;
@ -626,6 +626,9 @@ udpAudio::~udpAudio()
}
}
void udpAudio::sendTxAudio(QByteArray audio)
{
quint8 p[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
@ -634,9 +637,9 @@ void udpAudio::sendTxAudio(QByteArray audio)
0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00
};
int counter = 0;
if (((txCodec == 0x01 || txCodec == 0x02) && audio.length() != 960) || (txCodec == 0x04 && audio.length() != 1920)) {
qDebug() << "Unsupported TX audio length :" << audio.length() << " With codec: " << txCodec;
}
//if (((txCodec == 0x01 || txCodec == 0x02) && audio.length() != 960) || (txCodec == 0x04 && audio.length() != 1920)) {
// qDebug() << "Unsupported TX audio length :" << audio.length() << " With codec: " << txCodec;
//}
while (counter < audio.length())
{
QByteArray tx = QByteArray::fromRawData((const char*)p, sizeof(p));
@ -654,6 +657,7 @@ void udpAudio::sendTxAudio(QByteArray audio)
sendAudioSeq++;
}
}
void udpAudio::changeBufferSize(quint16 value)
@ -661,6 +665,8 @@ void udpAudio::changeBufferSize(quint16 value)
emit haveChangeBufferSize(value);
}
void udpAudio::DataReceived()
{
while (udp->hasPendingDatagrams()) {
@ -677,9 +683,11 @@ void udpAudio::DataReceived()
remoteSID = qFromBigEndian<quint32>(r.mid(8, 4));
if (!periodicRunning) {
periodicRunning = true;
pkt7Timer = new QTimer(this);
connect(pkt7Timer, &QTimer::timeout, this, &udpBase::SendPkt7Idle);
pkt7Timer->start(3000); // send pkt7 idle packets every 3 seconds
}
}
break;

Wyświetl plik

@ -69,7 +69,7 @@ public:
quint16 port=0;
QTimer *pkt7Timer=Q_NULLPTR; // Send pkt7 packets every 3 seconds
QTimer *pkt0Timer=Q_NULLPTR; // Send pkt0 packets every 1000ms.
QTimer *periodic=Q_NULLPTR; // Send pkt0 packets every 1000ms.
QTimer* periodic = Q_NULLPTR; // Send pkt0 packets every 1000ms.
bool periodicRunning = false;
bool sentPacketConnect2 = false;
time_t lastReceived = time(0);