Stereo downmix multichannel audio

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

Stereo downmix multichannel audio

Post by lnnzgs »

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
Respected Member
Posts: 360
Joined: Wed May 31, 2017 6:55 pm

Post by CousinItt »

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

Post by akp »

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

Post by lnnzgs »

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
Respected Member
Posts: 360
Joined: Wed May 31, 2017 6:55 pm

Post by CousinItt »

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