Need RPi GPIO output of sample-rate

Status
This old topic is closed. If you want to reopen this topic, contact a moderator using the "Report Post" button.
I would like to output two or three bits of encoded sample-rate of the track playing to the GPIO's of the Raspberry Pi, but I am not a programmer and I don't know if this information is a variable that can be pulled from DietPi or not.

I believe I already have one bit that distinguishes 44.1/88.2/176.4 and 48/96/192 from Digi boards, so I need the other two bits.

Is this difficult. Can anyone write the code?

Thanks
 
So, you are using a hifiberry digi+ or another alsa output?
For alsa devices, the actual samplerate is shown in this file
Code:
LibreELECpi2:~ # cat /proc/asound/card0/pcm0p/sub0/hw_params
access: RW_INTERLEAVED
format: S24_LE
subformat: STD
channels: 2
rate: 44100 (44100/1)
period_size: 2205
buffer_size: 8820
LibreELECpi2:~ #
I don't know dietPi, but you may use python or shell with wiringPi to monitor this file, scan the rate line then set GPIOs accordingly.
 
Last edited:
So, you are using a hifiberry digi+ or another alsa output?
For alsa devices, the actual samplerate is shown in this file
Code:
LibreELECpi2:~ # cat /proc/asound/card0/pcm0p/sub0/hw_params
access: RW_INTERLEAVED
format: S24_LE
subformat: STD
channels: 2
rate: 44100 (44100/1)
period_size: 2205
buffer_size: 8820
LibreELECpi2:~ #
I don't know dietPi, but you may use python or shell with wiringPi to monitor this file, scan the rate line then set GPIOs accordingly.

Cool. I will give this a try manually. I need someone to write the code to scan this and output to GPIOs. This would need to be incorporated into a non-volatile SD image, or made easy for me to just add a patch to the image once it's running, if that is possible.

I can try wiringPi first to see if I can do it myself. No sure they have instructions for scanning this file and then setting the appropriate bits though. I'm a novice at software. I'm a hardware designer.
 
One hint when using simple shell:
grep rate /proc/asound/card0/pcm0p/sub0/hw_params | sed -e 's/rate: \([0-9]*\) .*/\1/'

It will scan the file and extract only the sample rate value (or empty string if no output)
You can then test the value and use gpio utility to set the according GPIOs.
The GPIO utility | Gordons Projects

When your shell is fine, you can loop on it every second or two (multiple ways to do it)
 
One hint when using simple shell:


It will scan the file and extract only the sample rate value (or empty string if no output)
You can then test the value and use gpio utility to set the according GPIOs.
The GPIO utility | Gordons Projects

When your shell is fine, you can loop on it every second or two (multiple ways to do it)

Can I use WiringPi commands from PuTTY?

I tried logging into PuTTY while the board was playing music and the prompt does not come up. I though DietPi could multi-task. Do I have to log into PuTTY first and then start music?
 
Can I use WiringPi commands from PuTTY?
Yes. WiringPi comes with the gpio utility that you use from command line and shell scripts.
The GPIO utility | Gordons Projects

I tried logging into PuTTY while the board was playing music and the prompt does not come up. I though DietPi could multi-task. Do I have to log into PuTTY first and then start music?
I don't use DietPi but it's based on raspbian so I don't see why you couldn't connect by ssh with putty, music playing or not.
DietPi / Fuzon • View topic - Getting started | Download DietPi image
 
Status
This old topic is closed. If you want to reopen this topic, contact a moderator using the "Report Post" button.