I2S, HIFI Audio Pi Hats

Hi guys (Raxda and users),

Just got my RockPi4 up and running. I want to use it for Hifi DSP applications. I’m using the Ubuntu server image and installed ALSA and ALSA utils.

aplay -l gives me:
**** List of PLAYBACK Hardware Devices ****
card 0: rockchipes8316c [rockchip,es8316-codec], device 0: ff880000.i2s-ES8316 HiFi ES8316 HiFi-0 []
Subdevices: 1/1
Subdevice #0: subdevice #0
card 1: HDMICODEC [HDMI-CODEC], device 0: ff8a0000.i2s-i2s-hifi i2s-hifi-0 []
Subdevices: 1/1
Subdevice #0: subdevice #0

The first seems to be the onboard stereo CODEC. But I want to use my own Pi HAT with a much higher quality DAC on it. I’ve probed the I2S pins but they seem to be flatlines. So… the I2S pins on the 40 pin PI header are connected to I2S1? And the ESP CODEC is connected to I2S0?

See page 59 of the RK 3399 CODEC:
http://opensource.rock-chips.com/images/6/60/Rockchip_RK3399_Datasheet_V1.6-20170301.pdf

Cheers,

Pieter

I can see in:

…that I2S0 is indeed hardwired to the ESP CODEC by Raxda, and the RK3399 datasheet claims I2S2 is hardwired to HDMI.

Now… how to add support for a HIFI HAT? Just add the device tree config in this big .dts file? Is there a way to easily recompile the RockPi4 kernel? @jack

Rock Pi 4 is a lost opportunity regarding audio. The internal STEREO codec is hardwired to multichannel I2S0 which leaves only the STEREO I2S1 for the external header. So no multichannel audio I/O is available via I2S, forget that board. On Nano PI M4 for an example all I2S0 pins have been routed to separate GPIO1 header.

See the rockpi4b DTS for connections made on board:

@mhelin Yes, aware of that. But for me personally, stereo would be fine. So, I’m keeping my thumbs crossed. Do you have any boards (faster than pi3) that can do multichannel?

I just love it when people with little to no understanding of audio start barfing out their “knowledge”.

An i2s bus is made up out of 3 or more wires.
bit clock,
frame clock,
data1

dataN

Each data wire, according to i2s protocol specification, is capable of carrying 2 channels.
The two channels are distinguished based on state of the frame clock signal.
Clock goes up: channel 0 transmits.
Clock goes down: channel 1 transmits.

And this is where your knowledge ends.

Here is some new knowledge for you;
A 48 kHz signal, with a 16 bit sample size, and 2 channels, requires 48000 * 16 * 2 = 1.536 MHz bit clock, in the least.

So what happens if you crank the clock speed up to, say, 6 MHz?
I’ll tell you what happens: you still have your 2 channel audio, but it is in a 128 bit window, leaving 96 bits of empty space.

So think about what you can do with that, with just a little bit of modification to the protocol…

  1. Instead of the frame clock changing state at the start of each channel’s sample, just pulse the frame clock for 1 bit at the very beginning of a cycle.
  2. Now just line up 8 channels worth of data and dump it out on the line.

How do you know when one channel ends and the next begins?

  • the first channel begins with the frame clock pulse.
  • each subsequent channel begins 8 bits after the beginning of the previous channel.

This is called “TDM”, and in this mode of operation, most codec’s can handle 8 channels.

And yes, this hardware DOES support it.

@superduper This board does not support 8 channel audio I/O, check the RK3399 datasheet and schematics. I2S1 is the only I2S bus connected to the pin header. It might be possible to pinmux different signals to those pins (maybe from I2S0), don’t know.

This is what datasheet tells:

  • I2S0/I2S2 support up to 8 channels TX and 8 channels RX. I2S1 supports up to 2
    channels TX and 2 channels RX
  • I2S2 is connected to HDMI and DisplayPort internally. I2S0 and I2S1 are exposed
    for peripherals.

There is no mention on TDM support, yes I know what it means.
http://opensource.rock-chips.com/images/6/60/Rockchip_RK3399_Datasheet_V1.6-20170301.pdf

So if the chip really supports TDM over I2S1 the why do they keep it secret, why don’t they tell it.

Anyway, Nano Pi M4 (SBC) has a separate header for all I2S0 signals.

Edit:
Found another datasheet:
http://opensource.rock-chips.com/images/e/ee/Rockchip_RK3399TRM_V1.4_Part1-20170408.pdf

It documents various PCM modes which look like TDM. Anyway, none of them supports 8 channel audio input (which is my main interest). The 8 channel modes have their uses though.