Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 30 additions & 2 deletions share/crts/plugins/Filters/tx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include <errno.h>
#include <string>
#include <uhd/usrp/multi_usrp.hpp>
#include <liquid/liquid.h>

#include "crts/debug.h"
#include "crts/Filter.hpp"
Expand Down Expand Up @@ -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<float> * buffer_resamp; // TODO: use std lib container instead?

////////////////////////////////////////////////////////////////
// Inline helper/wrapper utilities to set and get parameters
Expand Down Expand Up @@ -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?
Expand Down Expand Up @@ -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<float>[2048];

DSPEW();
}

Expand All @@ -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();
}

Expand Down Expand Up @@ -398,10 +420,16 @@ void Tx::input(void *buffer, size_t len, uint32_t channelNum)

size_t numFrames = len/(numTxChannels*sizeof(std::complex<float>));

// 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
Expand Down