XCORE-200 Multichannel Audio DSP App Note?

Technical discussions related to any XMOS development kit or reference design. Eg XK-1A, sliceKIT, etc.
rlim
Member++
Posts: 16
Joined: Wed May 12, 2010 10:00 pm

XCORE-200 Multichannel Audio DSP App Note?

Post by rlim »

Hi,
Will there be a sequel to 'Adding DSP to the USB Audio 2.0 L1 Reference Design' for the XCORE-200 Multichannel Audio version? In particular, I would like to do digital crossovers where I split the single channel into 2 audio outputs. Presumably, the samples get fed into the biquad core with 2 separate filter coefficients for say high and low-pass. And I suppose 2 audio driver cores should be instantiated operating in parallel? Not really a coder, but stitching parts into the reference code, that I can do. An app note would be great.
Thanks,
Richard


User avatar
infiniteimprobability
XCore Legend
Posts: 1126
Joined: Thu May 27, 2010 10:08 am
Contact:

Post by infiniteimprobability »

Hi,
nothing planned at this stage. I could look into making a quick example if you'd like? There are hooks into main{} without having to get too dirty in the ref design..
User avatar
infiniteimprobability
XCore Legend
Posts: 1126
Joined: Thu May 27, 2010 10:08 am
Contact:

Post by infiniteimprobability »

Here you go. A simple dsp in output datapath example. Takes channels 0 & 1 of the output, sends them to a DSP thread which generates 4 processed channels and outputs them on 0..3 of the DAC.

Make the following changes to audio.xc (to tap into the audio path):

Code: Select all

@@ -34,6 +34,15 @@
 
 #include "print.h"
 
+#include "user_dsp.h"
+unsafe streaming chanend c_dsp_glob; /* Datapath to DSP tasks. We use a global channel end to avoid plumbing all through the USB audio stack */
+void dsp_init_chanend(streaming chanend c_dsp)
+{
+    unsafe {
+        c_dsp_glob = (unsafe streaming chanend) c_dsp;
+    }
+}
+
 static unsigned samplesOut[NUM_USB_CHAN_OUT];
 
 /* Two buffers for ADC data to allow for DAC and ADC ports being offset */
@@ -268,6 +277,11 @@ static inline unsigned DoSampleTransfer(chanend c_out, const int readBuffNo, con
 #else
         inuint(c_out);
 #endif
+        unsafe{
+            for(int i=0; i<N_CHANS_DSP_PRE; i++) c_dsp_glob <: samplesOut[i];
+            for(int i=0; i<N_CHANS_DSP_POST; i++) c_dsp_glob :> samplesOut[i];
+        }
+
 #if NUM_USB_CHAN_IN > 0
 #pragma loop unroll
 #if  NUM_USB_CHAN_IN < I2S_CHANS_ADC
Please see here https://unix.stackexchange.com/question ... iff-output if you need help on diff format


and add these files to src/extensions/
Attachments
user_main.h
(411 Bytes) Downloaded 661 times
user_main.h
(411 Bytes) Downloaded 661 times
user_dsp.xc
(796 Bytes) Downloaded 689 times
user_dsp.xc
(796 Bytes) Downloaded 689 times
user_dsp.h
(309 Bytes) Downloaded 656 times
user_dsp.h
(309 Bytes) Downloaded 656 times
rlim
Member++
Posts: 16
Joined: Wed May 12, 2010 10:00 pm

Post by rlim »

Are the above 2 lines legitimate code, or was it a cut and paste anomaly:
@@ -34,6 +34,15 @@

@@ -268,6 +277,11 @@ static inline unsigned DoSampleTransfer(chanend c_out, const int readBuffNo, con

Thanks!
User avatar
infiniteimprobability
XCore Legend
Posts: 1126
Joined: Thu May 27, 2010 10:08 am
Contact:

Post by infiniteimprobability »

If you follow the link I provided you'll see it's unified diff format. I didn't want to paste a whole file for software that is controlled under a click through license. Explanation as follows:

@@ -34,6 +34,15 @@

means:

at line 34 in the original file, 6 lines were turned into 15 with the change. The additions will be shown as + and subtractions (of which there are none in this case) are shown as -

If you don't want to apply this as a patch using a tool, then just add the + lines at line 34 (removing the leading+) and then the next block of + lines at line 268 (if done before the first change) or at line 277 if you already applied the first block
User avatar
infiniteimprobability
XCore Legend
Posts: 1126
Joined: Thu May 27, 2010 10:08 am
Contact:

Post by infiniteimprobability »

rlim, how did you get on? Did this work? If so let us know as this is quite a common requirement and the thread may help others.

Thanks!!
rlim
Member++
Posts: 16
Joined: Wed May 12, 2010 10:00 pm

Post by rlim »

Thanks for your replies. I haven't been working on this actively. I wish I could. I think you have given enough information for almost anyone to proceed. I will definitely update here once I make some headway. Really appreciate your direction.
alexjaw
Active Member
Posts: 35
Joined: Wed Jan 24, 2018 9:13 am

Post by alexjaw »

This is a very good example for how to intercept the audio stream in the framework - thank's infiniteimprobability!
Ram
Junior Member
Posts: 7
Joined: Fri Oct 27, 2017 6:59 am

Post by Ram »

I tried the above code sample from @infiniteimprobability and got it to work pretty much out of the box on Linux Mint 17 with the USB 2.0 Audio Multichannel board. Thanks!
I then tried to insert a biquad filter into the above code but am getting stuck there. I borrowed the build_biquad_coefficients and module_biquad from sc_dsp_filters after reading AN01008 (which is meant for L1 though) and managed to build it successfully with the app_usb_aud_xk_216_mc. However when I merely insert ANY call to biquadAsm or biquadCascade as shown below, the thing seems to hang because the board does not show up in my computer at all. Is this the wrong biquad to adapt? Should I use lib_dsp instead? Any pointers would be greatly appreciated.
Thanks! - Ram

void user_dsp(streaming chanend c_dsp)
{
//Do DSP. Note we do after sample exchange (reduce pressure on audio task)
samps_dsp_post[0] = samps_dsp_pre[0];
samps_dsp_post[1] = samps_dsp_pre[1] >> 3; //attenuate by 18dB
samps_dsp_post[2] = samps_dsp_pre[0] >> 3; //attenuate by 18dB
samps_dsp_post[3] = samps_dsp_pre[1];

biquadCascade(bs[0], samps_dsp_post[0]); // INSERTION OF A MERE CALL to biquadCascade HERE CAUSES PROBLEMS

}//While(1)
Ram
Junior Member
Posts: 7
Joined: Fri Oct 27, 2017 6:59 am

Post by Ram »

OK, I think I was barking up the wrong tree here. I guess I just need to use lib_dsp instead of sc_dsp_filters. I tried a biquad using lib_dsp and it works fine. Is there is any reason to look at sc_dsp_filters for the XCORE chips?
Post Reply