aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--doc/example.ini13
-rw-r--r--src/DabMod.cpp50
-rw-r--r--src/FormatConverter.cpp103
-rw-r--r--src/FormatConverter.h53
-rw-r--r--src/InputFileReader.cpp17
-rw-r--r--src/Makefile.am1
6 files changed, 216 insertions, 21 deletions
diff --git a/doc/example.ini b/doc/example.ini
index 3c81c04..43adacb 100644
--- a/doc/example.ini
+++ b/doc/example.ini
@@ -113,11 +113,22 @@ filtertapsfile=simple_taps.txt
output=uhd
[fileoutput]
-; The file output writes I/Q float values (i.e. complex float)
+; Two output formats are supported: In the default mode,
+; the file output writes I/Q float values (i.e. complex float)
; to the file. The I and Q samples can take values up to
; 100000 in absolute magnitude with gainmode FIX.
; With gainmode VAR, they should never exceed 50000.
; With gainmode MAX, thet are limited to 32767.
+;format=complexf
+;
+; When the format is set to s8, the output writes I/Q 8-bit
+; signed integers, where the magnitude is multiplied by 128/50000
+; effectively mapping the gainmode VAR range of -50000 -- 50000
+; to -128 -- 128. For other gainmodes, use the digital_gain setting
+; to make sure you don't create clipping.
+;format=s8
+
+; The output file:
filename=/dev/stdout
[uhdoutput]
diff --git a/src/DabMod.cpp b/src/DabMod.cpp
index 06d1254..82f03e5 100644
--- a/src/DabMod.cpp
+++ b/src/DabMod.cpp
@@ -35,6 +35,7 @@
#include "DabModulator.h"
#include "InputMemory.h"
#include "OutputFile.h"
+#include "FormatConverter.h"
#if defined(HAVE_OUTPUT_UHD)
# include "OutputUHD.h"
#endif
@@ -176,6 +177,7 @@ int main(int argc, char* argv[])
std::string outputName;
int useZeroMQOutput = 0;
int useFileOutput = 0;
+ std::string fileOutputFormat = "complexf";
int useUHDOutput = 0;
uint64_t frame = 0;
@@ -187,6 +189,17 @@ int main(int argc, char* argv[])
GainMode gainMode = GAIN_VAR;
Buffer data;
+
+ /* UHD requires the input I and Q samples to be in the interval
+ * [-1.0,1.0], otherwise they get truncated, which creates very
+ * wide-spectrum spikes. Depending on the Transmission Mode, the
+ * Gain Mode and the sample rate (and maybe other parameters), the
+ * samples can have peaks up to about 48000. The value of 50000
+ * should guarantee that with a digital gain of 1.0, UHD never clips
+ * our samples.
+ */
+ const float normalise_factor = 50000.0f;
+
std::string filterTapsFilename = "";
// Two configuration sources exist: command line and (new) INI file
@@ -207,6 +220,7 @@ int main(int argc, char* argv[])
Flowgraph* flowgraph = NULL;
DabModulator* modulator = NULL;
InputMemory* input = NULL;
+ FormatConverter* format_converter = NULL;
ModOutput* output = NULL;
RemoteControllers rcs;
@@ -498,6 +512,8 @@ int main(int argc, char* argv[])
goto END_MAIN;
}
useFileOutput = 1;
+
+ fileOutputFormat = pt.get("fileoutput.format", fileOutputFormat);
}
#if defined(HAVE_OUTPUT_UHD)
else if (output_selected == "uhd") {
@@ -761,23 +777,23 @@ int main(int argc, char* argv[])
goto END_MAIN;
}
-
if (useFileOutput) {
- // Opening COFDM output file
- output = new OutputFile(outputName);
+ if (fileOutputFormat == "complexf") {
+ output = new OutputFile(outputName);
+ }
+ else if (fileOutputFormat == "s8") {
+ // We must normalise the samples to the interval [-127.0; 127.0]
+ normalise = 127.0f / normalise_factor;
+
+ format_converter = new FormatConverter();
+
+ output = new OutputFile(outputName);
+ }
}
#if defined(HAVE_OUTPUT_UHD)
else if (useUHDOutput) {
- /* UHD requires the input I and Q samples to be in the interval
- * [-1.0,1.0], otherwise they get truncated, which creates very
- * wide-spectrum spikes. Depending on the Transmission Mode, the
- * Gain Mode and the sample rate (and maybe other parameters), the
- * samples can have peaks up to about 48000. The value of 50000
- * should guarantee that with a digital gain of 1.0, UHD never clips
- * our samples.
- */
- normalise = 1.0f/50000.0f;
+ normalise = 1.0f / normalise_factor;
outputuhd_conf.sampleRate = outputRate;
try {
@@ -793,7 +809,7 @@ int main(int argc, char* argv[])
#if defined(HAVE_ZEROMQ)
else if (useZeroMQOutput) {
/* We normalise the same way as for the UHD output */
- normalise = 1.0f/50000.0f;
+ normalise = 1.0f / normalise_factor;
output = new OutputZeroMQ(outputName);
}
@@ -805,7 +821,13 @@ int main(int argc, char* argv[])
modulator = new DabModulator(modconf, &rcs, logger, outputRate, clockRate,
dabMode, gainMode, digitalgain, normalise, filterTapsFilename);
flowgraph->connect(input, modulator);
- flowgraph->connect(modulator, output);
+ if (format_converter) {
+ flowgraph->connect(modulator, format_converter);
+ flowgraph->connect(format_converter, output);
+ }
+ else {
+ flowgraph->connect(modulator, output);
+ }
#if defined(HAVE_OUTPUT_UHD)
if (useUHDOutput) {
diff --git a/src/FormatConverter.cpp b/src/FormatConverter.cpp
new file mode 100644
index 0000000..766b6d8
--- /dev/null
+++ b/src/FormatConverter.cpp
@@ -0,0 +1,103 @@
+/*
+ Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010, 2011 Her Majesty
+ the Queen in Right of Canada (Communications Research Center Canada)
+
+ Copyright (C) 2014
+ Matthias P. Braendli, matthias.braendli@mpb.li
+
+ http://opendigitalradio.org
+
+ This flowgraph block converts complexf to signed integer.
+ */
+/*
+ This file is part of ODR-DabMod.
+
+ ODR-DabMod is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as
+ published by the Free Software Foundation, either version 3 of the
+ License, or (at your option) any later version.
+
+ ODR-DabMod is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with ODR-DabMod. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "FormatConverter.h"
+#include "PcDebug.h"
+
+#include <malloc.h>
+#include <sys/types.h>
+#include <string.h>
+#include <stdexcept>
+#include <assert.h>
+
+#ifdef __SSE__
+# include <xmmintrin.h>
+#endif
+
+FormatConverter::FormatConverter(void) :
+ ModCodec(ModFormat(sizeof(complexf)),
+ ModFormat(sizeof(int8_t))) { }
+
+/* Expect the input samples to be in the range [-255.0, 255.0] */
+int FormatConverter::process(Buffer* const dataIn, Buffer* dataOut)
+{
+ PDEBUG("FormatConverter::process(dataIn: %p, dataOut: %p)\n",
+ dataIn, dataOut);
+
+ size_t sizeIn = dataIn->getLength() / sizeof(float);
+ dataOut->setLength(sizeIn * sizeof(int8_t));
+
+ float* in = reinterpret_cast<float*>(dataIn->getData());
+
+#if 0
+ // Disabled because subscripting a __m64 doesn't seem to work
+ // on all platforms.
+
+ /*
+ _mm_cvtps_pi8 does:
+ |<----------- 128 bits ------------>|
+ __m128 | I1 | Q1 | I2 | Q2 | in float
+ __m64 |I1Q1I2Q2|00000000| in int8_t
+ */
+
+ uint32_t* out = reinterpret_cast<uint32_t*>(dataOut->getData());
+
+ assert(sizeIn % 16 == 0);
+ assert((uintptr_t)in % 16 == 0);
+ for(size_t i = 0, j = 0; i < sizeIn; i+=16, j+=4)
+ {
+ __m128 a1 = _mm_load_ps(in+i+0);
+ __m128 a2 = _mm_load_ps(in+i+4);
+ __m128 a3 = _mm_load_ps(in+i+8);
+ __m128 a4 = _mm_load_ps(in+i+12);
+ __m64 b1 = _mm_cvtps_pi8(a1);
+ __m64 b2 = _mm_cvtps_pi8(a2);
+ __m64 b3 = _mm_cvtps_pi8(a3);
+ __m64 b4 = _mm_cvtps_pi8(a4);
+ out[j+0] = b1[0];
+ out[j+1] = b2[0];
+ out[j+2] = b3[0];
+ out[j+3] = b4[0];
+ }
+#else
+ int8_t* out = reinterpret_cast<int8_t*>(dataOut->getData());
+
+ // Slow implementation that uses _ftol()
+ for (size_t i = 0; i < sizeIn; i++) {
+ out[i] = in[i];
+ }
+#endif
+
+ return 1;
+}
+
+const char* FormatConverter::name()
+{
+ return "FormatConverter";
+}
+
diff --git a/src/FormatConverter.h b/src/FormatConverter.h
new file mode 100644
index 0000000..0243685
--- /dev/null
+++ b/src/FormatConverter.h
@@ -0,0 +1,53 @@
+/*
+ Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010, 2011 Her Majesty
+ the Queen in Right of Canada (Communications Research Center Canada)
+
+ Copyright (C) 2014
+ Matthias P. Braendli, matthias.braendli@mpb.li
+
+ http://opendigitalradio.org
+
+ This flowgraph block converts complexf to signed integer.
+ */
+/*
+ This file is part of ODR-DabMod.
+
+ ODR-DabMod is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as
+ published by the Free Software Foundation, either version 3 of the
+ License, or (at your option) any later version.
+
+ ODR-DabMod is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with ODR-DabMod. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef FORMAT_CONVERTER_H
+#define FORMAT_CONVERTER_H
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#include "porting.h"
+#include "ModCodec.h"
+#include <complex>
+#include <stdint.h>
+
+typedef std::complex<float> complexf;
+
+class FormatConverter : public ModCodec
+{
+ public:
+ FormatConverter(void);
+
+ int process(Buffer* const dataIn, Buffer* dataOut);
+ const char* name();
+};
+
+#endif // FORMAT_CONVERTER_H
+
diff --git a/src/InputFileReader.cpp b/src/InputFileReader.cpp
index 52fbb99..205fbfa 100644
--- a/src/InputFileReader.cpp
+++ b/src/InputFileReader.cpp
@@ -284,13 +284,18 @@ int InputFileReader::GetNextFrame(void* buffer)
if (read_bytes != frameSize) {
// A short read of a frame (i.e. reading an incomplete frame)
// is not tolerated. Input files must not contain incomplete frames
- fprintf(stderr,
- "Unable to read a complete frame of %u data bytes from input file!\n",
- frameSize);
+ if (read_bytes != 0) {
+ fprintf(stderr,
+ "Unable to read a complete frame of %u data bytes from input file!\n",
+ frameSize);
- perror(filename_.c_str());
- logger_.level(error) << "Unable to read from input file!";
- return -1;
+ perror(filename_.c_str());
+ logger_.level(error) << "Unable to read from input file!";
+ return -1;
+ }
+ else {
+ return 0;
+ }
}
memset(&((uint8_t*)buffer)[frameSize], 0x55, 6144 - frameSize);
diff --git a/src/Makefile.am b/src/Makefile.am
index 922ce52..f8ba7c2 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -110,6 +110,7 @@ odr_dabmod_SOURCES = DabMod.cpp \
ThreadsafeQueue.h \
Log.cpp Log.h \
RemoteControl.cpp RemoteControl.h \
+ FormatConverter.cpp FormatConverter.h \
zmq.hpp
nodist_odr_dabmod_SOURCES = $(FFT_SRC)