From 606d41bc30d75e785e3a13d72c73990b9eac13b4 Mon Sep 17 00:00:00 2001 From: "Charles J. Cliffe" Date: Fri, 12 Aug 2016 20:31:20 -0400 Subject: [PATCH] Make audio the signal level instead of I/Q.. Fix attack/decay base to sample time. --- src/demod/DemodulatorThread.cpp | 82 ++++++++++++++++----------------- 1 file changed, 41 insertions(+), 41 deletions(-) diff --git a/src/demod/DemodulatorThread.cpp b/src/demod/DemodulatorThread.cpp index e7ef7c6..347ad73 100644 --- a/src/demod/DemodulatorThread.cpp +++ b/src/demod/DemodulatorThread.cpp @@ -102,45 +102,6 @@ void DemodulatorThread::run() { continue; } - float currentSignalLevel = 0; - float accum = 0; - - for (std::vector::iterator i = inp->data.begin(); i != inp->data.end(); i++) { - accum += abMagnitude(0.948059448969, 0.392699081699, i->real, i->imag); - } - - currentSignalLevel = linearToDb(accum / float(inp->data.size())); - if (currentSignalLevel < DEMOD_SIGNAL_MIN+1) { - currentSignalLevel = DEMOD_SIGNAL_MIN+1; - } - - float sampleTime = float(inp->data.size()) / float(inp->sampleRate); - float sf = signalFloor.load(), sc = signalCeil.load(), sl = squelchLevel.load(); - - if (currentSignalLevel > sc) { - sc = currentSignalLevel; - } - - if (currentSignalLevel < sf) { - sf = currentSignalLevel; - } - - if (sl+1.0f > sc) { - sc = sl+1.0f; - } - - if ((sf+2.0f) > sc) { - sc = sf+2.0f; - } - - sc -= (sc - (currentSignalLevel + 2.0f)) * sampleTime * 0.15f; - sf += ((currentSignalLevel - 5.0f) - sf) * sampleTime * 0.15f; - - signalFloor.store(sf); - signalCeil.store(sc); - -// std::cout << "sf:" << sf << "sc: " << sc << std::endl; - std::vector *inputData; inputData = &inp->data; @@ -167,11 +128,50 @@ void DemodulatorThread::run() { } cModem->demodulate(cModemKit, &modemData, ati); + + float currentSignalLevel = 0; + float accum = 0; + float sampleTime = float(inp->data.size()) / float(inp->sampleRate); + + if (audioOutputQueue != nullptr && ati && ati->data.size()) { + for (std::vector::iterator i = ati->data.begin(); i != ati->data.end(); i++) { + accum += abMagnitude(0.948059448969, 0.392699081699, *i, 0.0); + } + + currentSignalLevel = linearToDb(accum / float(inp->data.size())); + if (currentSignalLevel < DEMOD_SIGNAL_MIN+1) { + currentSignalLevel = DEMOD_SIGNAL_MIN+1; + } + + float sf = signalFloor.load(), sc = signalCeil.load(), sl = squelchLevel.load(); + + if (currentSignalLevel > sc) { + sc = currentSignalLevel; + } + + if (currentSignalLevel < sf) { + sf = currentSignalLevel; + } + + if (sl+1.0f > sc) { + sc = sl+1.0f; + } + + if ((sf+2.0f) > sc) { + sc = sf+2.0f; + } + + sc -= (sc - (currentSignalLevel + 2.0f)) * sampleTime * 0.15f; + sf += ((currentSignalLevel - 5.0f) - sf) * sampleTime * 0.15f; + + signalFloor.store(sf); + signalCeil.store(sc); + } if (currentSignalLevel > signalLevel) { - signalLevel = signalLevel + (currentSignalLevel - signalLevel) * 0.5; + signalLevel = signalLevel + (currentSignalLevel - signalLevel) * 0.5 * sampleTime * 10.0; } else { - signalLevel = signalLevel + (currentSignalLevel - signalLevel) * 0.05; + signalLevel = signalLevel + (currentSignalLevel - signalLevel) * 0.05 * sampleTime * 10.0; } bool squelched = (squelchEnabled && (signalLevel < squelchLevel));