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

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

Wed Jun 10, 2020 12:35 pm

Hi, meanwhile I was playing with bcm2835-i2s.c and when i delay the data 8 bits like this:

Code: Select all

 486		data_delay = slot_width - data_length + 8; 
Everything works fine for 24bit audio (not for 16 bit though of course), I could use a workaround and convert the 16 to 24 bit i guess. But I'd rather make it right.

Any help or idea for where to look is much appreciated.

Greetings frog_pi

Edit:

I also tried to get 16 instead of 15 bit of data (when using 16 bit audio) with:

Code: Select all

 486		data_delay = slot_width - data_length - 1 
but that didn't help at all, it's just 15 bits in the wrong place then ^^

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

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

Fri Jun 12, 2020 1:34 pm

frog_pi wrote:
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?
I tested your overlay on the latest raspbian kernel (4.19.118) and couldn't reproduce this issue. The LSB was nicely aligned with the trailing frameclock edge.

Playing a 16-bit testfile with 0x8001 on the left channel and 0x7ffe on the right one:
rj.png
rj.png (9.31 KiB) Viewed 891 times
Testing with 24bit and speaker-test also worked as it should.

Make sure you actually loaded the correct overlay and don't have any .asoundrc (or soundserver etc) which changes the format.

In general using right-justified mode with the generic spdif transmitter codec will be a bit tricky if you want to support different sample lengths as the MSB will be at different absolute positions. You'll need to use an .asoundrc file to set a fixed format (eg S24_LE) and setup your DAC for that configuration (or choose a format that matches what the DAC expects).

so long,

Hias

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

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

Fri Jun 12, 2020 2:54 pm

Hi, first of all thanks a ton for your effort and help!!

I checked:

-Fresh installed Pi OS 4.19.118 (so i guess there should be no soundserver installed, didn't find any either, i guess you mean something like pulseaudio)

- Correct overlay is loaded (I only compiled one on the fresh OS):

Code: Select all

pi@raspberrypi:/boot/overlays $ aplay -l
**** List of PLAYBACK Hardware Devices ****
card 0: GenericRJ [GenericRJ], device 0: bcm2835-i2s-dit-hifi dit-hifi-0 [bcm2835-i2s-dit-hifi dit-hifi-0]
  Subdevices: 1/1
  Subdevice #0: subdevice #0

- no alsa config file:

Code: Select all

pi@raspberrypi:/boot/overlays $ cat ~/.asoundrc
cat: /home/pi/.asoundrc: No such file or directory
pi@raspberrypi:/boot/overlays $ cat /etc/asound.conf
cat: /etc/asound.conf: No such file or directory
pi@raspberrypi:/boot/overlays $ cat /etc/alsa/conf.d
cat: /etc/alsa/conf.d: No such file or directory

I also tried a standard asoundrc but that didn't make a difference:

Code: Select all

pcm.!default {
        type hw
        card 0
}

ctl.!default {
        type hw           
        card 0
}

Really strange alltogether ^^

But if I have to set a fixed format anyway in asoundrc, i'll leave the 8 bit delay in the bcm2835-i2s.c and set alsa to fix 24bit audio, as this works just fine. In case I find the problem I'll let you know though.

Thanks again,
greetings frog_pi

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

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

Fri Jun 12, 2020 3:09 pm

Hi Hias,

Please may I ask you a very basic question - in which DTS can I find the configuration of CLK source for the I2S peripheral, i.e. PLLD clock? I found DTS where PLLD and oscillator are the only two available for the pcm clock https://elixir.bootlin.com/linux/latest ... 35.c#L1524 , but I did not find a place where PLLD_PER is configured as source for the "PCM_MCLK" input mentioned in the RPi datasheet. I found only the GP0/1/2 clock registers which can specify the source but did not find one of them being assigned to the PCM peripheral in master mode.

Thanks a lot for your help,

Pavel.

pkuhar
Posts: 4
Joined: Wed Jul 24, 2019 4:36 pm

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

Fri Jun 12, 2020 5:32 pm

I'm using a PDM microphone on RPI4b setup from instructions here.
It works, bit I get about 33% DC offset.
Does anyone have any experience or hints about this?
Checking with the microscope the mean voltage is 1.62V. so that looks ok.

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

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

Fri Jun 12, 2020 7:28 pm

Hello HiassofT,
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).
Thank you for your answer.

I have Three more questions:
1/ Does anyone know of a ready to use I2S driver that would work in slave mode up to 354 KHz ?

2/ Is there any advantage to use Frame Master and Clock Slave or is it better Frams SLAVE AND Clock SLAVE ?

3/ I use Squeezelite as the I2S audio player,
I'm using Squeezelite v1.9.7-1256 along with LMS 8.0 latest build on Dietpi OS.
I'm doing Upsampling with the Sox Command inside Squeezelite

My command is:

Code: Select all

squeezelite -a 24:4:16:0 -r 176400 -R -u vLs::0.5:28:: -p 95 -C 5 -s 127.0.0.1
I use a slaved Pi to an external bitclock at 176400 KHz in Frame Master mode (the pi is doing the WS integer clock division)

I can play my 192K - 44K1Hz wav and flac files => OK :D
I can play Deezer/Qobuz/BandCamp/SoundCloud 320K or 128K CBR, MP3 along with some web radios that are also 320K CBR, MP3 Radio like Linn or Naim => OK :D
But I can't play most of the Web radios like FIP or similar (128K CBR, Radio). They are not upsampled !

I also did a fresh install with two settings:
a) One with Pi n Master mode with i-sabre-q2m driver and Pi clok running at 176400 Khz
b) One with Pi in Slave Mode with generic driver and my hardware clock running at 176400 Khz

With Pi Master every stream are upsampled => OK
With Pi Slave, most Web Radios are not upsampled, other streams are correctly upsampled :x

EVERYTHING ELSE IS IDENTICAL.

The question is WHY ? :?:

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

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

Fri Jun 12, 2020 8:31 pm

bricolodu13 wrote:
Fri Jun 12, 2020 7:28 pm
My command is:

Code: Select all

squeezelite -a 24:4:16:0 -r 176400 -R -u vLs::0.5:28:: -p 95 -C 5 -s 127.0.0.1
My 2 cents - since you have not specified the X parameter to resampling (non-integer resampling, in squeezelite IMO incorrectly called asynchronous), squeezelite cannot find any integer-based samplerate to 48kHz. The parameter -r being a single number specifies maximum samplerate, and the soundcard is queried about all available samplerates up to -r value https://github.com/ralph-irving/squeeze ... lsa.c#L272 It is possible each driver specifies different range of samplerates.

IMO adding the X parameter will fix the problem.

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

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

Sat Jun 13, 2020 8:00 am

Thank you phofman, this is it ! 8-)

Still, now, I would like to be able to resync in slave mode at the Max Frequency supported by my DAC , that is 352800KHz

Does any one know a ready to use driver ?

alexxDIY
Posts: 1
Joined: Wed Jun 17, 2020 4:52 am

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

Wed Jun 17, 2020 9:35 am

Thanks for the information in this thread
I just would like to share my project - raspberry pi 24bit/384k I2S card

Here's my page regarding this project:

alexxdiy.blogspot.com

i hope it will be interesting....
Attachments
DSC_3653.JPG
DSC_3653.JPG (46.54 KiB) Viewed 736 times

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

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

Wed Jun 17, 2020 2:10 pm

Thank you for sharing your very interesting project, including all the source code and programming procedures. That is quite unusual for projects like this.

Sumesh
Posts: 1
Joined: Thu Jul 16, 2020 10:11 am

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

Thu Jul 16, 2020 10:17 am

Nice Idea and a great project. Would like hear more from you..
How do i contact you?
Regards,
Sumesh

alexxDIY wrote:
Wed Jun 17, 2020 9:35 am
Thanks for the information in this thread
I just would like to share my project - raspberry pi 24bit/384k I2S card

Here's my page regarding this project:

alexxdiy.blogspot.com

i hope it will be interesting....

mhelin
Posts: 128
Joined: Wed Oct 17, 2012 7:18 pm

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

Sat Jul 18, 2020 12:57 pm

No I2S input?

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

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

Mon Jul 27, 2020 3:11 pm

I'm experiencing a strange problem with Pi4B, Hifiberry MiniAmp and Adafruit I2S SPH0645LM4H Mic:

After a while (maybe 5-15 minutes), the sound gets choppy and crackling.

- It only happens when the Mic is connected.
- What's even more weird is, it doesn't get better after a reboot or a power-off.
- When I power it off and leave it a while (maybe half an hour), then power it back on, the sound is good again.

I have tested this with two different Pi4s, Miniamps, Mic, sdcards, cables.

Anybody have an idea why this might be and how to further debug it?

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

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

Thu Jul 30, 2020 12:58 pm

Did more testing. Changed Rasbian back to 2020-01-13, same issue. Upgraded Firmware and Kernel to the latest versions via rpi-update. Same issue.

Then tried a Pi3B+ instead of the Pi4. At first I thought no issue. But, it turned out that after a while, it also shows the issue. There is some cracking/noise, but not as bad as on the Pi4.

Cory Parsnipson
Posts: 8
Joined: Thu Apr 30, 2020 3:44 am

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

Sat Aug 01, 2020 9:46 pm

Is it possible to run I2S pins through an I2C expander?

For context, I'm thinking about buying a Pimoroni Hyperpixel, but this thing has a shield that covers (and uses) all 40 GPIO pins. I want to keep my sound circuitry though so I need some way to get more GPIO pins.

The Hyper pixel supposedly has a I2C interface sticking out the other side that I can use for input. I think I can hook that up to a GPIO expander or two for buttons and sound. If it's relevant, I have an adafruit I2S stereo decoder feeding into two LM386 amps + speakers.

Is it possible to change the I2S pins to be on the other side of an I2C gpio expander? I'm not sure if the BCK, LRCK, or DOUT pins are somehow special (like PWM or something) where you can't just map them to any GPIO pins.

I feel like this is kind of a stupid question, but I'm not familiar enough with RPi GPIO or I2S/I2C enough to understand what I'm reading on google..

trejan
Posts: 2186
Joined: Tue Jul 02, 2019 2:28 pm

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

Sat Aug 01, 2020 10:45 pm

Cory Parsnipson wrote:
Sat Aug 01, 2020 9:46 pm
Is it possible to change the I2S pins to be on the other side of an I2C gpio expander? I'm not sure if the BCK, LRCK, or DOUT pins are somehow special (like PWM or something) where you can't just map them to any GPIO pins.
No. I2S has a similar looking name but it is completely different to I2C and you can't feed I2S data over I2C. You can't reassign the pins either as there is only 1 available mapping that fits on the GPIO header. The Hyperpixel display uses all the GPIOs on the header anyway including the additional I2C interface which it uses for the touchscreen controller.

Cory Parsnipson
Posts: 8
Joined: Thu Apr 30, 2020 3:44 am

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

Sat Aug 01, 2020 11:22 pm

Ok thanks for the answer! Gotta keep looking for a screen, I guess.. :(

Canto
Posts: 1
Joined: Thu Aug 06, 2020 6:40 pm
Location: San Luis Obispo, California(CA), 93401

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

Sat Aug 08, 2020 2:02 pm

I've used both.

I2S is easy to get running but complicated in the chip. The chips themselves usually have DSP engines and so can do things like equalization, filtration and a host of other things just by setting registers. The good news is that you get to control everything, the bad new is that you get to control everything. I love them.

DAC output is easy to get running but you'll need an outboard amplifier anyway. The nice thing about it is that you can put the output on a scope and see what you got. I2S chips (at least the ones I'm familiar with) do this with PWM so there is no relationship between the digital waveform and the analog one that you can just drop on a scope and look at to see what screwy thing is going on in your audio stream.

Debugging I2S means peering over analyzer traces of the bitstream. Debugging DAC means peering over scope traces.this content.

There is also the FCC to consider. So far I haven't been through FCC on the couple of products that I've done with I2S. In the distant past, the PWM output has been an issue. These new crops of I2S amps claim to have PWM designed to skate into FCC...

For your application, the biggest problem is the amplifier. Your choice probably comes down to which amp is capable of pushing enough power. What's the input of that? use it.

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