mirror of
https://github.com/f4exb/sdrangel.git
synced 2024-11-26 17:58:43 -05:00
IntHalfbandFilterEO1: Optimized versions of workInterpolateCenter and myInterpolate
This commit is contained in:
parent
822fff3aac
commit
a60e2b7597
@ -587,6 +587,7 @@ public:
|
|||||||
m_ptr = HBFIRFilterTraits<HBFilterOrder>::hbMod[m_ptr + 2 - 1];
|
m_ptr = HBFIRFilterTraits<HBFilterOrder>::hbMod[m_ptr + 2 - 1];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Optimized upsampler by 2 not calculating FIR with inserted null samples */
|
||||||
void myInterpolateOptimized(qint32 *x1, qint32 *y1, qint32 *x2, qint32 *y2)
|
void myInterpolateOptimized(qint32 *x1, qint32 *y1, qint32 *x2, qint32 *y2)
|
||||||
{
|
{
|
||||||
// insert sample into ring double buffer
|
// insert sample into ring double buffer
|
||||||
|
@ -125,7 +125,6 @@ public:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool workDecimateCenter(qint32 *x, qint32 *y)
|
bool workDecimateCenter(qint32 *x, qint32 *y)
|
||||||
{
|
{
|
||||||
// insert sample into ring-buffer
|
// insert sample into ring-buffer
|
||||||
@ -459,6 +458,7 @@ public:
|
|||||||
advancePointer();
|
advancePointer();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Optimized upsampler by 2 not calculating FIR with inserted null samples */
|
||||||
void myInterpolateOptimized(qint32 *x1, qint32 *y1, qint32 *x2, qint32 *y2)
|
void myInterpolateOptimized(qint32 *x1, qint32 *y1, qint32 *x2, qint32 *y2)
|
||||||
{
|
{
|
||||||
// insert sample into ring double buffer
|
// insert sample into ring double buffer
|
||||||
|
@ -94,6 +94,40 @@ public:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Optimized upsampler by 2 not calculating FIR with inserted null samples */
|
||||||
|
bool workInterpolateCenterOptimized(Sample* sampleIn, Sample *SampleOut)
|
||||||
|
{
|
||||||
|
switch(m_state)
|
||||||
|
{
|
||||||
|
case 0:
|
||||||
|
// return the middle peak
|
||||||
|
SampleOut->setReal(m_samples[m_ptr + (HBFIRFilterTraits<HBFilterOrder>::hbOrder/4) - 1][0]);
|
||||||
|
SampleOut->setImag(m_samples[m_ptr + (HBFIRFilterTraits<HBFilterOrder>::hbOrder/4) - 1][1]);
|
||||||
|
m_state = 1; // next state
|
||||||
|
return false; // tell caller we didn't consume the sample
|
||||||
|
|
||||||
|
default:
|
||||||
|
// calculate with non null samples
|
||||||
|
doInterpolateFIR(SampleOut);
|
||||||
|
|
||||||
|
// insert sample into ring double buffer
|
||||||
|
m_samples[m_ptr][0] = sampleIn->real();
|
||||||
|
m_samples[m_ptr][1] = sampleIn->imag();
|
||||||
|
m_samples[m_ptr + HBFIRFilterTraits<HBFilterOrder>::hbOrder/2][0] = sampleIn->real();
|
||||||
|
m_samples[m_ptr + HBFIRFilterTraits<HBFilterOrder>::hbOrder/2][1] = sampleIn->imag();
|
||||||
|
|
||||||
|
// advance pointer
|
||||||
|
if (m_ptr < (HBFIRFilterTraits<HBFilterOrder>::hbOrder/2) - 1) {
|
||||||
|
m_ptr++;
|
||||||
|
} else {
|
||||||
|
m_ptr = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
m_state = 0; // next state
|
||||||
|
return true; // tell caller we consumed the sample
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
bool workDecimateCenter(int32_t *x, int32_t *y)
|
bool workDecimateCenter(int32_t *x, int32_t *y)
|
||||||
{
|
{
|
||||||
// insert sample into ring-buffer
|
// insert sample into ring-buffer
|
||||||
@ -427,9 +461,34 @@ public:
|
|||||||
advancePointer();
|
advancePointer();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Optimized upsampler by 2 not calculating FIR with inserted null samples */
|
||||||
|
void myInterpolateOptimized(qint32 *x1, qint32 *y1, qint32 *x2, qint32 *y2)
|
||||||
|
{
|
||||||
|
// insert sample into ring double buffer
|
||||||
|
m_samples[m_ptr][0] = *x1;
|
||||||
|
m_samples[m_ptr][1] = *y1;
|
||||||
|
m_samples[m_ptr + HBFIRFilterTraits<HBFilterOrder>::hbOrder/2][0] = *x1;
|
||||||
|
m_samples[m_ptr + HBFIRFilterTraits<HBFilterOrder>::hbOrder/2][1] = *y1;
|
||||||
|
|
||||||
|
// advance pointer
|
||||||
|
if (m_ptr < (HBFIRFilterTraits<HBFilterOrder>::hbOrder/2) - 1) {
|
||||||
|
m_ptr++;
|
||||||
|
} else {
|
||||||
|
m_ptr = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
// first output sample calculated with the middle peak
|
||||||
|
*x1 = m_samples[m_ptr + (HBFIRFilterTraits<HBFilterOrder>::hbOrder/4) - 1][0];
|
||||||
|
*y1 = m_samples[m_ptr + (HBFIRFilterTraits<HBFilterOrder>::hbOrder/4) - 1][1];
|
||||||
|
|
||||||
|
// second sample calculated with the filter
|
||||||
|
doInterpolateFIR(x2, y2);
|
||||||
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
int32_t m_even[2][HBFIRFilterTraits<HBFilterOrder>::hbOrder]; // double buffer technique
|
int32_t m_even[2][HBFIRFilterTraits<HBFilterOrder>::hbOrder]; // double buffer technique
|
||||||
int32_t m_odd[2][HBFIRFilterTraits<HBFilterOrder>::hbOrder]; // double buffer technique
|
int32_t m_odd[2][HBFIRFilterTraits<HBFilterOrder>::hbOrder]; // double buffer technique
|
||||||
|
int32_t m_samples[HBFIRFilterTraits<HBFilterOrder>::hbOrder][2]; // double buffer technique
|
||||||
|
|
||||||
int m_ptr;
|
int m_ptr;
|
||||||
int m_size;
|
int m_size;
|
||||||
@ -579,6 +638,48 @@ protected:
|
|||||||
*x = iAcc >> (HBFIRFilterTraits<HBFilterOrder>::hbShift -1); // HB_SHIFT incorrect do not loose the gained bit
|
*x = iAcc >> (HBFIRFilterTraits<HBFilterOrder>::hbShift -1); // HB_SHIFT incorrect do not loose the gained bit
|
||||||
*y = qAcc >> (HBFIRFilterTraits<HBFilterOrder>::hbShift -1);
|
*y = qAcc >> (HBFIRFilterTraits<HBFilterOrder>::hbShift -1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void doInterpolateFIR(Sample* sample)
|
||||||
|
{
|
||||||
|
qint32 iAcc = 0;
|
||||||
|
qint32 qAcc = 0;
|
||||||
|
|
||||||
|
qint16 a = m_ptr;
|
||||||
|
qint16 b = m_ptr + (HBFIRFilterTraits<HBFilterOrder>::hbOrder / 2) - 1;
|
||||||
|
|
||||||
|
// go through samples in buffer
|
||||||
|
for (int i = 0; i < HBFIRFilterTraits<HBFilterOrder>::hbOrder / 4; i++)
|
||||||
|
{
|
||||||
|
iAcc += (m_samples[a][0] + m_samples[b][0]) * HBFIRFilterTraits<HBFilterOrder>::hbCoeffs[i];
|
||||||
|
qAcc += (m_samples[a][1] + m_samples[b][1]) * HBFIRFilterTraits<HBFilterOrder>::hbCoeffs[i];
|
||||||
|
a++;
|
||||||
|
b--;
|
||||||
|
}
|
||||||
|
|
||||||
|
sample->setReal(iAcc >> (HBFIRFilterTraits<HBFilterOrder>::hbShift -1));
|
||||||
|
sample->setImag(qAcc >> (HBFIRFilterTraits<HBFilterOrder>::hbShift -1));
|
||||||
|
}
|
||||||
|
|
||||||
|
void doInterpolateFIR(qint32 *x, qint32 *y)
|
||||||
|
{
|
||||||
|
qint32 iAcc = 0;
|
||||||
|
qint32 qAcc = 0;
|
||||||
|
|
||||||
|
qint16 a = m_ptr;
|
||||||
|
qint16 b = m_ptr + (HBFIRFilterTraits<HBFilterOrder>::hbOrder / 2) - 1;
|
||||||
|
|
||||||
|
// go through samples in buffer
|
||||||
|
for (int i = 0; i < HBFIRFilterTraits<HBFilterOrder>::hbOrder / 4; i++)
|
||||||
|
{
|
||||||
|
iAcc += (m_samples[a][0] + m_samples[b][0]) * HBFIRFilterTraits<HBFilterOrder>::hbCoeffs[i];
|
||||||
|
qAcc += (m_samples[a][1] + m_samples[b][1]) * HBFIRFilterTraits<HBFilterOrder>::hbCoeffs[i];
|
||||||
|
a++;
|
||||||
|
b--;
|
||||||
|
}
|
||||||
|
|
||||||
|
*x = iAcc >> (HBFIRFilterTraits<HBFilterOrder>::hbShift -1);
|
||||||
|
*y = qAcc >> (HBFIRFilterTraits<HBFilterOrder>::hbShift -1);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
template<uint32_t HBFilterOrder>
|
template<uint32_t HBFilterOrder>
|
||||||
@ -592,6 +693,8 @@ IntHalfbandFilterEO1<HBFilterOrder>::IntHalfbandFilterEO1()
|
|||||||
m_even[1][i] = 0;
|
m_even[1][i] = 0;
|
||||||
m_odd[0][i] = 0;
|
m_odd[0][i] = 0;
|
||||||
m_odd[1][i] = 0;
|
m_odd[1][i] = 0;
|
||||||
|
m_samples[i][0] = 0;
|
||||||
|
m_samples[i][1] = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
m_ptr = 0;
|
m_ptr = 0;
|
||||||
|
Loading…
Reference in New Issue
Block a user