Stereo downmix multichannel audio

Sub forums for various specialist XMOS applications. e.g. USB audio, motor control and robotics.
lnnzgs
New User
Posts: 2
Joined: Tue Nov 26, 2019 1:20 pm

Stereo downmix multichannel audio

Postby lnnzgs » Thu Jan 16, 2020 1:40 pm

Hi there,

I'm planning to implement a stereo downmix for the 8 channels coming from USB to the two channels on analog output.
(I'm working on the xk-audio-216-mc board)

Firstly I've try to convert stereo to mono with something like this at the end of audio.xc@DoSampleTransfer

Code: Select all

unsigned left = samplesOut[0] / 2;
unsigned right = samplesOut[1] / 2;
unsigned mono = left + right;

samplesOut[0] = mono;
But it's just produce noise on output..

After reading this thread USB Audio Reference Changes

I've also try

Code: Select all

samplesOut[0] = (samplesOut[0] >> 1) + (samplesOut[1] >> 1);
But same result

These two solutions don't produce noise only when I've the same signal on both input channels.

Can you tell me if I've miss something please ?
User avatar
CousinItt
XCore Addict
Posts: 165
Joined: Wed May 31, 2017 6:55 pm

Postby CousinItt » Thu Jan 16, 2020 6:11 pm

Are you sure the samples are unsigned? I'd expect a signed type.
User avatar
akp
Respected Member
Posts: 381
Joined: Thu Nov 26, 2015 11:47 pm

Postby akp » Fri Jan 17, 2020 3:21 pm

You could try

Code: Select all

samplesOut[0] = (unsigned)((int)samplesOut[0] >> 1) + ((int)samplesOut[1] >> 1);
this will generate arithmetic shift right rather than logical shift right, retaining the correct sign bit
lnnzgs
New User
Posts: 2
Joined: Tue Nov 26, 2019 1:20 pm

Postby lnnzgs » Tue Jan 21, 2020 10:14 am

From the usb audio software provided by xmos :

Code: Select all

static unsigned samplesOut[NUM_USB_CHAN_OUT];

/* Two buffers for ADC data to allow for DAC and ADC ports being offset */
static unsigned samplesIn_0[NUM_USB_CHAN_IN];
static unsigned samplesIn_1[I2S_CHANS_ADC];
...
#if NUM_USB_CHAN_OUT > 0
#pragma loop unroll
        for(int i = 0; i < NUM_USB_CHAN_OUT; i++)
        {
            int tmp = inuint(c_out);
            samplesOut[i] = tmp;
        }
#else
        inuint(c_out);
#endif
Thanks a lot, it seems ok if I use tmp or if I cast samples as int before sending them to my mixer

Do you know why samples array are declared as unsigned ?
User avatar
CousinItt
XCore Addict
Posts: 165
Joined: Wed May 31, 2017 6:55 pm

Postby CousinItt » Wed Jan 22, 2020 1:13 pm

It may be just for convenience or to avoid warnings. The basic data transfer functions for channels only deal with unsigned data.

Who is online

Users browsing this forum: No registered users and 0 guests