AN00231 SPDIF-Receive-to-I2S-output-using-ASRC x->192kHz

Sub forums for various specialist XMOS applications. e.g. USB audio, motor control and robotics.
ffomich
Experienced Member
Posts: 114
Joined: Mon Sep 15, 2014 1:32 pm

AN00231 SPDIF-Receive-to-I2S-output-using-ASRC x->192kHz

Postby ffomich » Tue Dec 19, 2017 11:06 am

Hi,
I have modified original AN00231 project for my self-made board.

I want to convert input 44.1/48/88.2/96 to 192 output.
After changing ASRC_N_OUT_IN_RATIO_MAX from 3(default) to 5 in the app_config.h conversion from 44.1/48 -> 192 works correctly.
But in modes 88.2/96 -> 192 the output sound has distortion.

Here is console output

Code: Select all

Starting I2S
SR change in lib_audio_codec - 192000
Initializing I2S to 192000Hz and MCLK to 24576000Hz
// input 48k
New rate in SRC in=1, out=5
New rate in SRC in=1, out=5
spdif rate ave=48003, valid=1, i2s rate=191999, valid=1, i2s_buff=-1, fs_ratio=0x400010F, nom_fs=0x4000000
spdif rate ave=48003, valid=1, i2s rate=191999, valid=1, i2s_buff=-1, fs_ratio=0x4000067, nom_fs=0x4000000
spdif rate ave=48003, valid=1, i2s rate=191999, valid=1, i2s_buff=-2, fs_ratio=0x3FFFE26, nom_fs=0x4000000
// change input to 44.1k
New rate in SRC in=0, out=5
New rate in SRC in=0, out=5
spdif rate ave=44102, valid=1, i2s rate=191999, valid=1, i2s_buff=-15, fs_ratio=0x3ACB121, nom_fs=0x3ACCCCC
spdif rate ave=44102, valid=1, i2s rate=192000, valid=1, i2s_buff=-7, fs_ratio=0x3ACCDA7, nom_fs=0x3ACCCCC
spdif rate ave=44101, valid=1, i2s rate=191999, valid=1, i2s_buff=2, fs_ratio=0x3ACD9D0, nom_fs=0x3ACCCCC
// change input to 32k
spdif rate ave=7662, valid=0, i2s rate=191103, valid=0, i2s_buff=-3, fs_ratio=0x3ACCCCC, nom_fs=0x3ACCCCC
// change input to 96k
spdif rate ave=61037, valid=0, i2s rate=191496, valid=0, i2s_buff=55, fs_ratio=0x3ACCCCC, nom_fs=0x3ACCCCC
spdif rate ave=61232, valid=0, i2s rate=191443, valid=0, i2s_buff=19, fs_ratio=0x3ACCCCC, nom_fs=0x3ACCCCC
// change input to 88.2k
spdif rate ave=61061, valid=0, i2s rate=191494, valid=0, i2s_buff=66, fs_ratio=0x3ACCCCC, nom_fs=0x3ACCCCC
spdif rate ave=61233, valid=0, i2s rate=191449, valid=0, i2s_buff=19, fs_ratio=0x3ACCCCC, nom_fs=0x3ACCCCC
// change input to 48k
New rate in SRC in=1, out=5
New rate in SRC in=1, out=5
spdif rate ave=48003, valid=1, i2s rate=191999, valid=1, i2s_buff=-1, fs_ratio=0x4000712, nom_fs=0x4000000
Could anybody confirm that original project on the xCORE-200 Multichannel Audio Platform can convert 88.2/96 -> 192 ?
Do I need to change any defines in the app_config.h ?
User avatar
infiniteimprobability
XCore Legend
Posts: 1120
Joined: Thu May 27, 2010 10:08 am

Postby infiniteimprobability » Wed Dec 20, 2017 10:09 am

Hi,
the code was written to be as optimal as possible in terms of resource usage - the core of it (spdif, i2s, asrc + control) uses just 5 threads, which means it can fit in a single tile device like an XL208. It makes a lot of use of combinable and distributable which are ways of inlining/flattening tasks into existing threads. The down side to that though is that it can affect performance.

I am not 100% surprised that it doesn't support 88/96->192 out of the box. If you look at the ASRC Processor Usage table here https://www.xmos.com/support/libraries/lib_src you can see that 96->96k (original spec) takes 67MHz and 48->192 takes 66MHz. But 96->192k takes 87MHz. My guess is that, with the FIFO handling and communication overhead, the asrc task doesn't have enough time to complete.

Each ASRC task is given 100MHz so that only leaves 13MHz for all of the other stuff (overhead and buffering). That *should* be enough with some optimisation but I don't know how far it is from that requirement now.

So what to do?

There are a number of options:

Low hanging fruit (I have not tried these - they are just suggestions):

- increase ASRC_N_IN_SAMPLES to, say, 32 to reduce the calling overhead
- Change the clock to 600MHz in xk-audio-216-mc.xn. This is only a quick fix for a demo, the chip is not guaranteed to run above 500Mhz..
- Change from -O2 to -O3 in the Makefile
- Turn off debug prints

More ideas:

- make serial2block and block2serial non distributable
- change the rate server so that "case i_fs_ratio.get_ratio" is replaced by a shared memory read. There is a timing case where "case t_period_calc when timerafter(t_calc_trigger) " has just fired and the asrc requests the ratio, it will have to wait for that case to complete first before it can be served it's ratio

Failing that it would need app re-architecting so that the asrc task is really slimmed down and tasks outside of it handle the buffer management etc.. Much more work but we know this is feasible because of the 83MHz performance requirement.
ffomich
Experienced Member
Posts: 114
Joined: Mon Sep 15, 2014 1:32 pm

Postby ffomich » Mon Dec 25, 2017 9:51 am

I have tried
- increase ASRC_N_IN_SAMPLES to, say, 32 to reduce the calling overhead
- Change the clock to 600MHz in xk-audio-216-mc.xn. This is only a quick fix for a demo, the chip is not guaranteed to run above 500Mhz..
- Change from -O2 to -O3 in the Makefile
- Turn off debug prints

- make serial2block and block2serial non distributable
There is no changes in the sound. The distortion is present still.
dweeb4
Active Member
Posts: 52
Joined: Mon Jan 19, 2015 12:47 pm

Postby dweeb4 » Wed Jan 10, 2018 1:57 am

So on a XU216 SPDIF input with 2*resampling or the default 3* will work fine with the existing libraries or is 192KHz output out of bounds?
ffomich, did you get any further on this?
I saw your other thread (July) on this - are you using the 2*SPDIFreceiver() here?
ffomich
Experienced Member
Posts: 114
Joined: Mon Sep 15, 2014 1:32 pm

Postby ffomich » Wed Jan 10, 2018 11:25 am

Hi, dweeb4.

In this project I use only 1 spdifReceive() with ASRC.
Adding ASRC with wrapper into my project required 3 cores, 3 timers and 12+ chanends.

I have no any progress in solving 88.2/96->192 sound distortion. I will operate only in 44.1/48->192 modes, so it's enough for me.
dweeb4
Active Member
Posts: 52
Joined: Mon Jan 19, 2015 12:47 pm

Postby dweeb4 » Wed Jan 10, 2018 11:39 am

OK, thanks, ff
XU216 has 16 cores so that's fine
3 timers ? Are these not assigned by the ASRC software or do you mean 3 oscillators?
12+ channels? Can you explain this please?
ffomich
Experienced Member
Posts: 114
Joined: Mon Sep 15, 2014 1:32 pm

Postby ffomich » Wed Jan 10, 2018 11:51 am

Here is build report of my project

Code: Select all

Constraint check for tile[0]:
  Cores available:            8,   used:          6 .  OKAY
  Timers available:          10,   used:          6 .  OKAY
  Chanends available:        32,   used:         26+.  MAYBE
  Memory available:       262144,   used:      81820 .  OKAY
    (Stack: 12636, Code: 42368, Data: 26816)
Constraints checks PASSED WITH CAVEATS.
Constraint check for tile[1]:
  Cores available:            8,   used:          6 .  OKAY
  Timers available:          10,   used:          8 .  OKAY
  Chanends available:        32,   used:         26 .  OKAY
  Memory available:       262144,   used:      49708 .  OKAY
    (Stack: 2972, Code: 33184, Data: 13552)
Constraints checks PASSED.
Build Complete
dweeb4 wrote:3 timers ? Are these not assigned by the ASRC software or do you mean 3 oscillators?
As I understand 3 timers are used by the ASRC wrapper for input rate calculation and something else.
dweeb4 wrote:12+ channels? Can you explain this please?
I see this notation in the report but I can't explain what it means.
dweeb4
Active Member
Posts: 52
Joined: Mon Jan 19, 2015 12:47 pm

Postby dweeb4 » Wed Jan 10, 2018 11:57 am

Right, thanks!
User avatar
xlordofpainx
Experienced Member
Posts: 78
Joined: Thu Mar 08, 2018 2:44 pm

Postby xlordofpainx » Tue May 08, 2018 9:35 am

Image

Image

Using xCore-200 MCAB

I also tried getting 192, but I am getting only 186. The settings I've changed are ASRC_N_OUT_IN_RATIO_MAX from 3(default) to 5 and 192 default frequency for I2S. same as ff. Analyzing the data as shown in picture above says that I am getting only 186 max from 44.1, besides that the LEDs on the board are blinking like crazy. Any ideas?
ffomich
Experienced Member
Posts: 114
Joined: Mon Sep 15, 2014 1:32 pm

Postby ffomich » Tue May 08, 2018 12:08 pm

Hi,
1. Have you got issues running original project on the xCore-200 board? Do you see correct frequencies in the console output? Does BUTTON1 change I2S SR?

2. Do you see correct I2S SR ~192000 in the console output running project with two modifications?

Who is online

Users browsing this forum: No registered users and 0 guests