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 {
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) {
delete srcmix->currentInput.data;
}

View File

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

View File

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

View File

@ -39,7 +39,7 @@ void SDRPostThread::threadMain() {
#ifdef __APPLE__
pthread_t tID = pthread_self(); // ID of this thread
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);
#endif
@ -82,7 +82,6 @@ void SDRPostThread::threadMain() {
iqVisualQueue.load()->push(visualDataOut);
}
if (demodulators_add.size()) {
while (!demodulators_add.empty()) {
demodulators.push_back(demodulators_add.back());
@ -104,7 +103,6 @@ void SDRPostThread::threadMain() {
int activeDemods = 0;
bool pushedData = false;
std::atomic<int> *c = new std::atomic<int>;
if (demodulators.size()) {
@ -119,20 +117,14 @@ void SDRPostThread::threadMain() {
activeDemods++;
}
c->store(activeDemods);
bool demodActive = false;
if (demodulators.size()) {
DemodulatorThreadIQData dummyDataOut;
dummyDataOut.frequency = data_in.frequency;
dummyDataOut.bandwidth = data_in.bandwidth;
dummyDataOut.data = NULL;
DemodulatorThreadIQData demodDataOut;
demodDataOut.frequency = data_in.frequency;
demodDataOut.bandwidth = data_in.bandwidth;
demodDataOut.setRefCount(c);
demodDataOut.data = data_in.data;
DemodulatorThreadIQData *demodDataOut = new DemodulatorThreadIQData;
demodDataOut->frequency = data_in.frequency;
demodDataOut->bandwidth = data_in.bandwidth;
demodDataOut->setRefCount(activeDemods);
demodDataOut->data.assign(dataOut.data->begin(), dataOut.data->begin() + dataOut.data->size());
std::vector<DemodulatorInstance *>::iterator 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))) {
if (demod->isActive()) {
demod->setActive(false);
DemodulatorThreadIQData *dummyDataOut = new DemodulatorThreadIQData;
dummyDataOut->frequency = data_in.frequency;
dummyDataOut->bandwidth = data_in.bandwidth;
demodQueue->push(dummyDataOut);
}
} else if (!demod->isActive()) {
@ -156,17 +151,15 @@ void SDRPostThread::threadMain() {
demodQueue->push(demodDataOut);
pushedData = true;
}
}
}
if (!pushedData) {
delete demodDataOut;
}
}
}
delete dataOut.data;
delete c;
}
}
}
std::cout << "SDR post-processing thread done." << std::endl;
}