AnsweredAssumed Answered

BF706 Fir filter codec problem?

Question asked by jie070428 on Aug 9, 2018
Latest reply on Aug 14, 2018 by jie070428

This is my programming code for the fir filter, I use the filter header file in the routine, my filter coefficient uses the data type long double, and my program uses the fract32 type, I have data on it. Conversion. I have been unable to achieve the effect of the fir filter, I hope you can help me solve it, or can you upload your fir program code? Thank you very much!

 

 

#include <filter.h>
#include <fract2float_conv.h>
#include <fract.h>
#include "AudioCallback.h"
#define NUM_STAGES 19
#define SAMPLES_PER_CHAN 32
fract32 inLeft[SAMPLES_PER_CHAN];
fract32 inRight[SAMPLES_PER_CHAN];
fract32 outLeft[SAMPLES_PER_CHAN];
fract32 outRight[SAMPLES_PER_CHAN];
/* Filter coefficients generated by a filter design tool */
long double a_coeffs_low_1khz[ NUM_STAGES+ 1] = {
0.0056875030502704814L,
0.0077454009452989012L,
0.013373821271223L,
0.022490889801401574L,
0.034509874043985686L,
0.048390349721389926L,
0.062759053391392025L,
0.076084405100706562L,
0.08687990466444219L,
0.093906594457164302L,
0.093906594457164302L,
0.08687990466444219L,
0.076084405100706562L,
0.062759053391392025L,
0.048390349721389926L,
0.034509874043985686L,
0.022490889801401574L,
0.013373821271223L,
0.0077454009452989012L,
0.0056875030502704814L};
fract32 long_double_to_fr32 (long double a_coeffs_low_1khz);
/* Coefficients and delay line for the iir function */
fract32 df1_coeffs[(2 * NUM_STAGES) + 2];
fract32 delayLeft[(2 * NUM_STAGES) + 2];
fract32 delayRight[(2 * NUM_STAGES) + 2];
fir_state_fr32 stateLeft;
fir_state_fr32 stateRight;
/* initialize the IIR filter */
void FilterInit(FILTER_MODE mode)
{
int i;
/* Configure filter state */
fir_init (stateLeft, a_coeffs_low_1khz, delayLeft, (NUM_STAGES+1),1);
fir_init (stateRight, a_coeffs_low_1khz, delayRight, (NUM_STAGES+1),1);
/* Zero delay line to start or reset the filter */
for (i = 0; i < ((2 * NUM_STAGES) + 2); i++)
{
delayLeft[i] = 0;
delayRight[i] = 0;
}
}

/* Compute filter response */
void AudioFilter(const fract32 dataIn[], fract32 dataOut[])
{
int n;
int i;

/* separate channels (2D DMA would be better) */
i = 0;
for (n=0; n<SAMPLES_PER_CHAN; n++){
inLeft[n] = dataIn[i++];
inRight[n] = dataIn[i++];
}

/* left channel filter */
fir_fr32 (inLeft, outLeft, SAMPLES_PER_CHAN, &stateLeft);

/* right channel filter */
fir_fr32 (inRight, outRight, SAMPLES_PER_CHAN, &stateRight);

/* combine channels (2D DMA would be better) */
i = 0;
for (n=0; n<SAMPLES_PER_CHAN; n++){
dataOut[i++] = outLeft[n];
dataOut[i++] = outRight[n];
}

}

Outcomes