project-owner / PeppyMeter

PeppyMeter Repository
GNU General Public License v3.0
62 stars 13 forks source link

Question about use for recording with Raspberry Pi #7

Closed nls-GitHub closed 1 year ago

nls-GitHub commented 1 year ago

My application is for recording with the Raspberry Pi, I am using the Audio Injector Stereo board. There is a Python program which uses the 'arecord' command to generate wav files, convert them to MP3 files and upload them to a shared network drive. It is mostly an unattended setup, with cron starting the recordings at scheduled times for specific time durations, remotely monitored to a certain extent. Can PeppyMeter be used to check the recording levels remotely, and perhaps even sent to a local display for the times when the recordings are done manually? How would I integrate this with my Python program and the 'arecord'? All other sound devices are disabled, so the Audio Injector board is the only ALSA device for sound, as a default. Thanks.

project-owner commented 1 year ago

Hi,

I've never tried to use PeppyMeter for recording purposes. Though I think it should be doable. You need to prepare the ALSA configuration file similar to this one: https://github.com/project-owner/peppyalsa.doc/wiki/Configuration

Regarding checking levels remotely, the following functionality can be probably used: https://github.com/project-owner/PeppyMeter.doc/wiki/Web-Server In that case PeppyMeter will send level data as a Json object to the remote Web server. In that Web server you can handle that data as you want. This was tested only in a local network. Depending on a speed of your local network you can experience some lag.

First, I would recommend to install PeppyMeter and make it working in a terminal: https://github.com/project-owner/peppyalsa.doc/wiki/VU-Meter Then you can try to leverage a display.

Best regards

nls-GitHub commented 1 year ago

Thanks for the feedback, would be good if there is a confirmation that this works for audio inputs. I should have been more clear about the remote access, that is already there with SSH and Remote.It, I might try to use VNC if necessary. So that is not a consideration for this, I am only interested in being able to get the audio levels programmatically. So where exactly do the values get picked up from, I have yet to read the documentation thoroughly?

project-owner commented 1 year ago

I was contacted several times regarding meter usage for input. But I don't know if that was implemented or not. There is a peppyalsa plugin: https://github.com/project-owner/peppyalsa.doc/wiki It sends a level data to a Linux named pipe. PeppyMeter picks that data up from a named pipe.

Best regards

nls-GitHub commented 1 year ago

I tried to follow the install instructions in the wiki for peppyalsa, it seemed to have quite a few warnings. But I went through to the end, and when I tried the aplay command, it showed the following:

pi@raspberrypi:~/Music $ aplay -D peppyalsa test.wav Playing WAVE 'test.wav' : Signed 16 bit Little Endian, Rate 44100 Hz, Mono aplay: set_params:1349: Channels count non available

The entire install log file is at https://drive.google.com/file/d/1hqPnnxvCa18GP12u31eHOclo4Sg1jCne/view?usp=sharing. Would it be possible to review and let me know what could be wrong? In particular, there seemed to be a missing directory.

pi@raspberrypi:~/peppyalsa $ aclocal && libtoolize aclocal: warning: couldn't open directory 'm4': No such file or directory libtoolize: putting auxiliary files in '.'. libtoolize: linking file './ltmain.sh' libtoolize: putting macros in AC_CONFIG_MACRO_DIRS, 'm4'. libtoolize: linking file 'm4/libtool.m4' libtoolize: linking file 'm4/ltoptions.m4' libtoolize: linking file 'm4/ltsugar.m4' libtoolize: linking file 'm4/ltversion.m4' libtoolize: linking file 'm4/lt~obsolete.m4'

My Raspbian installation is the 32-bit Bullseye Lite version, so headless. Are the install instructions compatible for that? Thanks.

project-owner commented 1 year ago

It looks OK. You can ignore warnings. Do you hear anything when you use 'aplay'?

nls-GitHub commented 1 year ago

For some reason, I am not hearing the audio output from my Fe-Pi board, the recording works though! The website for that board is not active, I am not sure whether the alsamixer settings are correct or not. So I switched back to the default Pi headphones, and while I can hear the wav file audio with the "aplay -D peppyalsa ... " command, I don't see the L and R bar graphs that are supposed to be there when meter_show is set to 1 in the .asoundrc file.

project-owner commented 1 year ago

Please open two terminals. In one run command: cat /home/pi/myfifo If everything works fine it will display binary data (garbage on screen). Another command to try 'tail -f /home/pi/myfifo'. In the other terminal run that 'aplay' command.

If you won't see L/R channels in the terminal and no garbage from 'cat' or 'tail' then there is something wrong - data doesn't come to the named pipe (/home/pi/myfifo).

nls-GitHub commented 1 year ago

This is the response from the cat /home/pi/myfifo command when aplay is running.

image

So where would I see the L/R channel bar-graphs on the terminal, as indicated in the Wiki page for peppyalsa?

project-owner commented 1 year ago

It should be visible in another terminal where you run 'aplay'.

nls-GitHub commented 1 year ago

image

I thought that it might depend on the order the two commands are issued, but either way, I don't see the L/R bar-graphs for the 'aplay' command.

project-owner commented 1 year ago

Have you actually compiled and started the program which shows the meter in a terminal? https://github.com/project-owner/peppyalsa.doc/wiki/VU-Meter-Usage#using-client-program-supplied-with-plugin

nls-GitHub commented 1 year ago

No, I wanted to take it step by step. Actually I need to check whether I enabled the meter_show again, with all the back and forth changes, will report back later in the day! I will have to come up with some type of a standalone display for the VU meter anyway, with the type of setup we have, so I will need to look at the example programs for using the data in the byte structure, and not use them as is. The most important thing is that this work for inputs, as we are only interested in recording and not playback. Hopefully I can test that also later today. Thanks for all the help so far!

nls-GitHub commented 1 year ago

Some updates. I did not have the meter_show set to 1, so corrected that. With the Pi headphones as the audio, I can now see the L and R bar-graphs with the 'aplay' command. I then switched the audio board to Fe-Pi in the config.txt, rebooted, checked both raspi-config and alsamixer to make sure that the default was that board. aplay by itself works well, I can even see the vu meter if I use the -vv option. But if I use the '-D peppyalsa' with that command, I get the error.

pi@raspberrypi:~/Music $ aplay -D peppyalsa /home/pi/Music/test.wav Playing WAVE '/home/pi/Music/test.wav' : Signed 16 bit Little Endian, Rate 44100 Hz, Mono aplay: set_params:1349: Channels count non available pi@raspberrypi:~/Music $

I then tried the arecord command with the '-D peppyalsa'. Here I get the "Unknown PCM" error.

pi@raspberrypi:~/Music $ sudo arecord -D peppyalsa -f cd -c 1 -d 300 /home/pi/Music/test.wav ALSA lib pcm.c:2660:(snd_pcm_open_noupdate) Unknown PCM peppyalsa arecord: main:830: audio open error: No such file or directory pi@raspberrypi:~/Music $

project-owner commented 1 year ago

Regarding output, make sure that card/device numbers for your audio card are the same in the .asoundrc and in the output from the command 'aplay -l' or 'aplay -L'. For example hw:0,0 if card/device is 0/0 or hw:1,0 if card/device is 1/0. Make sure that you changed all occurrences of the card/device in the file .asoundrc.

Regarding input, I cannot help you that much. Can you hear any audio while recording? You should probably split signal and redirect it accordingly. Though that's pretty complicated task in the ALSA configuration.

If you will be out of ideas try to post questions on forums. Here is pretty helpful one: https://www.diyaudio.com/community/threads/peppymeter.291010/page-28 Maybe someone will help you there.

nls-GitHub commented 1 year ago

image

image

Both 'aplay' and 'arecord' work fine by themselves, I can hear the playback and the recording is correct, but the problem is only when I use the '-D peppyalsa' option. They abort with the error messages. But it does work if the audio output is via the Pi headphones. So it is puzzling.

nls-GitHub commented 1 year ago

I started afresh with a new Raspbian Lite install, did the upgrades, and configured the Fe-Pi audio board. Checked both 'aplay' and 'arecord' to make sure that they work properly. Then I followed the Express install procedure from https://github.com/project-owner/peppyalsa.doc/wiki/Express. I then tried the 'aplay' command with the '-D peppyalsa' option, tried it with 'sudo' also, but keep getting the "cannot open" error for a shared library file. That file is there is the specified path, so I am totally stumped.

image

project-owner commented 1 year ago

I didn't try Express installation for a long time. Have you tried a regular procedure? https://github.com/project-owner/peppyalsa.doc/wiki/Installation

nls-GitHub commented 1 year ago

The Expert installation was what I had tried earlier, which also didn't work properly with the Fe-Pi audio board as reported earlier. Perhaps I will give that another try with a fresh install. Is there a way to easily uninstall this add-on, or do I have to start out with a new Raspbian Lite install?

project-owner commented 1 year ago

The whole peppyalsa plugin is just this file: /usr/local/lib/libpeppyalsa.so If you remove it you remove the plugin.

nls-GitHub commented 1 year ago

I tried the other install method again, no luck. I even tried with the legacy Buster Lite release, same issues. 'aplay' works fine by itself, but using the '-D peppyalsa' gives all kinds of error messages and the command aborts. Shouldn't this be independent of which audio device is used, if alsa is managing that?

image

project-owner commented 1 year ago

Do you mean that 'aplay' works fine with on-board audio using 'peppyalsa' device but still doesn't work with Fe-Pi board? I'm not sure what could be the reason. The ALSA configuration looks OK to me. When you define 'peppyalsa' in the config file you make a signal go through two additional ALSA plugins: 'meter' and 'peppyalsa'.

I would still recommend to post the question on diyAudio forum. The ALSA experts on that forum could be helpful.

nls-GitHub commented 1 year ago

I tried one more experiment, enabling both the on-board audio as well as the Fe-Pi board in /boot/config.txt. So 'aplay -l' shows - image

If the card number is 0, everything is fine. image

If I edit .asoundrc to change the card number from 0 to 1, I get the error. image

nls-GitHub commented 1 year ago

From the help that I received at https://www.diyaudio.com/community/threads/peppymeter.291010/page-29, it seems to be a mono/stereo issue, which I don't fully understand, but manageable. I am now trying to move to the next step of using the Python program, and getting a module not found error. image What would be causing this? Thanks for all the help.

project-owner commented 1 year ago

Hmm, how did you install the PeppyMeter? Did you use the 'git clone' command? It should be like this: git clone https://github.com/project-owner/PeppyMeter.git assuming that 'git' was installed.

nls-GitHub commented 1 year ago

Yes, I followed the instructions at https://github.com/project-owner/peppyalsa.doc/wiki/Expert. 'git' had to be installed with the Raspbian Lite, but not for the version with the desktop.

project-owner commented 1 year ago

Those instructions are for the installation of the 'peppyalsa' plugin. To install the Python program PeppyMeter you need to follow these instructions: https://github.com/project-owner/PeppyMeter.doc/wiki/Installation

nls-GitHub commented 1 year ago

Sorry, I gave the wrong link earlier. I had followed the instructions in the link you sent. Is there a requirement that peppymeter.py be in the PeppyMeter folder, along with the other files? I had it in a different folder. But even if I move it to that folder, I get the following - image

project-owner commented 1 year ago

Yes, all files should be in the same folder. What kind of display are you trying to use? Is it HDMI, DSI or SPI? Does it have a touchscreen?

nls-GitHub commented 1 year ago

HDMI, no touch screen for now while testing, but my plan is to have it in the actual installation. The current setup has a push-button switch and LED connected to digital IO pins, and they are used to initiate and terminate the manual recordings, and indicate the status by different flashing rates of the LED. Along with the PeppyMeter, I can add those features and more via the touch screen HDMI display, it will be much more user-friendly.

project-owner commented 1 year ago

For HDMI display you need to set False for this property: https://github.com/project-owner/PeppyMeter/blob/c9056bd7e798e0d07bc77587c25f75dda0c80018/config.txt#L25 and change this property to /dev/fb0: https://github.com/project-owner/PeppyMeter/blob/c9056bd7e798e0d07bc77587c25f75dda0c80018/config.txt#L19

nls-GitHub commented 1 year ago

image image image

I never know when 'sudo' should be used, so tried with and without, getting different errors with both. I am now using the Desktop version of Raspbian Bullseye. My other question is whether it is possible to use the Lite version and still have PyGame display the meters and other controls on a small HDMI display.

project-owner commented 1 year ago

If you are trying to do that in a headless mode to avoid the issue you need to start the program this way: openvt -s -w -- python3 peppymeter.py Also the following steps should be done for pi user to avoid sudo when you start the program: https://github.com/project-owner/PeppyPlayers.doc/wiki/Headless#user-pi-configuration

nls-GitHub commented 1 year ago

My current testing is with the Raspbian Bullseye with the Desktop environment. How do I avoid the errors that are showing up? The question about the Lite version was for the final installation, where all we need is the VU meter display and some other controls and indictors, not a full desktop. My question about the use of 'sudo' was regarding the different error messages - unable to open console, unable to open mouse.

project-owner commented 1 year ago

I installed 'Raspberry Pi OS with desktop and recommended software' from here: https://www.raspberrypi.com/software/operating-systems/#raspberry-pi-os-32-bit configured 'pi' user by copying file userconf.txt to the boot folder

Connected HDMI monitor, USB mouse and keyboard.

Opened a terminal on a desktop. I installed PeppyMeter using command: git clone https://github.com/project-owner/PeppyMeter.git then cd PeppyMeter Then without making any configuration changes I ran the command: python3 peppymeter.py and was able to see PeppyMeter UI in a separate window.

nls-GitHub commented 1 year ago

I really need to apologize! I am so used to working via SSH that I was trying everything on the SSH terminal window and not on the terminal of the HDMI monitor! Now that I did that, I see another window popup with the meters. The main terminal is showing "libpng warning: iCCP: known incorrect sRGBprofile" message for some meters. So would the 'aplay' or 'arecord' commands be executed in another terminal window for the values to show up on the meters?

project-owner commented 1 year ago

You can ignore those warnings. No matter how you are running aplay/arecord as they use peppyalsa plugin which in turn is using a named pipe. PeppyMeter will get data from that pipe.

nls-GitHub commented 1 year ago

Thanks. Shouldn't I be able to start the peppymeter.py program automatically at reboot using cron and have the meter show up? I tried adding the line '@reboot python3 /home/pi/PeppyMeter/peppymeter.py &' command, but that didn't seem to work. I also tried '@reboot openvt -s -w -- python3 /home/pi/PeppyMeter/peppymeter.py &'.

project-owner commented 1 year ago

I've never tried to do that in OS with Desktop. In a Lite OS (w/o Desktop) you can start it from the /etc/rc.local using this command: su pi -c 'cd /home/pi/PeppyMeter; openvt -s -- python3 peppymeter.py' or using service by providing the file similar to this one (e.g. peppy.service): https://github.com/project-owner/Peppy.doc/blob/master/files/peppy.service in the folder /etc/systemd/system

nls-GitHub commented 1 year ago

I went back to the Lite version and tried the two methods, don't seem to be having much success. The first method with the rc.local triggers an error message during boot about being unable to open /dev/tty2, permission denied. Also, should that command have the -w option or not for the openvt? For the second method, I followed https://www.makeuseof.com/what-is-systemd-launch-programs-raspberry-pi/#:~:text=If%20you%20managed%20to%20run,reboot%20to%20restart%20your%20Pi. to create the service, assume that the working folder should be /home/pi/PeppyMeter and not Peppy as shown in the link you provided. When I tried to test the service with the 'sudo systemctl start peppy.service' command, it just returns with a prompt and I don't see anything on the monitor.

project-owner commented 1 year ago

To fix the first issue you need either complete these steps: https://github.com/project-owner/PeppyPlayers.doc/wiki/Headless#user-pi-configuration or use 'sudo'. I just gave you the example of the systemd file. It should be changed for PeppyMeter accordingly. It works after reboot (not interactively).

project-owner commented 1 year ago

Also make sure that the Pygame library is installed: https://github.com/project-owner/PeppyMeter.doc/wiki/Installation

nls-GitHub commented 1 year ago

I got past the earlier error by making the changes listed under "User pi configuration". Now I am getting a different set of error messages related to pygame. Hope the screenshot is readable. Many thanks for your help, slow and steady progress, I guess. image

project-owner commented 1 year ago

I don't use Pygame 2 yet. I use 1.9.6. Check this thread to fix the issue: https://forums.raspberrypi.com/viewtopic.php?t=333733

nls-GitHub commented 1 year ago

I installed that, and now it is complaining about some other libraries - vc4, kms-swrast and swrast. I just installed pygame per the instructions, and it seems to be 2.1.2. Is all this because of some incompatibility with Bullseye and I am better off with the legacy Buster Lite?

image

project-owner commented 1 year ago

That's right. I would recommend to use Buster Lite because of all these issues. That's (and some other) the main reason why I still use Buster Lite and Pygame 1.9.6 Hopefully you will have less issues with Buster Lite :)

nls-GitHub commented 1 year ago

Okay, I will get started with the Buster Lite, install the various packages, and report back. But perhaps this project needs to be reviewed to work properly with Bullseye Lite. I was able to get the meters to show up on Bullseye with Desktop which presumably has pygame 2.1.2, so it is probably some minor additions.

project-owner commented 1 year ago

This is in my TODO list. Because of all those issues the raspberry team decided to support Buster for another 2 years. There is no any new code just security patches. There are some other issues with Bullseye which is using Python 3.9 and Pygame 2. This combination doesn't work with some other libraries. Also Pygame 2 doesn't support CD drives anymore.

I've tried to switch to Bullseye, Pygame 2 and Python 3.9 two times already and spent too much time trying to fix all those issues. So decided to stay with Buster for another year or so.

nls-GitHub commented 1 year ago

Thanks. The steps to modfy the ALSA libraries are very involved, would be good if a later version of ALSA can be easily installed with Buster. I think that I did everything right with Buster Lite, it seems to have PyGame 1.9.4.post1 as a default. I got this error when I booted up with the commands in the rc.local file. image

project-owner commented 1 year ago

Try to add 'pi' user to the 'input' group: https://www.diyaudio.com/community/threads/peppy-player.288412/post-6274358

nls-GitHub commented 1 year ago

Didn't help, same error message. image