Realtime Audio Loopback, Measuring, and DSP

New to XMOS and XCore? Get started here.
student_researcher
Newbie
Posts: 1
Joined: Sat Mar 13, 2021 7:29 pm

Realtime Audio Loopback, Measuring, and DSP

Post by student_researcher »

Hello,

I am a student researcher attempting to use the xCORE-200 MC Audio board for DSP. I am very new to xmos and DSP in general, but I have been spending a lot of time reading the manuals and code examples. I can use xTime Composer to successfully run the I2S loopback demo (AN00162), and I have read over the code and feel that I understand it well enough. However, when I try modify the i2s_loopback function to display the sample, the loopback stops working and I hear a high pitch sound. I suspect this is because I am interrupting the real time ADC and DAC. I do not understand why i2s stops working when I try to modify it. Please note that I have redirected stdout to the XTAG to preserve realtime functionality. For example, here is a custom interface I made:

Code: Select all

[[distributable]]
void read_signal(server interface share_signal_if i) {
    printf("Starting task: read_signal\n");
    while(1) {
        select {
            case i.share(int32_t sample):
                printf("Received sample: %d\n", sample);
                xscope_int(0, sample);
                break;
        }
    }
}
When I use a simple variable test, I can view the variable in console and loopback works just fine:

Code: Select all

    case i2s.receive(size_t n_chans, int32_t in_samps[n_chans]):
      first_sample = in_samps[0];
      delay_microseconds(10);
      for (int i = 0; i < n_chans; i++) samples[i] = in_samps[i]; // copy samples
      i.share(test);  // works just fine
      test++;
      if (test >= 10) {
          test = 0;
      }
      break;
But when I try to print anything related to the sample, the loopback stops working:

Code: Select all

    case i2s.receive(size_t n_chans, int32_t in_samps[n_chans]):
      first_sample = in_samps[0];
      delay_microseconds(10);
      for (int i = 0; i < n_chans; i++) samples[i] = in_samps[i]; // copy samples
      i.share(first_sample);  // breaks loopback
      test++;
      if (test >= 10) {
          test = 0;
      }
      break;
I have searched through the examples, manuals, and GitHub but I have not found any examples that perform real time DSP on this board. I was hoping I could be pointed in the right direction. It would be very helpful to look at specific examples of real-time audio processing, measuring, etc. For example, maybe I am going about this completely wrong and I should not be using i2s at all! I'm not sure.

The end goal of this project is to read audio from a microphone, perform some DSP (specifically active noise canceling), and output through a speaker. I am just using a small interview microphone that plugs into a 3.5mm jack, but the I2S loopback does not work with that, so any information on that front would also be appreciated.

Thank you for your time in reading this message. Any information on how to get started with this will be much appreciated.


User avatar
CousinItt
XCore Addict
Posts: 245
Joined: Wed May 31, 2017 6:55 pm

Post by CousinItt »

Try using the debug printing library (see links below), remembering to enable the xscope link. Making your function distributable may also be slowing it (or something else) down, so try without if you can.

https://www.xmos.ai/download/AN00239:-U ... .0rc1).pdf

https://www.xmos.ai/download/lib_loggin ... .0rc1).pdf