Author Topic: Audio I2S and Raspberry  (Read 527 times)

0 Members and 1 Guest are viewing this topic.

Offline luiHS

  • Frequent Contributor
  • **
  • Posts: 458
  • Country: es
Audio I2S and Raspberry
« on: May 15, 2021, 08:25:02 am »

Hi.

I am developing a product, which uses an RT1064 microcontroller for process tasks, and a Raspberry for playing video and audio.

As a sound amplifier I have chosen a STA369 chip that integrates 4 channels configurable as simple or bridged. I will use a 3 channel setup, two simple and one bridged. This chip is controlled by I2C, and the audio input is digital by I2S.

I have not done anything before using I2S, and the question is whether it is a standard port that can be used with any I2S device. It would be a matter of connecting the I2S output of Raspberry to STA369 and configuring the Raspberry so that the sound is output through I2S.
 

Offline gamalot

  • Frequent Contributor
  • **
  • Posts: 631
  • Country: au
  • Correct my English
    • Youtube
Re: Audio I2S and Raspberry
« Reply #1 on: May 15, 2021, 11:17:39 am »
IIRC, There is no MCLK output on the I2S interface of the Raspberry Pi.

Online Jacon

  • Contributor
  • Posts: 40
  • Country: pl
Re: Audio I2S and Raspberry
« Reply #2 on: May 15, 2021, 01:10:13 pm »
IIRC, There is no MCLK output on the I2S interface of the Raspberry Pi.
So, would you explain, how those countless HiFi I/O HATs for RasPi are working ?
For example, this one:
https://www.hifiberry.com/docs/data-sheets/datasheet-dac-adc-pro/
 

Offline luiHS

  • Frequent Contributor
  • **
  • Posts: 458
  • Country: es
Re: Audio I2S and Raspberry
« Reply #3 on: May 15, 2021, 01:30:49 pm »
IIRC, There is no MCLK output on the I2S interface of the Raspberry Pi.

Thanks, I've been looking for information on that.

My question now is if that clock signal MCLK can be injected externally with an oscillator. I have seen schematics with the PCM5121 DAC for Raspberry, which use external oscillators by switching between two of them based on the sampling frequency.

In the STA369 the external clock frequency provided to the XTI pin must be a multiple of the input sampling frequency (fs).
According with the datasheet table may be these 6 values for sound sampled to 44.1Hz and 48Khz:

 576*fs, 128*fs,  256*fs, 384*fs,  512*fs,  768*fs

This means, for example, for 256*fs, 11.2896 Mhz for a sound sampled at 44.1Khz and 12.288 Mhz for a sound sampled at 48Khz. Both oscillators available from Mouser.

https://www.mouser.es/ProductDetail/Epson-Timing/SG-8018CE-122880M-TJHPA3?qs=%252B6g0mu59x7IJ%252BhMyNAL4Rw%3D%3D
https://www.mouser.es/ProductDetail/Epson-Timing/SG-8018CE-112896M-TJHPA3?qs=OTrKUuiFdkahoS5c5bbz0w%3D%3D
« Last Edit: May 15, 2021, 02:33:14 pm by luiHS »
 

Online Jacon

  • Contributor
  • Posts: 40
  • Country: pl
Re: Audio I2S and Raspberry
« Reply #4 on: May 15, 2021, 03:31:01 pm »
 

Offline SiliconWizard

  • Super Contributor
  • ***
  • Posts: 6857
  • Country: fr
Re: Audio I2S and Raspberry
« Reply #5 on: May 15, 2021, 07:11:19 pm »
IIRC, There is no MCLK output on the I2S interface of the Raspberry Pi.

Thanks, I've been looking for information on that.

My question now is if that clock signal MCLK can be injected externally with an oscillator.

Nope. Not that I know of. But I may be missing something. Most DACs out  there won't take a MCLK which is not synchronized with the BCLK (bit clock), and conversely, I don't think there is any clock input you can use on the RPi as a MCLK for I2S.

There are DACs, such as the PCM5102A ( https://www.ti.com/product/PCM5102A ), which can generate MCLK internally (with an integrated PLL) from BCLK. Those can be used directly with RPi's without any nasty trick involved.
 

Offline luiHS

  • Frequent Contributor
  • **
  • Posts: 458
  • Country: es
Re: Audio I2S and Raspberry
« Reply #6 on: May 15, 2021, 07:58:19 pm »
Quote
My question now is if that clock signal MCLK can be injected externally with an oscillator.

Nope. Not that I know of. But I may be missing something. Most DACs out  there won't take a MCLK which is not synchronized with the BCLK (bit clock), and conversely, I don't think there is any clock input you can use on the RPi as a MCLK for I2S.

There are DACs, such as the PCM5102A ( https://www.ti.com/product/PCM5102A ), which can generate MCLK internally (with an integrated PLL) from BCLK. Those can be used directly with RPi's without any nasty trick involved.

Thank you, something like that was afraid, that the clock signal can not be independent of other clock signals. This is a problem then, to be able to connect 4-wire I2S devices to a Raspberry.

I will have to use a PCM5100 or PCM5122 DAC (PCM5102 is out of stock everywhere), and amplifiers with analog input. It's a shame because the STA639 has volume control, tone control, 8 EQ filters per channel and 4 configurable amplifiers, controlled by I2C.

Another option is to add a CS8421 chip, which generates the MCLK signal from 3-wire I2S, but it is a somewhat expensive chip.
« Last Edit: May 15, 2021, 08:05:31 pm by luiHS »
 

Offline oPossum

  • Super Contributor
  • ***
  • Posts: 1219
  • Country: us
  • The other white meat.
Re: Audio I2S and Raspberry
« Reply #7 on: May 15, 2021, 10:28:02 pm »
I2S can be configured to operate in slave mode and use an externally supplied SCLK (BCLK). This can be derived from an external MCLK so everything stays in sync.

An example using a CPLD: https://alexxdiy.blogspot.com/2020/05/high-quality-raspberri-pi-i2s-hat-part.html

 

Offline technix

  • Super Contributor
  • ***
  • Posts: 3503
  • Country: cn
  • From Shanghai With Love
    • My Untitled Blog
Re: Audio I2S and Raspberry
« Reply #8 on: May 16, 2021, 11:16:45 am »
Raspberry Pi I2S interface have no MCLK, instead the external chips are supposed to source MCLK from a separate oscillator.
 

Offline SiliconWizard

  • Super Contributor
  • ***
  • Posts: 6857
  • Country: fr
Re: Audio I2S and Raspberry
« Reply #9 on: May 16, 2021, 05:34:52 pm »
Quote
My question now is if that clock signal MCLK can be injected externally with an oscillator.

Nope. Not that I know of. But I may be missing something. Most DACs out  there won't take a MCLK which is not synchronized with the BCLK (bit clock), and conversely, I don't think there is any clock input you can use on the RPi as a MCLK for I2S.

There are DACs, such as the PCM5102A ( https://www.ti.com/product/PCM5102A ), which can generate MCLK internally (with an integrated PLL) from BCLK. Those can be used directly with RPi's without any nasty trick involved.

Thank you, something like that was afraid, that the clock signal can not be independent of other clock signals. This is a problem then, to be able to connect 4-wire I2S devices to a Raspberry.

I will have to use a PCM5100 or PCM5122 DAC (PCM5102 is out of stock everywhere), and amplifiers with analog input. It's a shame because the STA639 has volume control, tone control, 8 EQ filters per channel and 4 configurable amplifiers, controlled by I2C.

Another option is to add a CS8421 chip, which generates the MCLK signal from 3-wire I2S, but it is a somewhat expensive chip.

One option would be to do just what the PCM51xx do internally: add a PLL. So you could use any I2S-compatible chip, including the STA639, with an additional PLL.
Use the BCLK as input for the PLL, and set it to generate a synchronized MCLK - typical MCLK would be 256xFs, for instance, so if your I2S data stream is a typical 64 bits per frame (thus BCLK = 64xFs), you'll need to set up a 4x multplier for the PLL. You get the idea. Tons of PLL ICs out there.
 

Offline luiHS

  • Frequent Contributor
  • **
  • Posts: 458
  • Country: es
Re: Audio I2S and Raspberry
« Reply #10 on: May 17, 2021, 03:37:30 am »
One option would be to do just what the PCM51xx do internally: add a PLL. So you could use any I2S-compatible chip, including the STA639, with an additional PLL.
Use the BCLK as input for the PLL, and set it to generate a synchronized MCLK - typical MCLK would be 256xFs, for instance, so if your I2S data stream is a typical 64 bits per frame (thus BCLK = 64xFs), you'll need to set up a 4x multplier for the PLL. You get the idea. Tons of PLL ICs out there.


Ok thanks I will try ICS502, 511 or 512 to multiply BCLK x4 and get MCLK in sync.

« Last Edit: May 17, 2021, 03:47:17 am by luiHS »
 

Offline Bassman59

  • Super Contributor
  • ***
  • Posts: 1852
  • Country: us
  • Yes, I do this for a living
Re: Audio I2S and Raspberry
« Reply #11 on: May 17, 2021, 04:11:30 pm »
Raspberry Pi I2S interface have no MCLK, instead the external chips are supposed to source MCLK from a separate oscillator.

I haven't looked, but I assume that the Raspberry Pi's I2S ports can be configured to work in slave mode (BCLK, LRCLK as inputs), and it's a simple matter to build a "hat" with a 24.576 MHz oscillator for the modulator clock and picking converters which can divide MCLK down to BCLK and LRCLK internally and provide them as outputs.

There's a separate issue of implementing support for more than one sample frequency, and to support the 44.1 kHz family as well as the 48 kHz family you need two oscillators.

Or you can use converters which can take in a reference clock like 27 MHz and will synthesize the correct MCLK and divide that down to BCLK or LRCLK. It all depends on the goals.
 

Offline technix

  • Super Contributor
  • ***
  • Posts: 3503
  • Country: cn
  • From Shanghai With Love
    • My Untitled Blog
Re: Audio I2S and Raspberry
« Reply #12 on: May 17, 2021, 04:24:30 pm »
I haven't looked, but I assume that the Raspberry Pi's I2S ports can be configured to work in slave mode (BCLK, LRCLK as inputs), and it's a simple matter to build a "hat" with a 24.576 MHz oscillator for the modulator clock and picking converters which can divide MCLK down to BCLK and LRCLK internally and provide them as outputs.
You may be able to get away with running Pi I2S in master mode and run the codec on an independent clock. The internal I2S PLL for the Pi is reasonably good IMO. My WM8978G board runs in that mode and it works good enough in an non-trivial playback test (shairport-sync streaming audio from my iPhone, test song is Daft Punk's Get Lucky from Apple Music for its dynamic range, and it works reasonably well.)
 
There's a separate issue of implementing support for more than one sample frequency, and to support the 44.1 kHz family as well as the 48 kHz family you need two oscillators.

Or you can use converters which can take in a reference clock like 27 MHz and will synthesize the correct MCLK and divide that down to BCLK or LRCLK. It all depends on the goals.
This is where small FPGAs can shine, converting an virtually arbitrary input frequency into any output frequency you like using its internal PLL, accessed over I2C.
 

Offline luiHS

  • Frequent Contributor
  • **
  • Posts: 458
  • Country: es
Re: Audio I2S and Raspberry
« Reply #13 on: May 18, 2021, 02:00:50 am »
 
Finally, I will use a TAS5805M, this is also I2S but it doesn't need MCLK signal. It is only two channel but cheaper and at the end of the datasheet there is a beautiful scheme to create a fully digital 2.1 amplifier controlled by I2C.

I also found information from people who have already used it to connect to Raspberry by I2S, with the start commands to send by I2C from a C program. https://www.diyaudio.com/forums/class-d/335099-tas5825m-based-amp.html

I would have liked to try the multiplier PLL thing to create the MCLK signal for the STA369, or to try a DAC like the PCM5100, but the priority is to design the circuit with the least complication and loss of time. I knew almost nothing about I2S, but I see that it is not that simple, at least not with a Raspberry as it lacks the MCLK signal.
« Last Edit: May 18, 2021, 02:03:31 am by luiHS »
 

Offline SiliconWizard

  • Super Contributor
  • ***
  • Posts: 6857
  • Country: fr
Re: Audio I2S and Raspberry
« Reply #14 on: May 19, 2021, 05:14:32 pm »
Well, the TAS5805M is a decent amplifier for what you want to do. As can be read in its DS, "The device has an internal PLL that is used to take SCLK (Bit Clock) as reference clock and create the higher rate clocks required by the DSP and the DAC clock.", which is why an external MCLK is not needed. Same as with the PCM5102A and such.

As to the RPi, it's pretty common for SBCs that their I2S signals do not include MCLK, neither as an output or as an input.
The latter would require a hybrid master/slave mode, which is even less common on those SBCs. You can usually do this with MCUs supporting I2S, though. I have done this a few years ago with a dsPIC33 MCU, but there were pitfalls. If the external MCLK was not synchronized to the CPU clock, then you'd need to go through a code trick (software sync) in order for the I2S peripheral to start properly. That was bad. I dunno if the same pitfalls apply to other MCUs out there - but I'm suspecting so.
 
The following users thanked this post: luiHS


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf