aboutsummaryrefslogtreecommitdiffstats
path: root/src/FormatConverter.cpp
diff options
context:
space:
mode:
authorMatthias P. Braendli <matthias.braendli@mpb.li>2024-10-29 23:52:22 +0100
committerMatthias P. Braendli <matthias.braendli@mpb.li>2024-10-29 23:52:22 +0100
commitf1a3db6d7dc1461bcf4a8933a77267698fdffd30 (patch)
treeb20e5054899335f340e26b9220c85691eeb70087 /src/FormatConverter.cpp
parent933021ed44e6c1bd2cf1dee91fc033c145c061af (diff)
downloaddabmod-f1a3db6d7dc1461bcf4a8933a77267698fdffd30.tar.gz
dabmod-f1a3db6d7dc1461bcf4a8933a77267698fdffd30.tar.bz2
dabmod-f1a3db6d7dc1461bcf4a8933a77267698fdffd30.zip
Rework fixed point config setting
Diffstat (limited to 'src/FormatConverter.cpp')
-rw-r--r--src/FormatConverter.cpp142
1 files changed, 84 insertions, 58 deletions
diff --git a/src/FormatConverter.cpp b/src/FormatConverter.cpp
index a52f501..1821442 100644
--- a/src/FormatConverter.cpp
+++ b/src/FormatConverter.cpp
@@ -34,9 +34,10 @@
#include <stdexcept>
#include <assert.h>
-FormatConverter::FormatConverter(const std::string& format) :
+FormatConverter::FormatConverter(bool input_is_complexfix_wide, const std::string& format_out) :
ModCodec(),
- m_format(format)
+ m_input_complexfix_wide(input_is_complexfix_wide),
+ m_format_out(format_out)
{ }
FormatConverter::~FormatConverter()
@@ -55,67 +56,95 @@ int FormatConverter::process(Buffer* const dataIn, Buffer* dataOut)
size_t num_clipped_samples = 0;
- size_t sizeIn = dataIn->getLength() / sizeof(float);
- float* in = reinterpret_cast<float*>(dataIn->getData());
- if (m_format == "s16") {
- dataOut->setLength(sizeIn * sizeof(int16_t));
- int16_t* out = reinterpret_cast<int16_t*>(dataOut->getData());
-
- for (size_t i = 0; i < sizeIn; i++) {
- if (in[i] < INT16_MIN) {
- out[i] = INT16_MIN;
- num_clipped_samples++;
- }
- else if (in[i] > INT16_MAX) {
- out[i] = INT16_MAX;
- num_clipped_samples++;
- }
- else {
- out[i] = in[i];
+ if (m_input_complexfix_wide) {
+ size_t sizeIn = dataIn->getLength() / sizeof(int32_t);
+ int32_t* in = reinterpret_cast<int32_t*>(dataIn->getData());
+ if (m_format_out == "s16") {
+ dataOut->setLength(sizeIn * sizeof(int16_t));
+ int16_t* out = reinterpret_cast<int16_t*>(dataOut->getData());
+
+ for (size_t i = 0; i < sizeIn; i++) {
+ if (in[i] < INT16_MIN) {
+ out[i] = INT16_MIN;
+ num_clipped_samples++;
+ }
+ else if (in[i] > INT16_MAX) {
+ out[i] = INT16_MAX;
+ num_clipped_samples++;
+ }
+ else {
+ out[i] = in[i];
+ }
}
}
- }
- else if (m_format == "u8") {
- dataOut->setLength(sizeIn * sizeof(int8_t));
- uint8_t* out = reinterpret_cast<uint8_t*>(dataOut->getData());
-
- for (size_t i = 0; i < sizeIn; i++) {
- const auto samp = in[i] + 128.0f;
- if (samp < 0) {
- out[i] = 0;
- num_clipped_samples++;
- }
- else if (samp > UINT8_MAX) {
- out[i] = UINT8_MAX;
- num_clipped_samples++;
- }
- else {
- out[i] = samp;
- }
-
+ else {
+ throw std::runtime_error("FormatConverter: Invalid fix format " + m_format_out);
}
}
- else if (m_format == "s8") {
- dataOut->setLength(sizeIn * sizeof(int8_t));
- int8_t* out = reinterpret_cast<int8_t*>(dataOut->getData());
-
- for (size_t i = 0; i < sizeIn; i++) {
- if (in[i] < INT8_MIN) {
- out[i] = INT8_MIN;
- num_clipped_samples++;
+ else {
+ size_t sizeIn = dataIn->getLength() / sizeof(float);
+ float* in = reinterpret_cast<float*>(dataIn->getData());
+
+ if (m_format_out == "s16") {
+ dataOut->setLength(sizeIn * sizeof(int16_t));
+ int16_t* out = reinterpret_cast<int16_t*>(dataOut->getData());
+
+ for (size_t i = 0; i < sizeIn; i++) {
+ if (in[i] < INT16_MIN) {
+ out[i] = INT16_MIN;
+ num_clipped_samples++;
+ }
+ else if (in[i] > INT16_MAX) {
+ out[i] = INT16_MAX;
+ num_clipped_samples++;
+ }
+ else {
+ out[i] = in[i];
+ }
}
- else if (in[i] > INT8_MAX) {
- out[i] = INT8_MAX;
- num_clipped_samples++;
+ }
+ else if (m_format_out == "u8") {
+ dataOut->setLength(sizeIn * sizeof(int8_t));
+ uint8_t* out = reinterpret_cast<uint8_t*>(dataOut->getData());
+
+ for (size_t i = 0; i < sizeIn; i++) {
+ const auto samp = in[i] + 128.0f;
+ if (samp < 0) {
+ out[i] = 0;
+ num_clipped_samples++;
+ }
+ else if (samp > UINT8_MAX) {
+ out[i] = UINT8_MAX;
+ num_clipped_samples++;
+ }
+ else {
+ out[i] = samp;
+ }
+
}
- else {
- out[i] = in[i];
+ }
+ else if (m_format_out == "s8") {
+ dataOut->setLength(sizeIn * sizeof(int8_t));
+ int8_t* out = reinterpret_cast<int8_t*>(dataOut->getData());
+
+ for (size_t i = 0; i < sizeIn; i++) {
+ if (in[i] < INT8_MIN) {
+ out[i] = INT8_MIN;
+ num_clipped_samples++;
+ }
+ else if (in[i] > INT8_MAX) {
+ out[i] = INT8_MAX;
+ num_clipped_samples++;
+ }
+ else {
+ out[i] = in[i];
+ }
}
}
- }
- else {
- throw std::runtime_error("FormatConverter: Invalid format " + m_format);
+ else {
+ throw std::runtime_error("FormatConverter: Invalid format " + m_format_out);
+ }
}
m_num_clipped_samples.store(num_clipped_samples);
@@ -136,10 +165,7 @@ size_t FormatConverter::get_num_clipped_samples() const
size_t FormatConverter::get_format_size(const std::string& format)
{
// Returns 2*sizeof(SAMPLE_TYPE) because we have I + Q
- if (format == "fixedpoint") {
- return 4;
- }
- else if (format == "s16") {
+ if (format == "s16") {
return 4;
}
else if (format == "u8") {