diff options
author | Matthias P. Braendli <matthias.braendli@mpb.li> | 2017-05-07 14:47:45 +0200 |
---|---|---|
committer | Matthias P. Braendli <matthias.braendli@mpb.li> | 2017-05-07 14:47:45 +0200 |
commit | 30b6ffb8afae8aee5bfc2f92d704202635bc7f3b (patch) | |
tree | 21828f314743e4ddf72b7fa58100889e5369ef0c | |
parent | bfce4874a0410f8f6521875d7e975f80d05544d4 (diff) | |
download | dabmod-30b6ffb8afae8aee5bfc2f92d704202635bc7f3b.tar.gz dabmod-30b6ffb8afae8aee5bfc2f92d704202635bc7f3b.tar.bz2 dabmod-30b6ffb8afae8aee5bfc2f92d704202635bc7f3b.zip |
Add u8 format to FormatConverter
This is compatible with some tools like welle.io that take
u8 input
-rw-r--r-- | doc/example.ini | 3 | ||||
-rw-r--r-- | src/DabMod.cpp | 11 | ||||
-rw-r--r-- | src/FormatConverter.cpp | 27 | ||||
-rw-r--r-- | src/FormatConverter.h | 8 |
4 files changed, 37 insertions, 12 deletions
diff --git a/doc/example.ini b/doc/example.ini index f8cec36..56adcb2 100644 --- a/doc/example.ini +++ b/doc/example.ini @@ -156,6 +156,9 @@ output=uhd ; 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. +; +; The format u8 is the same as s8, except that the values are mapped +; between 0 and 255. ;format=s8 ; The output file: 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; }; |