#include
#include
void test_IPPTest2() {
// In this test we create two different resample objects with different kaiser window parameters (diffeent FIR coeffs)
// For the first object: we get the filters coeffcients (pFilter1) and also ressample a dirac (to see filter IR). We see in the output ressampled signal the impulse response of the filter.
// For the second object: we set a new filter to the ressampler with the SETFilter method: we set first filter coeffcients (pFilter1). Then we also ressample a dirac (to see the new filter IR, that should be the same as the first)
// We observe that in second filter, the first coefficient of the dirac corresponds to the first sample of its initial filter before setting the coefficeients of 1st filter to the second filter (the one created at Initi of the second filter).
// That seems to me a bug or I am usign not correctly the methods.
// STEP 0: basic configuration + creation of signals
//Basic test where I try to use an external FIR set of coefficients and check if I find them in the correct order on the impulse response
unsigned int kfs = 44100; //samplerate
const unsigned int upSampFactor = 2;
//input signals to resample: a dirac function
static constexpr unsigned int kInL = 200;
float sdiracinput[kInL];
for (unsigned int s = 0; s < kInL; ++s) { //init array with zeros
sdiracinput[s] = 0.f;
}
int diracPos = 5; //set a unity sample at position diracPos
sdiracinput[diracPos] = 1.f;
float sOut1[kInL * upSampFactor]; //buffer where put the output resampled signal for first resampler
float sOut2[kInL * upSampFactor]; //buffer where put the output resampled signal for second resampler
for (unsigned int s = 0; s < kInL * upSampFactor; ++s) { //init arrays with zeros
sOut1[s] = 0.f;
sOut2[s] = 0.f;
}
auto L = kInL / 2; //The number of input vector elements to resample.
IppsResamplingPolyphaseFixed_32f* m_state1; //resampling object 1
IppsResamplingPolyphaseFixed_32f* m_state2; //resampling object 1
Ipp32f* pExtFIRCoefs; //buffer with the external filter coefficients
float* pFilter1 = NULL;
// history_length : this is the variable that defines how much points has the filter.
int history_length = 3;
int inRate = kfs; int outRate = kfs * upSampFactor; // M=2 configuration
{ //First filter
// Ressampling basic creation (GetSize + Init functions)
int specSize = 0; int len = 0; int height = 0; //these 3 vars are filled by GetSize
IppStatus getSize_IppStatus = ippsResamplePolyphaseFixedGetSize_32f(inRate, outRate, 2 * (history_length - 1), &specSize, &len, &height, ippAlgHintFast); //we can also choose ippAlgHintAccurate
auto statusSize = ippGetStatusString(getSize_IppStatus);
m_state1 = (IppsResamplingPolyphaseFixed_32f*)ippsMalloc_8u(specSize);
IppStatus init_IppStatus = ippsResamplePolyphaseFixedInit_32f(inRate, outRate, 2 * (history_length - 1), 0.95f, 5.0f, m_state1, ippAlgHintFast); //rollf= 0.95 , alpha = 5.0 are the parameters to define the FIR filter
auto statusInit = ippGetStatusString(init_IppStatus);
// Get filter object (coefficients) of the first ressampling object and save it on pFilter1
pFilter1 = ippsMalloc_32f(len * height);
IppStatus init_GetFiltStatus = ippsResamplePolyphaseGetFixedFilter_32f(pFilter1, len, height, m_state1);
auto statusGetFilt = ippGetStatusString(init_GetFiltStatus);
// Resampling a dirac with the first ressampler object
Ipp64f ptime = len / 2;
int outLen = 0; //The number of calculated output vector elements (to be updated by ResamplePolyphase function)
Ipp32f norm = 1.f; //The norm factor for output samples (we set to one to observe FIR impulse repsonse)
IppStatus resamp_IppStatus = ippsResamplePolyphaseFixed_32f(sdiracinput, L, sOut1, norm, &ptime, &outLen, m_state1);
auto statusResamp = ippGetStatusString(resamp_IppStatus);
//sOut1 contains the impulse repsonse of the first filter
}
{ //Second filter
// Ressampling basic creation (GetSize + Init functions)
int specSize = 0; int len2 = 0; int height2 = 0; //these 3 vars are filled by GetSize
IppStatus getSize_IppStatus = ippsResamplePolyphaseFixedGetSize_32f(inRate, outRate, 2 * (history_length - 1), &specSize, &len2, &height2, ippAlgHintFast); //we can also choose ippAlgHintAccurate
auto statusSize = ippGetStatusString(getSize_IppStatus);
m_state2 = (IppsResamplingPolyphaseFixed_32f*)ippsMalloc_8u(specSize); //in resampler.cpp we use ippsMalloc_8u (and in demo code also). Which is the difference ?
IppStatus init_IppStatus = ippsResamplePolyphaseFixedInit_32f(inRate, outRate, 2 * (history_length - 1), 0.95f, 9.0f, m_state2, ippAlgHintFast); //rollf= 0.95 , alpha = 9.0 (changing alpha changes the coefficients)
auto statusInit = ippGetStatusString(init_IppStatus);
const bool flag_test__get_internal_filter = false; //just for information purposes , if true we read the coeffcients of the FIR defined by the init function
float* pFilter = NULL;
if (flag_test__get_internal_filter) {
pFilter = ippsMalloc_32f(len2 * height2);
IppStatus init_GetFiltStatus = ippsResamplePolyphaseGetFixedFilter_32f(pFilter, len2, height2, m_state2);
auto statusGetFilt = ippGetStatusString(init_GetFiltStatus);
}
// STEP 2: Set an external FIR coefficients to the ressampling object (we set the coefficients of first ressampler to this second ressampler)
IppStatus setFilt_IppStatus = ippsResamplePolyphaseSetFixedFilter_32f((const Ipp32f*)pFilter1, len2, height2, (IppsResamplingPolyphaseFixed_32f*)m_state2);
auto statusSetFilt = ippGetStatusString(setFilt_IppStatus);
{ //In case we want to recover the filter coefficients we can set the flag to true and break after the GetFilter
bool flag_verif_filter = false;
if (flag_verif_filter) {
float* pFilterVerif = ippsMalloc_32f(len2 * height2);
IppStatus init_GetFiltStatus2 = ippsResamplePolyphaseGetFixedFilter_32f(pFilterVerif, len2, height2, m_state2);
auto statusGetFilt2 = ippGetStatusString(init_GetFiltStatus2);
}
}
// Resampling configuration + resampling
Ipp64f ptime = len2 / 2;
int outLen = 0; //The number of calculated output vector elements (to be updated by ResamplePolyphase function)
Ipp32f norm = 1.f; //The norm factor for output samples.
IppStatus resamp_IppStatus = ippsResamplePolyphaseFixed_32f(sdiracinput, L, sOut2, norm, &ptime, &outLen, m_state2);
auto statusResamp = ippGetStatusString(resamp_IppStatus);
//sOut2 should contain the impulse repsonse of the first filter because we have make a SetFixedFilter to the second ressampler using the filter from first ressampler
//however the first coefficient we observe on the impulse response correspond to the coefficient of the initial filter of ressampler 2 (rollf= 0.95 , alpha = 9.0)
}
bool break_here = true; // line added to break at the end and be able to check all the variables
}