aboutsummaryrefslogtreecommitdiffstats
path: root/src/FormatConverter.cpp
diff options
context:
space:
mode:
authorMatthias P. Braendli <matthias.braendli@mpb.li>2017-05-07 14:47:45 +0200
committerMatthias P. Braendli <matthias.braendli@mpb.li>2017-05-07 14:47:45 +0200
commit30b6ffb8afae8aee5bfc2f92d704202635bc7f3b (patch)
tree21828f314743e4ddf72b7fa58100889e5369ef0c /src/FormatConverter.cpp
parentbfce4874a0410f8f6521875d7e975f80d05544d4 (diff)
downloaddabmod-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
Diffstat (limited to 'src/FormatConverter.cpp')
-rw-r--r--src/FormatConverter.cpp27
1 files changed, 20 insertions, 7 deletions
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