mirror of
https://github.com/f4exb/sdrangel.git
synced 2024-11-17 05:41:56 -05:00
IntHalfBand FIR filter SSE optimizations
This commit is contained in:
parent
2f02d9dd69
commit
9f74c82715
@ -194,6 +194,94 @@ const int32_t HBFIRFilterTraits<96>::hbCoeffs[24] = {
|
||||
(int32_t)( 0.3177437550265513332981015537370694801211 * (1 << hbShift)),
|
||||
};
|
||||
|
||||
const int16_t HBFIRFilterTraits<112>::hbMod[112+6] = {
|
||||
111,112,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,33,34,35,36,37,38,39,40,41,42,43,44,45,46,
|
||||
47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,
|
||||
70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,91,92,
|
||||
93,94,95,96,97,98,99,100,101,102,103,104,105,106,107,108,109,110,111,
|
||||
112,0,1,2
|
||||
};
|
||||
|
||||
|
||||
const int32_t HBFIRFilterTraits<112>::hbCoeffs[28] = {
|
||||
//* Remez as in https://www.dsprelated.com/showcode/270.php */
|
||||
(int32_t)(-0.0000057182612173497993884982611156875265 * (1 << hbShift)),
|
||||
(int32_t)( 0.0000134089330475142792093150995169636985 * (1 << hbShift)),
|
||||
(int32_t)(-0.0000285019056923813186876261183133607346 * (1 << hbShift)),
|
||||
(int32_t)( 0.0000540489980941085909355720007241075109 * (1 << hbShift)),
|
||||
(int32_t)(-0.0000947833751586818473982426480617391462 * (1 << hbShift)),
|
||||
(int32_t)( 0.0001567867952902222809536542103003853299 * (1 << hbShift)),
|
||||
(int32_t)(-0.0002476681450895876299839182266282477940 * (1 << hbShift)),
|
||||
(int32_t)( 0.0003767405865262860096935593201550318554 * (1 << hbShift)),
|
||||
(int32_t)(-0.0005551920408570068304551781146471967077 * (1 << hbShift)),
|
||||
(int32_t)( 0.0007962529081739059839267769191906154447 * (1 << hbShift)),
|
||||
(int32_t)(-0.0011153731476064448775026294313761354715 * (1 << hbShift)),
|
||||
(int32_t)( 0.0015304714714705458088878087252737714152 * (1 << hbShift)),
|
||||
(int32_t)(-0.0020622467141092528514212389723070373293 * (1 << hbShift)),
|
||||
(int32_t)( 0.0027347048425079849461039049884902851772 * (1 << hbShift)),
|
||||
(int32_t)(-0.0035759786171320282616159502708796935622 * (1 << hbShift)),
|
||||
(int32_t)( 0.0046196952795832949348331375460929848487 * (1 << hbShift)),
|
||||
(int32_t)(-0.0059072308383088713984454543037827534135 * (1 << hbShift)),
|
||||
(int32_t)( 0.0074914857942512255370437479484735376900 * (1 << hbShift)),
|
||||
(int32_t)(-0.0094433233524672671732602680094714742154 * (1 << hbShift)),
|
||||
(int32_t)( 0.0118628557280401076418074879370578855742 * (1 << hbShift)),
|
||||
(int32_t)(-0.0149000865720731560937206694461565348320 * (1 << hbShift)),
|
||||
(int32_t)( 0.0187949228094094408780811988890491193160 * (1 << hbShift)),
|
||||
(int32_t)(-0.0239611153097040799342387629167205886915 * (1 << hbShift)),
|
||||
(int32_t)( 0.0311823240686547251132587632582726655528 * (1 << hbShift)),
|
||||
(int32_t)(-0.0421443341867254184229807378869736567140 * (1 << hbShift)),
|
||||
(int32_t)( 0.0612443342926724393349147135268140118569 * (1 << hbShift)),
|
||||
(int32_t)(-0.1046363792986205604185201423206308390945 * (1 << hbShift)),
|
||||
(int32_t)( 0.3178181645034457436516106554336147382855 * (1 << hbShift)),
|
||||
};
|
||||
|
||||
|
||||
const int16_t HBFIRFilterTraits<128>::hbMod[128+6] = {
|
||||
127,128,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,33,34,35,36,37,38,39,40,41,42,43,44,45,46,
|
||||
47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,
|
||||
70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,91,92,
|
||||
93,94,95,96,97,98,99,100,101,102,103,104,105,106,107,108,109,110,111,
|
||||
112,113,114,115,116,117,118,119,120,121,122,123,124,125,126,127,128,0,1,2
|
||||
};
|
||||
|
||||
|
||||
const int32_t HBFIRFilterTraits<128>::hbCoeffs[32] = {
|
||||
//* Remez as in https://www.dsprelated.com/showcode/270.php */
|
||||
(int32_t)(-0.0000013530084481063586964138655693856705 * (1 << hbShift)),
|
||||
(int32_t)( 0.0000035468835939308468221931557040615957 * (1 << hbShift)),
|
||||
(int32_t)(-0.0000080263259193852748679242486984364291 * (1 << hbShift)),
|
||||
(int32_t)( 0.0000160249362715262112246382419922241525 * (1 << hbShift)),
|
||||
(int32_t)(-0.0000293930772937943995460653712203935584 * (1 << hbShift)),
|
||||
(int32_t)( 0.0000506245785103059592661099708177374623 * (1 << hbShift)),
|
||||
(int32_t)(-0.0000829848508757281692112955928664064231 * (1 << hbShift)),
|
||||
(int32_t)( 0.0001306421953216197048494584542766006052 * (1 << hbShift)),
|
||||
(int32_t)(-0.0001988007175677746298826653603697423023 * (1 << hbShift)),
|
||||
(int32_t)( 0.0002938302746977689504891129157471141298 * (1 << hbShift)),
|
||||
(int32_t)(-0.0004233934809845499216279796073081342911 * (1 << hbShift)),
|
||||
(int32_t)( 0.0005965709177428588560684885599982862914 * (1 << hbShift)),
|
||||
(int32_t)(-0.0008239883872841064762701512869114139903 * (1 << hbShift)),
|
||||
(int32_t)( 0.0011179618447797630680778935285957231827 * (1 << hbShift)),
|
||||
(int32_t)(-0.0014926744261021872121897313689942166093 * (1 << hbShift)),
|
||||
(int32_t)( 0.0019644262679035678388628216595179765136 * (1 << hbShift)),
|
||||
(int32_t)(-0.0025520032927806384458191413244776413194 * (1 << hbShift)),
|
||||
(int32_t)( 0.0032772538071471992750238744207536001340 * (1 << hbShift)),
|
||||
(int32_t)(-0.0041660018952565701713663948169141804101 * (1 << hbShift)),
|
||||
(int32_t)( 0.0052495120038521464814196271220225753495 * (1 << hbShift)),
|
||||
(int32_t)(-0.0065668614662222155736737150277804175857 * (1 << hbShift)),
|
||||
(int32_t)( 0.0081688408784787811672822854802689107601 * (1 << hbShift)),
|
||||
(int32_t)(-0.0101245136956070701239607245724982931279 * (1 << hbShift)),
|
||||
(int32_t)( 0.0125326183062810583845880785247572930530 * (1 << hbShift)),
|
||||
(int32_t)(-0.0155423066893098579810406079104723175988 * (1 << hbShift)),
|
||||
(int32_t)( 0.0193932322698959942741669948418348212726 * (1 << hbShift)),
|
||||
(int32_t)(-0.0244995384963461564076236953724219347350 * (1 << hbShift)),
|
||||
(int32_t)( 0.0316459368298866380864176051090908003971 * (1 << hbShift)),
|
||||
(int32_t)(-0.0425198999626832385700936356442980468273 * (1 << hbShift)),
|
||||
(int32_t)( 0.0615208850123762293615747864805598510429 * (1 << hbShift)),
|
||||
(int32_t)(-0.1048057030317238041972061068918264936656 * (1 << hbShift)),
|
||||
(int32_t)( 0.3178751792920155860855402352171950042248 * (1 << hbShift)),
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
@ -37,7 +37,7 @@ struct HBFIRFilterTraits<32>
|
||||
static const int32_t hbOrder = 32;
|
||||
static const int32_t hbShift = 14;
|
||||
static const int16_t hbMod[32+6];
|
||||
static const int32_t hbCoeffs[8];
|
||||
static const int32_t hbCoeffs[8] __attribute__ ((aligned (16)));
|
||||
};
|
||||
|
||||
template<>
|
||||
@ -46,7 +46,7 @@ struct HBFIRFilterTraits<48>
|
||||
static const int32_t hbOrder = 48;
|
||||
static const int32_t hbShift = 14;
|
||||
static const int16_t hbMod[48+6];
|
||||
static const int32_t hbCoeffs[12];
|
||||
static const int32_t hbCoeffs[12] __attribute__ ((aligned (16)));
|
||||
};
|
||||
|
||||
template<>
|
||||
@ -55,7 +55,7 @@ struct HBFIRFilterTraits<64>
|
||||
static const int32_t hbOrder = 64;
|
||||
static const int32_t hbShift = 14;
|
||||
static const int16_t hbMod[64+6];
|
||||
static const int32_t hbCoeffs[16];
|
||||
static const int32_t hbCoeffs[16] __attribute__ ((aligned (16)));
|
||||
};
|
||||
|
||||
template<>
|
||||
@ -64,7 +64,7 @@ struct HBFIRFilterTraits<80>
|
||||
static const int32_t hbOrder = 80;
|
||||
static const int32_t hbShift = 14;
|
||||
static const int16_t hbMod[80+6];
|
||||
static const int32_t hbCoeffs[20];
|
||||
static const int32_t hbCoeffs[20] __attribute__ ((aligned (16)));
|
||||
};
|
||||
|
||||
template<>
|
||||
@ -73,7 +73,25 @@ struct HBFIRFilterTraits<96>
|
||||
static const int32_t hbOrder = 96;
|
||||
static const int32_t hbShift = 16;
|
||||
static const int16_t hbMod[96+6];
|
||||
static const int32_t hbCoeffs[24];
|
||||
static const int32_t hbCoeffs[24] __attribute__ ((aligned (16)));
|
||||
};
|
||||
|
||||
template<>
|
||||
struct HBFIRFilterTraits<112>
|
||||
{
|
||||
static const int32_t hbOrder = 112;
|
||||
static const int32_t hbShift = 19;
|
||||
static const int16_t hbMod[112+6];
|
||||
static const int32_t hbCoeffs[28] __attribute__ ((aligned (16)));
|
||||
};
|
||||
|
||||
template<>
|
||||
struct HBFIRFilterTraits<128>
|
||||
{
|
||||
static const int32_t hbOrder = 128;
|
||||
static const int32_t hbShift = 19;
|
||||
static const int16_t hbMod[128+6];
|
||||
static const int32_t hbCoeffs[32] __attribute__ ((aligned (16)));
|
||||
};
|
||||
|
||||
#endif /* SDRBASE_DSP_HBFILTERTRAITS_H_ */
|
||||
|
@ -35,30 +35,23 @@ public:
|
||||
bool workDecimateCenter(Sample* sample)
|
||||
{
|
||||
// insert sample into ring-buffer
|
||||
m_samplesDB[m_ptr][0] = sample->real();
|
||||
m_samplesDB[m_ptr][1] = sample->imag();
|
||||
m_samplesDB[m_ptr + m_size][0] = sample->real();
|
||||
m_samplesDB[m_ptr + m_size][1] = sample->imag();
|
||||
storeSample((FixReal) sample->real(), (FixReal) sample->imag());
|
||||
|
||||
switch(m_state)
|
||||
{
|
||||
case 0:
|
||||
// advance write-pointer
|
||||
m_ptr = (m_ptr + 1) % m_size;
|
||||
|
||||
// next state
|
||||
m_state = 1;
|
||||
|
||||
// tell caller we don't have a new sample
|
||||
return false;
|
||||
|
||||
default:
|
||||
// save result
|
||||
doFIR(sample);
|
||||
|
||||
// advance write-pointer
|
||||
m_ptr = (m_ptr + 1) % m_size;
|
||||
|
||||
// next state
|
||||
m_state = 0;
|
||||
|
||||
@ -74,39 +67,25 @@ public:
|
||||
{
|
||||
case 0:
|
||||
// insert sample into ring-buffer
|
||||
m_samplesDB[m_ptr][0] = 0;
|
||||
m_samplesDB[m_ptr][1] = 0;
|
||||
m_samplesDB[m_ptr + m_size][0] = 0;
|
||||
m_samplesDB[m_ptr + m_size][1] = 0;
|
||||
|
||||
storeSample(0, 0);
|
||||
// save result
|
||||
doFIR(SampleOut);
|
||||
|
||||
// advance write-pointer
|
||||
m_ptr = (m_ptr + 1) % m_size;
|
||||
|
||||
// next state
|
||||
m_state = 1;
|
||||
|
||||
// tell caller we didn't consume the sample
|
||||
return false;
|
||||
|
||||
default:
|
||||
// insert sample into ring-buffer
|
||||
m_samplesDB[m_ptr][0] = sampleIn->real();
|
||||
m_samplesDB[m_ptr][1] = sampleIn->imag();
|
||||
m_samplesDB[m_ptr + m_size][0] = sampleIn->real();
|
||||
m_samplesDB[m_ptr + m_size][1] = sampleIn->imag();
|
||||
|
||||
storeSample((FixReal) sampleIn->real(), (FixReal) sampleIn->imag());
|
||||
// save result
|
||||
doFIR(SampleOut);
|
||||
|
||||
// advance write-pointer
|
||||
m_ptr = (m_ptr + 1) % m_size;
|
||||
|
||||
// next state
|
||||
m_state = 0;
|
||||
|
||||
// tell caller we consumed the sample
|
||||
return true;
|
||||
}
|
||||
@ -115,33 +94,25 @@ public:
|
||||
bool workDecimateCenter(qint32 *x, qint32 *y)
|
||||
{
|
||||
// insert sample into ring-buffer
|
||||
m_samplesDB[m_ptr][0] = *x;
|
||||
m_samplesDB[m_ptr][1] = *y;
|
||||
m_samplesDB[m_ptr + m_size][0] = *x;
|
||||
m_samplesDB[m_ptr + m_size][1] = *y;
|
||||
storeSample(*x, *y);
|
||||
|
||||
switch(m_state)
|
||||
{
|
||||
case 0:
|
||||
// advance write-pointer
|
||||
m_ptr = (m_ptr + 1) % m_size;
|
||||
|
||||
// next state
|
||||
m_state = 1;
|
||||
|
||||
// tell caller we don't have a new sample
|
||||
return false;
|
||||
|
||||
default:
|
||||
// save result
|
||||
doFIR(x, y);
|
||||
|
||||
// advance write-pointer
|
||||
m_ptr = (m_ptr + 1) % m_size;
|
||||
|
||||
// next state
|
||||
m_state = 0;
|
||||
|
||||
// tell caller we have a new sample
|
||||
return true;
|
||||
}
|
||||
@ -154,71 +125,45 @@ public:
|
||||
{
|
||||
case 0:
|
||||
// insert sample into ring-buffer
|
||||
m_samplesDB[m_ptr][0] = -sample->imag();
|
||||
m_samplesDB[m_ptr][1] = sample->real();
|
||||
m_samplesDB[m_ptr + m_size][0] = -sample->imag();
|
||||
m_samplesDB[m_ptr + m_size][1] = sample->real();
|
||||
|
||||
storeSample((FixReal) -sample->imag(), (FixReal) sample->real());
|
||||
// advance write-pointer
|
||||
m_ptr = (m_ptr + 1) % m_size;
|
||||
|
||||
// next state
|
||||
m_state = 1;
|
||||
|
||||
// tell caller we don't have a new sample
|
||||
return false;
|
||||
|
||||
case 1:
|
||||
// insert sample into ring-buffer
|
||||
m_samplesDB[m_ptr][0] = -sample->real();
|
||||
m_samplesDB[m_ptr][1] = -sample->imag();
|
||||
m_samplesDB[m_ptr + m_size][0] = -sample->real();
|
||||
m_samplesDB[m_ptr + m_size][1] = -sample->imag();
|
||||
|
||||
storeSample((FixReal) -sample->real(), (FixReal) -sample->imag());
|
||||
// save result
|
||||
doFIR(sample);
|
||||
|
||||
// advance write-pointer
|
||||
m_ptr = (m_ptr + 1) % m_size;
|
||||
|
||||
// next state
|
||||
m_state = 2;
|
||||
|
||||
// tell caller we have a new sample
|
||||
return true;
|
||||
|
||||
case 2:
|
||||
// insert sample into ring-buffer
|
||||
m_samplesDB[m_ptr][0] = sample->imag();
|
||||
m_samplesDB[m_ptr][1] = -sample->real();
|
||||
m_samplesDB[m_ptr + m_size][0] = sample->imag();
|
||||
m_samplesDB[m_ptr + m_size][1] = -sample->real();
|
||||
|
||||
storeSample((FixReal) sample->imag(), (FixReal) -sample->real());
|
||||
// advance write-pointer
|
||||
m_ptr = (m_ptr + 1) % m_size;
|
||||
|
||||
// next state
|
||||
m_state = 3;
|
||||
|
||||
// tell caller we don't have a new sample
|
||||
return false;
|
||||
|
||||
default:
|
||||
// insert sample into ring-buffer
|
||||
m_samplesDB[m_ptr][0] = sample->real();
|
||||
m_samplesDB[m_ptr][1] = sample->imag();
|
||||
m_samplesDB[m_ptr + m_size][0] = sample->real();
|
||||
m_samplesDB[m_ptr + m_size][1] = sample->imag();
|
||||
|
||||
storeSample((FixReal) sample->real(), (FixReal) sample->imag());
|
||||
// save result
|
||||
doFIR(sample);
|
||||
|
||||
// advance write-pointer
|
||||
m_ptr = (m_ptr + 1) % m_size;
|
||||
|
||||
// next state
|
||||
m_state = 0;
|
||||
|
||||
// tell caller we have a new sample
|
||||
return true;
|
||||
}
|
||||
@ -233,10 +178,7 @@ public:
|
||||
{
|
||||
case 0:
|
||||
// insert sample into ring-buffer
|
||||
m_samplesDB[m_ptr][0] = 0;
|
||||
m_samplesDB[m_ptr][1] = 0;
|
||||
m_samplesDB[m_ptr + m_size][0] = 0;
|
||||
m_samplesDB[m_ptr + m_size][1] = 0;
|
||||
storeSample(0, 0);
|
||||
|
||||
// save result
|
||||
doFIR(&s);
|
||||
@ -254,10 +196,7 @@ public:
|
||||
|
||||
case 1:
|
||||
// insert sample into ring-buffer
|
||||
m_samplesDB[m_ptr][0] = sampleIn->real();
|
||||
m_samplesDB[m_ptr][1] = sampleIn->imag();
|
||||
m_samplesDB[m_ptr + m_size][0] = sampleIn->real();
|
||||
m_samplesDB[m_ptr + m_size][1] = sampleIn->imag();
|
||||
storeSample((FixReal) sampleIn->real(), (FixReal) sampleIn->imag());
|
||||
|
||||
// save result
|
||||
doFIR(&s);
|
||||
@ -275,10 +214,7 @@ public:
|
||||
|
||||
case 2:
|
||||
// insert sample into ring-buffer
|
||||
m_samplesDB[m_ptr][0] = 0;
|
||||
m_samplesDB[m_ptr][1] = 0;
|
||||
m_samplesDB[m_ptr + m_size][0] = 0;
|
||||
m_samplesDB[m_ptr + m_size][1] = 0;
|
||||
storeSample(0, 0);
|
||||
|
||||
// save result
|
||||
doFIR(&s);
|
||||
@ -296,10 +232,7 @@ public:
|
||||
|
||||
default:
|
||||
// insert sample into ring-buffer
|
||||
m_samplesDB[m_ptr][0] = sampleIn->real();
|
||||
m_samplesDB[m_ptr][1] = sampleIn->imag();
|
||||
m_samplesDB[m_ptr + m_size][0] = sampleIn->real();
|
||||
m_samplesDB[m_ptr + m_size][1] = sampleIn->imag();
|
||||
storeSample((FixReal) sampleIn->real(), (FixReal) sampleIn->imag());
|
||||
|
||||
// save result
|
||||
doFIR(&s);
|
||||
@ -324,71 +257,45 @@ public:
|
||||
{
|
||||
case 0:
|
||||
// insert sample into ring-buffer
|
||||
m_samplesDB[m_ptr][0] = sample->imag();
|
||||
m_samplesDB[m_ptr][1] = -sample->real();
|
||||
m_samplesDB[m_ptr + m_size][0] = sample->imag();
|
||||
m_samplesDB[m_ptr + m_size][1] = -sample->real();
|
||||
|
||||
storeSample((FixReal) sample->imag(), (FixReal) -sample->real());
|
||||
// advance write-pointer
|
||||
m_ptr = (m_ptr + 1) % m_size;
|
||||
|
||||
// next state
|
||||
m_state = 1;
|
||||
|
||||
// tell caller we don't have a new sample
|
||||
return false;
|
||||
|
||||
case 1:
|
||||
// insert sample into ring-buffer
|
||||
m_samplesDB[m_ptr][0] = -sample->real();
|
||||
m_samplesDB[m_ptr][1] = -sample->imag();
|
||||
m_samplesDB[m_ptr + m_size][0] = -sample->real();
|
||||
m_samplesDB[m_ptr + m_size][1] = -sample->imag();
|
||||
|
||||
storeSample((FixReal) -sample->real(), (FixReal) -sample->imag());
|
||||
// save result
|
||||
doFIR(sample);
|
||||
|
||||
// advance write-pointer
|
||||
m_ptr = (m_ptr + 1) % m_size;
|
||||
|
||||
// next state
|
||||
m_state = 2;
|
||||
|
||||
// tell caller we have a new sample
|
||||
return true;
|
||||
|
||||
case 2:
|
||||
// insert sample into ring-buffer
|
||||
m_samplesDB[m_ptr][0] = -sample->imag();
|
||||
m_samplesDB[m_ptr][1] = sample->real();
|
||||
m_samplesDB[m_ptr + m_size][0] = -sample->imag();
|
||||
m_samplesDB[m_ptr + m_size][1] = sample->real();
|
||||
|
||||
storeSample((FixReal) -sample->imag(), (FixReal) sample->real());
|
||||
// advance write-pointer
|
||||
m_ptr = (m_ptr + 1) % m_size;
|
||||
|
||||
// next state
|
||||
m_state = 3;
|
||||
|
||||
// tell caller we don't have a new sample
|
||||
return false;
|
||||
|
||||
default:
|
||||
// insert sample into ring-buffer
|
||||
m_samplesDB[m_ptr][0] = sample->real();
|
||||
m_samplesDB[m_ptr][1] = sample->imag();
|
||||
m_samplesDB[m_ptr + m_size][0] = sample->real();
|
||||
m_samplesDB[m_ptr + m_size][1] = sample->imag();
|
||||
|
||||
storeSample((FixReal) sample->real(), (FixReal) sample->imag());
|
||||
// save result
|
||||
doFIR(sample);
|
||||
|
||||
// advance write-pointer
|
||||
m_ptr = (m_ptr + 1) % m_size;
|
||||
|
||||
// next state
|
||||
m_state = 0;
|
||||
|
||||
// tell caller we have a new sample
|
||||
return true;
|
||||
}
|
||||
@ -403,10 +310,7 @@ public:
|
||||
{
|
||||
case 0:
|
||||
// insert sample into ring-buffer
|
||||
m_samplesDB[m_ptr][0] = 0;
|
||||
m_samplesDB[m_ptr][1] = 0;
|
||||
m_samplesDB[m_ptr + m_size][0] = 0;
|
||||
m_samplesDB[m_ptr + m_size][1] = 0;
|
||||
storeSample(0, 0);
|
||||
|
||||
// save result
|
||||
doFIR(&s);
|
||||
@ -424,10 +328,7 @@ public:
|
||||
|
||||
case 1:
|
||||
// insert sample into ring-buffer
|
||||
m_samplesDB[m_ptr][0] = sampleIn->real();
|
||||
m_samplesDB[m_ptr][1] = sampleIn->imag();
|
||||
m_samplesDB[m_ptr + m_size][0] = sampleIn->real();
|
||||
m_samplesDB[m_ptr + m_size][1] = sampleIn->imag();
|
||||
storeSample((FixReal) sampleIn->real(), (FixReal) sampleIn->imag());
|
||||
|
||||
// save result
|
||||
doFIR(&s);
|
||||
@ -445,10 +346,7 @@ public:
|
||||
|
||||
case 2:
|
||||
// insert sample into ring-buffer
|
||||
m_samplesDB[m_ptr][0] = 0;
|
||||
m_samplesDB[m_ptr][1] = 0;
|
||||
m_samplesDB[m_ptr + m_size][0] = 0;
|
||||
m_samplesDB[m_ptr + m_size][1] = 0;
|
||||
storeSample(0, 0);
|
||||
|
||||
// save result
|
||||
doFIR(&s);
|
||||
@ -466,10 +364,7 @@ public:
|
||||
|
||||
default:
|
||||
// insert sample into ring-buffer
|
||||
m_samplesDB[m_ptr][0] = sampleIn->real();
|
||||
m_samplesDB[m_ptr][1] = sampleIn->imag();
|
||||
m_samplesDB[m_ptr + m_size][0] = sampleIn->real();
|
||||
m_samplesDB[m_ptr + m_size][1] = sampleIn->imag();
|
||||
storeSample((FixReal) sampleIn->real(), (FixReal) sampleIn->imag());
|
||||
|
||||
// save result
|
||||
doFIR(&s);
|
||||
@ -489,39 +384,21 @@ public:
|
||||
|
||||
void myDecimate(const Sample* sample1, Sample* sample2)
|
||||
{
|
||||
m_samplesDB[m_ptr][0] = sample1->real();
|
||||
m_samplesDB[m_ptr][1] = sample1->imag();
|
||||
m_samplesDB[m_ptr + m_size][0] = sample1->real();
|
||||
m_samplesDB[m_ptr + m_size][1] = sample1->imag();
|
||||
|
||||
storeSample((FixReal) sample1->real(), (FixReal) sample1->imag());
|
||||
m_ptr = (m_ptr + 1) % m_size;
|
||||
|
||||
m_samplesDB[m_ptr][0] = sample2->real();
|
||||
m_samplesDB[m_ptr][1] = sample2->imag();
|
||||
m_samplesDB[m_ptr + m_size][0] = sample2->real();
|
||||
m_samplesDB[m_ptr + m_size][1] = sample2->imag();
|
||||
|
||||
storeSample((FixReal) sample2->real(), (FixReal) sample2->imag());
|
||||
doFIR(sample2);
|
||||
|
||||
m_ptr = (m_ptr + 1) % m_size;
|
||||
}
|
||||
|
||||
void myDecimate(qint32 x1, qint32 y1, qint32 *x2, qint32 *y2)
|
||||
{
|
||||
m_samplesDB[m_ptr][0] = x1;
|
||||
m_samplesDB[m_ptr][1] = y1;
|
||||
m_samplesDB[m_ptr + m_size][0] = x1;
|
||||
m_samplesDB[m_ptr + m_size][1] = y1;
|
||||
|
||||
storeSample(x1, y1);
|
||||
m_ptr = (m_ptr + 1) % m_size;
|
||||
|
||||
m_samplesDB[m_ptr][0] = *x2;
|
||||
m_samplesDB[m_ptr][1] = *y2;
|
||||
m_samplesDB[m_ptr + m_size][0] = *x2;
|
||||
m_samplesDB[m_ptr + m_size][1] = *y2;
|
||||
|
||||
storeSample(*x2, *y2);
|
||||
doFIR(x2, y2);
|
||||
|
||||
m_ptr = (m_ptr + 1) % m_size;
|
||||
}
|
||||
|
||||
@ -533,10 +410,18 @@ protected:
|
||||
|
||||
void storeSample(const FixReal& sampleI, const FixReal& sampleQ)
|
||||
{
|
||||
m_samplesDB[m_ptr][0] = sampleI;
|
||||
m_samplesDB[m_ptr][1] = sampleQ;
|
||||
m_samplesDB[m_ptr + m_size][0] = sampleI;
|
||||
m_samplesDB[m_ptr + m_size][1] = sampleQ;
|
||||
}
|
||||
|
||||
void storeSample(qint32 x, qint32 y)
|
||||
{
|
||||
m_samplesDB[m_ptr][0] = x;
|
||||
m_samplesDB[m_ptr][1] = y;
|
||||
m_samplesDB[m_ptr + m_size][0] = x;
|
||||
m_samplesDB[m_ptr + m_size][1] = y;
|
||||
}
|
||||
|
||||
void doFIR(Sample* sample)
|
||||
|
649
sdrbase/dsp/inthalfbandfiltereo1.h
Normal file
649
sdrbase/dsp/inthalfbandfiltereo1.h
Normal file
@ -0,0 +1,649 @@
|
||||
///////////////////////////////////////////////////////////////////////////////////
|
||||
// Copyright (C) 2016 F4EXB //
|
||||
// written by Edouard Griffiths //
|
||||
// //
|
||||
// Integer half-band FIR based interpolator and decimator //
|
||||
// This is the even/odd double buffer variant. Really useful only when SIMD is //
|
||||
// used //
|
||||
// //
|
||||
// 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 <http://www.gnu.org/licenses/>. //
|
||||
///////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef SDRBASE_DSP_INTHALFBANDFILTEREO_H_
|
||||
#define SDRBASE_DSP_INTHALFBANDFILTEREO_H_
|
||||
|
||||
#ifdef USE_SIMD
|
||||
#include <smmintrin.h>
|
||||
#endif
|
||||
|
||||
#include <stdint.h>
|
||||
#include "dsp/dsptypes.h"
|
||||
#include "dsp/hbfiltertraits.h"
|
||||
#include "util/export.h"
|
||||
|
||||
template<uint32_t HBFilterOrder>
|
||||
class SDRANGEL_API IntHalfbandFilterEO1 {
|
||||
public:
|
||||
IntHalfbandFilterEO1();
|
||||
|
||||
// downsample by 2, return center part of original spectrum
|
||||
bool workDecimateCenter(Sample* sample)
|
||||
{
|
||||
// insert sample into ring-buffer
|
||||
storeSample((FixReal) sample->real(), (FixReal) sample->imag());
|
||||
|
||||
switch(m_state)
|
||||
{
|
||||
case 0:
|
||||
// advance write-pointer
|
||||
advancePointer();
|
||||
// next state
|
||||
m_state = 1;
|
||||
// tell caller we don't have a new sample
|
||||
return false;
|
||||
|
||||
default:
|
||||
// save result
|
||||
doFIR(sample);
|
||||
// advance write-pointer
|
||||
advancePointer();
|
||||
// next state
|
||||
m_state = 0;
|
||||
|
||||
// tell caller we have a new sample
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
// upsample by 2, return center part of original spectrum - double buffer variant
|
||||
bool workInterpolateCenter(Sample* sampleIn, Sample *SampleOut)
|
||||
{
|
||||
switch(m_state)
|
||||
{
|
||||
case 0:
|
||||
// insert sample into ring-buffer
|
||||
storeSample(0, 0);
|
||||
// save result
|
||||
doFIR(SampleOut);
|
||||
// advance write-pointer
|
||||
advancePointer();
|
||||
// next state
|
||||
m_state = 1;
|
||||
// tell caller we didn't consume the sample
|
||||
return false;
|
||||
|
||||
default:
|
||||
// insert sample into ring-buffer
|
||||
storeSample((FixReal) sampleIn->real(), (FixReal) sampleIn->imag());
|
||||
// save result
|
||||
doFIR(SampleOut);
|
||||
// advance write-pointer
|
||||
advancePointer();
|
||||
// next state
|
||||
m_state = 0;
|
||||
// tell caller we consumed the sample
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
bool workDecimateCenter(qint32 *x, qint32 *y)
|
||||
{
|
||||
// insert sample into ring-buffer
|
||||
storeSample(*x, *y);
|
||||
|
||||
switch(m_state)
|
||||
{
|
||||
case 0:
|
||||
// advance write-pointer
|
||||
advancePointer();
|
||||
// next state
|
||||
m_state = 1;
|
||||
// tell caller we don't have a new sample
|
||||
return false;
|
||||
|
||||
default:
|
||||
// save result
|
||||
doFIR(x, y);
|
||||
// advance write-pointer
|
||||
advancePointer();
|
||||
// next state
|
||||
m_state = 0;
|
||||
// tell caller we have a new sample
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
// downsample by 2, return lower half of original spectrum
|
||||
bool workDecimateLowerHalf(Sample* sample)
|
||||
{
|
||||
switch(m_state)
|
||||
{
|
||||
case 0:
|
||||
// insert sample into ring-buffer
|
||||
storeSample((FixReal) -sample->imag(), (FixReal) sample->real());
|
||||
// advance write-pointer
|
||||
advancePointer();
|
||||
// next state
|
||||
m_state = 1;
|
||||
// tell caller we don't have a new sample
|
||||
return false;
|
||||
|
||||
case 1:
|
||||
// insert sample into ring-buffer
|
||||
storeSample((FixReal) -sample->real(), (FixReal) -sample->imag());
|
||||
// save result
|
||||
doFIR(sample);
|
||||
// advance write-pointer
|
||||
advancePointer();
|
||||
// next state
|
||||
m_state = 2;
|
||||
// tell caller we have a new sample
|
||||
return true;
|
||||
|
||||
case 2:
|
||||
// insert sample into ring-buffer
|
||||
storeSample((FixReal) sample->imag(), (FixReal) -sample->real());
|
||||
// advance write-pointer
|
||||
advancePointer();
|
||||
// next state
|
||||
m_state = 3;
|
||||
// tell caller we don't have a new sample
|
||||
return false;
|
||||
|
||||
default:
|
||||
// insert sample into ring-buffer
|
||||
storeSample((FixReal) sample->real(), (FixReal) sample->imag());
|
||||
// save result
|
||||
doFIR(sample);
|
||||
// advance write-pointer
|
||||
advancePointer();
|
||||
// next state
|
||||
m_state = 0;
|
||||
// tell caller we have a new sample
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
// upsample by 2, from lower half of original spectrum - double buffer variant
|
||||
bool workInterpolateLowerHalf(Sample* sampleIn, Sample *sampleOut)
|
||||
{
|
||||
Sample s;
|
||||
|
||||
switch(m_state)
|
||||
{
|
||||
case 0:
|
||||
// insert sample into ring-buffer
|
||||
storeSample(0, 0);
|
||||
|
||||
// save result
|
||||
doFIR(&s);
|
||||
sampleOut->setReal(s.imag());
|
||||
sampleOut->setImag(-s.real());
|
||||
|
||||
// advance write-pointer
|
||||
advancePointer();
|
||||
|
||||
// next state
|
||||
m_state = 1;
|
||||
|
||||
// tell caller we didn't consume the sample
|
||||
return false;
|
||||
|
||||
case 1:
|
||||
// insert sample into ring-buffer
|
||||
storeSample((FixReal) sampleIn->real(), (FixReal) sampleIn->imag());
|
||||
|
||||
// save result
|
||||
doFIR(&s);
|
||||
sampleOut->setReal(-s.real());
|
||||
sampleOut->setImag(-s.imag());
|
||||
|
||||
// advance write-pointer
|
||||
advancePointer();
|
||||
|
||||
// next state
|
||||
m_state = 2;
|
||||
|
||||
// tell caller we consumed the sample
|
||||
return true;
|
||||
|
||||
case 2:
|
||||
// insert sample into ring-buffer
|
||||
storeSample(0, 0);
|
||||
|
||||
// save result
|
||||
doFIR(&s);
|
||||
sampleOut->setReal(-s.imag());
|
||||
sampleOut->setImag(s.real());
|
||||
|
||||
// advance write-pointer
|
||||
advancePointer();
|
||||
|
||||
// next state
|
||||
m_state = 3;
|
||||
|
||||
// tell caller we didn't consume the sample
|
||||
return false;
|
||||
|
||||
default:
|
||||
// insert sample into ring-buffer
|
||||
storeSample((FixReal) sampleIn->real(), (FixReal) sampleIn->imag());
|
||||
|
||||
// save result
|
||||
doFIR(&s);
|
||||
sampleOut->setReal(s.real());
|
||||
sampleOut->setImag(s.imag());
|
||||
|
||||
// advance write-pointer
|
||||
advancePointer();
|
||||
|
||||
// next state
|
||||
m_state = 0;
|
||||
|
||||
// tell caller we consumed the sample
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
// downsample by 2, return upper half of original spectrum
|
||||
bool workDecimateUpperHalf(Sample* sample)
|
||||
{
|
||||
switch(m_state)
|
||||
{
|
||||
case 0:
|
||||
// insert sample into ring-buffer
|
||||
storeSample((FixReal) sample->imag(), (FixReal) -sample->real());
|
||||
// advance write-pointer
|
||||
advancePointer();
|
||||
// next state
|
||||
m_state = 1;
|
||||
// tell caller we don't have a new sample
|
||||
return false;
|
||||
|
||||
case 1:
|
||||
// insert sample into ring-buffer
|
||||
storeSample((FixReal) -sample->real(), (FixReal) -sample->imag());
|
||||
// save result
|
||||
doFIR(sample);
|
||||
// advance write-pointer
|
||||
advancePointer();
|
||||
// next state
|
||||
m_state = 2;
|
||||
// tell caller we have a new sample
|
||||
return true;
|
||||
|
||||
case 2:
|
||||
// insert sample into ring-buffer
|
||||
storeSample((FixReal) -sample->imag(), (FixReal) sample->real());
|
||||
// advance write-pointer
|
||||
advancePointer();
|
||||
// next state
|
||||
m_state = 3;
|
||||
// tell caller we don't have a new sample
|
||||
return false;
|
||||
|
||||
default:
|
||||
// insert sample into ring-buffer
|
||||
storeSample((FixReal) sample->real(), (FixReal) sample->imag());
|
||||
// save result
|
||||
doFIR(sample);
|
||||
// advance write-pointer
|
||||
advancePointer();
|
||||
// next state
|
||||
m_state = 0;
|
||||
// tell caller we have a new sample
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
// upsample by 2, move original spectrum to upper half - double buffer variant
|
||||
bool workInterpolateUpperHalf(Sample* sampleIn, Sample *sampleOut)
|
||||
{
|
||||
Sample s;
|
||||
|
||||
switch(m_state)
|
||||
{
|
||||
case 0:
|
||||
// insert sample into ring-buffer
|
||||
storeSample(0, 0);
|
||||
|
||||
// save result
|
||||
doFIR(&s);
|
||||
sampleOut->setReal(-s.imag());
|
||||
sampleOut->setImag(s.real());
|
||||
|
||||
// advance write-pointer
|
||||
advancePointer();
|
||||
|
||||
// next state
|
||||
m_state = 1;
|
||||
|
||||
// tell caller we didn't consume the sample
|
||||
return false;
|
||||
|
||||
case 1:
|
||||
// insert sample into ring-buffer
|
||||
storeSample((FixReal) sampleIn->real(), (FixReal) sampleIn->imag());
|
||||
|
||||
// save result
|
||||
doFIR(&s);
|
||||
sampleOut->setReal(-s.real());
|
||||
sampleOut->setImag(-s.imag());
|
||||
|
||||
// advance write-pointer
|
||||
advancePointer();
|
||||
|
||||
// next state
|
||||
m_state = 2;
|
||||
|
||||
// tell caller we consumed the sample
|
||||
return true;
|
||||
|
||||
case 2:
|
||||
// insert sample into ring-buffer
|
||||
storeSample(0, 0);
|
||||
|
||||
// save result
|
||||
doFIR(&s);
|
||||
sampleOut->setReal(s.imag());
|
||||
sampleOut->setImag(-s.real());
|
||||
|
||||
// advance write-pointer
|
||||
advancePointer();
|
||||
|
||||
// next state
|
||||
m_state = 3;
|
||||
|
||||
// tell caller we didn't consume the sample
|
||||
return false;
|
||||
|
||||
default:
|
||||
// insert sample into ring-buffer
|
||||
storeSample((FixReal) sampleIn->real(), (FixReal) sampleIn->imag());
|
||||
|
||||
// save result
|
||||
doFIR(&s);
|
||||
sampleOut->setReal(s.real());
|
||||
sampleOut->setImag(s.imag());
|
||||
|
||||
// advance write-pointer
|
||||
advancePointer();
|
||||
|
||||
// next state
|
||||
m_state = 0;
|
||||
|
||||
// tell caller we consumed the sample
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
void myDecimate(const Sample* sample1, Sample* sample2)
|
||||
{
|
||||
storeSample((FixReal) sample1->real(), (FixReal) sample1->imag());
|
||||
advancePointer();
|
||||
|
||||
storeSample((FixReal) sample2->real(), (FixReal) sample2->imag());
|
||||
doFIR(sample2);
|
||||
advancePointer();
|
||||
}
|
||||
|
||||
void myDecimate(qint32 x1, qint32 y1, qint32 *x2, qint32 *y2)
|
||||
{
|
||||
storeSample(x1, y1);
|
||||
advancePointer();
|
||||
|
||||
storeSample(*x2, *y2);
|
||||
doFIR(x2, y2);
|
||||
advancePointer();
|
||||
}
|
||||
|
||||
protected:
|
||||
qint32 m_even[2][HBFIRFilterTraits<HBFilterOrder>::hbOrder]; // double buffer technique
|
||||
qint32 m_odd[2][HBFIRFilterTraits<HBFilterOrder>::hbOrder]; // double buffer technique
|
||||
|
||||
int m_ptr;
|
||||
int m_sizeEO;
|
||||
int m_state;
|
||||
|
||||
void storeSample(const FixReal& sampleI, const FixReal& sampleQ)
|
||||
{
|
||||
if ((m_ptr % 2) == 0)
|
||||
{
|
||||
m_even[0][m_ptr/2] = sampleI;
|
||||
m_even[1][m_ptr/2] = sampleQ;
|
||||
m_even[0][m_ptr/2 + m_sizeEO] = sampleI;
|
||||
m_even[1][m_ptr/2 + m_sizeEO] = sampleQ;
|
||||
}
|
||||
else
|
||||
{
|
||||
m_odd[0][m_ptr/2] = sampleI;
|
||||
m_odd[1][m_ptr/2] = sampleQ;
|
||||
m_odd[0][m_ptr/2 + m_sizeEO] = sampleI;
|
||||
m_odd[1][m_ptr/2 + m_sizeEO] = sampleQ;
|
||||
}
|
||||
}
|
||||
|
||||
void storeSample(qint32 x, qint32 y)
|
||||
{
|
||||
if ((m_ptr % 2) == 0)
|
||||
{
|
||||
m_even[0][m_ptr/2] = x;
|
||||
m_even[1][m_ptr/2] = y;
|
||||
m_even[0][m_ptr/2 + m_sizeEO] = x;
|
||||
m_even[1][m_ptr/2 + m_sizeEO] = y;
|
||||
}
|
||||
else
|
||||
{
|
||||
m_odd[0][m_ptr/2] = x;
|
||||
m_odd[1][m_ptr/2] = y;
|
||||
m_odd[0][m_ptr/2 + m_sizeEO] = x;
|
||||
m_odd[1][m_ptr/2 + m_sizeEO] = y;
|
||||
}
|
||||
}
|
||||
|
||||
void advancePointer()
|
||||
{
|
||||
m_ptr = (m_ptr + 1) % (2*m_sizeEO);
|
||||
}
|
||||
|
||||
void doFIR(Sample* sample)
|
||||
{
|
||||
int a = m_ptr/2 + m_sizeEO; // tip pointer
|
||||
int b = m_ptr/2 + 1; // tail pointer
|
||||
|
||||
qint32 iAcc = 0;
|
||||
qint32 qAcc = 0;
|
||||
|
||||
#ifdef USE_SIMD
|
||||
//#warning "IntHalfbandFiler SIMD"
|
||||
const __m128i* h = (const __m128i*) HBFIRFilterTraits<HBFilterOrder>::hbCoeffs;
|
||||
__m128i sumI = _mm_setzero_si128();
|
||||
__m128i sumQ = _mm_setzero_si128();
|
||||
__m128i sa, sb;
|
||||
a -= 3;
|
||||
|
||||
for (int i = 0; i < HBFIRFilterTraits<HBFilterOrder>::hbOrder / 16; i++)
|
||||
{
|
||||
if ((m_ptr % 2) == 0)
|
||||
{
|
||||
sa = _mm_shuffle_epi32(_mm_loadu_si128((__m128i*) &(m_even[0][a])), _MM_SHUFFLE(0,1,2,3));
|
||||
sb = _mm_loadu_si128((__m128i*) &(m_even[0][b]));
|
||||
sumI = _mm_add_epi32(sumI, _mm_mullo_epi32(_mm_add_epi32(sa, sb), *h));
|
||||
|
||||
sa = _mm_shuffle_epi32(_mm_loadu_si128((__m128i*) &(m_even[1][a])), _MM_SHUFFLE(0,1,2,3));
|
||||
sb = _mm_loadu_si128((__m128i*) &(m_even[1][b]));
|
||||
sumQ = _mm_add_epi32(sumQ, _mm_mullo_epi32(_mm_add_epi32(sa, sb), *h));
|
||||
}
|
||||
else
|
||||
{
|
||||
sa = _mm_shuffle_epi32(_mm_loadu_si128((__m128i*) &(m_odd[0][a])), _MM_SHUFFLE(0,1,2,3));
|
||||
sb = _mm_loadu_si128((__m128i*) &(m_odd[0][b]));
|
||||
sumI = _mm_add_epi32(sumI, _mm_mullo_epi32(_mm_add_epi32(sa, sb), *h));
|
||||
|
||||
sa = _mm_shuffle_epi32(_mm_loadu_si128((__m128i*) &(m_odd[1][a])), _MM_SHUFFLE(0,1,2,3));
|
||||
sb = _mm_loadu_si128((__m128i*) &(m_odd[1][b]));
|
||||
sumQ = _mm_add_epi32(sumQ, _mm_mullo_epi32(_mm_add_epi32(sa, sb), *h));
|
||||
}
|
||||
|
||||
a -= 4;
|
||||
b += 4;
|
||||
++h;
|
||||
}
|
||||
|
||||
// horizontal add of four 32 bit partial sums
|
||||
|
||||
sumI = _mm_add_epi32(sumI, _mm_srli_si128(sumI, 8));
|
||||
sumI = _mm_add_epi32(sumI, _mm_srli_si128(sumI, 4));
|
||||
iAcc = _mm_cvtsi128_si32(sumI);
|
||||
|
||||
sumQ = _mm_add_epi32(sumQ, _mm_srli_si128(sumQ, 8));
|
||||
sumQ = _mm_add_epi32(sumQ, _mm_srli_si128(sumQ, 4));
|
||||
qAcc = _mm_cvtsi128_si32(sumQ);
|
||||
#else
|
||||
for (int i = 0; i < HBFIRFilterTraits<HBFilterOrder>::hbOrder / 4; i++)
|
||||
{
|
||||
if ((m_ptr % 2) == 0)
|
||||
{
|
||||
iAcc += (m_even[0][a] + m_even[0][b]) * HBFIRFilterTraits<HBFilterOrder>::hbCoeffs[i];
|
||||
qAcc += (m_even[1][a] + m_even[1][b]) * HBFIRFilterTraits<HBFilterOrder>::hbCoeffs[i];
|
||||
}
|
||||
else
|
||||
{
|
||||
iAcc += (m_odd[0][a] + m_odd[0][b]) * HBFIRFilterTraits<HBFilterOrder>::hbCoeffs[i];
|
||||
qAcc += (m_odd[1][a] + m_odd[1][b]) * HBFIRFilterTraits<HBFilterOrder>::hbCoeffs[i];
|
||||
}
|
||||
|
||||
a -= 1;
|
||||
b += 1;
|
||||
}
|
||||
#endif
|
||||
|
||||
if ((m_ptr % 2) == 0)
|
||||
{
|
||||
iAcc += ((qint32)m_odd[0][m_ptr/2 + m_sizeEO/2]) << (HBFIRFilterTraits<HBFilterOrder>::hbShift - 1);
|
||||
qAcc += ((qint32)m_odd[1][m_ptr/2 + m_sizeEO/2]) << (HBFIRFilterTraits<HBFilterOrder>::hbShift - 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
iAcc += ((qint32)m_even[0][m_ptr/2 + m_sizeEO/2 + 1]) << (HBFIRFilterTraits<HBFilterOrder>::hbShift - 1);
|
||||
qAcc += ((qint32)m_even[1][m_ptr/2 + m_sizeEO/2 + 1]) << (HBFIRFilterTraits<HBFilterOrder>::hbShift - 1);
|
||||
}
|
||||
|
||||
sample->setReal(iAcc >> HBFIRFilterTraits<HBFilterOrder>::hbShift -1);
|
||||
sample->setImag(qAcc >> HBFIRFilterTraits<HBFilterOrder>::hbShift -1);
|
||||
}
|
||||
|
||||
void doFIR(qint32 *x, qint32 *y)
|
||||
{
|
||||
int a = m_ptr/2 + m_sizeEO; // tip pointer
|
||||
int b = m_ptr/2 + 1; // tail pointer
|
||||
|
||||
qint32 iAcc = 0;
|
||||
qint32 qAcc = 0;
|
||||
|
||||
#ifdef USE_SIMD
|
||||
const __m128i* h = (const __m128i*) HBFIRFilterTraits<HBFilterOrder>::hbCoeffs;
|
||||
__m128i sumI = _mm_setzero_si128();
|
||||
__m128i sumQ = _mm_setzero_si128();
|
||||
__m128i sa, sb;
|
||||
a -= 3;
|
||||
|
||||
for (int i = 0; i < HBFIRFilterTraits<HBFilterOrder>::hbOrder / 16; i++)
|
||||
{
|
||||
if ((m_ptr % 2) == 0)
|
||||
{
|
||||
sa = _mm_shuffle_epi32(_mm_loadu_si128((__m128i*) &(m_even[0][a])), _MM_SHUFFLE(0,1,2,3));
|
||||
sb = _mm_loadu_si128((__m128i*) &(m_even[0][b]));
|
||||
sumI = _mm_add_epi32(sumI, _mm_mullo_epi32(_mm_add_epi32(sa, sb), *h));
|
||||
|
||||
sa = _mm_shuffle_epi32(_mm_loadu_si128((__m128i*) &(m_even[1][a])), _MM_SHUFFLE(0,1,2,3));
|
||||
sb = _mm_loadu_si128((__m128i*) &(m_even[1][b]));
|
||||
sumQ = _mm_add_epi32(sumQ, _mm_mullo_epi32(_mm_add_epi32(sa, sb), *h));
|
||||
}
|
||||
else
|
||||
{
|
||||
sa = _mm_shuffle_epi32(_mm_loadu_si128((__m128i*) &(m_odd[0][a])), _MM_SHUFFLE(0,1,2,3));
|
||||
sb = _mm_loadu_si128((__m128i*) &(m_odd[0][b]));
|
||||
sumI = _mm_add_epi32(sumI, _mm_mullo_epi32(_mm_add_epi32(sa, sb), *h));
|
||||
|
||||
sa = _mm_shuffle_epi32(_mm_loadu_si128((__m128i*) &(m_odd[1][a])), _MM_SHUFFLE(0,1,2,3));
|
||||
sb = _mm_loadu_si128((__m128i*) &(m_odd[1][b]));
|
||||
sumQ = _mm_add_epi32(sumQ, _mm_mullo_epi32(_mm_add_epi32(sa, sb), *h));
|
||||
}
|
||||
|
||||
a -= 4;
|
||||
b += 4;
|
||||
++h;
|
||||
}
|
||||
|
||||
// horizontal add of four 32 bit partial sums
|
||||
|
||||
sumI = _mm_add_epi32(sumI, _mm_srli_si128(sumI, 8));
|
||||
sumI = _mm_add_epi32(sumI, _mm_srli_si128(sumI, 4));
|
||||
iAcc = _mm_cvtsi128_si32(sumI);
|
||||
|
||||
sumQ = _mm_add_epi32(sumQ, _mm_srli_si128(sumQ, 8));
|
||||
sumQ = _mm_add_epi32(sumQ, _mm_srli_si128(sumQ, 4));
|
||||
qAcc = _mm_cvtsi128_si32(sumQ);
|
||||
#else
|
||||
for (int i = 0; i < HBFIRFilterTraits<HBFilterOrder>::hbOrder / 4; i++)
|
||||
{
|
||||
if ((m_ptr % 2) == 0)
|
||||
{
|
||||
iAcc += (m_even[0][a] + m_even[0][b]) * HBFIRFilterTraits<HBFilterOrder>::hbCoeffs[i];
|
||||
qAcc += (m_even[1][a] + m_even[1][b]) * HBFIRFilterTraits<HBFilterOrder>::hbCoeffs[i];
|
||||
}
|
||||
else
|
||||
{
|
||||
iAcc += (m_odd[0][a] + m_odd[0][b]) * HBFIRFilterTraits<HBFilterOrder>::hbCoeffs[i];
|
||||
qAcc += (m_odd[1][a] + m_odd[1][b]) * HBFIRFilterTraits<HBFilterOrder>::hbCoeffs[i];
|
||||
}
|
||||
|
||||
a -= 1;
|
||||
b += 1;
|
||||
}
|
||||
#endif
|
||||
if ((m_ptr % 2) == 0)
|
||||
{
|
||||
iAcc += ((qint32)m_odd[0][m_ptr/2 + m_sizeEO/2]) << (HBFIRFilterTraits<HBFilterOrder>::hbShift - 1);
|
||||
qAcc += ((qint32)m_odd[1][m_ptr/2 + m_sizeEO/2]) << (HBFIRFilterTraits<HBFilterOrder>::hbShift - 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
iAcc += ((qint32)m_even[0][m_ptr/2 + m_sizeEO/2 + 1]) << (HBFIRFilterTraits<HBFilterOrder>::hbShift - 1);
|
||||
qAcc += ((qint32)m_even[1][m_ptr/2 + m_sizeEO/2 + 1]) << (HBFIRFilterTraits<HBFilterOrder>::hbShift - 1);
|
||||
}
|
||||
|
||||
*x = iAcc >> (HBFIRFilterTraits<HBFilterOrder>::hbShift -1); // HB_SHIFT incorrect do not loose the gained bit
|
||||
*y = qAcc >> (HBFIRFilterTraits<HBFilterOrder>::hbShift -1);
|
||||
}
|
||||
};
|
||||
|
||||
template<uint32_t HBFilterOrder>
|
||||
IntHalfbandFilterEO1<HBFilterOrder>::IntHalfbandFilterEO1()
|
||||
{
|
||||
m_sizeEO = HBFIRFilterTraits<HBFilterOrder>::hbOrder/2;
|
||||
|
||||
for (int i = 0; i < 2*m_sizeEO; i++)
|
||||
{
|
||||
m_even[0][i] = 0;
|
||||
m_even[1][i] = 0;
|
||||
m_odd[0][i] = 0;
|
||||
m_odd[1][i] = 0;
|
||||
}
|
||||
|
||||
m_ptr = 0;
|
||||
m_state = 0;
|
||||
}
|
||||
|
||||
#endif /* SDRBASE_DSP_INTHALFBANDFILTEREO_H_ */
|
@ -202,20 +202,20 @@ void UpChannelizer::applyConfiguration()
|
||||
}
|
||||
|
||||
UpChannelizer::FilterStage::FilterStage(Mode mode) :
|
||||
m_filter(new IntHalfbandFilterDB<UPCHANNELIZER_HB_FILTER_ORDER>),
|
||||
m_filter(new IntHalfbandFilterEO1<UPCHANNELIZER_HB_FILTER_ORDER>),
|
||||
m_workFunction(0)
|
||||
{
|
||||
switch(mode) {
|
||||
case ModeCenter:
|
||||
m_workFunction = &IntHalfbandFilterDB<UPCHANNELIZER_HB_FILTER_ORDER>::workInterpolateCenter;
|
||||
m_workFunction = &IntHalfbandFilterEO1<UPCHANNELIZER_HB_FILTER_ORDER>::workInterpolateCenter;
|
||||
break;
|
||||
|
||||
case ModeLowerHalf:
|
||||
m_workFunction = &IntHalfbandFilterDB<UPCHANNELIZER_HB_FILTER_ORDER>::workInterpolateLowerHalf;
|
||||
m_workFunction = &IntHalfbandFilterEO1<UPCHANNELIZER_HB_FILTER_ORDER>::workInterpolateLowerHalf;
|
||||
break;
|
||||
|
||||
case ModeUpperHalf:
|
||||
m_workFunction = &IntHalfbandFilterDB<UPCHANNELIZER_HB_FILTER_ORDER>::workInterpolateUpperHalf;
|
||||
m_workFunction = &IntHalfbandFilterEO1<UPCHANNELIZER_HB_FILTER_ORDER>::workInterpolateUpperHalf;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -23,7 +23,7 @@
|
||||
#include <QMutex>
|
||||
#include "util/export.h"
|
||||
#include "util/message.h"
|
||||
#include "dsp/inthalfbandfilterdb.h"
|
||||
#include "dsp/inthalfbandfiltereo1.h"
|
||||
|
||||
#define UPCHANNELIZER_HB_FILTER_ORDER 96
|
||||
|
||||
@ -69,8 +69,8 @@ protected:
|
||||
ModeUpperHalf
|
||||
};
|
||||
|
||||
typedef bool (IntHalfbandFilterDB<UPCHANNELIZER_HB_FILTER_ORDER>::*WorkFunction)(Sample* sIn, Sample *sOut);
|
||||
IntHalfbandFilterDB<UPCHANNELIZER_HB_FILTER_ORDER>* m_filter;
|
||||
typedef bool (IntHalfbandFilterEO1<UPCHANNELIZER_HB_FILTER_ORDER>::*WorkFunction)(Sample* sIn, Sample *sOut);
|
||||
IntHalfbandFilterEO1<UPCHANNELIZER_HB_FILTER_ORDER>* m_filter;
|
||||
WorkFunction m_workFunction;
|
||||
|
||||
FilterStage(Mode mode);
|
||||
|
Loading…
Reference in New Issue
Block a user