aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/DabMod.cpp13
-rw-r--r--src/DabModulator.cpp10
-rw-r--r--src/DabModulator.h6
-rw-r--r--src/GainControl.cpp85
-rw-r--r--src/GainControl.h55
-rw-r--r--src/RemoteControl.cpp3
6 files changed, 118 insertions, 54 deletions
diff --git a/src/DabMod.cpp b/src/DabMod.cpp
index d8614a7..92f07eb 100644
--- a/src/DabMod.cpp
+++ b/src/DabMod.cpp
@@ -101,7 +101,7 @@ void printUsage(char* progName, FILE* out = stderr)
" [-o offset]"
" [-O offsetfile]"
" [-T filter_taps_file]"
- " [-a amplitude]"
+ " [-a gain]"
" [-c clockrate]"
" [-g gainMode]"
" [-h]"
@@ -173,7 +173,8 @@ int main(int argc, char* argv[])
size_t outputRate = 2048000;
size_t clockRate = 0;
unsigned dabMode = 0;
- float amplitude = 1.0f;
+ float digitalgain = 1.0f;
+ float normalise = 1.0f;
GainMode gainMode = GAIN_VAR;
Buffer data;
@@ -231,7 +232,7 @@ int main(int argc, char* argv[])
break;
case 'a':
- amplitude = strtof(optarg, NULL);
+ digitalgain = strtof(optarg, NULL);
break;
case 'c':
clockRate = strtol(optarg, NULL, 0);
@@ -400,7 +401,7 @@ int main(int argc, char* argv[])
gainMode = (GainMode)pt.get("modulator.gainmode", 0);
dabMode = pt.get("modulator.mode", dabMode);
clockRate = pt.get("modulator.dac_clk_rate", (size_t)0);
- amplitude = pt.get("modulator.digital_gain", amplitude);
+ digitalgain = pt.get("modulator.digital_gain", digitalgain);
outputRate = pt.get("modulator.rate", outputRate);
// FIR Filter parameters:
@@ -683,7 +684,7 @@ int main(int argc, char* argv[])
}
#if defined(HAVE_OUTPUT_UHD)
else if (useUHDOutput) {
- amplitude /= 32000.0f;
+ normalise = 1.0f/32768.0f;
outputuhd_conf.sampleRate = outputRate;
try {
output = new OutputUHD(outputuhd_conf, logger);
@@ -700,7 +701,7 @@ int main(int argc, char* argv[])
data.setLength(6144);
input = new InputMemory(&data);
modulator = new DabModulator(modconf, rc, logger, outputRate, clockRate,
- dabMode, gainMode, amplitude, filterTapsFilename);
+ dabMode, gainMode, digitalgain, normalise, filterTapsFilename);
flowgraph->connect(input, modulator);
flowgraph->connect(modulator, output);
diff --git a/src/DabModulator.cpp b/src/DabModulator.cpp
index e41f999..7f246d8 100644
--- a/src/DabModulator.cpp
+++ b/src/DabModulator.cpp
@@ -56,7 +56,8 @@ DabModulator::DabModulator(
BaseRemoteController* rc,
Logger& logger,
unsigned outputRate, unsigned clockRate,
- unsigned dabMode, GainMode gainMode, float factor,
+ unsigned dabMode, GainMode gainMode,
+ float digGain, float normalise,
std::string filterTapsFilename
) :
ModCodec(ModFormat(1), ModFormat(0)),
@@ -65,7 +66,8 @@ DabModulator::DabModulator(
myClockRate(clockRate),
myDabMode(dabMode),
myGainMode(gainMode),
- myFactor(factor),
+ myDigGain(digGain),
+ myNormalise(normalise),
myEtiReader(EtiReader(modconf, myLogger)),
myFlowgraph(NULL),
myFilterTapsFilename(filterTapsFilename),
@@ -198,7 +200,9 @@ int DabModulator::process(Buffer* const dataIn, Buffer* dataOut)
}
cifOfdm = new OfdmGenerator((1 + myNbSymbols), myNbCarriers, mySpacing);
- cifGain = new GainControl(mySpacing, myGainMode, myFactor);
+ cifGain = new GainControl(mySpacing, myGainMode, myDigGain, myNormalise);
+ cifGain->enrol_at(*myRC);
+
cifGuard = new GuardIntervalInserter(myNbSymbols, mySpacing,
myNullSize, mySymSize);
if (myFilterTapsFilename != "") {
diff --git a/src/DabModulator.h b/src/DabModulator.h
index 425c098..21f9f61 100644
--- a/src/DabModulator.h
+++ b/src/DabModulator.h
@@ -51,7 +51,8 @@ public:
Logger& logger,
unsigned outputRate = 2048000, unsigned clockRate = 0,
unsigned dabMode = 0, GainMode gainMode = GAIN_VAR,
- float factor = 1.0, std::string filterTapsFilename = "");
+ float digGain = 1.0, float normalise = 1.0,
+ std::string filterTapsFilename = "");
DabModulator(const DabModulator& copy);
virtual ~DabModulator();
@@ -70,7 +71,8 @@ protected:
unsigned myClockRate;
unsigned myDabMode;
GainMode myGainMode;
- float myFactor;
+ float myDigGain;
+ float myNormalise;
EtiReader myEtiReader;
Flowgraph* myFlowgraph;
OutputMemory* myOutput;
diff --git a/src/GainControl.cpp b/src/GainControl.cpp
index 6c4254b..0bb0967 100644
--- a/src/GainControl.cpp
+++ b/src/GainControl.cpp
@@ -26,35 +26,47 @@
#include <stdio.h>
#include <stdexcept>
+#include <string>
+using namespace std;
-GainControl::GainControl(size_t framesize, GainMode mode, float factor) :
- ModCodec(ModFormat(framesize * sizeof(complexf)), ModFormat(framesize * sizeof(complexf))),
+
+GainControl::GainControl(size_t framesize,
+ GainMode mode,
+ float digGain,
+ float normalise) :
+ ModCodec(ModFormat(framesize * sizeof(complexf)),
+ ModFormat(framesize * sizeof(complexf))),
+ RemoteControllable("gain"),
#ifdef __SSE__
d_frameSize(framesize * sizeof(complexf) / sizeof(__m128)),
#else // !__SSE__
d_frameSize(framesize),
#endif
- d_factor(factor)
+ d_digGain(digGain),
+ d_normalise(normalise)
{
PDEBUG("GainControl::GainControl(%zu, %u) @ %p\n", framesize, mode, this);
+ /* register the parameters that can be remote controlled */
+ RC_ADD_PARAMETER(digital, "Digital Gain");
+
switch(mode) {
- case GAIN_FIX:
- PDEBUG("Gain mode: fix\n");
- computeGain = computeGainFix;
- break;
- case GAIN_MAX:
- PDEBUG("Gain mode: max\n");
- computeGain = computeGainMax;
- break;
- case GAIN_VAR:
- PDEBUG("Gain mode: var\n");
- computeGain = computeGainVar;
- break;
- default:
- throw std::runtime_error(
- "GainControl::GainControl invalid computation gain mode!");
+ case GAIN_FIX:
+ PDEBUG("Gain mode: fix\n");
+ computeGain = computeGainFix;
+ break;
+ case GAIN_MAX:
+ PDEBUG("Gain mode: max\n");
+ computeGain = computeGainMax;
+ break;
+ case GAIN_VAR:
+ PDEBUG("Gain mode: var\n");
+ computeGain = computeGainVar;
+ break;
+ default:
+ throw std::runtime_error(
+ "GainControl::GainControl invalid computation gain mode!");
}
}
@@ -89,7 +101,7 @@ int GainControl::process(Buffer* const dataIn, Buffer* dataOut)
for (size_t i = 0; i < sizeIn; i += d_frameSize) {
gain128.m = computeGain(in, d_frameSize);
- gain128.m = _mm_mul_ps(gain128.m, _mm_set1_ps(d_factor));
+ gain128.m = _mm_mul_ps(gain128.m, _mm_set1_ps(d_normalise * d_digGain));
PDEBUG("********** Gain: %10f **********\n", gain128.f[0]);
@@ -117,7 +129,7 @@ int GainControl::process(Buffer* const dataIn, Buffer* dataOut)
}
for (size_t i = 0; i < sizeIn; i += d_frameSize) {
- gain = d_factor * computeGain(in, d_frameSize);
+ gain = d_normalise * d_digGain * computeGain(in, d_frameSize);
PDEBUG("********** Gain: %10f **********\n", gain);
@@ -367,3 +379,36 @@ float GainControl::computeGainVar(const complexf* in, size_t sizeIn)
return gain;
}
#endif // __SSE__
+
+void GainControl::set_parameter(const string& parameter, const string& value)
+{
+ stringstream ss(value);
+ ss.exceptions ( stringstream::failbit | stringstream::badbit );
+
+ if (parameter == "digital") {
+ float new_factor;
+ ss >> new_factor;
+ d_digGain = new_factor;
+ }
+ else {
+ stringstream ss;
+ ss << "Parameter '" << parameter
+ << "' is not exported by controllable " << get_rc_name();
+ throw ParameterError(ss.str());
+ }
+}
+
+const string GainControl::get_parameter(const string& parameter) const
+{
+ stringstream ss;
+ if (parameter == "digital") {
+ ss << std::fixed << d_digGain;
+ }
+ else {
+ ss << "Parameter '" << parameter <<
+ "' is not exported by controllable " << get_rc_name();
+ throw ParameterError(ss.str());
+ }
+ return ss.str();
+}
+
diff --git a/src/GainControl.h b/src/GainControl.h
index 4cf4ae1..65b94da 100644
--- a/src/GainControl.h
+++ b/src/GainControl.h
@@ -27,12 +27,12 @@
# include <config.h>
#endif
-
#include "ModCodec.h"
-
+#include "RemoteControl.h"
#include <sys/types.h>
#include <complex>
+#include <string>
#ifdef __SSE__
# include <xmmintrin.h>
#endif
@@ -42,31 +42,44 @@ typedef std::complex<float> complexf;
enum GainMode { GAIN_FIX, GAIN_MAX, GAIN_VAR };
-class GainControl : public ModCodec
+class GainControl : public ModCodec, public RemoteControllable
{
-public:
- GainControl(size_t frameSize, GainMode mode = GAIN_VAR, float factor = 1.0f);
- virtual ~GainControl();
- GainControl(const GainControl&);
- GainControl& operator=(const GainControl&);
+ public:
+ GainControl(size_t framesize,
+ GainMode mode = GAIN_VAR,
+ float digGain = 1.0f,
+ float normalise = 1.0f);
+
+ virtual ~GainControl();
+ GainControl(const GainControl&);
+ GainControl& operator=(const GainControl&);
+
+
+ int process(Buffer* const dataIn, Buffer* dataOut);
+ const char* name() { return "GainControl"; }
+ /* Functions for the remote control */
+ /* Base function to set parameters. */
+ virtual void set_parameter(const std::string& parameter,
+ const std::string& value);
- int process(Buffer* const dataIn, Buffer* dataOut);
- const char* name() { return "GainControl"; }
+ /* Getting a parameter always returns a string. */
+ virtual const std::string get_parameter(const std::string& parameter) const;
-protected:
- size_t d_frameSize;
- float d_factor;
+ protected:
+ size_t d_frameSize;
+ float d_digGain;
+ float d_normalise;
#ifdef __SSE__
- __m128 (*computeGain)(const __m128* in, size_t sizeIn);
- __m128 static computeGainFix(const __m128* in, size_t sizeIn);
- __m128 static computeGainMax(const __m128* in, size_t sizeIn);
- __m128 static computeGainVar(const __m128* in, size_t sizeIn);
+ __m128 (*computeGain)(const __m128* in, size_t sizeIn);
+ __m128 static computeGainFix(const __m128* in, size_t sizeIn);
+ __m128 static computeGainMax(const __m128* in, size_t sizeIn);
+ __m128 static computeGainVar(const __m128* in, size_t sizeIn);
#else // !__SSE__
- float (*computeGain)(const complexf* in, size_t sizeIn);
- float static computeGainFix(const complexf* in, size_t sizeIn);
- float static computeGainMax(const complexf* in, size_t sizeIn);
- float static computeGainVar(const complexf* in, size_t sizeIn);
+ float (*computeGain)(const complexf* in, size_t sizeIn);
+ float static computeGainFix(const complexf* in, size_t sizeIn);
+ float static computeGainMax(const complexf* in, size_t sizeIn);
+ float static computeGainVar(const complexf* in, size_t sizeIn);
#endif // __SSE__
};
diff --git a/src/RemoteControl.cpp b/src/RemoteControl.cpp
index 854de76..5bbd2f8 100644
--- a/src/RemoteControl.cpp
+++ b/src/RemoteControl.cpp
@@ -224,8 +224,7 @@ void RemoteControllerTelnet::dispatch_command(tcp::socket& socket, string comman
reply(socket, "Error: Invalid parameter value. ");
}
}
- else
- {
+ else {
reply(socket, "Incorrect parameters for command 'set'");
}
}