Move DC blocking filter to SDRThread

- DC blocker + Channelizer too heavy together
This commit is contained in:
Charles J. Cliffe 2015-10-15 01:35:03 -04:00
parent 938d10366c
commit 249e04e69c
4 changed files with 21 additions and 30 deletions

View File

@ -18,8 +18,6 @@ SDRPostThread::SDRPostThread() : IOThread() {
nRunDemods = 0; nRunDemods = 0;
doRefresh.store(false); doRefresh.store(false);
dcFilter = iirfilt_crcf_create_dc_blocker(0.0005);
} }
SDRPostThread::~SDRPostThread() { SDRPostThread::~SDRPostThread() {
@ -180,22 +178,7 @@ void SDRPostThread::run() {
// } // }
// } // }
if (dataSize > fpData.capacity()) {
fpData.reserve(dataSize);
}
if (dataSize != fpData.size()) {
fpData.resize(dataSize);
}
if (data_in->dcCorrected) {
fpData.assign(data_in->data.begin(), data_in->data.end());
} else {
iirfilt_crcf_execute_block(dcFilter, &data_in->data[0], dataSize, &fpData[0]);
}
if (iqVisualQueue != NULL || iqDataOutQueue != NULL) { if (iqVisualQueue != NULL || iqDataOutQueue != NULL) {
int num_vis_samples = fpData.size();
bool doIQVis = iqVisualQueue && !iqVisualQueue->full(); bool doIQVis = iqVisualQueue && !iqVisualQueue->full();
bool doIQOut = iqDataOutQueue != NULL; bool doIQOut = iqDataOutQueue != NULL;
@ -204,7 +187,7 @@ void SDRPostThread::run() {
iqDataOut->frequency = data_in->frequency; iqDataOut->frequency = data_in->frequency;
iqDataOut->sampleRate = data_in->sampleRate; iqDataOut->sampleRate = data_in->sampleRate;
iqDataOut->data.assign(fpData.begin(), fpData.begin() + num_vis_samples); iqDataOut->data.assign(data_in->data.begin(), data_in->data.begin() + dataSize);
if (doIQVis) { if (doIQVis) {
iqVisualQueue->push(iqDataOut); iqVisualQueue->push(iqDataOut);
@ -234,7 +217,7 @@ void SDRPostThread::run() {
// channelize data // channelize data
// firpfbch2 output rate is 2 x ( input rate / channels ) // firpfbch2 output rate is 2 x ( input rate / channels )
for (int i = 0, iMax = dataSize; i < iMax; i+=numChannels/2) { for (int i = 0, iMax = dataSize; i < iMax; i+=numChannels/2) {
firpfbch2_crcf_execute(channelizer, &fpData[i], &dataOut[i * 2]); firpfbch2_crcf_execute(channelizer, &data_in->data[i], &dataOut[i * 2]);
} }
for (int i = 0, iMax = numChannels; i < iMax; i++) { for (int i = 0, iMax = numChannels; i < iMax; i++) {

View File

@ -28,7 +28,6 @@ protected:
std::mutex busy_demod; std::mutex busy_demod;
std::vector<DemodulatorInstance *> demodulators; std::vector<DemodulatorInstance *> demodulators;
iirfilt_crcf dcFilter;
std::atomic_bool swapIQ; std::atomic_bool swapIQ;
private: private:

View File

@ -29,6 +29,8 @@ SDRThread::SDRThread() : IOThread() {
hasPPM.store(false); hasPPM.store(false);
hasHardwareDC.store(false); hasHardwareDC.store(false);
numChannels.store(8); numChannels.store(8);
dcFilter = iirfilt_crcf_create_dc_blocker(0.0005);
} }
SDRThread::~SDRThread() { SDRThread::~SDRThread() {
@ -88,7 +90,7 @@ void SDRThread::init() {
numChannels.store(getOptimalChannelCount(sampleRate.load())); numChannels.store(getOptimalChannelCount(sampleRate.load()));
numElems.store(getOptimalElementCount(sampleRate.load(), 30)); numElems.store(getOptimalElementCount(sampleRate.load(), 30));
inpBuffer.data.resize(numElems.load());
buffs[0] = malloc(numElems * 2 * sizeof(float)); buffs[0] = malloc(numElems * 2 * sizeof(float));
} }
@ -104,26 +106,31 @@ void SDRThread::readStream(SDRThreadIQDataQueue* iqDataOutQueue) {
int flags; int flags;
long long timeNs; long long timeNs;
SDRThreadIQData *dataOut = buffers.getBuffer();
if (dataOut->data.size() != numElems) {
dataOut->data.resize(numElems);
}
int n_read = 0; int n_read = 0;
while (n_read != numElems && !terminated) { while (n_read != numElems && !terminated) {
int n_stream_read = device->readStream(stream, buffs, numElems-n_read, flags, timeNs); int n_stream_read = device->readStream(stream, buffs, numElems-n_read, flags, timeNs);
if (n_stream_read > 0) { if (n_stream_read > 0) {
memcpy(&dataOut->data[n_read], buffs[0], n_stream_read * sizeof(float) * 2); memcpy(&inpBuffer.data[n_read], buffs[0], n_stream_read * sizeof(float) * 2);
n_read += n_stream_read; n_read += n_stream_read;
} else { } else {
dataOut->data.resize(n_read);
break; break;
} }
} }
// std::cout << n_read << std::endl;
if (n_read > 0 && !terminated) { if (n_read > 0 && !terminated) {
SDRThreadIQData *dataOut = buffers.getBuffer();
if (hasHardwareDC) {
dataOut->data.assign(inpBuffer.data.begin(), inpBuffer.data.begin()+n_read);
} else {
if (dataOut->data.size() != n_read) {
dataOut->data.resize(n_read);
}
iirfilt_crcf_execute_block(dcFilter, &inpBuffer.data[0], n_read, &dataOut->data[0]);
}
dataOut->setRefCount(1); dataOut->setRefCount(1);
dataOut->frequency = frequency.load(); dataOut->frequency = frequency.load();
dataOut->sampleRate = sampleRate.load(); dataOut->sampleRate = sampleRate.load();
@ -154,6 +161,7 @@ void SDRThread::readLoop() {
sampleRate.store(device->getSampleRate(SOAPY_SDR_RX,0)); sampleRate.store(device->getSampleRate(SOAPY_SDR_RX,0));
numChannels.store(getOptimalChannelCount(sampleRate.load())); numChannels.store(getOptimalChannelCount(sampleRate.load()));
numElems.store(getOptimalElementCount(sampleRate.load(), 60)); numElems.store(getOptimalElementCount(sampleRate.load(), 60));
inpBuffer.data.resize(numElems.load());
free(buffs[0]); free(buffs[0]);
buffs[0] = malloc(numElems.load() * 2 * sizeof(float)); buffs[0] = malloc(numElems.load() * 2 * sizeof(float));
rate_changed.store(false); rate_changed.store(false);

View File

@ -77,7 +77,8 @@ protected:
SoapySDR::Device *device; SoapySDR::Device *device;
void *buffs[1]; void *buffs[1];
ReBuffer<SDRThreadIQData> buffers; ReBuffer<SDRThreadIQData> buffers;
iirfilt_crcf dcFilter;
SDRThreadIQData inpBuffer;
std::atomic<DeviceConfig *> deviceConfig; std::atomic<DeviceConfig *> deviceConfig;
std::atomic<SDRDeviceInfo *> deviceInfo; std::atomic<SDRDeviceInfo *> deviceInfo;