Analog modems now somewhat functional

- Still major memory leaks.. :)
This commit is contained in:
Charles J. Cliffe 2015-11-17 23:23:23 -05:00
parent f53e228849
commit 5f6b492478
6 changed files with 37 additions and 31 deletions

View File

@ -34,7 +34,7 @@ DemodulatorInstance::DemodulatorInstance() :
pipeAudioData = new AudioThreadInputQueue;
threadQueueControl = new DemodulatorThreadControlCommandQueue;
demodulatorThread = new DemodulatorThread();
demodulatorThread = new DemodulatorThread(this);
demodulatorThread->setInputQueue("IQDataInput",pipeIQDemodData);
demodulatorThread->setInputQueue("ControlQueue",threadQueueControl);
demodulatorThread->setOutputQueue("NotifyQueue",pipeDemodNotify);
@ -291,11 +291,7 @@ void DemodulatorInstance::setDemodulatorType(std::string demod_type_in) {
checkBandwidth();
demodulatorPreThread->getParams().demodType = currentDemodType;
} else if (demodulatorThread && threadQueueControl) {
DemodulatorThreadControlCommand command;
command.cmd = DemodulatorThreadControlCommand::DEMOD_THREAD_CMD_CTL_TYPE;
command.demodType = demod_type_in;
checkBandwidth();
threadQueueControl->push(command);
demodulatorPreThread->setDemodType(currentDemodType);
}
}

View File

@ -64,6 +64,8 @@ void DemodulatorPreThread::run() {
std::vector<liquid_float_complex> in_buf_data;
std::vector<liquid_float_complex> out_buf_data;
setDemodType(params.demodType);
while (!terminated) {
DemodulatorThreadIQData *inp;
iqInputQueue->pop(inp);
@ -199,9 +201,11 @@ void DemodulatorPreThread::run() {
switch (result.cmd) {
case DemodulatorWorkerThreadResult::DEMOD_WORKER_THREAD_RESULT_FILTERS:
msresamp_crcf_destroy(iqResampler);
if (result.iqResampler) {
if (iqResampler) {
msresamp_crcf_destroy(iqResampler);
}
iqResampler = result.iqResampler;
iqResampleRatio = result.iqResampleRatio;
}
@ -224,6 +228,7 @@ void DemodulatorPreThread::run() {
if (result.modemType != "") {
demodType = result.modemType;
params.demodType = result.modemType;
demodTypeChanged.store(false);
}
break;
@ -254,6 +259,8 @@ void DemodulatorPreThread::setDemodType(std::string demodType) {
this->newDemodType = demodType;
DemodulatorWorkerThreadCommand command(DemodulatorWorkerThreadCommand::DEMOD_WORKER_THREAD_CMD_MAKE_DEMOD);
command.demodType = demodType;
command.bandwidth = params.bandwidth;
command.audioSampleRate = params.audioSampleRate;
workerQueue->push(command);
}

View File

@ -1,5 +1,6 @@
#include "CubicSDRDefs.h"
#include "DemodulatorThread.h"
#include "DemodulatorInstance.h"
#include <vector>
#include <cmath>
@ -11,8 +12,9 @@
#include <pthread.h>
#endif
DemodulatorThread::DemodulatorThread() : IOThread(), iqAutoGain(NULL), amOutputCeil(1), amOutputCeilMA(1), amOutputCeilMAA(1), audioSampleRate(0), squelchLevel(0), signalLevel(0), squelchEnabled(false), iqInputQueue(NULL), audioOutputQueue(NULL), audioVisOutputQueue(NULL), threadQueueControl(NULL), threadQueueNotify(NULL) {
DemodulatorThread::DemodulatorThread(DemodulatorInstance *parent) : IOThread(), iqAutoGain(NULL), amOutputCeil(1), amOutputCeilMA(1), amOutputCeilMAA(1), audioSampleRate(0), squelchLevel(0), signalLevel(0), squelchEnabled(false), iqInputQueue(NULL), audioOutputQueue(NULL), audioVisOutputQueue(NULL), threadQueueControl(NULL), threadQueueNotify(NULL), cModem(nullptr), cModemKit(nullptr) {
demodInstance = parent;
muted.store(false);
agcEnabled.store(false);
@ -122,6 +124,8 @@ void DemodulatorThread::run() {
iqInputQueue->pop(inp);
// std::lock_guard < std::mutex > lock(inp->m_mutex);
audioSampleRate = demodInstance->getAudioSampleRate();
int bufSize = inp->data.size();
if (!bufSize) {
@ -131,7 +135,9 @@ void DemodulatorThread::run() {
if (inp->modemKit && inp->modemKit != cModemKit) {
cModem->disposeKit(cModemKit);
if (cModemKit != nullptr) {
cModem->disposeKit(cModemKit);
}
cModemKit = inp->modemKit;
}
@ -174,6 +180,9 @@ void DemodulatorThread::run() {
modemData.sampleRate = inp->sampleRate;
modemData.data.assign(inputData->begin(), inputData->end());
modemData.setRefCount(1);
AudioThreadInput *ati = NULL;
ati = outputBuffers.getBuffer();
@ -506,11 +515,7 @@ void DemodulatorThread::run() {
ati->peak = p;
}
}
} else if (ati) {
ati->decRefCount();
}
} else if (ati) {
ati->decRefCount();
}
if (ati && audioVisOutputQueue != NULL && audioVisOutputQueue->empty()) {
@ -545,18 +550,18 @@ void DemodulatorThread::run() {
} else {
int numAudioWritten = ati->data.size();
ati_vis->channels = 1;
if (numAudioWritten > bufSize) {
// if (numAudioWritten > bufSize) {
ati_vis->inputRate = audioSampleRate;
if (num_vis > numAudioWritten) {
num_vis = numAudioWritten;
}
ati_vis->data.assign(ati->data.begin(), ati->data.begin() + num_vis);
} else {
if (num_vis > bufSize) {
num_vis = bufSize;
}
ati_vis->data.assign(ati->data.begin(), ati->data.begin() + num_vis);
}
// } else {
// if (num_vis > bufSize) {
// num_vis = bufSize;
// }
// ati_vis->data.assign(ati->data.begin(), ati->data.begin() + num_vis);
// }
// std::cout << "Signal: " << agc_crcf_get_signal_level(agc) << " -- " << agc_crcf_get_rssi(agc) << "dB " << std::endl;
}
@ -574,8 +579,6 @@ void DemodulatorThread::run() {
}
if (!threadQueueControl->empty()) {
// int newDemodType = DEMOD_TYPE_NULL;
while (!threadQueueControl->empty()) {
DemodulatorThreadControlCommand command;
threadQueueControl->pop(command);
@ -587,9 +590,6 @@ void DemodulatorThread::run() {
case DemodulatorThreadControlCommand::DEMOD_THREAD_CMD_CTL_SQUELCH_OFF:
squelchEnabled = false;
break;
// case DemodulatorThreadControlCommand::DEMOD_THREAD_CMD_CTL_TYPE:
// newDemodType = command.demodType;
// break;
default:
break;
}

View File

@ -10,11 +10,12 @@
typedef ThreadQueue<AudioThreadInput *> DemodulatorThreadOutputQueue;
#define DEMOD_VIS_SIZE 2048
class DemodulatorInstance;
class DemodulatorThread : public IOThread {
public:
DemodulatorThread();
DemodulatorThread(DemodulatorInstance *parent);
~DemodulatorThread();
void onBindOutput(std::string name, ThreadQueueBase *threadQueue);
@ -45,6 +46,7 @@ public:
//#endif
protected:
DemodulatorInstance *demodInstance;
ReBuffer<AudioThreadInput> outputBuffers;
std::vector<liquid_float_complex> agcData;

View File

@ -3,7 +3,7 @@
#include <vector>
DemodulatorWorkerThread::DemodulatorWorkerThread() : IOThread(),
commandQueue(NULL), resultQueue(NULL) {
commandQueue(NULL), resultQueue(NULL), cModem(nullptr), cModemKit(nullptr) {
}
DemodulatorWorkerThread::~DemodulatorWorkerThread() {
@ -41,7 +41,7 @@ void DemodulatorWorkerThread::run() {
}
if (filterChanged && !terminated) {
if ((makeDemod || filterChanged) && !terminated) {
DemodulatorWorkerThreadResult result(DemodulatorWorkerThreadResult::DEMOD_WORKER_THREAD_RESULT_FILTERS);
float As = 60.0f; // stop-band attenuation [dB]
@ -55,14 +55,14 @@ void DemodulatorWorkerThread::run() {
cModem = Modem::makeModem(filterCommand.demodType);
cModemType = filterCommand.demodType;
}
result.modem = cModem;
if (filterCommand.bandwidth && filterCommand.audioSampleRate) {
result.modem = cModem;
if (cModem != nullptr) {
cModemKit = cModem->buildKit(filterCommand.bandwidth, filterCommand.audioSampleRate);
}
result.modemKit = cModemKit;
}
result.modemKit = cModemKit;
if (filterCommand.bandwidth) {
result.bandwidth = filterCommand.bandwidth;

View File

@ -74,5 +74,6 @@ void ModemAnalog::buildAudioOutput(ModemKitAnalog *akit, AudioThreadInput *audio
msresamp_rrrf_execute(akit->audioResampler, &demodOutputData[0], demodOutputData.size(), &resampledOutputData[0], &numAudioWritten);
audioOut->channels = 1;
audioOut->sampleRate = akit->audioSampleRate;
audioOut->data.assign(resampledOutputData.begin(), resampledOutputData.begin() + numAudioWritten);
}