convert inline buffers to dynamic growth per instance

This commit is contained in:
Charles J. Cliffe 2014-12-24 03:03:34 -05:00
parent 576a77e095
commit b487cf9901
4 changed files with 72 additions and 32 deletions

View File

@ -104,6 +104,9 @@ void DemodulatorPreThread::threadMain() {
std::deque<DemodulatorThreadPostIQData *> buffers;
std::deque<DemodulatorThreadPostIQData *>::iterator buffers_i;
std::vector<liquid_float_complex> in_buf_data;
std::vector<liquid_float_complex> out_buf_data;
while (!terminated) {
DemodulatorThreadIQData *inp;
inputQueue->pop(inp);
@ -167,11 +170,17 @@ void DemodulatorPreThread::threadMain() {
if (data->size()) {
int bufSize = data->size() / 2;
liquid_float_complex in_buf_data[bufSize];
liquid_float_complex out_buf_data[bufSize];
if (in_buf_data.size() != bufSize) {
if (in_buf_data.capacity() < bufSize) {
in_buf_data.reserve(bufSize);
out_buf_data.reserve(bufSize);
}
in_buf_data.resize(bufSize);
out_buf_data.resize(bufSize);
}
liquid_float_complex *in_buf = in_buf_data;
liquid_float_complex *out_buf = out_buf_data;
liquid_float_complex *in_buf = &in_buf_data[0];
liquid_float_complex *out_buf = &out_buf_data[0];
liquid_float_complex *temp_buf = NULL;
for (int i = 0; i < bufSize; i++) {
@ -215,11 +224,9 @@ void DemodulatorPreThread::threadMain() {
resamp->resampler = resampler;
postInputQueue->push(resamp);
}
inp->decRefCount();
} else {
inp->decRefCount();
}
if (!workerResults->empty()) {
while (!workerResults->empty()) {

View File

@ -41,6 +41,11 @@ void DemodulatorThread::threadMain() {
std::deque<AudioThreadInput *> buffers;
std::deque<AudioThreadInput *>::iterator buffers_i;
std::vector<liquid_float_complex> resampled_data;
std::vector<liquid_float_complex> agc_data;
std::vector<float> demod_output;
std::vector<float> resampled_audio_output;
while (!terminated) {
DemodulatorThreadPostIQData *inp;
postInputQueue->pop(inp);
@ -64,24 +69,43 @@ void DemodulatorThread::threadMain() {
}
int out_size = ceil((float) (bufSize) * inp->resample_ratio);
liquid_float_complex resampled_data[out_size];
liquid_float_complex agc_data[out_size];
if (agc_data.size() != out_size) {
if (agc_data.capacity() < out_size) {
agc_data.reserve(out_size);
resampled_data.reserve(out_size);
}
agc_data.resize(out_size);
resampled_data.resize(out_size);
}
unsigned int num_written;
msresamp_crcf_execute(resampler, &(inp->data[0]), bufSize, resampled_data, &num_written);
msresamp_crcf_execute(resampler, &(inp->data[0]), bufSize, &resampled_data[0], &num_written);
agc_crcf_execute_block(agc, resampled_data, num_written, agc_data);
agc_crcf_execute_block(agc, &resampled_data[0], num_written, &agc_data[0]);
float audio_resample_ratio = inp->audio_resample_ratio;
float demod_output[num_written];
freqdem_demodulate_block(fdem, agc_data, num_written, demod_output);
if (demod_output.size() != num_written) {
if (demod_output.capacity() < num_written) {
demod_output.reserve(num_written);
}
demod_output.resize(num_written);
}
freqdem_demodulate_block(fdem, &agc_data[0], num_written, &demod_output[0]);
int audio_out_size = ceil((float) (num_written) * audio_resample_ratio);
float resampled_audio_output[audio_out_size];
if (audio_out_size != resampled_audio_output.size()) {
if (resampled_audio_output.capacity() < audio_out_size) {
resampled_audio_output.reserve(audio_out_size);
}
resampled_audio_output.resize(audio_out_size);
}
unsigned int num_audio_written;
msresamp_rrrf_execute(audio_resampler, demod_output, num_written, resampled_audio_output, &num_audio_written);
msresamp_rrrf_execute(audio_resampler, &demod_output[0], num_written, &resampled_audio_output[0], &num_audio_written);
if (audioInputQueue != NULL) {
if (!squelch_enabled || ((agc_crcf_get_signal_level(agc)) >= 0.1)) {
@ -101,7 +125,7 @@ void DemodulatorThread::threadMain() {
ati->setRefCount(1);
ati->channels = 1;
ati->data.assign(resampled_audio_output, resampled_audio_output + num_audio_written);
ati->data.assign(resampled_audio_output.begin(), resampled_audio_output.begin() + num_audio_written);
audioInputQueue->push(ati);
}
@ -116,12 +140,12 @@ void DemodulatorThread::threadMain() {
if (num_vis > num_audio_written) {
num_vis = num_audio_written;
}
ati_vis->data.assign(resampled_audio_output, resampled_audio_output + num_vis);
ati_vis->data.assign(resampled_audio_output.begin(), resampled_audio_output.begin() + num_vis);
} else {
if (num_vis > num_written) {
num_vis = num_written;
}
ati_vis->data.assign(demod_output, demod_output + num_vis);
ati_vis->data.assign(demod_output.begin(), demod_output.begin() + num_vis);
}
visOutQueue->push(ati_vis);

View File

@ -53,6 +53,7 @@ void SDRPostThread::threadMain() {
std::deque<DemodulatorThreadIQData *> buffers;
std::deque<DemodulatorThreadIQData *>::iterator buffers_i;
std::vector<signed char> dataOut;
while (!terminated) {
SDRThreadIQData *data_in;
@ -61,29 +62,34 @@ void SDRPostThread::threadMain() {
// std::lock_guard < std::mutex > lock(data_in->m_mutex);
if (data_in && data_in->data.size()) {
SDRThreadIQData *dataOut = new SDRThreadIQData;
if (data_in->data.size() > dataOut.capacity()) {
dataOut.reserve(data_in->data.size());
}
dataOut->frequency = data_in->frequency;
dataOut->bandwidth = data_in->bandwidth;
dataOut->data.assign(data_in->data.begin(), data_in->data.end());
dataOut.assign(data_in->data.begin(), data_in->data.end());
for (int i = 0, iMax = dataOut->data.size() / 2; i < iMax; i++) {
x.real = (float) dataOut->data[i * 2] / 127.0;
x.imag = (float) dataOut->data[i * 2 + 1] / 127.0;
for (int i = 0, iMax = dataOut.size() / 2; i < iMax; i++) {
x.real = (float) dataOut[i * 2] / 127.0;
x.imag = (float) dataOut[i * 2 + 1] / 127.0;
iirfilt_crcf_execute(dcFilter, x, &y);
dataOut->data[i * 2] = (signed char) floor(y.real * 127.0);
dataOut->data[i * 2 + 1] = (signed char) floor(y.imag * 127.0);
dataOut[i * 2] = (signed char) floor(y.real * 127.0);
dataOut[i * 2 + 1] = (signed char) floor(y.imag * 127.0);
}
if (iqDataOutQueue != NULL) {
iqDataOutQueue.load()->push(dataOut);
SDRThreadIQData *visDataOut = new SDRThreadIQData;
visDataOut->frequency = data_in->frequency;
visDataOut->bandwidth = data_in->bandwidth;
visDataOut->data.assign(dataOut.begin(), dataOut.end());
iqDataOutQueue.load()->push(visDataOut);
}
if (iqVisualQueue != NULL && iqVisualQueue.load()->empty()) {
SDRThreadIQData *visualDataOut = new SDRThreadIQData;
visualDataOut->data.assign(dataOut->data.begin(), dataOut->data.begin() + (FFT_SIZE * 2));
visualDataOut->data.assign(dataOut.begin(), dataOut.begin() + (FFT_SIZE * 2));
iqVisualQueue.load()->push(visualDataOut);
}
@ -142,7 +148,7 @@ void SDRPostThread::threadMain() {
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());
demodDataOut->data.assign(dataOut.begin(), dataOut.begin() + dataOut.size());
std::vector<DemodulatorInstance *>::iterator i;
for (i = demodulators.begin(); i != demodulators.end(); i++) {
@ -175,7 +181,6 @@ void SDRPostThread::threadMain() {
}
}
}
delete dataOut;
}
data_in->decRefCount();
}

View File

@ -181,6 +181,10 @@ void SDRThread::threadMain() {
dataOut->frequency = frequency;
dataOut->bandwidth = bandwidth;
if (dataOut->data.capacity() < n_read) {
dataOut->data.reserve(n_read);
}
if (dataOut->data.size() != n_read) {
dataOut->data.resize(n_read);
}