nerves-project / nerves_system_rpi3

Base Nerves system configuration for the Raspberry Pi 3
Apache License 2.0
93 stars 71 forks source link

Include alsautils like aplay? #36

Closed fhunleth closed 1 year ago

fhunleth commented 6 years ago

We currently enable several Linux sound drivers, but don't enable alsautils. While it would be nice to have an hex package that plays audio, the only way that I know of now is to make calls to aplay and the other alsa tools. This requires making a custom system for audio. I'm leaning to include alsautils so that audio can work without a custom system. Anyone have concerns? I'd apply this to all of the other RPi systems for consistency as well.

dkarter commented 6 years ago

Yes playing sound would be awesome! any examples of this in the wild?

ConnorRigby commented 6 years ago

@dkarter i have a custom system that uses alsa-utils in production. I use it for espeak.

lasseebert commented 6 years ago

I am also trying to get audio working on a rpi with a custom built system, but no luck so far.

@ConnorRigby: Any chance you could share your working config? (nerves_defconfig, linux_4.4.defconfig, config.txt, whichever are changed from the default).

ConnorRigby commented 6 years ago

here is my custom system. It enables a couple alsa utilities.

I wouldn't use this system if you can avoid it. It has python and a few other heavy dependencies that make mix firmware take much longer than it needs.

lasseebert commented 6 years ago

@ConnorRigby Thanks :smiley: Now I should be able to diff with my own.

ConnorRigby commented 6 years ago

@lasseebert something i forgot about you will need to add audio=on: https://github.com/FarmBot-Labs/nerves_system_farmbot_rpi3/blob/master/config.txt#L18

lasseebert commented 6 years ago

Thanks @ConnorRigby. Finally got it working :)

Note to self and others: The same config does not work with the rpi image, only the rpi3. I initially tried to get it working on an original RaspPi, but continued on a RaspPi 3. Also: It seems the I need to wait a few seconds before using any audio, otherwise it is not yet initalized.

brianmay commented 6 years ago

The bulk of my customisation for rpi2 and rpi3 is:

--- a/config.txt
+++ b/config.txt
@@ -16,6 +16,7 @@ gpu_mem=192

 # Enable I2C and SPI
 dtparam=i2c_arm=on,spi=on
+dtparam=audio=on

 # Comment this in or modify to enable OneWire
 # NOTE: check that the overlay that you specify is in the boot partition or
diff --git a/nerves_defconfig b/nerves_defconfig
index 0bff65b..0f50285 100644
--- a/nerves_defconfig
+++ b/nerves_defconfig
@@ -29,6 +29,15 @@ BR2_LINUX_KERNEL_DTS_SUPPORT=y
 BR2_LINUX_KERNEL_INTREE_DTS_NAME="bcm2710-rpi-3-b bcm2710-rpi-cm3 bcm2710-rpi-3-b-plus"
 BR2_LINUX_KERNEL_EXT_KERNEL_WIRELESS_REGDB=y
 BR2_PACKAGE_BUSYBOX_CONFIG="${BR2_EXTERNAL_NERVES_PATH}/board/nerves-common/busybox-1.22.config"
+BR2_PACKAGE_ALSA_UTILS=y
+BR2_PACKAGE_ALSA_UTILS_AMIXER=y
+BR2_PACKAGE_ALSA_UTILS_APLAY=y
+BR2_PACKAGE_ESPEAK=y
+BR2_PACKAGE_ESPEAK_AUDIO_BACKEND_ALSA=y
+BR2_PACKAGE_MPD=y
+BR2_PACKAGE_MPD_FFMPEG=y
+BR2_PACKAGE_MPD_FLAC=y
+BR2_PACKAGE_MPD_MPC=y
 BR2_PACKAGE_E2FSPROGS=y
 # BR2_PACKAGE_E2FSPROGS_FSCK is not set
 BR2_PACKAGE_RPI_FIRMWARE=y

So I wouldn't mind having these enabled by default. Question is how much we want to enable? This will increase the size of every build based on a default image.

fhunleth commented 6 years ago

I think that we should enable it. The Raspberry Pi configurations haven't been minimal in a long time and I don't remember alsa being a big addition. I assume espeak isn't big either. mpd's addition of ffmpeg worries be a little but if you tell me that it's a <500KB adder to the image then I might be ok with that. The bigger issue for me is maintenance since things in the default configuration tend to come back to me or Justin to fix should anything go wrong with them. If there's an easy way to check that they work in our integration tests, that would be super helpful. I don't know if it's as simple as running espeak and checking the exit code? If it is, could you add that to an integration test? See https://github.com/nerves-project/nerves_system_rpi3/blob/master/test/priv/test/test_test.exs. Admittedly, the tests are pretty weak, but we intend to improve.

brianmay commented 6 years ago

espeak supports writing to stdout, this might help for testing. I use this script:

#!/bin/sh
set -e
espeak -ven+f5 -k5 -w /tmp/out.wav "$*"
aplay -q /tmp/out.wav
#espeak -ven+f5 -k5 -w /dev/stdout "$*" | aplay -q -;

I did it this way when I found using espeak directly to ALSA seems to stutter occasionally. The commented out version probably would be better, and I was using it on my pre-nerves setup, but for some reason it doesn't work on a nerves image, and I have no idea why.

mpd probably can be tested with mpd --help and mpc version. I have no idea how big this is likely to be, and it probably depends on what plugins you enable in mpd (e.g. ffmpeg I imagine will pull in ffmpeg).

ConnorRigby commented 5 years ago

@fhunleth this can be closed now right?

fhunleth commented 5 years ago

It's not completely fixed. I added espeak and some ALSA to the systems. I'm not very happy with the size added to the systems vs. the functionality added. For example, only .wav files can be played back now. That's not ideal, but I didn't know the best way of adding support for other codecs nor how to verify that what I added actually worked.

As a side comment, it's also important that we get Elixir libraries that wrap the calls to espeak and ALSA to make them easy to use. The docs are hard for me to be sure how to best use them, so I feel for others using this.

rayrrr commented 4 years ago

Good point @fhunleth. Someone is finally working on an Elixir ALSA lib: https://github.com/karlsson/xalsa. I hope these projects can help each other!

karlsson commented 4 years ago

Hi, I am actually trying to get xalsa and some layer on top of that: https://github.com/karlsson/granulix , to run on my rpi3 using Nerves. I started to convert the Makefiles to similar as in https://github.com/ConnorRigby/hello_calendar and it builds fine (Thanks @ConnorRigby). I can burn the firmware onto my rpi but I have problems opening the device. I have tried with different names in my mix.exs but none is working sofar: defp pcms("host"), do: ["plughw:PCH,0": 2] defp pcms(_rpi), do: ["plughw:ALSA,1": 2]

My aplay -L looks a bit empty though so I am wondering if I need to add things in some configuration:

null
    Discard all samples (playback) or generate zero samples (capture)
default:CARD=ALSA
    bcm2835 ALSA, bcm2835 ALSA
    Default Audio Device
sysdefault:CARD=ALSA
    bcm2835 ALSA, bcm2835 ALSA
    Default Audio Device
:ok

I am pretty new to both Elixir and Nerves so any ideas are appreciated.

karlsson commented 4 years ago

Hi again, for xalsa I found out that the alsa setup (in xalsa) is too rigid for rpi3 and so I need to fix this. Nothing to do with Nerves configuration.

fhunleth commented 4 years ago

@karlsson Thanks for the update. I've spoken to a couple people, but I'm not sure we have ideas for you. We are very interested in your progress.

karlsson commented 4 years ago

Thanks @fhunleth, I have added an issue to xalsa so that you can see what I think needs to be done and follow the progress for adapting it to rpi3.

jjcarstens commented 1 year ago

Closing stale issue. Let's open a new issue if more work needs to be evaluated.