ganzgustav22
Posts: 59
Joined: Tue Feb 11, 2020 1:04 pm

Re: STICKY: The I2S sound thread. [I2S works]

Thu Mar 12, 2020 3:46 pm

Are there any recommendations or experiences regarding maximum wire length? I'd like to place the mic about 1 meter apart from the Raspberry Pi4. Using the Adafruit SPH0645LM4H I2S MEMS mic.


Edit: Tried it out now, used an old Cat.5 ethernet cable as signal/power wires, length about 1.5 meter, works fine.

cogeniac3
Posts: 1
Joined: Sun Mar 29, 2020 3:32 pm

Re: STICKY: The I2S sound thread. [I2S works]

Sun Mar 29, 2020 4:11 pm

I am working on a system to externally clock I2S data out of the Pi and into an asynchronous rate converter (ASRC), DSP and a DAC.

My question relates to the word size and format for I2S in the Pi. Since we will have a variety of different music sources (44.1/16 PCM, 48/16 AAC, 96/24 and 192/24 FLAC, etc) I am curious how the Pi manages the word sizes.

Specifically, the ASRC takes I2S data in left justified 24 bit format, but it uses clocks where the BCLK is 64 times the LRCK. As I understand it, the ASRC (which in this case will be the master) takes the first 24 bits, and discards anything after that. My concern, however, is that if the Pi has, say 16 bit data, and I give it a 32 bit BCLK, does the I2S driver know to fill in the remaining bits with zeroes, or does it choke if the clocks don't match the bit depth of the source material?

If it is the latter, then I'll need to create a new buffer and pad the lower 16 or 8 bits with zeroes before clocking the data out. This also means the external bit clock would need to change depending on the source bit depth, which will be messy.

My current external clock is programmable. It has two master clocks: One at 24576 MHz and the other at 22579.2 MHz. These then get divided down to create BCLK and LRCK for the appropriate sample rate. So the Pi tells me the sample rate of the material, and I can select divider ratios. Currently, however, the divider ratios have BCLK at 32x the LRCK rate. I really don't want to have to buffer and pad the I2S stream on the ASRC board, so being able to get the Pi to output all data at 32 bits would be great.

Anyone dealt with this before?

HiassofT
Posts: 283
Joined: Fri Jun 30, 2017 10:07 pm
Location: Salzburg, Austria
Contact: Website

Re: STICKY: The I2S sound thread. [I2S works]

Mon Mar 30, 2020 5:42 pm

It's not problem to transfer data with more bclk cycles than valid data bits, the I2S block will automatically pad them. Just use the set_bclk_ratio or set_tdm_slot functions to set that to eg 64 bclk cycles per frame.

so long,

Hias

fuwen0202
Posts: 13
Joined: Sat Mar 07, 2020 12:51 pm

Re: STICKY: The I2S sound thread. [I2S works]

Sat Apr 18, 2020 3:57 pm

itsikhefez wrote:
Wed Mar 04, 2020 11:29 am
In continuation to ^^, I've been able to build a basic driver with DKMS and it can be found in /lib/modules/.../kernel/sound/soc/bcm/snd-soc-<mydriver>.ko.

I've added this to /etc/modules and when running dmesg I get:
`[ 2.204423] snd_soc_<mydriver>: loading out-of-tree module taints kernel.`

but the DAC is not detected.
`aplay: device_list:272: no soundcards found...`

FWIW, I've copied basically the same impl of a driver that does work... so I'm thinking this is some sort of mapping somewhere.
Any tips on how to proceed or debug?

`
sonow,if u found some solvtion of wm8731? Look forward to your test

MKSounds
Posts: 6
Joined: Fri Apr 27, 2018 12:57 pm

Re: STICKY: The I2S sound thread. [I2S works]

Sat May 02, 2020 7:35 pm

Hi,
I was just wondering if it is necessary for newer kernel and hardware versions (e.g. Raspi 4) to change the compatible field in the dt overlays?
Can I use

Code: Select all

compatible = "brcm,bcm2708"
with the RPi 4 or do I need to change that to

Code: Select all

compatible = "brcm,bcm2835"
?
Regards, Markus

HiassofT
Posts: 283
Joined: Fri Jun 30, 2017 10:07 pm
Location: Salzburg, Austria
Contact: Website

Re: STICKY: The I2S sound thread. [I2S works]

Sat May 02, 2020 7:42 pm

AFAIK the bootloader doesn't check the compatible property (yet) but as brcm,bcm2835 is now the recommended value it wouldn't hurt changing it.

My guess is though that bcm2708 should keep working for a long time, if the bootloader started rejecting bcm2708 that would cause serious issues with HATs that have DT overlays in their EEPROM.

so long,

Hias

ritchrock
Posts: 4
Joined: Mon May 04, 2020 4:02 pm

Re: STICKY: The I2S sound thread. [I2S works]

Mon May 04, 2020 4:14 pm

Hi all,

Forgive me if I missed my questions while reading through this thread.

My setup: XMOS Xcore-200 as I2S master. XMOS chip will program and control ADC/DAC, act as hardware DSP and clock from SI5351A.

Can Raspberry Pi 4 connect via I2S TDM 8 channels In & 8 channels out with at least 24-bit word length? If yes, what is the max sample rate?

Thank you very much!

ritchrock
Posts: 4
Joined: Mon May 04, 2020 4:02 pm

Re: STICKY: The I2S sound thread. [I2S works]

Tue May 05, 2020 8:59 pm

Hoping someone can answer my question! Many thanks.

HiassofT
Posts: 283
Joined: Fri Jun 30, 2017 10:07 pm
Location: Salzburg, Austria
Contact: Website

Re: STICKY: The I2S sound thread. [I2S works]

Wed May 06, 2020 9:00 am

bcm2835-i2s hardware is 2-channel only. You can set up the link for 8ch 24/32bit TDM but can only send/receive on 2 of the TDM slots.

so long,

Hias

ritchrock
Posts: 4
Joined: Mon May 04, 2020 4:02 pm

Re: STICKY: The I2S sound thread. [I2S works]

Wed May 06, 2020 10:39 pm

I see. I found your earlier post (finally) where you mention the 'quirk'. So, to get 8 channels in/out via TDM slave, I would set up as shown in the attached figure 5, where frame sync rising edge only occurs after 8 slots?

Which overlay, etc should I look at to get started?
Attachments
tdmsetup.JPG
tdmsetup.JPG (141.25 KiB) Viewed 1153 times

ritchrock
Posts: 4
Joined: Mon May 04, 2020 4:02 pm

Re: STICKY: The I2S sound thread. [I2S works]

Thu May 07, 2020 3:44 am

I found yet another thread on this forum where you lay things out pretty well. viewtopic.php?t=193550&start=25

On the hardware side I have lots of flexibility with clocks and timing. This thread is a few years old now — is there a good Rpi example available to start from these days?

HiassofT
Posts: 283
Joined: Fri Jun 30, 2017 10:07 pm
Location: Salzburg, Austria
Contact: Website

Re: STICKY: The I2S sound thread. [I2S works]

Fri May 08, 2020 12:39 pm

The info in the linked thread is still valid, I'm not aware of anyone implementing this though.

And, as mentioned in the last post of that thread, you can save yourself a lot of hassle by using a different SoC with more capable audio interfaces - RPi isn't really suited for that.

so long,

Hias

phofman
Posts: 12
Joined: Mon Oct 07, 2019 1:37 pm

Re: STICKY: The I2S sound thread. [I2S works]

Mon May 18, 2020 5:52 pm

Please is it already known/anywhere documented how fast can slaved RPi4 I2S duplex in/out 24 bit work? The alsa driver has a fixed 384kHz limit but the commit only says "worked OK at this rate". To prevent the usual discussion about useless high samplerates - I am looking at options for a signal analyzer, not a regular audio :-)

I am sorry if I have missed this information somewhere earlier in this thread.

Thanks a lot.

Pavel.

HiassofT
Posts: 283
Joined: Fri Jun 30, 2017 10:07 pm
Location: Salzburg, Austria
Contact: Website

Re: STICKY: The I2S sound thread. [I2S works]

Tue May 19, 2020 8:50 am

The maximum PCM clock rate is 25MHz, see Eric's commit review here https://mailman.alsa-project.org/piperm ... 27126.html

so long,

Hias

phofman
Posts: 12
Joined: Mon Oct 07, 2019 1:37 pm

Re: STICKY: The I2S sound thread. [I2S works]

Tue May 19, 2020 8:59 am

Hias, thanks for the link.

Please is the MASH filter mentioned as the limiting factor used when using the I2S ports in slave mode (i.e. BCLK and LRCLK provided by an external clock chip)?

The 25MHz limit would fit 512kHz samplerate with 24-bit/ch I2S.

phofman
Posts: 12
Joined: Mon Oct 07, 2019 1:37 pm

Re: STICKY: The I2S sound thread. [I2S works]

Tue May 19, 2020 9:30 am

IIUC the MASH limit applies when generating the clock signal by the SoC itself
table.png
table.png (94 KiB) Viewed 944 times
My intention is to use an external programmable clock e.g. LMK03806. 768kHz @ 24bit I2S would require 36MHz bitclock. I could not find any docs specifying the max external clock frequency (i.e. max processing speed) of the PCM peripheral in BCM2811/35.

Thanks a lot for your help.

Pavel.

HiassofT
Posts: 283
Joined: Fri Jun 30, 2017 10:07 pm
Location: Salzburg, Austria
Contact: Website

Re: STICKY: The I2S sound thread. [I2S works]

Tue May 19, 2020 11:14 am

IIRC MASH modes aren't used in the clock driver, it uses a plain fractional divider (at MASH mode 0).

In slave mode the PCM clock isn't used at all (as clock is provided externally), but it's rather unclear if there might be other limiting factors in the I2S block - the 25MHz clock limit is the only spec we got.

If you want to go beyond the specced limit you'll be pretty much on your own. You could build your own patched kernel and see if it works, but there's no guarantee for that.

so long,

Hias

phofman
Posts: 12
Joined: Mon Oct 07, 2019 1:37 pm

Re: STICKY: The I2S sound thread. [I2S works]

Tue May 19, 2020 11:29 am

Hias, thanks, good to know there is currently no known obstacle. Raising the limit in kernel is trivial, but the test requires building the clock circuit and the DAC/ADC which expense I wanted to avoid if there was any known problem.

Even the 512kHz samplerate would be useful. That is why I want to use a flexible clocking circuit easily configurable to any frequency.

Please do you know if there were any tests about maximum frequency transferrable via the 40pin header? I read about some 40MHz SPI, but do not know if the device was connected through the pins. Not very HF-friendly layout, I know.

Thanks a lot!

HiassofT
Posts: 283
Joined: Fri Jun 30, 2017 10:07 pm
Location: Salzburg, Austria
Contact: Website

Re: STICKY: The I2S sound thread. [I2S works]

Tue May 19, 2020 12:56 pm

I'm not 100% sure if there are specs available, but a while ago I probed the SPI clock signal (which runs at about 30MHz) of the TV hat and the signal looked fine viewtopic.php?p=1384233#p1384233

With proper trace routing etc I'd guess 40-50MHz shouldn't be a problem, too. Breadboard and flying wires are quite certainly out of question , though :-)

so long,

Hias

phofman
Posts: 12
Joined: Mon Oct 07, 2019 1:37 pm

Re: STICKY: The I2S sound thread. [I2S works]

Tue May 19, 2020 1:03 pm

That trace looks very good indeed, thanks for a positive push. It's certainly needed :-)

Too bad, I cannot stick a QFN package into my breadboard :-)

p0sixn0w
Posts: 1
Joined: Wed May 27, 2020 3:35 am

Re: STICKY: The I2S sound thread. [I2S works]

Wed May 27, 2020 3:39 am

Hello guys!
Please ask me if it possible to connect several audio codecs over i2s to raspberry?
I want to make an audio system with software DSP (crossover/filter/Q/ etc)

frog_pi
Posts: 3
Joined: Mon Jun 08, 2020 9:33 am

Re: STICKY: The I2S sound thread. [I2S works]

Mon Jun 08, 2020 10:04 am

Hi guys, I could use a little help with my overlay, I'm trying to output right justified. THe overlay gets loaded as it should, soundcard is there in alsa as expected BUT when I use 16 bit audio I get very low volume, could I be missing one data bit here?
And when I try to output 24 bit audio I get normal volume but only noise (almost threw my of the chair because i had the volume so far up from testing with 16 bit ^^), a quick scope check confirmed looks pretty much like left justified. Anyone an idea what could be the culprit?

My dts:

Code: Select all

/dts-v1/;
/plugin/;

/ {
        fragment@0 {
                target = <&i2s>;
                __overlay__ {
                        #sound-dai-cells = <0>;
                        status = "okay";

                        cpu_port: port {
                                cpu_endpoint: endpoint {
                                        remote-endpoint = <&codec_endpoint>;
                                        dai-format = "right_j";
                                        dai-tdm-slot-num = <2>;
                                        dai-tdm-slot-width = <32>;
                                        bitclock-master;
                                        frame-master;
                                };
                        };
                };
        };


        fragment@1 {
                target-path = "/";
                __overlay__ {
                        spdif-transmitter {
                                #address-cells = <0>;
                                #size-cells = <0>;
                                #sound-dai-cells = <0>;
                                compatible = "linux,spdif-dit";
                                status = "okay";

                                codec_port: port {
                                        codec_endpoint: endpoint {
                                                remote-endpoint = <&cpu_endpoint>;
                                        };
                                };
                        };
                };
        };

        fragment@2 {
                target = <&sound>;
                __overlay__ {
                        compatible = "audio-graph-card";
                        label = "GenericRJ";
                        dais = <&cpu_port>;
                        status = "okay";
                };
        };
};


modprobe:

Code: Select all

Module                  Size  Used by
cmac                   16384  1
bnep                   20480  2
hci_uart               40960  1
btbcm                  16384  1 hci_uart
serdev                 20480  1 hci_uart
bluetooth             389120  24 hci_uart,bnep,btbcm
ecdh_generic           28672  2 bluetooth
8021q                  32768  0
garp                   16384  1 8021q
stp                    16384  1 garp
llc                    16384  2 garp,stp
brcmfmac              315392  0
brcmutil               16384  1 brcmfmac
snd_soc_audio_graph_card    16384  1
snd_soc_simple_card_utils    16384  1 snd_soc_audio_graph_card
raspberrypi_hwmon      16384  0
hwmon                  16384  1 raspberrypi_hwmon
cfg80211              651264  1 brcmfmac
rfkill                 28672  6 bluetooth,cfg80211
bcm2835_codec          36864  0
bcm2835_v4l2           45056  0
v4l2_mem2mem           24576  1 bcm2835_codec
v4l2_common            16384  1 bcm2835_v4l2
bcm2835_mmal_vchiq     32768  2 bcm2835_codec,bcm2835_v4l2
videobuf2_vmalloc      16384  1 bcm2835_v4l2
videobuf2_dma_contig    20480  1 bcm2835_codec
videobuf2_memops       16384  2 videobuf2_dma_contig,videobuf2_vmalloc
videobuf2_v4l2         24576  3 bcm2835_codec,bcm2835_v4l2,v4l2_mem2mem
videobuf2_common       45056  4 bcm2835_codec,bcm2835_v4l2,v4l2_mem2mem,videobuf2_v4l2
snd_soc_spdif_tx       16384  1
snd_soc_bcm2835_i2s    20480  2
videodev              200704  6 bcm2835_codec,v4l2_common,videobuf2_common,bcm2835_v4l2,v4l2_mem2mem,videobuf2_v4l2
snd_soc_core          192512  4 snd_soc_spdif_tx,snd_soc_audio_graph_card,snd_soc_simple_card_utils,snd_soc_bcm2835_i2s
media                  36864  3 bcm2835_codec,videodev,v4l2_mem2mem
snd_compress           20480  1 snd_soc_core
snd_pcm_dmaengine      16384  1 snd_soc_core
vc_sm_cma              36864  1 bcm2835_mmal_vchiq
snd_pcm               102400  3 snd_pcm_dmaengine,snd_soc_bcm2835_i2s,snd_soc_core
snd_timer              32768  1 snd_pcm
snd                    73728  6 snd_compress,snd_timer,snd_soc_core,snd_pcm
uio_pdrv_genirq        16384  0
uio                    20480  1 uio_pdrv_genirq
fixed                  16384  0
ip_tables              24576  0
x_tables               32768  1 ip_tables
ipv6                  454656  26
Attachments
SDS00007.png
24bit audio
SDS00007.png (35.94 KiB) Viewed 604 times
SDS00008.png
16bit audio
SDS00008.png (34.2 KiB) Viewed 604 times

bricolodu13
Posts: 42
Joined: Tue Aug 07, 2012 2:05 pm

Re: STICKY: The I2S sound thread. [I2S works]

Mon Jun 08, 2020 1:40 pm

Hello,

I have tried to slave the Pi to an external Clock running at 11.289600 ‬MHz for a 352,800KHz audio file
I tried to specify the external Clock limit but, the way I did, It failled and stuck to 188,4KHz files limit (with the corresponding clock) in Slave mode.

PS: I'm making the WS with integer division from the PI CPU, is it better to also slave the WS ?

Here is my dts

Code: Select all

/dts-v1/;
/plugin/;

/ {
        fragment@0 {
                target = <&i2s>;
                __overlay__ {
                        #sound-dai-cells = <0>;
                        status = "okay";

                        cpu_port: port {
                                cpu_endpoint: endpoint {
                                        remote-endpoint = <&codec_endpoint>;
                                        dai-format = "i2s";
                                };
                        };
                };
        };


        fragment@1 {
                target-path = "/";
                __overlay__ {
                        spdif-transmitter {
                                #address-cells = <0>;
                                #size-cells = <0>;
                                #sound-dai-cells = <0>;
                                compatible = "linux,spdif-dit";
                                status = "okay";

                                codec_port: port {
                                        codec_endpoint: endpoint {
                                                remote-endpoint = <&cpu_endpoint>;
                                                bitclock-master;
                                                frame-slave;
                                                system-clock-frequency = <11289600>;
                                        };
                                };
                        };
                };
        };


        fragment@2 {
                target = <&sound>;
                __overlay__ {
                        compatible = "audio-graph-card";
                        label = "Slave_I2S";
                        dais = <&cpu_port>;
                        status = "okay";
                };
        };
};

bricolodu13
Posts: 42
Joined: Tue Aug 07, 2012 2:05 pm

Re: STICKY: The I2S sound thread. [I2S works]

Tue Jun 09, 2020 8:25 am

Let me ask similar relatedquestion :

Is it possible to indicate somehow a frequency limit inside the dts.

88K2, 192K, 384K.

Thank you for your help

HiassofT
Posts: 283
Joined: Fri Jun 30, 2017 10:07 pm
Location: Salzburg, Austria
Contact: Website

Re: STICKY: The I2S sound thread. [I2S works]

Wed Jun 10, 2020 11:01 am

bricolodu13 wrote:
Tue Jun 09, 2020 8:25 am
Is it possible to indicate somehow a frequency limit inside the dts.

88K2, 192K, 384K.
No, that's not possible. The available formats and samplerates are determined by what the I2S controller and the codec support (only formats/rates supported by both of them will be available).

So, if you are using eg the generic spdif codec you'll only get 8kHz-192kHz.
https://github.com/raspberrypi/linux/bl ... tter.c#L27

Code: Select all

#define STUB_RATES	SNDRV_PCM_RATE_8000_192000
so long,

Hias

Return to “Interfacing (DSI, CSI, I2C, etc.)”