From 107efd36914ee25218d13608572deba4e4963215 Mon Sep 17 00:00:00 2001 From: f4exb Date: Wed, 2 Sep 2015 00:25:29 +0200 Subject: [PATCH] Deep redesign: do decimation chain fully on 32 bit signed integers --- include-gpl/dsp/decimators.h | 84 ++++++++++++++--------------- include-gpl/dsp/inthalfbandfilter.h | 6 +-- 2 files changed, 45 insertions(+), 45 deletions(-) diff --git a/include-gpl/dsp/decimators.h b/include-gpl/dsp/decimators.h index ffc46b721..348fb8bf5 100644 --- a/include-gpl/dsp/decimators.h +++ b/include-gpl/dsp/decimators.h @@ -101,7 +101,7 @@ private: template void Decimators::decimate1(SampleVector::iterator* it, const T* buf, qint32 len) { - qint16 xreal, yimag; + qint32 xreal, yimag; for (int pos = 0; pos < len; pos += 2) { @@ -116,7 +116,7 @@ void Decimators::decimate1(SampleVector::iterator* it, co template void Decimators::decimate2_u(SampleVector::iterator* it, const T* buf, qint32 len) { - qint16 xreal, yimag; + qint32 xreal, yimag; for (int pos = 0; pos < len - 7; pos += 8) { @@ -137,7 +137,7 @@ void Decimators::decimate2_u(SampleVector::iterator* it, template void Decimators::decimate2_inf(SampleVector::iterator* it, const T* buf, qint32 len) { - qint16 xreal, yimag; + qint32 xreal, yimag; for (int pos = 0; pos < len - 7; pos += 8) { @@ -158,7 +158,7 @@ void Decimators::decimate2_inf(SampleVector::iterator* it template void Decimators::decimate2_sup(SampleVector::iterator* it, const T* buf, qint32 len) { - qint16 xreal, yimag; + qint32 xreal, yimag; for (int pos = 0; pos < len - 7; pos += 8) { @@ -183,8 +183,8 @@ void Decimators::decimate2_cen(SampleVector::iterator* it while (pos < len - 3) { - qint16 x0 = buf[pos+0] << decimation_shifts::pre2; - qint16 y0 = buf[pos+1] << decimation_shifts::pre2; + qint32 x0 = buf[pos+0] << decimation_shifts::pre2; + qint32 y0 = buf[pos+1] << decimation_shifts::pre2; pos += 2; if (m_decimator2.workDecimateCenter(&x0, &y0)) @@ -203,14 +203,14 @@ void Decimators::decimate4_cen(SampleVector::iterator* it while (pos < len) { - qint16 x0 = buf[pos+0] << decimation_shifts::pre4; - qint16 y0 = buf[pos+1] << decimation_shifts::pre4; + qint32 x0 = buf[pos+0] << decimation_shifts::pre4; + qint32 y0 = buf[pos+1] << decimation_shifts::pre4; pos += 2; if (m_decimator2.workDecimateCenter(&x0, &y0)) { - qint16 x1 = x0; - qint16 y1 = y0; + qint32 x1 = x0; + qint32 y1 = y0; if (m_decimator4.workDecimateCenter(&x1, &y1)) { @@ -229,19 +229,19 @@ void Decimators::decimate8_cen(SampleVector::iterator* it while (pos < len) { - qint16 x0 = buf[pos+0] << decimation_shifts::pre8; - qint16 y0 = buf[pos+1] << decimation_shifts::pre8; + qint32 x0 = buf[pos+0] << decimation_shifts::pre8; + qint32 y0 = buf[pos+1] << decimation_shifts::pre8; pos += 2; if (m_decimator2.workDecimateCenter(&x0, &y0)) { - qint16 x1 = x0; - qint16 y1 = y0; + qint32 x1 = x0; + qint32 y1 = y0; if (m_decimator4.workDecimateCenter(&x1, &y1)) { - qint16 x2 = x1; - qint16 y2 = y1; + qint32 x2 = x1; + qint32 y2 = y1; if (m_decimator8.workDecimateCenter(&x2, &y2)) { @@ -261,24 +261,24 @@ void Decimators::decimate16_cen(SampleVector::iterator* i while (pos < len) { - qint16 x0 = buf[pos+0] << decimation_shifts::pre16; - qint16 y0 = buf[pos+1] << decimation_shifts::pre16; + qint32 x0 = buf[pos+0] << decimation_shifts::pre16; + qint32 y0 = buf[pos+1] << decimation_shifts::pre16; pos += 2; if (m_decimator2.workDecimateCenter(&x0, &y0)) { - qint16 x1 = x0; - qint16 y1 = y0; + qint32 x1 = x0; + qint32 y1 = y0; if (m_decimator4.workDecimateCenter(&x1, &y1)) { - qint16 x2 = x1; - qint16 y2 = y1; + qint32 x2 = x1; + qint32 y2 = y1; if (m_decimator8.workDecimateCenter(&x2, &y2)) { - qint16 x3 = x2; - qint16 y3 = y2; + qint32 x3 = x2; + qint32 y3 = y2; if (m_decimator16.workDecimateCenter(&x3, &y3)) { @@ -299,29 +299,29 @@ void Decimators::decimate32_cen(SampleVector::iterator* i while (pos < len) { - qint16 x0 = buf[pos+0] << decimation_shifts::pre32; - qint16 y0 = buf[pos+1] << decimation_shifts::pre32; + qint32 x0 = buf[pos+0] << decimation_shifts::pre32; + qint32 y0 = buf[pos+1] << decimation_shifts::pre32; pos += 2; if (m_decimator2.workDecimateCenter(&x0, &y0)) { - qint16 x1 = x0; - qint16 y1 = y0; + qint32 x1 = x0; + qint32 y1 = y0; if (m_decimator4.workDecimateCenter(&x1, &y1)) { - qint16 x2 = x1; - qint16 y2 = y1; + qint32 x2 = x1; + qint32 y2 = y1; if (m_decimator8.workDecimateCenter(&x2, &y2)) { - qint16 x3 = x2; - qint16 y3 = y2; + qint32 x3 = x2; + qint32 y3 = y2; if (m_decimator16.workDecimateCenter(&x3, &y3)) { - qint16 x4 = x3; - qint16 y4 = y3; + qint32 x4 = x3; + qint32 y4 = y3; if (m_decimator32.workDecimateCenter(&x4, &y4)) { @@ -339,7 +339,7 @@ void Decimators::decimate32_cen(SampleVector::iterator* i template void Decimators::decimate4_inf(SampleVector::iterator* it, const T* buf, qint32 len) { - qint16 xreal, yimag; + qint32 xreal, yimag; for (int pos = 0; pos < len - 7; pos += 8) { @@ -362,7 +362,7 @@ void Decimators::decimate4_sup(SampleVector::iterator* it // Inf (LSB): // x y x y x y x y / x -> 0,-3,-4,7 / y -> 1,2,-5,-6 // [ rotate: 0, 1, -3, 2, -4, -5, 7, -6] - qint16 xreal, yimag; + qint32 xreal, yimag; for (int pos = 0; pos < len - 7; pos += 8) { @@ -379,7 +379,7 @@ void Decimators::decimate4_sup(SampleVector::iterator* it template void Decimators::decimate8_inf(SampleVector::iterator* it, const T* buf, qint32 len) { - qint16 xreal[2], yimag[2]; + qint32 xreal[2], yimag[2]; for (int pos = 0; pos < len - 15; pos += 8) { @@ -402,7 +402,7 @@ void Decimators::decimate8_inf(SampleVector::iterator* it template void Decimators::decimate8_sup(SampleVector::iterator* it, const T* buf, qint32 len) { - qint16 xreal[2], yimag[2]; + qint32 xreal[2], yimag[2]; for (int pos = 0; pos < len - 15; pos += 8) { @@ -427,7 +427,7 @@ void Decimators::decimate16_inf(SampleVector::iterator* i { // Offset tuning: 4x downsample and rotate, then // downsample 4x more. [ rotate: 0, 1, -3, 2, -4, -5, 7, -6] - qint16 xreal[4], yimag[4]; + qint32 xreal[4], yimag[4]; for (int pos = 0; pos < len - 31; ) { @@ -455,7 +455,7 @@ void Decimators::decimate16_sup(SampleVector::iterator* i { // Offset tuning: 4x downsample and rotate, then // downsample 4x more. [ rotate: 1, 0, -2, 3, -5, -4, 6, -7] - qint16 xreal[4], yimag[4]; + qint32 xreal[4], yimag[4]; for (int pos = 0; pos < len - 31; ) { @@ -481,7 +481,7 @@ void Decimators::decimate16_sup(SampleVector::iterator* i template void Decimators::decimate32_inf(SampleVector::iterator* it, const T* buf, qint32 len) { - qint16 xreal[8], yimag[8]; + qint32 xreal[8], yimag[8]; for (int pos = 0; pos < len - 63; ) { @@ -512,7 +512,7 @@ void Decimators::decimate32_inf(SampleVector::iterator* i template void Decimators::decimate32_sup(SampleVector::iterator* it, const T* buf, qint32 len) { - qint16 xreal[8], yimag[8]; + qint32 xreal[8], yimag[8]; for (int pos = 0; pos < len - 63; ) { diff --git a/include-gpl/dsp/inthalfbandfilter.h b/include-gpl/dsp/inthalfbandfilter.h index b63a20f51..25a9ff3b6 100644 --- a/include-gpl/dsp/inthalfbandfilter.h +++ b/include-gpl/dsp/inthalfbandfilter.h @@ -51,7 +51,7 @@ public: } } - bool workDecimateCenter(qint16 *x, qint16 *y) + bool workDecimateCenter(qint32 *x, qint32 *y) { // insert sample into ring-buffer m_samples[m_ptr][0] = *x; @@ -277,7 +277,7 @@ public: m_ptr = mod33[m_ptr + 2 - 1]; } - void myDecimate(qint16 x1, qint16 y1, qint16 *x2, qint16 *y2) + void myDecimate(qint32 x1, qint32 y1, qint32 *x2, qint32 *y2) { static const qint16 mod33[38] = { 31,32,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19, 20,21,22,23,24,25,26,27,28,29,30,31,32,0,1,2}; @@ -385,7 +385,7 @@ protected: sample->setImag(qAcc >> HB_SHIFT); } - void doFIR(qint16 *x, qint16 *y) + void doFIR(qint32 *x, qint32 *y) { // coefficents