From f922789e2dd0972cfa8da568a2a57e54289425a2 Mon Sep 17 00:00:00 2001 From: Elliott Liggett Date: Sun, 1 Aug 2021 13:51:14 -0700 Subject: [PATCH] Compiles, and does not crash! Audio sounds bad, which means the plugin code is starting to work. Current bugs: buffer size seems to be changing between 2728 bytes and 1112 bytes, so will need to make the plugin buffer dynamic. --- audiohandler.cpp | 39 ++++++++++++++++++++++++--------------- audiohandler.h | 4 ++++ rigcommander.cpp | 8 +++++--- 3 files changed, 33 insertions(+), 18 deletions(-) diff --git a/audiohandler.cpp b/audiohandler.cpp index b7a53af..921849e 100644 --- a/audiohandler.cpp +++ b/audiohandler.cpp @@ -303,6 +303,7 @@ void audioHandler::setupLADSP() // setup for the plugin: int lPluginIndex; + pre_control = 0.01f; void *pvPluginHandle = loadLADSPAPluginLibrary(pcPluginFilename); dlerror(); @@ -663,10 +664,6 @@ void audioHandler::incomingAudio(audioPacket inPacket) //qDebug(logAudio()) << "Adding packet to buffer:" << inPacket.seq << ": " << inPacket.data.length(); - if (!ringBuf->try_write(inPacket)) - { - qDebug(logAudio()) << "Buffer full! capacity:" << ringBuf->capacity() << "length" << ringBuf->size(); - } // Begin plugin code: @@ -679,17 +676,13 @@ void audioHandler::incomingAudio(audioPacket inPacket) qDebug() << "about to make byte array:"; // Why does the next line down crash!?!?! - QByteArray pluginOutputQBA; qDebug() << "made byte array."; -// pluginOutputQBA.reserve(inPacket.data.size()); -// pluginOutputQBA.resize(inPacket.data.size()); - pluginOutputQBA.fill('0', inPacket.data.size()); + qDebug(logAudio()) << "size of inPacket data: " << inPacket.data.size(); + qDebug(logAudio()) << "size of BUF_SIZE: " << BUF_SIZE; -// qDebug(logAudio()) << "plugin output QBA size: " << pluginOutputQBA.length(); - - volatile qint16* pluginOutput = (qint16*)pluginOutputQBA.data(); + pluginOutput16bitInterlaced = (uint16_t *)malloc(sizeof(uint16_t) * inPacket.data.size() ); // Copy data from "out" to pInBuffer: // copyDataIn(); @@ -705,23 +698,39 @@ void audioHandler::incomingAudio(audioPacket inPacket) pInBuffer[1][n/2] = (out[n+1] - mid) * scalingFactor; } + control = pre_control; runPlugin(); // copy data back out from pOutBuffer to inPacket.data - // pOutBuffer[0] has size BUF_SIZE/2 - // pOutBuffer[1] has size BUF_SIZE/2 + // pOut/inBuffer[0] has size BUF_SIZE/2 + // pOut/inBuffer[1] has size BUF_SIZE/2 // Maybe the issue is here? for (int n = 0; n+1 < BUF_SIZE; n += 2) { - pluginOutput[n] = (pOutBuffer[0][n/2] + 1) * max; - pluginOutput[n+1] = (pOutBuffer[1][n/2] + 1) * max; + pluginOutput16bitInterlaced[n] = (pOutBuffer[0][n/2] + 1) * max; + pluginOutput16bitInterlaced[n+1] = (pOutBuffer[1][n/2] + 1) * max; } // copyDataOut(); + for(int i=0; i < BUF_SIZE; i++) + { + inPacket.data[i] = pluginOutput16bitInterlaced[i]; + } + + // --- End plugin code. + + if (!ringBuf->try_write(inPacket)) + { + qDebug(logAudio()) << "Buffer full! capacity:" << ringBuf->capacity() << "length" << ringBuf->size(); + } + + + + free(pluginOutput16bitInterlaced); pluginMutex.unlock(); return; diff --git a/audiohandler.h b/audiohandler.h index ce34248..4442710 100644 --- a/audiohandler.h +++ b/audiohandler.h @@ -183,6 +183,10 @@ private: // --- Plugin support: QMutex pluginMutex; + //QByteArray pluginOutputQBA; + + uint16_t *pluginOutput16bitInterlaced; + uint16_t SAMPLE_RATE; uint16_t BUF_SIZE; const LADSPA_Descriptor * psDescriptor; diff --git a/rigcommander.cpp b/rigcommander.cpp index a6f9761..7fd9cd9 100644 --- a/rigcommander.cpp +++ b/rigcommander.cpp @@ -237,11 +237,12 @@ void rigCommander::prepDataAndSend(QByteArray data) //printHex(data, false, true); data.append(payloadSuffix); + // TODO: better filtering here if(data[4] != '\x15') { // We don't print out requests for meter levels - qDebug(logRig()) << "Final payload in rig commander to be sent to rig: "; - printHex(data); + //qDebug(logRig()) << "Final payload in rig commander to be sent to rig: "; + //printHex(data); } emit dataForComm(data); @@ -1177,11 +1178,12 @@ void rigCommander::parseCommand() bool isSpectrumData = payloadIn.startsWith(QByteArray().setRawData("\x27\x00", 2)); + // TODO: better filter here: if( (!isSpectrumData) && (payloadIn[00] != '\x15') ) { // We do not log spectrum and meter data, // as they tend to clog up any useful logging. - printHex(payloadIn); + // printHex(payloadIn); } switch(payloadIn[00])