XK‑EVK‑XU316 & sw_usb_audio: Line‑In Noise with No Input & Stereo→Mono Conversion Topic is solved

Discussions about USB Audio on XMOS devices
gunesgrkn
Junior Member
Posts: 6
Joined: Wed Jul 23, 2025 8:01 am

XK‑EVK‑XU316 & sw_usb_audio: Line‑In Noise with No Input & Stereo→Mono Conversion

Post by gunesgrkn »

Hello everyone,

I’m using the XK‑EVK‑XU316 board with the sw_usb_audio reference design, and it’s working great—thank you for that! However, I have two questions I’d appreciate your advice on:
1) Line‑In Noise When Nothing Is Connected
Even with nothing plugged into the line‑in jack, I still see an audio input “hiss” or interference.
I suspect this is due to the floating input picking up electromagnetic/thermal noise.
What are your recommendations for eliminating this?
Hardware: pull-down resistors, jack‑detect switch, better grounding or shielding?
Software: noise gate, muting when no signal detected, any built‑in API in sw_usb_audio?

2) Converting Stereo Input to Mono
I want the firmware to send only a single channel (mono) over USB instead of stereo.
Is it sufficient to set I2S_CHANS_ADC = 1 and I2S_CHANS_DAC = 1 in xua_conf.h, or do I need to override the sample‑transfer code (e.g. DoSampleTransfer or AudioHub) to implement a proper down‑mix?
What approaches have you used successfully in this library or on this platform?
Any pointers, code snippets, or forum links you can share would be very helpful.

Thanks in advance for your help!

Best regards,
Gürkan
View Solution
User avatar
Ross
Verified
XCore Legend
Posts: 1252
Joined: Thu Dec 10, 2009 9:20 pm
Location: Bristol, UK

Post by Ross »

Welcome :)

I'll leave 1) to the HW guru(s) on here..

For 2)

If you want 2 channels of I2S -> 1 channel USB you'll want to set some defines as following

I2S_CHANS_DAC = 0 // Number of i2s output channels from xcore
I2S_CHANS_ADC = 2 // Number of i2s input channels to xcore - should be 2 already

NUM_USB_CHAN_IN = 1 // Number of channels to USB host
NUM_USB_CHAN_OUT = 2 // Number of channels from USB host

(OUT/IN is from the host's perspective - this is standard USB nomenclature)

Set these in your xua_conf.h file.

For your stereo down mix, you could use the provided mixer for this, but for your app this could be deemed a bit over kill.

There is a function that you can over-ride - UserBufferManagement() - that was originally put in the cocode for dealing with simple loop backs etc.
However, it's been used ALOT for a place to inject DSP processing - we probably should update the name at this point.. (the default implementation is empty)

Anywho, you can add your down-mix here. You'll want to be a bit careful with your types to avoid overflow.

Something like the following (i made the code a bit more verbose than i might ordinarily to try an make it a bit clearer whats going on..

Code: Select all

void UserBufferManagement(unsigned sampsFromUsbToAudio[], unsigned sampsFromAudioToUsb[])
{
    int32_t left = (int32_t)sampsFromAudioToUsb[0];
    int32_t right = (int32_t)sampsFromAudioToUsb[1];

    int64_t mixed = (int64_t)left + (int64_t)right;
    mixed /= 2;

    sampsFromAudioToUsb[0] = (unsigned) mixed;
    sampsFromAudioToUsb[1] = 0; //seemed like a good idea 
}
Stick that in a file somewhere in your project source tree and the build system will find it.

I've not compiled or tested this... You'll likely want to deal with saturation (if (mixed > (int64_t)INT32_MAX) mixed =(int64_t) INT32_MAX etc)
if you're doing a lot of channels you might want to use the xcore MACS and LSATS instructions inline.

You should also note that the single channel device use case is not tested - multiples of two are the normal use case.
I'd start with NUM_USB_CHAN_IN =2 and sort the mixing out before dealing with that - if there is an issue id probably just ignore the "right" channel in the host - unless there is a specific issue with doing that

Good luck with your project :)
Technical Director @ XMOS. Opinions expressed are my own
Joe
Verified
Experienced Member
Posts: 126
Joined: Sun Dec 13, 2009 1:12 am

Post by Joe »

I haven't been able to recreate any noise on inputs. See:

https://github.com/xmos/sw_usb_audio/issues/298

What was your setup for measuring this noise?

Joe
XMOS hardware grey beard.
User avatar
Ross
Verified
XCore Legend
Posts: 1252
Joined: Thu Dec 10, 2009 9:20 pm
Location: Bristol, UK

Post by Ross »

Did you get your down mix working?
Technical Director @ XMOS. Opinions expressed are my own
gunesgrkn
Junior Member
Posts: 6
Joined: Wed Jul 23, 2025 8:01 am

Post by gunesgrkn »

yes. it is a good.
thanks for all.