I'm working with a XK-AUDIO-316-MC-AB demo board and I installed all the tools (XTC Tools 15.3, CMake, VS code, ...). I tried different examples and everything works fine.
Now I'd like to add some DSP elaboration starting from the example AN00246_xua_example. From doc AN01008 I followed the section Executing the DSP on the other physical core and I tried to add a comunication channel between the core that handles the USB audio and a new core that performs the DSP operation.
Unfortunately it doesn't work. I have some questions about this example:
- the dsp_filters_biquads is a function for xCORE-200, how I can replace to work with xcore.ai?
- Do I have to modify the UserBufferManagement inside the lib_xua?
- This example it's a good starting point to try the DSP capabilities of the xcore.ai processor?
Add DSP to lib_xua example
-
- Junior Member
- Posts: 4
- Joined: Fri Jan 10, 2025 10:13 am
-
- XCore Addict
- Posts: 246
- Joined: Mon Jan 08, 2018 4:14 pm
Hi Stephen,
AN00246 is a good start for testing dsp stuff, because you can start your dsp engine in the app_xua_example.xc easily. this is also where you will define your channels which are needed by the dsp task and the UserBufferManagement to talk to each other.
you do not have to modify lib_xua, just create your own UserBufferManagement function in you source code and make them global, as there are place holder defined as weak in lib_xua. Your own will replace the weak.
in lib_xcore_math/arch/xs3 you will find the biquad function in assembly file, made to produce 8 biquad in a raw. I let you find the dependencies and the header.h file in the api... be careful these routines have a worse thd+n than the xs2 routines. see AN02004
don't hesitate to share progress
fabriceo
AN00246 is a good start for testing dsp stuff, because you can start your dsp engine in the app_xua_example.xc easily. this is also where you will define your channels which are needed by the dsp task and the UserBufferManagement to talk to each other.
you do not have to modify lib_xua, just create your own UserBufferManagement function in you source code and make them global, as there are place holder defined as weak in lib_xua. Your own will replace the weak.
in lib_xcore_math/arch/xs3 you will find the biquad function in assembly file, made to produce 8 biquad in a raw. I let you find the dependencies and the header.h file in the api... be careful these routines have a worse thd+n than the xs2 routines. see AN02004
don't hesitate to share progress
fabriceo
-
- Junior Member
- Posts: 4
- Joined: Fri Jan 10, 2025 10:13 am
Finally I was able to filter the input signal with a very simple FIR. Here the code:
Then I tried to set up a communication channel between the UserBufferManagement and a new task as follow:
I add the libraries:
and in my main function I add this:
but I have several error, I can't understand how to set up a channel communication between tasks.
And VS code shows me #include errors detected with every include I have in this example project. Is there a guide to setup correctly VS code to work with xmos?
Code: Select all
#include "xcore_math.h"
#include <stdio.h>
#include <stdlib.h>
#define NUM_INPUTS 2
#define NUM_OUTPUTS 2
#define TAP_COUNT (35)
filter_fir_s32_t filter;
int32_t WORD_ALIGNED coefficients[TAP_COUNT] = {0};
int32_t WORD_ALIGNED sample_buffer[TAP_COUNT] = {0};
/**
* How to choose the final shift factor for a filter is beyond the scope of this example, but
* here a final scale of 2 bits seems to work correctly. Note that this shift is unsigned
* (i.e. negative values are treated as large right-shifts; they will not left-shift).
*/
right_shift_t filter_shr = 2;
void initialize_filter()
{
for(int lag = 0; lag < TAP_COUNT; lag++)
{
coefficients[lag] = 0;
}
coefficients[0] = 1 << 30;
filter_fir_s32_init(&filter, sample_buffer, TAP_COUNT, coefficients, filter_shr);
}
void UserBufferManagement(unsigned output_samples[NUM_OUTPUTS],
unsigned input_samples[NUM_INPUTS])
{
output_samples[0] =filter_fir_s32(&filter, output_samples[0]);
}
void UserBufferManagementInit()
{
initialize_filter();
}
Code: Select all
static chanend_t g_c;
void UserBufferManagement(unsigned output_samples[NUM_OUTPUTS],
unsigned input_samples[NUM_INPUTS])
{
chan_out_buf_word (g_c , (uint32_t *) output_samples , NUM_OUTPUTS );
chan_out_buf_word (g_c , (uint32_t *) input_samples , NUM_INPUTS );
chan_in_buf_word ( g_c , (uint32_t *) output_samples , NUM_OUTPUTS );
chan_in_buf_word ( g_c , (uint32_t *) input_samples , NUM_INPUTS );
}
void UserBufferManagementSetChan(chanend_t c)
{
g_c = c;
}
Code: Select all
#include "xcore/chanend.h"
#include "xcore/channel.h"
and in my main function I add this:
Code: Select all
chan c_data_transport;
on tile[1]: {
UserBufferManagementSetChan(c_data_transport);
}
And VS code shows me #include errors detected with every include I have in this example project. Is there a guide to setup correctly VS code to work with xmos?