How to get an echo reference (feedback) signal? Topic is solved

New to XMOS and XCore? Get started here.
Post Reply
jamqam
Junior Member
Posts: 6
Joined: Tue Oct 31, 2017 9:44 pm

How to get an echo reference (feedback) signal?

Post by jamqam »

Hello all,

I have an XP-USB-MIC-UF216, and would like to record audio with echo reference signal.
I just wanted to loop back audio output into one of output channels.

After I flashed USB 2.0 reference software from http://www.xmos.com/support/software/uac2, I could successfully record all the 7 microphone signals from the board over an audio editor such as Audacity. The XP-USB-MIC-UF216 has 7 microphones and I believe one channel is available since it outputs 8 channel.
So I just roughly guess maybe I can allocate the 8th channel to loop back audio output.

I'm looking at manuals and source code but I couldn't find any clue yet, even where I should start from.

I'll greatly appreciate it if someone shed a light for me on this or let me know if the board does not support such things, please.

Best,

J


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

Post by infiniteimprobability »

A good place to modify/route signals is in this function

Code: Select all

static inline unsigned DoSampleTransfer(chanend c_out, const int readBuffNo, const unsigned underflowWord)
{
    outuint(c_out, underflowWord);

    /* Check for sample freq change (or other command) or new samples from mixer*/
    if(testct(c_out))
    {
        unsigned command = inct(c_out);
#ifndef CODEC_MASTER
        if(dsdMode == DSD_MODE_OFF)
        {
            // Set clocks low
            p_lrclk <: 0;
            p_bclk <: 0;
        }
        else
        {
#if(DSD_CHANS_DAC != 0)
            /* DSD Clock might not be shared with lrclk or bclk... */
            p_dsd_clk <: 0;
#endif
        }
#endif
#if (DSD_CHANS_DAC > 0)
        if(dsdMode == DSD_MODE_DOP)
            dsdMode = DSD_MODE_OFF;
#endif
#pragma xta endpoint "received_command"
            return command;
    }
    else
    {
#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

<<<<<<<<HERE!>>>>>>>>>

#if NUM_USB_CHAN_IN > 0
#pragma loop unroll
#if  NUM_USB_CHAN_IN < I2S_CHANS_ADC
        for(int i = 0; i < NUM_USB_CHAN_IN; i++)
#else
        for(int i = 0; i < I2S_CHANS_ADC; i++)
#endif
        {
            if(readBuffNo)
                outuint(c_out, samplesIn_1[i]);
            else
                outuint(c_out, samplesIn_0[i]);
        }
        /* Send over the digi channels - no odd buffering required */
#pragma loop unroll
        for(int i = I2S_CHANS_ADC; i < NUM_USB_CHAN_IN; i++)
        {
            outuint(c_out, samplesIn_0[i]);
        }
#endif
    }

    return 0;

}
At that point you have the samples from USB (out from host) in samplesOut[] which are destined for I2S (if enabled). At this stage pdm mic signals are in samplesIn_0/1 and any I2S channels are in there too at higher indicies. You can write to samplesIn_0/1 at this stage as this is what gets sent to the host.
So a copy from samplesOut to samplesIn at this point will loop back from the host. You may want to add a ring buffer though to match the near/far latencies if you are doing time critical processing.

The latency through lib_mic_array is always 18 output clock cycles
jamqam
Junior Member
Posts: 6
Joined: Tue Oct 31, 2017 9:44 pm

Post by jamqam »

Dear infiniteimprobability,

Thank you very much.
I successfully loop-back the stereo audio output signal. Thank you again.

May I ask you a question for you? You seems to be expert.
I could successfully record loop-backed audio at only 44100Hz sampling rate without distortion. If I try to do it at other sampling frequency, e.g. 16000Hz, the signal is distorted.

Audio source sampling rate also seemed to be related. For example:

___Sampling rate__ | Loop-backed
-----------+------------| audio
Recorder| _Source_ | quality
-----------+------------+-----------
44100Hz | 44100Hz | Good
44100Hz | 16000Hz | Poor
16000Hz | 44100Hz | Poorer
16000Hz | 16000Hz | Poorest

Here is the setting I used:
1. Recording program: Audacity
2. Playback program: Totem Movie Player
3. OS: Ubuntu 16.14 LTS
4. Playback audio source sampling rate: 16000Hz, 44100Hz

Would you please kindly let me know where I should touch in the source code if I want to record it at specific sampling frequency?

Best regards,

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

Post by infiniteimprobability »

The device is a usb soundcard (as far as the host is concerned). It will run at whatever rate the host tells it to, the list of supported frequencies is provided by the device descriptors.
I don't understand why you should get distortion. I think you need to find out what the host is doing.
You can check the device rate by putting a scope on the LRCLK pin or printing the rate (see audiohw.xc) on sample rate change (make sure you enable xscope printing and run using --xscope).
I can't see a reason why a simple loopback code would cause this distortion. Maybe the host and device rate are not matched?
jamqam
Junior Member
Posts: 6
Joined: Tue Oct 31, 2017 9:44 pm

Post by jamqam »

infiniteimprobability wrote:The device is a usb soundcard (as far as the host is concerned). It will run at whatever rate the host tells it to, the list of supported frequencies is provided by the device descriptors.
I don't understand why you should get distortion. I think you need to find out what the host is doing.
You can check the device rate by putting a scope on the LRCLK pin or printing the rate (see audiohw.xc) on sample rate change (make sure you enable xscope printing and run using --xscope).
I can't see a reason why a simple loopback code would cause this distortion. Maybe the host and device rate are not matched?
Thank you for your advice. I'll update this post once I figure out.

Best,

J
jamqam
Junior Member
Posts: 6
Joined: Tue Oct 31, 2017 9:44 pm

Post by jamqam »

Dear infiniteimprobability,

Even though I was not able to figure out where it went wrong, at least I don't face the sound quality problem anymore.
What I have done was that I installed the latest USB 2.0 firmware over a new board.

Thank you again

Best,

J
Post Reply