diff --git a/share/crts/plugins/Filters/tx.cpp b/share/crts/plugins/Filters/tx.cpp index b244f22..b946f12 100644 --- a/share/crts/plugins/Filters/tx.cpp +++ b/share/crts/plugins/Filters/tx.cpp @@ -3,6 +3,7 @@ #include #include #include +#include #include "crts/debug.h" #include "crts/Filter.hpp" @@ -48,6 +49,9 @@ class Tx : public CRTSFilter // above. size_t numTxChannels; + // Arbitrary rate resampler to allow dynamic bandwidth adjustment + resamp_crcf resamp; + std::complex * buffer_resamp; // TODO: use std lib container instead? //////////////////////////////////////////////////////////////// // Inline helper/wrapper utilities to set and get parameters @@ -77,6 +81,16 @@ class Tx : public CRTSFilter return true; }; + bool setRateResamp(const double &r, size_t chan=0) + { + if (r < 0.01 || r > 1.0) { + WARN("software resampling rate must be in [0.01, 1]"); + return false; + } + resamp_crcf_set_rate(resamp, (float)r); + return true; + }; + bool setGain(const double &g, size_t chan=0) { // TODO: check return? @@ -299,6 +313,10 @@ Tx::Tx(int argc, const char **argv): } } + // instantiate arbitrary rate resampler and appropriate output buffer + resamp = resamp_crcf_create(1.0f, 12, 0.495f, 60.0f, 64); + buffer_resamp = new std::complex[2048]; + DSPEW(); } @@ -311,6 +329,10 @@ Tx::~Tx(void) // Or should stop() be the place to cleanup most of the // libuhd stuff. + // destroy arbitrary rate resampler and free output buffer + resamp_crcf_destroy(resamp); + delete [] buffer_resamp; + DSPEW(); } @@ -398,10 +420,16 @@ void Tx::input(void *buffer, size_t len, uint32_t channelNum) size_t numFrames = len/(numTxChannels*sizeof(std::complex)); + // resample result; note, because the resampler is restricted to always decimate, + // the size of the output buffer only needs to be at least the same size as the input + // TODO: increase output buffer size appropriately + unsigned int numFramesResamp; + resamp_crcf_execute(resamp, buffer, numFrames, buffer_resamp, &numFramesResamp); + // TODO: check for error here, and retry? - size_t ret = tx_stream->send(buffer, numFrames, metadata); + size_t ret = tx_stream->send(buffer_resamp, numFramesResamp, metadata); - if(ret != numFrames) + if(ret != numFramesResamp) WARN("wrote only %zu frames not %zu", ret, numFrames); // Mark the number of bytes to advance the input buffer which is not