summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/DabMod.cpp11
-rw-r--r--src/FormatConverter.cpp27
-rw-r--r--src/FormatConverter.h8
3 files changed, 34 insertions, 12 deletions
diff --git a/src/DabMod.cpp b/src/DabMod.cpp
index 4e4cdab..88c7524 100644
--- a/src/DabMod.cpp
+++ b/src/DabMod.cpp
@@ -197,8 +197,11 @@ static shared_ptr<ModOutput> prepare_output(
s.normalise = 1.0 / normalise_factor_file_var;
output = make_shared<OutputFile>(s.outputName);
}
- else if (s.fileOutputFormat == "s8") {
+ else if (s.fileOutputFormat == "s8" or
+ s.fileOutputFormat == "u8") {
// We must normalise the samples to the interval [-127.0; 127.0]
+ // The formatconverter will add 127 for u8 so that it ends up in
+ // [0; 255]
s.normalise = 127.0f / normalise_factor;
output = make_shared<OutputFile>(s.outputName);
@@ -284,8 +287,10 @@ int launch_modulator(int argc, char* argv[])
modulator_data m;
shared_ptr<FormatConverter> format_converter;
- if (mod_settings.useFileOutput and mod_settings.fileOutputFormat == "s8") {
- format_converter = make_shared<FormatConverter>();
+ if (mod_settings.useFileOutput and
+ (mod_settings.fileOutputFormat == "s8" or
+ mod_settings.fileOutputFormat == "u8")) {
+ format_converter = make_shared<FormatConverter>(mod_settings.fileOutputFormat);
}
auto output = prepare_output(mod_settings);
diff --git a/src/FormatConverter.cpp b/src/FormatConverter.cpp
index 89b3274..6826972 100644
--- a/src/FormatConverter.cpp
+++ b/src/FormatConverter.cpp
@@ -2,7 +2,7 @@
Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010, 2011 Her Majesty
the Queen in Right of Canada (Communications Research Center Canada)
- Copyright (C) 2014
+ Copyright (C) 2017
Matthias P. Braendli, matthias.braendli@mpb.li
http://opendigitalradio.org
@@ -39,8 +39,10 @@
# include <xmmintrin.h>
#endif
-FormatConverter::FormatConverter(void) :
- ModCodec() { }
+FormatConverter::FormatConverter(const std::string& format) :
+ ModCodec(),
+ m_offset_by_127(format == "u8")
+{ }
/* Expect the input samples to be in the range [-255.0, 255.0] */
int FormatConverter::process(Buffer* const dataIn, Buffer* dataOut)
@@ -54,6 +56,8 @@ int FormatConverter::process(Buffer* const dataIn, Buffer* dataOut)
float* in = reinterpret_cast<float*>(dataIn->getData());
#if 0
+#error "TODO: SSE FormatConvert does not support u8 yet"
+
// Disabled because subscripting a __m64 doesn't seem to work
// on all platforms.
@@ -84,11 +88,20 @@ int FormatConverter::process(Buffer* const dataIn, Buffer* dataOut)
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];
+ if (m_offset_by_127) {
+ uint8_t* out = reinterpret_cast<uint8_t*>(dataOut->getData());
+
+ for (size_t i = 0; i < sizeIn; i++) {
+ out[i] = in[i] + 128;
+ }
+ }
+ else {
+ int8_t* out = reinterpret_cast<int8_t*>(dataOut->getData());
+
+ for (size_t i = 0; i < sizeIn; i++) {
+ out[i] = in[i];
+ }
}
#endif
diff --git a/src/FormatConverter.h b/src/FormatConverter.h
index 86ce347..ce848b6 100644
--- a/src/FormatConverter.h
+++ b/src/FormatConverter.h
@@ -2,7 +2,7 @@
Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010, 2011 Her Majesty
the Queen in Right of Canada (Communications Research Center Canada)
- Copyright (C) 2014
+ Copyright (C) 2017
Matthias P. Braendli, matthias.braendli@mpb.li
http://opendigitalradio.org
@@ -35,6 +35,7 @@
#include "porting.h"
#include "ModPlugin.h"
#include <complex>
+#include <string>
#include <stdint.h>
typedef std::complex<float> complexf;
@@ -42,10 +43,13 @@ typedef std::complex<float> complexf;
class FormatConverter : public ModCodec
{
public:
- FormatConverter(void);
+ FormatConverter(const std::string& format);
int process(Buffer* const dataIn, Buffer* dataOut);
const char* name();
+
+ private:
+ bool m_offset_by_127 = false;
};