dsp_filters_biquad from lib_dsp on XCORE-200

If you have a simple question and just want an answer.
Unchyu2
Member++
Posts: 29
Joined: Tue Jun 17, 2014 11:40 am

dsp_filters_biquad from lib_dsp on XCORE-200

Post by Unchyu2 »

Hello,

I want to test out the functions from lib_dsp and I started with dsp_filters_biquad.
I read through the xCORE-200 DSP Library and I inserted the following code in my main processing loop:

Code: Select all

    int32_t filter_coeff[DSP_NUM_COEFFS_PER_BIQUAD] = { Q28(+0.998), Q28(-1.996), Q28(0.998),Q28(+1.996), Q28(-0.996) };
    int32_t filter_state[DSP_NUM_STATES_PER_BIQUAD] = { 0, 0, 0, 0 };
    for (int i = 0; i < NUM_USB_CHAN_IN/2; i++){
        int32_t result= dsp_filters_biquad(samplesIn[NUM_USB_CHAN_IN/2 + i] , filter_coeff, filter_state, 28 );
    }
the code compiles fine but when I run it on my device I get the following error:

Code: Select all

xrun: Program received signal ET_LOAD_STORE, Memory access exception.
      dsp_filters_biquad (input_sample=0, filter_coeffs=0x7fcdc, state_data=0x7fccc, q_format=28) at C:/Users/betatester1/Desktop/XMOS_Projects/SI_SI24/lib_dsp/src\dsp_filters.c:1087
      1087	    asm("ldd %0,%1,%2[0]":"=r"(c2),"=r"(c1):"r"(filter_coeffs));
      Current language:  auto; currently minimal
The values for samplesIn[] are received through a channel from the Audio core, the values for filter_coeff were computed using MatLab to stand for a High Pass Filter,
I have updated XtimeComposer to the latest version 14.2.1, I have the latest version of lib_dsp (3.0.0) and I am using a custom board that has the XU216-512-TQ128 uP.
If I remove the call to dsp_filters_biquad() and run the code, the board performs correctly.

Any help is appreciated,
Ilie


Gothmag
XCore Addict
Posts: 129
Joined: Wed May 11, 2016 3:50 pm

Post by Gothmag »

Code: Select all

for (int i = 0; i < NUM_USB_CHAN_IN/2; i++){
        int32_t result= dsp_filters_biquad(samplesIn[NUM_USB_CHAN_IN/2 + i] , filter_coeff, filter_state, 28 );}
samplesIn[NUM_USB_CHAN_IN/2 + i]
Is that really what you want to pass in? I would imagine you should just be using i.

Code: Select all

for (int i = 0; i < NUM_USB_CHAN_IN/2; i++){
        int32_t result= dsp_filters_biquad(samplesIn[i] , filter_coeff, filter_state, 28 );}
Unchyu2
Member++
Posts: 29
Joined: Tue Jun 17, 2014 11:40 am

Post by Unchyu2 »

I wanted to apply the DSP only to the second half of the AudioIn channels.
I later saw that I was using a single filter to process all the channels, which is not good, I should have declared a different vector of filter states for each channel.

Putting that aside, I rewrote my code to apply DPS only to the first channel:

Code: Select all

    int32_t filter_coeff[DSP_NUM_COEFFS_PER_BIQUAD] = { Q28(+0.998), Q28(-1.996), Q28(0.998),Q28(+1.996), Q28(-0.996) };
    int32_t filter_state[DSP_NUM_STATES_PER_BIQUAD] = { 0, 0, 0, 0 };
 while (1)    {
            // ...
            // GetSamplesFromDevice
#pragma loop unroll
            for (int i=0 ;i < NUM_USB_CHAN_IN; i++){
                sample = inuint(c_Audio);
                samplesIn[i]=sample;
            }
            // ...
    int32_t result= dsp_filters_biquad(samplesIn[0] , filter_coeff, filter_state, 28 );
            // ...
    }
But it yields the same Memory exception
User avatar
andrew
Experienced Member
Posts: 114
Joined: Fri Dec 11, 2009 10:22 am

Post by andrew »

Try declaring arrays globally so that they are double word aligned. The library may assume that for performance.
Unchyu2
Member++
Posts: 29
Joined: Tue Jun 17, 2014 11:40 am

Post by Unchyu2 »

Thank you,
That solved my problem, and the biquad behaves as intended.