pipimann
Posts: 22
Joined: Fri Mar 07, 2014 7:25 pm

I2S: Keep CLK and FS clocks enabled, when pausing

Tue Sep 16, 2014 11:32 am

I'm feeding I2S audio into a Si4713 radio transmitter IC. After a lot of struggling it works (I'm on the B+ and had to try out a lot of combinations of drivers etc. to have it working)

Still I'm unhappy: The 4713 needs to have a signal on its DCLK and FS pins to be able to switch into I2S mode at all. CLK and FS are not allowed to stop, otherwise the 4713 will leave digital mode.

They way it is working right now is, that I have to start mplayer and then initialize the radio IC. As soon as I pause, stop, skip to the next track the radio IC will leave digital mode and needs to be initialized again. This behavious is supposed to be normal. The datasheet says:
Ensure that DCLK and DFS are already supplied.
Is there a way to keep them supplied by configuring the Pi the right way? Do I have to use another driver? (Right now I could only making it work with latest raspian 2014-09-09 image and tjaekel's RCAplus configuration)

This is what my /etc/modules looks like:

Code: Select all

##snd-bcm2835
snd_soc_core
snd_soc_bcm2708_i2s
bcm2708_dmaengine
snd_soc_pcm1794a
snd_soc_rpi_dac
I also thought about using some kind of internal mixer and having a silence played back all the time and use mplayer to overlay it. Tried it with two mplayer instances but — of course — soundcard is already in use...

Do you guys have any idea how to handle this?

Thanks in advance,
Hans


User avatar
Douglas6
Posts: 4781
Joined: Sat Mar 16, 2013 5:34 am
Location: Chicago, IL

Re: I2S: Keep CLK and FS clocks enabled, when pausing

Tue Sep 16, 2014 3:38 pm

Yay! Instructions for building Pulseaudio 5 on Raspbian. Thanks for that link. Anyone with experience in this area, please see http://www.raspberrypi.org/forums/viewt ... 29&t=87138

pipimann
Posts: 22
Joined: Fri Mar 07, 2014 7:25 pm

Re: I2S: Keep CLK and FS clocks enabled, when pausing

Tue Sep 16, 2014 6:26 pm

Thank you — I think PulseAudio is the right direction. Unfortunately I was not able to compile it, following your instructions. (I'm on an uptodate system, 2014-09-09 raspbian image, updated, upgraded.)

For now I wanted to revert back to an older version and apt-get installed pulseaudio.

It seems I have a mashup of both... :)

Anyway: As long as I don't close mplayer, I2S connection is up and running. That's very good! To make it really solid I would like to keep audio output (silence) up, even if mplayer gets closed.

I found that there are modules that can be enabled/disabled, e.g. module-suspend-on-idle. I tried to disable it, but it doesn't help.

Can you give me any advise in which direction I would have to go?

Thank you!
Hans

pipimann
Posts: 22
Joined: Fri Mar 07, 2014 7:25 pm

Re: I2S: Keep CLK and FS clocks enabled, when pausing

Wed Sep 17, 2014 11:25 am

90% Done!

I still feel a bit uncomfortable about the way everything is "wired" but it works:
  • Configured pulseaudio to start up in system mode, removed supend-idle module from .pa file
  • Added an mplayer startup script as respawn process to /etc/inittab
  • Initialising the FM chip from /etc/rc.local
/etc/inittab

Code: Select all

...
mpl:2345:respawn:/home/pi/mplayer_starter.sh
...
I need to start mplayer as a respawn process, because when I made longer tests, mplayer wiped out from time to time. I want to make sure that it is automatically restarting, when it crashes.

/home/pi/mplayer_starter.sh

Code: Select all

#!/bin/bash -

if pidof -x "pulseaudio" >/dev/null; then
  # run as pi user
  sleep 1
  /bin/su - pi -c "/usr/bin/mplayer -slave -input file=/home/pi/.mplayer_control -playlist /home/pi/audio/playlist.txt -loop 0
fi

sleep 1
I want to make sure that pulseaudio is already running, before starting mplayer. I don't know if it's necessary, but mplayer should run as user pi. This user is member of pulse and pulse-access groups. Otherwise I would get an access denied error from mplayer/pulse.

/etc/rc.local

Code: Select all

...
# wait for mplayer 
while [ -z $(pidof -x mplayer) ]
do
  sleep 1
done

# mplayer is there - initialize radio via I2C
sudo python /home/pi/radio.py
First check if mplayer is already running — this will make sure that there is sound, means: DCLK and FS signals!
The python script needs to be excecuted as superuse, because of GPIO and SMBUS usage. (Strange: I thought rc.local is run by root, but my script failed. I need to put the sudo there...)

Thanks for the pulseaudio hint — It does the job!

Still I'm very open how to make this more elegant. As said — I feel a bit uncomfortable because everything is in a lot of locations, but I could not figure out how to make it better. The main problem is that they are all very dependent from each other:
  • radio IC needs PCM signal, before initialising
  • mplayer need to have pulse running before starting, etc.
Hans

Return to “Advanced users”