///////////////////////////////////////////////////////////////////////////////////
// Copyright (C) 2018 Edouard Griffiths, F4EXB                                   //
//                                                                               //
// This program is free software; you can redistribute it and/or modify          //
// it under the terms of the GNU General Public License as published by          //
// the Free Software Foundation as version 3 of the License, or                  //
//                                                                               //
// This program is distributed in the hope that it will be useful,               //
// but WITHOUT ANY WARRANTY; without even the implied warranty of                //
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the                  //
// GNU General Public License V3 for more details.                               //
//                                                                               //
// You should have received a copy of the GNU General Public License             //
// along with this program. If not, see .          //
//                                                                               //
// This decimation class includes unsigned to signed with shifting. Typically    //
// for 8 bit samples issued from RTL-SDR the conversion is:                      //
// signed = unsigned - 127. Here the "Shift" value is 127.                       //
// The shift value is given as a template parameter                              //
//                                                                               //
///////////////////////////////////////////////////////////////////////////////////
#ifndef INCLUDE_GPL_DSP_DECIMATORSU_H_
#define INCLUDE_GPL_DSP_DECIMATORSU_H_
#include "dsp/dsptypes.h"
#include "dsp/inthalfbandfiltereo.h"
#define DECIMATORS_HB_FILTER_ORDER 64
template
struct decimation_shifts
{
    static const uint pre1   = 0;
    static const uint pre2   = 0;
    static const uint post2  = 0;
    static const uint pre4   = 0;
    static const uint post4  = 0;
    static const uint pre8   = 0;
    static const uint post8  = 0;
    static const uint pre16  = 0;
    static const uint post16 = 0;
    static const uint pre32  = 0;
    static const uint post32 = 0;
    static const uint pre64  = 0;
    static const uint post64 = 0;
};
template<>
struct decimation_shifts<24, 24>
{
    static const uint pre1   = 0;
    static const uint pre2   = 0;
    static const uint post2  = 1;
    static const uint pre4   = 0;
    static const uint post4  = 2;
    static const uint pre8   = 0;
    static const uint post8  = 3;
    static const uint pre16  = 0;
    static const uint post16 = 4;
    static const uint pre32  = 0;
    static const uint post32 = 5;
    static const uint pre64  = 0;
    static const uint post64 = 6;
};
template<>
struct decimation_shifts<16, 16>
{
    static const uint pre1   = 0;
    static const uint pre2   = 0;
    static const uint post2  = 1;
    static const uint pre4   = 0;
    static const uint post4  = 2;
    static const uint pre8   = 0;
    static const uint post8  = 3;
    static const uint pre16  = 0;
    static const uint post16 = 4;
    static const uint pre32  = 0;
    static const uint post32 = 5;
    static const uint pre64  = 0;
    static const uint post64 = 6;
};
template<>
struct decimation_shifts<24, 16>
{
    static const uint pre1   = 8;
    static const uint pre2   = 7;
    static const uint post2  = 0;
    static const uint pre4   = 6;
    static const uint post4  = 0;
    static const uint pre8   = 5;
    static const uint post8  = 0;
    static const uint pre16  = 4;
    static const uint post16 = 0;
    static const uint pre32  = 3;
    static const uint post32 = 0;
    static const uint pre64  = 2;
    static const uint post64 = 0;
};
template<>
struct decimation_shifts<16, 12>
{
    static const uint pre1   = 4;
    static const uint pre2   = 3;
    static const uint post2  = 0;
    static const uint pre4   = 2;
    static const uint post4  = 0;
    static const uint pre8   = 1;
    static const uint post8  = 0;
    static const uint pre16  = 0;
    static const uint post16 = 0;
    static const uint pre32  = 0;
    static const uint post32 = 1;
    static const uint pre64  = 0;
    static const uint post64 = 2;
};
template<>
struct decimation_shifts<24, 12>
{
    static const uint pre1   = 12;
    static const uint pre2   = 11;
    static const uint post2  = 0;
    static const uint pre4   = 10;
    static const uint post4  = 0;
    static const uint pre8   = 9;
    static const uint post8  = 0;
    static const uint pre16  = 8;
    static const uint post16 = 0;
    static const uint pre32  = 7;
    static const uint post32 = 0;
    static const uint pre64  = 6;
    static const uint post64 = 0;
};
template<>
struct decimation_shifts<16, 8>
{
    static const uint pre1   = 8;
    static const uint pre2   = 7;
    static const uint post2  = 0;
    static const uint pre4   = 6;
    static const uint post4  = 0;
    static const uint pre8   = 5;
    static const uint post8  = 0;
    static const uint pre16  = 4;
    static const uint post16 = 0;
    static const uint pre32  = 3;
    static const uint post32 = 0;
    static const uint pre64  = 2;
    static const uint post64 = 0;
};
template<>
struct decimation_shifts<24, 8>
{
    static const uint pre1   = 16;
    static const uint pre2   = 15;
    static const uint post2  = 0;
    static const uint pre4   = 14;
    static const uint post4  = 0;
    static const uint pre8   = 13;
    static const uint post8  = 0;
    static const uint pre16  = 12;
    static const uint post16 = 0;
    static const uint pre32  = 11;
    static const uint post32 = 0;
    static const uint pre64  = 10;
    static const uint post64 = 0;
};
template
class DecimatorsU
{
public:
    // interleaved I/Q input buffer
	void decimate1(SampleVector::iterator* it, const T* buf, qint32 len);
	void decimate2_inf(SampleVector::iterator* it, const T* buf, qint32 len);
	void decimate2_sup(SampleVector::iterator* it, const T* buf, qint32 len);
	void decimate2_cen(SampleVector::iterator* it, const T* buf, qint32 len);
	void decimate4_inf(SampleVector::iterator* it, const T* buf, qint32 len);
	void decimate4_sup(SampleVector::iterator* it, const T* buf, qint32 len);
	void decimate4_cen(SampleVector::iterator* it, const T* buf, qint32 len);
	void decimate8_inf(SampleVector::iterator* it, const T* buf, qint32 len);
	void decimate8_sup(SampleVector::iterator* it, const T* buf, qint32 len);
	void decimate8_cen(SampleVector::iterator* it, const T* buf, qint32 len);
	void decimate16_inf(SampleVector::iterator* it, const T* buf, qint32 len);
	void decimate16_sup(SampleVector::iterator* it, const T* buf, qint32 len);
	void decimate16_cen(SampleVector::iterator* it, const T* buf, qint32 len);
	void decimate32_inf(SampleVector::iterator* it, const T* buf, qint32 len);
	void decimate32_sup(SampleVector::iterator* it, const T* buf, qint32 len);
	void decimate32_cen(SampleVector::iterator* it, const T* buf, qint32 len);
	void decimate64_inf(SampleVector::iterator* it, const T* buf, qint32 len);
	void decimate64_sup(SampleVector::iterator* it, const T* buf, qint32 len);
	void decimate64_cen(SampleVector::iterator* it, const T* buf, qint32 len);
private:
#ifdef SDR_RX_SAMPLE_24BIT
	IntHalfbandFilterEO m_decimator2;  // 1st stages
	IntHalfbandFilterEO m_decimator4;  // 2nd stages
	IntHalfbandFilterEO m_decimator8;  // 3rd stages
	IntHalfbandFilterEO m_decimator16; // 4th stages
	IntHalfbandFilterEO m_decimator32; // 5th stages
	IntHalfbandFilterEO m_decimator64; // 6th stages
#else
    IntHalfbandFilterEO m_decimator2;  // 1st stages
    IntHalfbandFilterEO m_decimator4;  // 2nd stages
    IntHalfbandFilterEO m_decimator8;  // 3rd stages
    IntHalfbandFilterEO m_decimator16; // 4th stages
    IntHalfbandFilterEO m_decimator32; // 5th stages
    IntHalfbandFilterEO m_decimator64; // 6th stages
#endif
};
template
void DecimatorsU::decimate1(SampleVector::iterator* it, const T* buf, qint32 len)
{
	qint32 xreal, yimag;
	for (int pos = 0; pos < len - 1; pos += 2)
	{
		xreal = buf[pos+0] - Shift;
		yimag = buf[pos+1] - Shift;
		(**it).setReal(xreal << decimation_shifts::pre1); // Valgrind optim (2 - comment not repeated)
		(**it).setImag(yimag << decimation_shifts::pre1);
		++(*it); // Valgrind optim (comment not repeated)
	}
}
template
void DecimatorsU::decimate2_inf(SampleVector::iterator* it, const T* buf, qint32 len)
{
    StorageType buf2[4];
    for (int pos = 0; pos < len - 7; pos += 8)
    {
        m_decimator2.myDecimateInf(
                (buf[pos+0] - Shift) << decimation_shifts::pre2,
                (buf[pos+1] - Shift) << decimation_shifts::pre2,
                (buf[pos+2] - Shift) << decimation_shifts::pre2,
                (buf[pos+3] - Shift) << decimation_shifts::pre2,
                (buf[pos+4] - Shift) << decimation_shifts::pre2,
                (buf[pos+5] - Shift) << decimation_shifts::pre2,
                (buf[pos+6] - Shift) << decimation_shifts::pre2,
                (buf[pos+7] - Shift) << decimation_shifts::pre2,
                &buf2[0]);
        (**it).setReal(buf2[0] >> decimation_shifts::post2);
        (**it).setImag(buf2[1] >> decimation_shifts::post2);
        ++(*it);
        (**it).setReal(buf2[2] >> decimation_shifts::post2);
        (**it).setImag(buf2[3] >> decimation_shifts::post2);
        ++(*it);
    }
}
template
void DecimatorsU::decimate2_sup(SampleVector::iterator* it, const T* buf, qint32 len)
{
    StorageType buf2[4];
    for (int pos = 0; pos < len - 7; pos += 8)
    {
        m_decimator2.myDecimateSup(
                (buf[pos+0] - Shift) << decimation_shifts::pre2,
                (buf[pos+1] - Shift) << decimation_shifts::pre2,
                (buf[pos+2] - Shift) << decimation_shifts::pre2,
                (buf[pos+3] - Shift) << decimation_shifts::pre2,
                (buf[pos+4] - Shift) << decimation_shifts::pre2,
                (buf[pos+5] - Shift) << decimation_shifts::pre2,
                (buf[pos+6] - Shift) << decimation_shifts::pre2,
                (buf[pos+7] - Shift) << decimation_shifts::pre2,
                &buf2[0]);
        (**it).setReal(buf2[0] >> decimation_shifts::post2);
        (**it).setImag(buf2[1] >> decimation_shifts::post2);
        ++(*it);
        (**it).setReal(buf2[2] >> decimation_shifts::post2);
        (**it).setImag(buf2[3] >> decimation_shifts::post2);
        ++(*it);
    }
}
template
void DecimatorsU::decimate4_inf(SampleVector::iterator* it, const T* buf, qint32 len)
{
    StorageType buf2[8], buf4[4];
    for (int pos = 0; pos < len - 15; pos += 16)
    {
        m_decimator2.myDecimateInf(
                (buf[pos+0] - Shift) << decimation_shifts::pre4,
                (buf[pos+1] - Shift) << decimation_shifts::pre4,
                (buf[pos+2] - Shift) << decimation_shifts::pre4,
                (buf[pos+3] - Shift) << decimation_shifts::pre4,
                (buf[pos+4] - Shift) << decimation_shifts::pre4,
                (buf[pos+5] - Shift) << decimation_shifts::pre4,
                (buf[pos+6] - Shift) << decimation_shifts::pre4,
                (buf[pos+7] - Shift) << decimation_shifts::pre4,
                &buf2[0]);
        m_decimator2.myDecimateInf(
                (buf[pos+8] - Shift) << decimation_shifts::pre4,
                (buf[pos+9] - Shift) << decimation_shifts::pre4,
                (buf[pos+10] - Shift) << decimation_shifts::pre4,
                (buf[pos+11] - Shift) << decimation_shifts::pre4,
                (buf[pos+12] - Shift) << decimation_shifts::pre4,
                (buf[pos+13] - Shift) << decimation_shifts::pre4,
                (buf[pos+14] - Shift) << decimation_shifts::pre4,
                (buf[pos+15] - Shift) << decimation_shifts::pre4,
                &buf2[4]);
        m_decimator4.myDecimateSup(
                buf2[0],
                buf2[1],
                buf2[2],
                buf2[3],
                buf2[4],
                buf2[5],
                buf2[6],
                buf2[7],
                &buf4[0]);
        (**it).setReal(buf4[0] >> decimation_shifts::post4);
        (**it).setImag(buf4[1] >> decimation_shifts::post4);
        ++(*it);
        (**it).setReal(buf4[2] >> decimation_shifts::post4);
        (**it).setImag(buf4[3] >> decimation_shifts::post4);
        ++(*it);
    }
}
template
void DecimatorsU::decimate4_sup(SampleVector::iterator* it, const T* buf, qint32 len)
{
    StorageType buf2[8], buf4[4];
    for (int pos = 0; pos < len - 15; pos += 16)
    {
        m_decimator2.myDecimateSup(
                (buf[pos+0] - Shift) << decimation_shifts::pre4,
                (buf[pos+1] - Shift) << decimation_shifts::pre4,
                (buf[pos+2] - Shift) << decimation_shifts::pre4,
                (buf[pos+3] - Shift) << decimation_shifts::pre4,
                (buf[pos+4] - Shift) << decimation_shifts::pre4,
                (buf[pos+5] - Shift) << decimation_shifts::pre4,
                (buf[pos+6] - Shift) << decimation_shifts::pre4,
                (buf[pos+7] - Shift) << decimation_shifts::pre4,
                &buf2[0]);
        m_decimator2.myDecimateSup(
                (buf[pos+8] - Shift) << decimation_shifts::pre4,
                (buf[pos+9] - Shift) << decimation_shifts::pre4,
                (buf[pos+10] - Shift) << decimation_shifts::pre4,
                (buf[pos+11] - Shift) << decimation_shifts::pre4,
                (buf[pos+12] - Shift) << decimation_shifts::pre4,
                (buf[pos+13] - Shift) << decimation_shifts::pre4,
                (buf[pos+14] - Shift) << decimation_shifts::pre4,
                (buf[pos+15] - Shift) << decimation_shifts::pre4,
                &buf2[4]);
        m_decimator4.myDecimateInf(
                buf2[0],
                buf2[1],
                buf2[2],
                buf2[3],
                buf2[4],
                buf2[5],
                buf2[6],
                buf2[7],
                &buf4[0]);
        (**it).setReal(buf4[0] >> decimation_shifts::post4);
        (**it).setImag(buf4[1] >> decimation_shifts::post4);
        ++(*it);
        (**it).setReal(buf4[2] >> decimation_shifts::post4);
        (**it).setImag(buf4[3] >> decimation_shifts::post4);
        ++(*it);
    }
}
template
void DecimatorsU::decimate8_inf(SampleVector::iterator* it, const T* buf, qint32 len)
{
    StorageType buf2[16], buf4[8], buf8[4];
    for (int pos = 0; pos < len - 31; pos += 32)
    {
        m_decimator2.myDecimateInf(
                (buf[pos+0] - Shift) << decimation_shifts::pre8,
                (buf[pos+1] - Shift) << decimation_shifts::pre8,
                (buf[pos+2] - Shift) << decimation_shifts::pre8,
                (buf[pos+3] - Shift) << decimation_shifts::pre8,
                (buf[pos+4] - Shift) << decimation_shifts::pre8,
                (buf[pos+5] - Shift) << decimation_shifts::pre8,
                (buf[pos+6] - Shift) << decimation_shifts::pre8,
                (buf[pos+7] - Shift) << decimation_shifts::pre8,
                &buf2[0]);
        m_decimator2.myDecimateInf(
                (buf[pos+8] - Shift) << decimation_shifts::pre8,
                (buf[pos+9] - Shift) << decimation_shifts::pre8,
                (buf[pos+10] - Shift) << decimation_shifts::pre8,
                (buf[pos+11] - Shift) << decimation_shifts::pre8,
                (buf[pos+12] - Shift) << decimation_shifts::pre8,
                (buf[pos+13] - Shift) << decimation_shifts::pre8,
                (buf[pos+14] - Shift) << decimation_shifts::pre8,
                (buf[pos+15] - Shift) << decimation_shifts::pre8,
                &buf2[4]);
        m_decimator2.myDecimateInf(
                (buf[pos+16] - Shift) << decimation_shifts::pre8,
                (buf[pos+17] - Shift) << decimation_shifts::pre8,
                (buf[pos+18] - Shift) << decimation_shifts::pre8,
                (buf[pos+19] - Shift) << decimation_shifts::pre8,
                (buf[pos+20] - Shift) << decimation_shifts::pre8,
                (buf[pos+21] - Shift) << decimation_shifts::pre8,
                (buf[pos+22] - Shift) << decimation_shifts::pre8,
                (buf[pos+23] - Shift) << decimation_shifts::pre8,
                &buf2[8]);
        m_decimator2.myDecimateInf(
                (buf[pos+24] - Shift) << decimation_shifts::pre8,
                (buf[pos+25] - Shift) << decimation_shifts::pre8,
                (buf[pos+26] - Shift) << decimation_shifts::pre8,
                (buf[pos+27] - Shift) << decimation_shifts::pre8,
                (buf[pos+28] - Shift) << decimation_shifts::pre8,
                (buf[pos+29] - Shift) << decimation_shifts::pre8,
                (buf[pos+30] - Shift) << decimation_shifts::pre8,
                (buf[pos+31] - Shift) << decimation_shifts::pre8,
                &buf2[12]);
        m_decimator4.myDecimateSup(
                &buf2[0],
                &buf4[0]);
        m_decimator4.myDecimateSup(
                &buf2[8],
                &buf4[4]);
        m_decimator8.myDecimateCen(
                &buf4[0],
                &buf8[0]);
        (**it).setReal(buf8[0] >> decimation_shifts::post8);
        (**it).setImag(buf8[1] >> decimation_shifts::post8);
        ++(*it);
        (**it).setReal(buf8[2] >> decimation_shifts::post8);
        (**it).setImag(buf8[3] >> decimation_shifts::post8);
        ++(*it);
    }
}
template
void DecimatorsU::decimate8_sup(SampleVector::iterator* it, const T* buf, qint32 len)
{
    StorageType buf2[16], buf4[8], buf8[4];
    for (int pos = 0; pos < len - 31; pos += 32)
    {
        m_decimator2.myDecimateSup(
                (buf[pos+0] - Shift) << decimation_shifts::pre8,
                (buf[pos+1] - Shift) << decimation_shifts::pre8,
                (buf[pos+2] - Shift) << decimation_shifts::pre8,
                (buf[pos+3] - Shift) << decimation_shifts::pre8,
                (buf[pos+4] - Shift) << decimation_shifts::pre8,
                (buf[pos+5] - Shift) << decimation_shifts::pre8,
                (buf[pos+6] - Shift) << decimation_shifts::pre8,
                (buf[pos+7] - Shift) << decimation_shifts::pre8,
                &buf2[0]);
        m_decimator2.myDecimateSup(
                (buf[pos+8] - Shift) << decimation_shifts::pre8,
                (buf[pos+9] - Shift) << decimation_shifts::pre8,
                (buf[pos+10] - Shift) << decimation_shifts::pre8,
                (buf[pos+11] - Shift) << decimation_shifts::pre8,
                (buf[pos+12] - Shift) << decimation_shifts::pre8,
                (buf[pos+13] - Shift) << decimation_shifts::pre8,
                (buf[pos+14] - Shift) << decimation_shifts::pre8,
                (buf[pos+15] - Shift) << decimation_shifts::pre8,
                &buf2[4]);
        m_decimator2.myDecimateSup(
                (buf[pos+16] - Shift) << decimation_shifts::pre8,
                (buf[pos+17] - Shift) << decimation_shifts::pre8,
                (buf[pos+18] - Shift) << decimation_shifts::pre8,
                (buf[pos+19] - Shift) << decimation_shifts::pre8,
                (buf[pos+20] - Shift) << decimation_shifts::pre8,
                (buf[pos+21] - Shift) << decimation_shifts::pre8,
                (buf[pos+22] - Shift) << decimation_shifts::pre8,
                (buf[pos+23] - Shift) << decimation_shifts::pre8,
                &buf2[8]);
        m_decimator2.myDecimateSup(
                (buf[pos+24] - Shift) << decimation_shifts::pre8,
                (buf[pos+25] - Shift) << decimation_shifts::pre8,
                (buf[pos+26] - Shift) << decimation_shifts::pre8,
                (buf[pos+27] - Shift) << decimation_shifts::pre8,
                (buf[pos+28] - Shift) << decimation_shifts::pre8,
                (buf[pos+29] - Shift) << decimation_shifts::pre8,
                (buf[pos+30] - Shift) << decimation_shifts::pre8,
                (buf[pos+31] - Shift) << decimation_shifts::pre8,
                &buf2[12]);
        m_decimator4.myDecimateInf(
                &buf2[0],
                &buf4[0]);
        m_decimator4.myDecimateInf(
                &buf2[8],
                &buf4[4]);
        m_decimator8.myDecimateCen(
                &buf4[0],
                &buf8[0]);
        (**it).setReal(buf8[0] >> decimation_shifts::post8);
        (**it).setImag(buf8[1] >> decimation_shifts::post8);
        ++(*it);
        (**it).setReal(buf8[2] >> decimation_shifts::post8);
        (**it).setImag(buf8[3] >> decimation_shifts::post8);
        ++(*it);
    }
}
template
void DecimatorsU::decimate16_inf(SampleVector::iterator* it, const T* buf, qint32 len)
{
    StorageType buf2[32], buf4[16], buf8[8], buf16[4];
    for (int pos = 0; pos < len - 63; pos += 64)
    {
        m_decimator2.myDecimateInf(
                (buf[pos+0] - Shift) << decimation_shifts::pre16,
                (buf[pos+1] - Shift) << decimation_shifts::pre16,
                (buf[pos+2] - Shift) << decimation_shifts::pre16,
                (buf[pos+3] - Shift) << decimation_shifts::pre16,
                (buf[pos+4] - Shift) << decimation_shifts::pre16,
                (buf[pos+5] - Shift) << decimation_shifts::pre16,
                (buf[pos+6] - Shift) << decimation_shifts::pre16,
                (buf[pos+7] - Shift) << decimation_shifts::pre16,
                &buf2[0]);
        m_decimator2.myDecimateInf(
                (buf[pos+8] - Shift) << decimation_shifts::pre16,
                (buf[pos+9] - Shift) << decimation_shifts::pre16,
                (buf[pos+10] - Shift) << decimation_shifts::pre16,
                (buf[pos+11] - Shift) << decimation_shifts::pre16,
                (buf[pos+12] - Shift) << decimation_shifts::pre16,
                (buf[pos+13] - Shift) << decimation_shifts::pre16,
                (buf[pos+14] - Shift) << decimation_shifts::pre16,
                (buf[pos+15] - Shift) << decimation_shifts::pre16,
                &buf2[4]);
        m_decimator2.myDecimateInf(
                (buf[pos+16] - Shift) << decimation_shifts::pre16,
                (buf[pos+17] - Shift) << decimation_shifts::pre16,
                (buf[pos+18] - Shift) << decimation_shifts::pre16,
                (buf[pos+19] - Shift) << decimation_shifts::pre16,
                (buf[pos+20] - Shift) << decimation_shifts::pre16,
                (buf[pos+21] - Shift) << decimation_shifts::pre16,
                (buf[pos+22] - Shift) << decimation_shifts::pre16,
                (buf[pos+23] - Shift) << decimation_shifts::pre16,
                &buf2[8]);
        m_decimator2.myDecimateInf(
                (buf[pos+24] - Shift) << decimation_shifts::pre16,
                (buf[pos+25] - Shift) << decimation_shifts::pre16,
                (buf[pos+26] - Shift) << decimation_shifts::pre16,
                (buf[pos+27] - Shift) << decimation_shifts::pre16,
                (buf[pos+28] - Shift) << decimation_shifts::pre16,
                (buf[pos+29] - Shift) << decimation_shifts::pre16,
                (buf[pos+30] - Shift) << decimation_shifts::pre16,
                (buf[pos+31] - Shift) << decimation_shifts::pre16,
                &buf2[12]);
        m_decimator2.myDecimateInf(
                (buf[pos+32] - Shift) << decimation_shifts::pre16,
                (buf[pos+33] - Shift) << decimation_shifts::pre16,
                (buf[pos+34] - Shift) << decimation_shifts::pre16,
                (buf[pos+35] - Shift) << decimation_shifts::pre16,
                (buf[pos+36] - Shift) << decimation_shifts::pre16,
                (buf[pos+37] - Shift) << decimation_shifts::pre16,
                (buf[pos+38] - Shift) << decimation_shifts::pre16,
                (buf[pos+39] - Shift) << decimation_shifts::pre16,
                &buf2[16]);
        m_decimator2.myDecimateInf(
                (buf[pos+40] - Shift) << decimation_shifts::pre16,
                (buf[pos+41] - Shift) << decimation_shifts::pre16,
                (buf[pos+42] - Shift) << decimation_shifts::pre16,
                (buf[pos+43] - Shift) << decimation_shifts::pre16,
                (buf[pos+44] - Shift) << decimation_shifts::pre16,
                (buf[pos+45] - Shift) << decimation_shifts::pre16,
                (buf[pos+46] - Shift) << decimation_shifts::pre16,
                (buf[pos+47] - Shift) << decimation_shifts::pre16,
                &buf2[20]);
        m_decimator2.myDecimateInf(
                (buf[pos+48] - Shift) << decimation_shifts::pre16,
                (buf[pos+49] - Shift) << decimation_shifts::pre16,
                (buf[pos+50] - Shift) << decimation_shifts::pre16,
                (buf[pos+51] - Shift) << decimation_shifts::pre16,
                (buf[pos+52] - Shift) << decimation_shifts::pre16,
                (buf[pos+53] - Shift) << decimation_shifts::pre16,
                (buf[pos+54] - Shift) << decimation_shifts::pre16,
                (buf[pos+55] - Shift) << decimation_shifts::pre16,
                &buf2[24]);
        m_decimator2.myDecimateInf(
                (buf[pos+56] - Shift) << decimation_shifts::pre16,
                (buf[pos+57] - Shift) << decimation_shifts::pre16,
                (buf[pos+58] - Shift) << decimation_shifts::pre16,
                (buf[pos+59] - Shift) << decimation_shifts::pre16,
                (buf[pos+60] - Shift) << decimation_shifts::pre16,
                (buf[pos+61] - Shift) << decimation_shifts::pre16,
                (buf[pos+62] - Shift) << decimation_shifts::pre16,
                (buf[pos+63] - Shift) << decimation_shifts::pre16,
                &buf2[28]);
        m_decimator4.myDecimateSup(
                &buf2[0],
                &buf4[0]);
        m_decimator4.myDecimateSup(
                &buf2[8],
                &buf4[4]);
        m_decimator4.myDecimateSup(
                &buf2[16],
                &buf4[8]);
        m_decimator4.myDecimateSup(
                &buf2[24],
                &buf4[12]);
        m_decimator8.myDecimateSup(
                &buf4[0],
                &buf8[0]);
        m_decimator8.myDecimateSup(
                &buf4[8],
                &buf8[4]);
        m_decimator16.myDecimateCen(
                &buf8[0],
                &buf16[0]);
        (**it).setReal(buf16[0] >> decimation_shifts::post16);
        (**it).setImag(buf16[1] >> decimation_shifts::post16);
        ++(*it);
        (**it).setReal(buf16[2] >> decimation_shifts::post16);
        (**it).setImag(buf16[3] >> decimation_shifts::post16);
        ++(*it);
    }
}
template
void DecimatorsU::decimate16_sup(SampleVector::iterator* it, const T* buf, qint32 len)
{
    StorageType buf2[32], buf4[16], buf8[8], buf16[4];
    for (int pos = 0; pos < len - 63; pos += 64)
    {
        m_decimator2.myDecimateSup(
                (buf[pos+0] - Shift) << decimation_shifts::pre16,
                (buf[pos+1] - Shift) << decimation_shifts::pre16,
                (buf[pos+2] - Shift) << decimation_shifts::pre16,
                (buf[pos+3] - Shift) << decimation_shifts::pre16,
                (buf[pos+4] - Shift) << decimation_shifts::pre16,
                (buf[pos+5] - Shift) << decimation_shifts::pre16,
                (buf[pos+6] - Shift) << decimation_shifts::pre16,
                (buf[pos+7] - Shift) << decimation_shifts::pre16,
                &buf2[0]);
        m_decimator2.myDecimateSup(
                (buf[pos+8] - Shift) << decimation_shifts::pre16,
                (buf[pos+9] - Shift) << decimation_shifts::pre16,
                (buf[pos+10] - Shift) << decimation_shifts::pre16,
                (buf[pos+11] - Shift) << decimation_shifts::pre16,
                (buf[pos+12] - Shift) << decimation_shifts::pre16,
                (buf[pos+13] - Shift) << decimation_shifts::pre16,
                (buf[pos+14] - Shift) << decimation_shifts::pre16,
                (buf[pos+15] - Shift) << decimation_shifts::pre16,
                &buf2[4]);
        m_decimator2.myDecimateSup(
                (buf[pos+16] - Shift) << decimation_shifts