Apply source formatting for demodulator thread

This commit is contained in:
Charles J. Cliffe 2015-11-18 21:13:04 -05:00
parent ea005014ae
commit 10aa9f86dd
2 changed files with 63 additions and 70 deletions

View File

@ -16,10 +16,12 @@ DemodulatorThread::DemodulatorThread(DemodulatorInstance *parent) : IOThread(),
demodInstance = parent; demodInstance = parent;
muted.store(false); muted.store(false);
agcEnabled.store(false); agcEnabled.store(false);
} }
DemodulatorThread::~DemodulatorThread() { DemodulatorThread::~DemodulatorThread() {
} }
void DemodulatorThread::onBindOutput(std::string name, ThreadQueueBase *threadQueue) { void DemodulatorThread::onBindOutput(std::string name, ThreadQueueBase *threadQueue) {
@ -54,7 +56,7 @@ void DemodulatorThread::run() {
while (!terminated) { while (!terminated) {
DemodulatorThreadPostIQData *inp; DemodulatorThreadPostIQData *inp;
iqInputQueue->pop(inp); iqInputQueue->pop(inp);
// std::lock_guard < std::mutex > lock(inp->m_mutex); // std::lock_guard < std::mutex > lock(inp->m_mutex);
audioSampleRate = demodInstance->getAudioSampleRate(); audioSampleRate = demodInstance->getAudioSampleRate();
@ -104,9 +106,9 @@ void DemodulatorThread::run() {
std::vector<liquid_float_complex> *inputData; std::vector<liquid_float_complex> *inputData;
if (agcEnabled) { if (agcEnabled) {
inputData = &agcData; inputData = &agcData;
} else { } else {
inputData = &inp->data; inputData = &inp->data;
} }
modemData.sampleRate = inp->sampleRate; modemData.sampleRate = inp->sampleRate;
@ -142,8 +144,8 @@ void DemodulatorThread::run() {
} }
if (ati && audioVisOutputQueue != NULL && audioVisOutputQueue->empty()) { if (ati && audioVisOutputQueue != NULL && audioVisOutputQueue->empty()) {
AudioThreadInput *ati_vis = audioVisBuffers.getBuffer(); AudioThreadInput *ati_vis = audioVisBuffers.getBuffer();
ati_vis->setRefCount(1); ati_vis->setRefCount(1);
ati_vis->sampleRate = inp->sampleRate; ati_vis->sampleRate = inp->sampleRate;
ati_vis->inputRate = inp->sampleRate; ati_vis->inputRate = inp->sampleRate;
@ -173,20 +175,20 @@ void DemodulatorThread::run() {
} else { } else {
int numAudioWritten = ati->data.size(); int numAudioWritten = ati->data.size();
ati_vis->channels = 1; ati_vis->channels = 1;
// if (numAudioWritten > bufSize) { // if (numAudioWritten > bufSize) {
ati_vis->inputRate = audioSampleRate; ati_vis->inputRate = audioSampleRate;
if (num_vis > numAudioWritten) { if (num_vis > numAudioWritten) {
num_vis = numAudioWritten; num_vis = numAudioWritten;
} }
ati_vis->data.assign(ati->data.begin(), ati->data.begin() + num_vis); ati_vis->data.assign(ati->data.begin(), ati->data.begin() + num_vis);
// } else { // } else {
// if (num_vis > bufSize) { // if (num_vis > bufSize) {
// num_vis = bufSize; // num_vis = bufSize;
// } // }
// ati_vis->data.assign(ati->data.begin(), ati->data.begin() + num_vis); // 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; // std::cout << "Signal: " << agc_crcf_get_signal_level(agc) << " -- " << agc_crcf_get_rssi(agc) << "dB " << std::endl;
} }
audioVisOutputQueue->push(ati_vis); audioVisOutputQueue->push(ati_vis);
@ -207,22 +209,21 @@ void DemodulatorThread::run() {
threadQueueControl->pop(command); threadQueueControl->pop(command);
switch (command.cmd) { switch (command.cmd) {
case DemodulatorThreadControlCommand::DEMOD_THREAD_CMD_CTL_SQUELCH_ON: case DemodulatorThreadControlCommand::DEMOD_THREAD_CMD_CTL_SQUELCH_ON:
squelchEnabled = true; squelchEnabled = true;
break; break;
case DemodulatorThreadControlCommand::DEMOD_THREAD_CMD_CTL_SQUELCH_OFF: case DemodulatorThreadControlCommand::DEMOD_THREAD_CMD_CTL_SQUELCH_OFF:
squelchEnabled = false; squelchEnabled = false;
break; break;
default: default:
break; break;
} }
} }
} }
inp->decRefCount(); inp->decRefCount();
} }
// end while !terminated // end while !terminated
outputBuffers.purge(); outputBuffers.purge();
@ -230,7 +231,7 @@ void DemodulatorThread::run() {
AudioThreadInput *dummy_vis; AudioThreadInput *dummy_vis;
audioVisOutputQueue->pop(dummy_vis); audioVisOutputQueue->pop(dummy_vis);
} }
audioVisBuffers.purge(); audioVisBuffers.purge();
DemodulatorThreadCommand tCmd(DemodulatorThreadCommand::DEMOD_THREAD_CMD_DEMOD_TERMINATED); DemodulatorThreadCommand tCmd(DemodulatorThreadCommand::DEMOD_THREAD_CMD_DEMOD_TERMINATED);
tCmd.context = this; tCmd.context = this;
@ -254,14 +255,13 @@ void DemodulatorThread::setMuted(bool muted) {
} }
void DemodulatorThread::setAGC(bool state) { void DemodulatorThread::setAGC(bool state) {
agcEnabled.store(state); agcEnabled.store(state);
} }
bool DemodulatorThread::getAGC() { bool DemodulatorThread::getAGC() {
return agcEnabled.load(); return agcEnabled.load();
} }
float DemodulatorThread::getSignalLevel() { float DemodulatorThread::getSignalLevel() {
return signalLevel.load(); return signalLevel.load();
} }

View File

@ -33,13 +33,6 @@ public:
void setSquelchLevel(float signal_level_in); void setSquelchLevel(float signal_level_in);
float getSquelchLevel(); float getSquelchLevel();
//
//#ifdef __APPLE__
// static void *pthread_helper(void *context) {
// return ((DemodulatorThread *) context)->threadMain();
// }
//#endif
protected: protected:
DemodulatorInstance *demodInstance; DemodulatorInstance *demodInstance;
ReBuffer<AudioThreadInput> outputBuffers; ReBuffer<AudioThreadInput> outputBuffers;