OSX fixes

This commit is contained in:
Charles J. Cliffe 2014-12-22 23:27:52 -05:00
parent 1dc218d346
commit 703501f32d
4 changed files with 41 additions and 47 deletions

View File

@ -94,7 +94,7 @@ static int audioCallback(void *outputBuffer, void *inputBuffer, unsigned int nBu
} }
} else { } else {
for (int i = 0, iMax = src->currentInput.channels * nBufferFrames; i < iMax; i++) { for (int i = 0, iMax = src->currentInput.channels * nBufferFrames; i < iMax; i++) {
if (srcmix->audio_queue_ptr >= srcmix->currentInput.data.size()) { if (srcmix->audio_queue_ptr >= srcmix->currentInput.data->size()) {
if (srcmix->currentInput.data) { if (srcmix->currentInput.data) {
delete srcmix->currentInput.data; delete srcmix->currentInput.data;
} }

View File

@ -59,11 +59,10 @@ class DemodulatorThreadIQData {
public: public:
unsigned int frequency; unsigned int frequency;
unsigned int bandwidth; unsigned int bandwidth;
std::vector<signed char> *data; std::vector<signed char> data;
std::atomic<int> *refCount;
DemodulatorThreadIQData() : DemodulatorThreadIQData() :
frequency(0), bandwidth(0), data(NULL), refCount(NULL) { frequency(0), bandwidth(0), refCount(0) {
} }
@ -71,28 +70,27 @@ public:
frequency = o.frequency; frequency = o.frequency;
bandwidth = o.bandwidth; bandwidth = o.bandwidth;
data = o.data; data = o.data;
refCount = o.refCount; refCount.store(o.refCount.load());
} }
void setRefCount(std::atomic<int> *rc) { void setRefCount(int rc) {
refCount = rc; refCount.store(rc);
} }
void cleanup() { void decRefCount() {
if (refCount) { refCount.store(refCount.load()-1);
refCount->store(refCount->load()-1); }
if (refCount->load() == 0) {
delete data; int getRefCount() {
data = NULL; return refCount.load();
delete refCount;
refCount = NULL;
}
}
} }
~DemodulatorThreadIQData() { ~DemodulatorThreadIQData() {
} }
private:
std::atomic<int> refCount;
}; };
class DemodulatorThreadPostIQData { class DemodulatorThreadPostIQData {
@ -146,7 +144,7 @@ public:
} }
}; };
typedef ThreadQueue<DemodulatorThreadIQData> DemodulatorThreadInputQueue; typedef ThreadQueue<DemodulatorThreadIQData *> DemodulatorThreadInputQueue;
typedef ThreadQueue<DemodulatorThreadPostIQData> DemodulatorThreadPostInputQueue; typedef ThreadQueue<DemodulatorThreadPostIQData> DemodulatorThreadPostInputQueue;
typedef ThreadQueue<DemodulatorThreadCommand> DemodulatorThreadCommandQueue; typedef ThreadQueue<DemodulatorThreadCommand> DemodulatorThreadCommandQueue;
typedef ThreadQueue<DemodulatorThreadControlCommand> DemodulatorThreadControlCommandQueue; typedef ThreadQueue<DemodulatorThreadControlCommand> DemodulatorThreadControlCommandQueue;

View File

@ -100,7 +100,7 @@ void DemodulatorPreThread::threadMain() {
std::cout << "Demodulator preprocessor thread started.." << std::endl; std::cout << "Demodulator preprocessor thread started.." << std::endl;
while (!terminated) { while (!terminated) {
DemodulatorThreadIQData inp; DemodulatorThreadIQData *inp;
inputQueue->pop(inp); inputQueue->pop(inp);
bool bandwidthChanged = false; bool bandwidthChanged = false;
@ -144,9 +144,9 @@ void DemodulatorPreThread::threadMain() {
} }
// Requested frequency is not center, shift it into the center! // Requested frequency is not center, shift it into the center!
if (inp.frequency != params.frequency) { if (inp->frequency != params.frequency) {
if ((params.frequency - inp.frequency) != shift_freq) { if ((params.frequency - inp->frequency) != shift_freq) {
shift_freq = params.frequency - inp.frequency; shift_freq = params.frequency - inp->frequency;
if (abs(shift_freq) <= (int) ((float) (SRATE / 2) * 1.5)) { if (abs(shift_freq) <= (int) ((float) (SRATE / 2) * 1.5)) {
nco_crcf_set_frequency(nco_shift, (2.0 * M_PI) * (((float) abs(shift_freq)) / ((float) SRATE))); nco_crcf_set_frequency(nco_shift, (2.0 * M_PI) * (((float) abs(shift_freq)) / ((float) SRATE)));
} }
@ -157,8 +157,8 @@ void DemodulatorPreThread::threadMain() {
continue; continue;
} }
std::vector<signed char> *data = inp.data; std::vector<signed char> *data = &inp->data;
if (data && data->size()) { if (data->size()) {
int bufSize = data->size() / 2; int bufSize = data->size() / 2;
liquid_float_complex in_buf_data[bufSize]; liquid_float_complex in_buf_data[bufSize];
@ -197,7 +197,10 @@ void DemodulatorPreThread::threadMain() {
resamp.resampler = resampler; resamp.resampler = resampler;
postInputQueue->push(resamp); postInputQueue->push(resamp);
inp.cleanup(); inp->decRefCount();
if (inp->getRefCount()<=0) {
delete inp;
}
} }
if (!workerResults->empty()) { if (!workerResults->empty()) {
@ -236,7 +239,7 @@ void DemodulatorPreThread::threadMain() {
void DemodulatorPreThread::terminate() { void DemodulatorPreThread::terminate() {
terminated = true; terminated = true;
DemodulatorThreadIQData inp; // push dummy to nudge queue DemodulatorThreadIQData *inp = new DemodulatorThreadIQData; // push dummy to nudge queue
inputQueue->push(inp); inputQueue->push(inp);
workerThread->terminate(); workerThread->terminate();
} }

View File

@ -39,7 +39,7 @@ void SDRPostThread::threadMain() {
#ifdef __APPLE__ #ifdef __APPLE__
pthread_t tID = pthread_self(); // ID of this thread pthread_t tID = pthread_self(); // ID of this thread
int priority = sched_get_priority_max( SCHED_FIFO) - 1; int priority = sched_get_priority_max( SCHED_FIFO) - 1;
sched_param prio = {priority}; // scheduling priority of thread sched_param prio = { priority }; // scheduling priority of thread
pthread_setschedparam(tID, SCHED_FIFO, &prio); pthread_setschedparam(tID, SCHED_FIFO, &prio);
#endif #endif
@ -82,7 +82,6 @@ void SDRPostThread::threadMain() {
iqVisualQueue.load()->push(visualDataOut); iqVisualQueue.load()->push(visualDataOut);
} }
if (demodulators_add.size()) { if (demodulators_add.size()) {
while (!demodulators_add.empty()) { while (!demodulators_add.empty()) {
demodulators.push_back(demodulators_add.back()); demodulators.push_back(demodulators_add.back());
@ -104,7 +103,6 @@ void SDRPostThread::threadMain() {
int activeDemods = 0; int activeDemods = 0;
bool pushedData = false; bool pushedData = false;
std::atomic<int> *c = new std::atomic<int>;
if (demodulators.size()) { if (demodulators.size()) {
@ -119,20 +117,14 @@ void SDRPostThread::threadMain() {
activeDemods++; activeDemods++;
} }
c->store(activeDemods);
bool demodActive = false; bool demodActive = false;
if (demodulators.size()) { if (demodulators.size()) {
DemodulatorThreadIQData dummyDataOut; DemodulatorThreadIQData *demodDataOut = new DemodulatorThreadIQData;
dummyDataOut.frequency = data_in.frequency; demodDataOut->frequency = data_in.frequency;
dummyDataOut.bandwidth = data_in.bandwidth; demodDataOut->bandwidth = data_in.bandwidth;
dummyDataOut.data = NULL; demodDataOut->setRefCount(activeDemods);
DemodulatorThreadIQData demodDataOut; demodDataOut->data.assign(dataOut.data->begin(), dataOut.data->begin() + dataOut.data->size());
demodDataOut.frequency = data_in.frequency;
demodDataOut.bandwidth = data_in.bandwidth;
demodDataOut.setRefCount(c);
demodDataOut.data = data_in.data;
std::vector<DemodulatorInstance *>::iterator i; std::vector<DemodulatorInstance *>::iterator i;
for (i = demodulators.begin(); i != demodulators.end(); i++) { for (i = demodulators.begin(); i != demodulators.end(); i++) {
@ -143,6 +135,9 @@ void SDRPostThread::threadMain() {
&& abs(data_in.frequency - demod->getParams().frequency) > (int) ((float) ((float) SRATE / 2.0))) { && abs(data_in.frequency - demod->getParams().frequency) > (int) ((float) ((float) SRATE / 2.0))) {
if (demod->isActive()) { if (demod->isActive()) {
demod->setActive(false); demod->setActive(false);
DemodulatorThreadIQData *dummyDataOut = new DemodulatorThreadIQData;
dummyDataOut->frequency = data_in.frequency;
dummyDataOut->bandwidth = data_in.bandwidth;
demodQueue->push(dummyDataOut); demodQueue->push(dummyDataOut);
} }
} else if (!demod->isActive()) { } else if (!demod->isActive()) {
@ -156,16 +151,14 @@ void SDRPostThread::threadMain() {
demodQueue->push(demodDataOut); demodQueue->push(demodDataOut);
pushedData = true; pushedData = true;
} }
if (!pushedData) {
delete demodDataOut;
}
} }
} }
delete dataOut.data;
if (!pushedData) {
delete dataOut.data;
delete c;
}
} }
} }
std::cout << "SDR post-processing thread done." << std::endl; std::cout << "SDR post-processing thread done." << std::endl;
} }