From 1ab555f832c764bd10cebeeee51d9f7ad5c4b2c6 Mon Sep 17 00:00:00 2001 From: Jörgen Scott Date: Wed, 4 Feb 2015 12:19:55 +0100 Subject: Removed magick numbers and added support for static delay in all dab modes --- src/OutputUHD.cpp | 54 ++++++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 44 insertions(+), 10 deletions(-) (limited to 'src/OutputUHD.cpp') diff --git a/src/OutputUHD.cpp b/src/OutputUHD.cpp index 741731e..91c030f 100644 --- a/src/OutputUHD.cpp +++ b/src/OutputUHD.cpp @@ -57,11 +57,11 @@ OutputUHD::OutputUHD( // the buffers at object initialisation. first_run(true), activebuffer(1), - myDelayBuf(196608) + myDelayBuf(0) { myMuting = 0; // is remote-controllable - myStaticDelay = 0; // is remote-controllable + myStaticDelayUs = 0; // is remote-controllable #if FAKE_UHD MDEBUG("OutputUHD:Using fake UHD output"); @@ -225,6 +225,7 @@ OutputUHD::OutputUHD( uwd.check_refclk_loss = true; } + SetDelayBuffer(config.dabMode); shared_ptr b(new barrier(2)); mySyncBarrier = b; @@ -246,6 +247,35 @@ OutputUHD::~OutputUHD() } } +void OutputUHD::SetDelayBuffer(unsigned int dabMode) +{ + // find out the duration of the transmission frame (Table 2 in ETSI 300 401) + switch (dabMode) { + case 0: // could happen when called from constructor and we take the mode from ETI + myTFDurationMs = 0; + break; + case 1: + myTFDurationMs = 96; + break; + case 2: + myTFDurationMs = 24; + break; + case 3: + myTFDurationMs = 24; + break; + case 4: + myTFDurationMs = 48; + break; + default: + throw std::runtime_error("OutPutUHD: invalid DAB mode"); + } + fprintf(stderr, "DelayBuf = %d\n", myTFDurationMs * myConf.sampleRate / 1000); + // The buffer size equals the number of samples per transmission frame so + // we calculate it by multiplying the duration of the transmission frame + // with the samplerate. + myDelayBuf.resize(myTFDurationMs * myConf.sampleRate / 1000); +} + int OutputUHD::process(Buffer* dataIn, Buffer* dataOut) { struct frame_timestamp ts; @@ -281,6 +311,10 @@ int OutputUHD::process(Buffer* dataIn, Buffer* dataOut) default: break; } + // we only set the delay buffer from the dab mode signaled in ETI if the + // dab mode was not set in contructor + if (myTFDurationMs == 0) + SetDelayBuffer(myEtiReader->getMode()); activebuffer = 1; @@ -307,7 +341,7 @@ int OutputUHD::process(Buffer* dataIn, Buffer* dataOut) myEtiReader->sourceContainsTimestamp(); // calculate delay - uint32_t noSampleDelay = (myStaticDelay * 2048) / 1000; + uint32_t noSampleDelay = (myStaticDelayUs * myConf.sampleRate / 1000) / 1000; uint32_t noByteDelay = noSampleDelay * sizeof(complexf); uint8_t* pInData = (uint8_t*) dataIn->getData(); @@ -655,13 +689,13 @@ void OutputUHD::set_parameter(const string& parameter, const string& value) else if (parameter == "staticdelay") { int adjust; ss >> adjust; - int newStaticDelay = myStaticDelay + adjust; - if (newStaticDelay > 96000) - myStaticDelay = newStaticDelay - 96000; - else if (newStaticDelay < 0) - myStaticDelay = newStaticDelay + 96000; + int newStaticDelayUs = myStaticDelayUs + adjust; + if (newStaticDelayUs > myTFDurationMs * 1000) + myStaticDelayUs = newStaticDelayUs - myTFDurationMs * 1000; + else if (newStaticDelayUs < 0) + myStaticDelayUs = newStaticDelayUs + myTFDurationMs * 1000; else - myStaticDelay = newStaticDelay; + myStaticDelayUs = newStaticDelayUs; } else if (parameter == "iqbalance") { ss >> myConf.frequency; @@ -689,7 +723,7 @@ const string OutputUHD::get_parameter(const string& parameter) const ss << myMuting; } else if (parameter == "staticdelay") { - ss << myStaticDelay; + ss << myStaticDelayUs; } else { ss << "Parameter '" << parameter << -- cgit v1.2.3 From e8e7350db3bbf1d408ca4b305329c17d545c91eb Mon Sep 17 00:00:00 2001 From: Jörgen Scott Date: Mon, 9 Feb 2015 10:17:01 +0100 Subject: Bug fix for static delay --- src/OutputUHD.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'src/OutputUHD.cpp') diff --git a/src/OutputUHD.cpp b/src/OutputUHD.cpp index 91c030f..3845439 100644 --- a/src/OutputUHD.cpp +++ b/src/OutputUHD.cpp @@ -341,7 +341,7 @@ int OutputUHD::process(Buffer* dataIn, Buffer* dataOut) myEtiReader->sourceContainsTimestamp(); // calculate delay - uint32_t noSampleDelay = (myStaticDelayUs * myConf.sampleRate / 1000) / 1000; + uint32_t noSampleDelay = (myStaticDelayUs * (myConf.sampleRate / 1000)) / 1000; uint32_t noByteDelay = noSampleDelay * sizeof(complexf); uint8_t* pInData = (uint8_t*) dataIn->getData(); @@ -690,10 +690,10 @@ void OutputUHD::set_parameter(const string& parameter, const string& value) int adjust; ss >> adjust; int newStaticDelayUs = myStaticDelayUs + adjust; - if (newStaticDelayUs > myTFDurationMs * 1000) - myStaticDelayUs = newStaticDelayUs - myTFDurationMs * 1000; + if (newStaticDelayUs > (myTFDurationMs * 1000)) + myStaticDelayUs = newStaticDelayUs - (myTFDurationMs * 1000); else if (newStaticDelayUs < 0) - myStaticDelayUs = newStaticDelayUs + myTFDurationMs * 1000; + myStaticDelayUs = newStaticDelayUs + (myTFDurationMs * 1000); else myStaticDelayUs = newStaticDelayUs; } -- cgit v1.2.3 From 413aeff4088a1d5adadf07cb1833091a197dc393 Mon Sep 17 00:00:00 2001 From: Jörgen Scott Date: Mon, 9 Feb 2015 12:42:00 +0100 Subject: added reset for static delay --- src/OutputUHD.cpp | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) (limited to 'src/OutputUHD.cpp') diff --git a/src/OutputUHD.cpp b/src/OutputUHD.cpp index 3845439..bfd24a8 100644 --- a/src/OutputUHD.cpp +++ b/src/OutputUHD.cpp @@ -269,7 +269,6 @@ void OutputUHD::SetDelayBuffer(unsigned int dabMode) default: throw std::runtime_error("OutPutUHD: invalid DAB mode"); } - fprintf(stderr, "DelayBuf = %d\n", myTFDurationMs * myConf.sampleRate / 1000); // The buffer size equals the number of samples per transmission frame so // we calculate it by multiplying the duration of the transmission frame // with the samplerate. @@ -687,15 +686,23 @@ void OutputUHD::set_parameter(const string& parameter, const string& value) ss >> myMuting; } else if (parameter == "staticdelay") { - int adjust; + int64_t adjust; ss >> adjust; - int newStaticDelayUs = myStaticDelayUs + adjust; - if (newStaticDelayUs > (myTFDurationMs * 1000)) - myStaticDelayUs = newStaticDelayUs - (myTFDurationMs * 1000); - else if (newStaticDelayUs < 0) - myStaticDelayUs = newStaticDelayUs + (myTFDurationMs * 1000); - else - myStaticDelayUs = newStaticDelayUs; + if (adjust > (myTFDurationMs * 1000)) + { // reset static delay for values outside range + myStaticDelayUs = 0; + } + else + { // the new adjust value is added to the existing delay and the result + // is wrapped around at TF duration + int newStaticDelayUs = myStaticDelayUs + adjust; + if (newStaticDelayUs > (myTFDurationMs * 1000)) + myStaticDelayUs = newStaticDelayUs - (myTFDurationMs * 1000); + else if (newStaticDelayUs < 0) + myStaticDelayUs = newStaticDelayUs + (myTFDurationMs * 1000); + else + myStaticDelayUs = newStaticDelayUs; + } } else if (parameter == "iqbalance") { ss >> myConf.frequency; -- cgit v1.2.3 From 277d29a529c37a8fe59883291e43db8ff8831b22 Mon Sep 17 00:00:00 2001 From: "Matthias P. Braendli" Date: Thu, 12 Feb 2015 10:20:54 +0100 Subject: indentation --- src/DabMod.cpp | 2 +- src/OutputUHD.cpp | 85 ++++++++++++++++++++++++++++--------------------------- src/OutputUHD.h | 9 +++--- 3 files changed, 49 insertions(+), 47 deletions(-) (limited to 'src/OutputUHD.cpp') diff --git a/src/DabMod.cpp b/src/DabMod.cpp index 214231c..77e5da4 100644 --- a/src/DabMod.cpp +++ b/src/DabMod.cpp @@ -535,7 +535,7 @@ int main(int argc, char* argv[]) outputuhd_conf.txgain = pt.get("uhdoutput.txgain", 0.0); outputuhd_conf.frequency = pt.get("uhdoutput.frequency", 0); std::string chan = pt.get("uhdoutput.channel", ""); - outputuhd_conf.dabMode = dabMode; + outputuhd_conf.dabMode = dabMode; if (outputuhd_conf.frequency == 0 && chan == "") { std::cerr << " UHD output enabled, but neither frequency nor channel defined.\n"; diff --git a/src/OutputUHD.cpp b/src/OutputUHD.cpp index bfd24a8..d033700 100644 --- a/src/OutputUHD.cpp +++ b/src/OutputUHD.cpp @@ -225,7 +225,7 @@ OutputUHD::OutputUHD( uwd.check_refclk_loss = true; } - SetDelayBuffer(config.dabMode); + SetDelayBuffer(config.dabMode); shared_ptr b(new barrier(2)); mySyncBarrier = b; @@ -249,30 +249,30 @@ OutputUHD::~OutputUHD() void OutputUHD::SetDelayBuffer(unsigned int dabMode) { - // find out the duration of the transmission frame (Table 2 in ETSI 300 401) + // find out the duration of the transmission frame (Table 2 in ETSI 300 401) switch (dabMode) { - case 0: // could happen when called from constructor and we take the mode from ETI - myTFDurationMs = 0; - break; - case 1: - myTFDurationMs = 96; - break; - case 2: - myTFDurationMs = 24; - break; - case 3: - myTFDurationMs = 24; - break; - case 4: - myTFDurationMs = 48; - break; - default: - throw std::runtime_error("OutPutUHD: invalid DAB mode"); + case 0: // could happen when called from constructor and we take the mode from ETI + myTFDurationMs = 0; + break; + case 1: + myTFDurationMs = 96; + break; + case 2: + myTFDurationMs = 24; + break; + case 3: + myTFDurationMs = 24; + break; + case 4: + myTFDurationMs = 48; + break; + default: + throw std::runtime_error("OutputUHD: invalid DAB mode"); } - // The buffer size equals the number of samples per transmission frame so - // we calculate it by multiplying the duration of the transmission frame - // with the samplerate. - myDelayBuf.resize(myTFDurationMs * myConf.sampleRate / 1000); + // The buffer size equals the number of samples per transmission frame so + // we calculate it by multiplying the duration of the transmission frame + // with the samplerate. + myDelayBuf.resize(myTFDurationMs * myConf.sampleRate / 1000); } int OutputUHD::process(Buffer* dataIn, Buffer* dataOut) @@ -310,10 +310,11 @@ int OutputUHD::process(Buffer* dataIn, Buffer* dataOut) default: break; } - // we only set the delay buffer from the dab mode signaled in ETI if the - // dab mode was not set in contructor - if (myTFDurationMs == 0) - SetDelayBuffer(myEtiReader->getMode()); + // we only set the delay buffer from the dab mode signaled in ETI if the + // dab mode was not set in contructor + if (myTFDurationMs == 0) { + SetDelayBuffer(myEtiReader->getMode()); + } activebuffer = 1; @@ -688,21 +689,21 @@ void OutputUHD::set_parameter(const string& parameter, const string& value) else if (parameter == "staticdelay") { int64_t adjust; ss >> adjust; - if (adjust > (myTFDurationMs * 1000)) - { // reset static delay for values outside range - myStaticDelayUs = 0; - } - else - { // the new adjust value is added to the existing delay and the result - // is wrapped around at TF duration - int newStaticDelayUs = myStaticDelayUs + adjust; - if (newStaticDelayUs > (myTFDurationMs * 1000)) - myStaticDelayUs = newStaticDelayUs - (myTFDurationMs * 1000); - else if (newStaticDelayUs < 0) - myStaticDelayUs = newStaticDelayUs + (myTFDurationMs * 1000); - else - myStaticDelayUs = newStaticDelayUs; - } + if (adjust > (myTFDurationMs * 1000)) + { // reset static delay for values outside range + myStaticDelayUs = 0; + } + else + { // the new adjust value is added to the existing delay and the result + // is wrapped around at TF duration + int newStaticDelayUs = myStaticDelayUs + adjust; + if (newStaticDelayUs > (myTFDurationMs * 1000)) + myStaticDelayUs = newStaticDelayUs - (myTFDurationMs * 1000); + else if (newStaticDelayUs < 0) + myStaticDelayUs = newStaticDelayUs + (myTFDurationMs * 1000); + else + myStaticDelayUs = newStaticDelayUs; + } } else if (parameter == "iqbalance") { ss >> myConf.frequency; diff --git a/src/OutputUHD.h b/src/OutputUHD.h index d002e98..c5d561b 100644 --- a/src/OutputUHD.h +++ b/src/OutputUHD.h @@ -171,7 +171,7 @@ struct OutputUHDConfig { double txgain; bool enableSync; bool muteNoTimestamps; - unsigned dabMode; + unsigned dabMode; /* allowed values : auto, int, sma, mimo */ std::string refclk_src; @@ -232,12 +232,13 @@ class OutputUHD: public ModOutput, public RemoteControllable { bool myMuting; private: - // methods - void SetDelayBuffer(unsigned int dabMode); + // Resize the internal delay buffer according to the dabMode and + // the sample rate. + void SetDelayBuffer(unsigned int dabMode); // data int myStaticDelayUs; // static delay in microseconds - int myTFDurationMs; // TF duration in milliseconds + int myTFDurationMs; // TF duration in milliseconds std::vector myDelayBuf; size_t lastLen; }; -- cgit v1.2.3