summaryrefslogtreecommitdiffstats
path: root/src/MemlessPoly.cpp
diff options
context:
space:
mode:
authorMatthias P. Braendli <matthias.braendli@mpb.li>2017-08-04 20:18:46 +0200
committerMatthias P. Braendli <matthias.braendli@mpb.li>2017-08-04 20:18:46 +0200
commite192f3f9f5cbdce9f7fd5d4196489467d60bf439 (patch)
tree099cdb4a96adb8decb58f6cef41140ab2250c072 /src/MemlessPoly.cpp
parentedf28ac88d46d0cbbccd99ad5973f2939271b51f (diff)
downloaddabmod-e192f3f9f5cbdce9f7fd5d4196489467d60bf439.tar.gz
dabmod-e192f3f9f5cbdce9f7fd5d4196489467d60bf439.tar.bz2
dabmod-e192f3f9f5cbdce9f7fd5d4196489467d60bf439.zip
Use 5 coefficients in MemlessPoly
Diffstat (limited to 'src/MemlessPoly.cpp')
-rw-r--r--src/MemlessPoly.cpp56
1 files changed, 29 insertions, 27 deletions
diff --git a/src/MemlessPoly.cpp b/src/MemlessPoly.cpp
index 5fbf724..90b859d 100644
--- a/src/MemlessPoly.cpp
+++ b/src/MemlessPoly.cpp
@@ -43,6 +43,7 @@
using namespace std;
+#define NUM_COEFS 5
// By default the signal is unchanged
static const std::array<complexf, 8> default_coefficients({{
@@ -76,37 +77,35 @@ void MemlessPoly::load_coefficients(const std::string &coefFile)
}
else {
std::ifstream coef_fstream(coefFile.c_str());
- if(!coef_fstream) {
- fprintf(stderr, "MemlessPoly: file %s could not be opened !\n", coefFile.c_str());
- throw std::runtime_error("MemlessPoly: Could not open file with coefs! ");
+ if (!coef_fstream) {
+ throw std::runtime_error("MemlessPoly: Could not open file with coefs!");
}
int n_coefs;
coef_fstream >> n_coefs;
if (n_coefs <= 0) {
- fprintf(stderr, "MemlessPoly: warning: coefs file has invalid format\n");
throw std::runtime_error("MemlessPoly: coefs file has invalid format.");
}
-
- if (n_coefs != 8) {
- throw std::runtime_error( "MemlessPoly: error: coefs file does not have 8 coefs\n");
+ else if (n_coefs != NUM_COEFS) {
+ throw std::runtime_error("MemlessPoly: invalid number of coefs: " +
+ std::to_string(coefs.size()));
}
- fprintf(stderr, "MemlessPoly: Reading %d coefs...\n", n_coefs);
+ etiLog.log(debug, "MemlessPoly: Reading %d coefs...", n_coefs);
coefs.resize(n_coefs);
- int n;
- for (n = 0; n < n_coefs; n++) {
+ for (int n = 0; n < n_coefs; n++) {
float a, b;
coef_fstream >> a;
coef_fstream >> b;
- coefs[n] = complexf(a, b)
- PDEBUG("MemlessPoly: coef: %f\n", coefs[n] );
+ coefs[n] = complexf(a, b);
+
if (coef_fstream.eof()) {
- fprintf(stderr, "MemlessPoly: file %s should contains %d coefs, but EOF reached "\
- "after %d coefs !\n", coefFile.c_str(), n_coefs, n);
- throw std::runtime_error("MemlessPoly: coefs file invalid ! ");
+ etiLog.log(error, "MemlessPoly: file %s should contains %d coefs, "
+ "but EOF reached after %d coefs !",
+ coefFile.c_str(), n_coefs, n);
+ throw std::runtime_error("MemlessPoly: coefs file invalid !");
}
}
}
@@ -130,18 +129,21 @@ int MemlessPoly::internal_process(Buffer* const dataIn, Buffer* dataOut)
{
std::lock_guard<std::mutex> lock(m_coefs_mutex);
for (size_t i = 0; i < sizeOut; i += 1) {
- float mag = std::abs(in[i]);
- //out[i] = in[i];
- out[i] = in[i] * (
- m_coefs[0] +
- m_coefs[1] * mag +
- m_coefs[2] * mag*mag +
- m_coefs[3] * mag*mag*mag +
- m_coefs[4] * mag*mag*mag*mag +
- m_coefs[5] * mag*mag*mag*mag*mag +
- m_coefs[6] * mag*mag*mag*mag*mag*mag +
- m_coefs[7] * mag*mag*mag*mag*mag*mag*mag
- );
+
+ /* Implement
+ a0 + a1*x + a2*x^2 + a3*x^3 + a4*x^4 + a5*x^5;
+ with less multiplications:
+ a0 + x*(a1 + x*(a2 + x*(a3 + x*(a3 + x*(a4 + a5*x)))));
+ */
+
+ /* Make sure to adapt NUM_COEFS when you change this */
+ out[i] =
+ m_coefs[0] + in[i] *
+ ( m_coefs[1] + in[i] *
+ ( m_coefs[2] + in[i] *
+ ( m_coefs[3] + in[i] *
+ ( m_coefs[4] + in[i] *
+ ( m_coefs[5] + in[i] )))));
}
}