-
- Posts: 20
- Joined: Tue Mar 06, 2012 8:16 pm
ALSA on Raspbian
Has anyone managed to get ALSA working? I've installed Shairport but can't get it to output anything through the headphone jack.
Re: ALSA on Raspbian
Many people have got sound working OK. Does this list help?
http://elinux.org/R-Pi_Troubleshooting#Sound
http://elinux.org/R-Pi_Troubleshooting#Sound
-
- Posts: 20
- Joined: Tue Mar 06, 2012 8:16 pm
Re: ALSA on Raspbian
Code: Select all
drewharris@drew-rpi:/opt/vc/src/hello_pi/hello_audio$ sudo make
cc -DSTANDALONE -D__STDC_CONSTANT_MACROS -D__STDC_LIMIT_MACROS -DTARGET_POSIX -D_LINUX -fPIC -DPIC -D_REENTRANT -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 -U_FORTIFY_SOURCE -Wall -g -DHAVE_LIBOPENMAX=2 -DOMX -DOMX_SKIP64BIT -ftree-vectorize -pipe -DUSE_EXTERNAL_OMX -DHAVE_LIBBCM_HOST -DUSE_EXTERNAL_LIBBCM_HOST -DUSE_VCHIQ_ARM -Wno-psabi -I/opt/vc/include/ -I/opt/vc/include/ -I./ -I../libs -g -c audio.c -o audio.o -Wno-deprecated-declarations
cc -DSTANDALONE -D__STDC_CONSTANT_MACROS -D__STDC_LIMIT_MACROS -DTARGET_POSIX -D_LINUX -fPIC -DPIC -D_REENTRANT -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 -U_FORTIFY_SOURCE -Wall -g -DHAVE_LIBOPENMAX=2 -DOMX -DOMX_SKIP64BIT -ftree-vectorize -pipe -DUSE_EXTERNAL_OMX -DHAVE_LIBBCM_HOST -DUSE_EXTERNAL_LIBBCM_HOST -DUSE_VCHIQ_ARM -Wno-psabi -I/opt/vc/include/ -I/opt/vc/include/ -I./ -I../libs -g -c sinewave.c -o sinewave.o -Wno-deprecated-declarations
cc -o hello_audio.bin -Wl,--whole-archive -L/opt/vc/lib/ -lGLESv2 -lEGL -lopenmaxil -lbcm_host -lvcos -lvchiq_arm ../libs/libilclient.a audio.o sinewave.o -Wl,--no-whole-archive -rdynamic
audio.o: In function `audioplay_create':
/opt/vc/src/hello_pi/hello_audio/audio.c:69: multiple definition of `audioplay_create'
../libs/libilclient.a(audioplay.c.o):audioplay.c:(.text+0x4): first defined here
audio.o: In function `audioplay_delete':
/opt/vc/src/hello_pi/hello_audio/audio.c:202: multiple definition of `audioplay_delete'
../libs/libilclient.a(audioplay.c.o):audioplay.c:(.text+0x34c): first defined here
audio.o: In function `audioplay_get_buffer':
/opt/vc/src/hello_pi/hello_audio/audio.c:226: multiple definition of `audioplay_get_buffer'
../libs/libilclient.a(audioplay.c.o):audioplay.c:(.text+0x3e0): first defined here
audio.o: In function `audioplay_play_buffer':
/opt/vc/src/hello_pi/hello_audio/audio.c:248: multiple definition of `audioplay_play_buffer'
../libs/libilclient.a(audioplay.c.o):audioplay.c:(.text+0x444): first defined here
audio.o: In function `audioplay_get_latency':
/opt/vc/src/hello_pi/hello_audio/audio.c:314: multiple definition of `audioplay_get_latency'
../libs/libilclient.a(audioplay.c.o):audioplay.c:(.text+0x54c): first defined here
collect2: ld returned 1 exit status
make: *** [hello_audio.bin] Error 1
rm sinewave.o audio.o
-
- Posts: 20
- Joined: Tue Mar 06, 2012 8:16 pm
Re: ALSA on Raspbian
Nevermind, skipping that and doing the modprobe step helped.
Thanks.
Thanks.
Re: ALSA on Raspbian
I think my ALSA is OK (started with the Pisces image) - aplay /usr/share/sounds/alsa/Front_Center.wav and speaker-test -twav work fine from a terminal in openbox.
But both vlc and mplayer are silent - mplayer gives and vlc gives Any help welcome.
But both vlc and mplayer are silent - mplayer gives
Code: Select all
Playing /mnt/server/Music/Keane/Hopes and Fears/01 Somewhere Only We Know.mp3.
libavformat version 53.21.0 (external)
Mismatching header version 53.19.0
Audio only file format detected.
Clip info:
Title: Somewhere Only We Know
Artist: Keane
Album: Hopes And Fears
Year: 2004
Comment: Created by Grip
Track: 1
Genre: Indie
Load subtitles in /mnt/server/Music/Keane/Hopes and Fears/
==========================================================================
Requested audio codec family [mpg123] (afm=mpg123) not available.
Enable it at compilation.
Opening audio decoder: [ffmpeg] FFmpeg/libavcodec audio decoders
libavcodec version 53.35.0 (external)
Mismatching header version 53.32.2
AUDIO: 44100 Hz, 2 ch, floatle, 128.0 kbit/4.54% (ratio: 16001->352800)
Selected audio codec: [ffmp3float] afm: ffmpeg (FFmpeg MPEG layer-3 audio)
==========================================================================
AO: [pulse] Init failed: Connection refused
Failed to initialize audio driver 'pulse'
[AO_ALSA] Unable to set hw-parameters: Invalid argument
Failed to initialize audio driver 'alsa'
[AO SDL] Samplerate: 44100Hz Channels: Stereo Format floatle
[AO SDL] using aalib audio driver.
[AO SDL] Unsupported audio format: 0x1d.
[AO SDL] Unable to open audio: No available audio device
Failed to initialize audio driver 'sdl:aalib'
Could not open/initialize audio device -> no sound.
Audio: no sound
Video: no video
Exiting... (End of file)
Code: Select all
[0x14b9f38] alsa audio output error: cannot commit hardware parameters: Invalid argument
[0x14b9f38] pulse audio output error: PulseAudio server connection failure: Connection refused
[0x14b9f38] oss audio output error: cannot open audio device (/dev/dsp)
[0x14b9f38] main audio output error: no suitable audio output module
[0x43f00a08] main decoder error: failed to create audio output
Daily driver: Pi3B, 64GB Samsung Evo+ @100MHz, DVB-T, onboard WiFi for internet, BT/USB dongle for KB/mouse, 250GB HDD via USB for media, Raspbian Jessie Lite with Openbox desktop.
Museum: Pi B
Museum: Pi B
-
- Posts: 200
- Joined: Tue Apr 17, 2012 4:10 pm
Re: ALSA on Raspbian
Title: Somewhere Only We Know
Artist: Keane
Album: Hopes And Fears
..there is a problem there for a start
Artist: Keane
Album: Hopes And Fears
..there is a problem there for a start

-
- Posts: 25
- Joined: Fri Jun 01, 2012 2:39 pm
Re: ALSA on Raspbian
I had the same problem with vlc - not cracked the problem yet. I installed xine and that works, as does using aplay and mpg123 so I'm assuming at the moment it's a vlc specific problem. Shame because I do like vlc. Xine seems to do the same job though.
Re: ALSA on Raspbian
The problem seems to be resolved by using -srate 48000 mplayer parameter, like this:
It shouldn't be needed, alsa driver should select this automaticaly. I will debug this some more.
Code: Select all
mplayer -srate 48000 FILE
Re: ALSA on Raspbian
Yes works for me, thanks.kadamski wrote:The problem seems to be resolved by using -srate 48000 mplayer parameter. ...
It shouldn't be needed, alsa driver should select this automaticaly. I will debug this some more.
Daily driver: Pi3B, 64GB Samsung Evo+ @100MHz, DVB-T, onboard WiFi for internet, BT/USB dongle for KB/mouse, 250GB HDD via USB for media, Raspbian Jessie Lite with Openbox desktop.
Museum: Pi B
Museum: Pi B
Re: ALSA on Raspbian
Just wanted to let you know that I've got some more information about the problem. It seems that alsa device 'default' is broken in that it not reporting it's capabilites correctly (it will return ok for every format/rate/channel numebers/etc you will try to set). This makes mplayer and VLC (and probably others) confused. You can change alsa device in mplayer do 'hw' using:
It lets you play audio files without resampling (which was enabled by -srate option). This gives us bonus for some less CPU used. In my case it was 9.5% vs 14% on some testing mp3. It's still quite high since using "-ao oss" give's me only 6.5% cpu usage.
BTW. Does anyone know if it's raspbian specific issue or maybe it is the same on other distros?
Code: Select all
mplayer -ao alsa:device=hw FILE
BTW. Does anyone know if it's raspbian specific issue or maybe it is the same on other distros?
Re: ALSA on Raspbian
Ok, found system wide solution. I'm don't know yet why it's working, though. Just configure alsa-lib with standard:
and it will work for both mplayer and vlc (and others). Just save that file in /etc/asound.conf (system wide) or in ~/.asoundrc (only for one user).
Code: Select all
pcm.!default {
type hw
card 0
}
ctl.!default {
type hw
card 0
}
Re: ALSA on Raspbian
I don't know if anybody is still interested but I have some more informations. Now i know why this config file fixess issues. It's not so easy to find proper documentation for ALSA but i was finally able to check what exactly "default" device in ALSA is (without modifications). It's defined in '/usr/share/alsa/pcm/default.conf' and defaults to be:
Which means, be default, "default" device uses plug plugin. It should, in theory be able to handle all possible formats on input and convert it to something that sound card is able to play. This is why it was reporting "ok" for every possible format i tried. But somehow, it does not convert things as it should and as soon as you try to commit wrong configuration to ALSA, it returns error.
So, when we use config file from my previous post, we override this and uses "hw" plugin instead of "plug". And "hw" can only use formats that are directly supported by hardware card. This is why it does report things correctly and makes mplayer and vlc switch to it's default save formats.
So now the only question is - why isn't "plug" plugin working as it should...
Code: Select all
type plug
slave.pcm {
type hw
card $CARD
}
So, when we use config file from my previous post, we override this and uses "hw" plugin instead of "plug". And "hw" can only use formats that are directly supported by hardware card. This is why it does report things correctly and makes mplayer and vlc switch to it's default save formats.
So now the only question is - why isn't "plug" plugin working as it should...
Re: ALSA on Raspbian
Oh, and I finally had time to install standard Debian Wheezy image and it has the same issue so it's not raspbian specific.
- mpthompson
- Posts: 620
- Joined: Fri Feb 03, 2012 7:18 pm
- Location: San Carlos, CA
Re: ALSA on Raspbian
Please, do continue to post what you find. I really haven't had time to play around with sound on my Raspberry Pi, but I will eventually. Having notes in these forums as to what problems people encountered and how they worked around them will definitely be a big help to me. I hope that much of the information in these forums, such as getting ALSA to work, will eventually be edited and find their way onto the Wiki. However, in the meantime this forum is the best place to keep track of issues and their solutions.kadamski wrote:I don't know if anybody is still interested but I have some more informations.
Re: ALSA on Raspbian
Some more informations, then:
I've written simple C program that was testing alsa capabilites. It set exactly the same parameters that are used by mplayer with my testing mp3. Then, I've checked that it stops returning error when i change PCM format from float to S16_LE.
I've wrriten simple alsa configuration, creating virtual "float" ALSA device that changes format to S16_LE and then passes this to plughw. Playing using this device works good. Here's the config file:
So for some reason, plughw is not converting format from float to int as it should.
I've written simple C program that was testing alsa capabilites. It set exactly the same parameters that are used by mplayer with my testing mp3. Then, I've checked that it stops returning error when i change PCM format from float to S16_LE.
I've wrriten simple alsa configuration, creating virtual "float" ALSA device that changes format to S16_LE and then passes this to plughw. Playing using this device works good. Here's the config file:
Code: Select all
pcm.float {
type lfloat
slave {
pcm "plughw:0,0"
format S16_LE
}
}
-
- Raspberry Pi Engineer & Forum Moderator
- Posts: 6740
- Joined: Wed Aug 17, 2011 7:41 pm
- Location: Cambridge
Re: ALSA on Raspbian
@kadamski
Yes, please continue investigating. Let me know if you think there's a problem with what the ALSA driver reports.
Yes, please continue investigating. Let me know if you think there's a problem with what the ALSA driver reports.
Re: ALSA on Raspbian
So it seems that plug plugin (or plughw device, that is a wrapper around this plugin) only works ok when you use configuration supported directly by the card. It claims supporting all possible values (and on my PC it accually does) but can not handle any conversion. Or at least can not convert format and channel number. I have to check if it's the same on debian squeeze, maybe it's a bug only in wheezy. What is strange for me is that it's hard to find much complaints about this problem on forums, nobody uses mplayer/vlc (or any other alsa application that produces float format PCM)?
Re: ALSA on Raspbian
Trying to get ALSA and MPD working to output to a USB DAC. I've done this many times on other platforms with no problem. But ALSA is having problems on the pi. I am using 1.0.24 drivers and aplay outputs the following:
The funny thing is, aplay -l lists the USB DAC just fine.
Is this the same issue being discussed here?
- Jim
Code: Select all
ALSA lib confmisc.c:768:(parse_card) cannot find card '0'
ALSA lib conf.c:4170:(_snd_config_evaluate) function snd_func_card_driver returned error: No such file or directory
ALSA lib confmisc.c:392:(snd_func_concat) error evaluating strings
ALSA lib conf.c:4170:(_snd_config_evaluate) function snd_func_concat returned error: No such file or directory
ALSA lib confmisc.c:1251:(snd_func_refer) error evaluating name
ALSA lib conf.c:4170:(_snd_config_evaluate) function snd_func_refer returned error: No such file or directory
ALSA lib conf.c:4649:(snd_config_expand) Evaluate error: No such file or directory
ALSA lib pcm.c:2190:(snd_pcm_open_noupdate) Unknown PCM default
aplay: main:654: audio open error: No such file or directory
Is this the same issue being discussed here?
- Jim
Re: ALSA on Raspbian
Not really but please post results of "aplay -l" and "aplay -L" and the commandline you have used to get this message. And .asoundrc or alsa.conf if you are using one.
Re: ALSA on Raspbian
kadamski -
Here is the output of the two commands. I am not using alsa.conf
- Jim
Here is the output of the two commands. I am not using alsa.conf
Code: Select all
root@piplayer:/music# aplay -l
**** List of PLAYBACK Hardware Devices ****
card 1: Interface [Schiit USB Interface], device 0: USB Audio [USB Audio]
Subdevices: 1/1
Subdevice #0: subdevice #0
card 1: Interface [Schiit USB Interface], device 1: USB Audio [USB Audio #1]
Subdevices: 1/1
Subdevice #0: subdevice #0
card 1: Interface [Schiit USB Interface], device 2: USB Audio [USB Audio #2]
Subdevices: 1/1
Subdevice #0: subdevice #0
Code: Select all
root@piplayer:/music# aplay -L
null
Discard all samples (playback) or generate zero samples (capture)
default:CARD=Interface
Schiit USB Interface, USB Audio
Default Audio Device
front:CARD=Interface,DEV=0
Schiit USB Interface, USB Audio
Front speakers
surround40:CARD=Interface,DEV=0
Schiit USB Interface, USB Audio
4.0 Surround output to Front and Rear speakers
surround41:CARD=Interface,DEV=0
Schiit USB Interface, USB Audio
4.1 Surround output to Front, Rear and Subwoofer speakers
surround50:CARD=Interface,DEV=0
Schiit USB Interface, USB Audio
5.0 Surround output to Front, Center and Rear speakers
surround51:CARD=Interface,DEV=0
Schiit USB Interface, USB Audio
5.1 Surround output to Front, Center, Rear and Subwoofer speakers
surround71:CARD=Interface,DEV=0
Schiit USB Interface, USB Audio
7.1 Surround output to Front, Center, Side, Rear and Woofer speakers
iec958:CARD=Interface,DEV=0
Schiit USB Interface, USB Audio
IEC958 (S/PDIF) Digital Audio Output
Re: ALSA on Raspbian
Please try using aplay like this:
Code: Select all
aplay - D hw:1,0 FILE.WAV
Re: ALSA on Raspbian
And back to my original research:
1. There is (almost) the same problem on Debian Squeeze. Plug plugin don't work there too. The only difference is that by default mplayer uses dome other audio codec for mp3 which produces integer PCM format instead of float one. Since RPi audio chipset supports most of audio configuration quite well as far as it's 2 channels and uses unsigned 8bit or signed 16 bits LE format, it works out of the box. Probably that's why it's working for most of people.
2. The problem seems to be in snd_pcm_hw_refine function of alsa-lib. And there's where i will be digging some more now.
1. There is (almost) the same problem on Debian Squeeze. Plug plugin don't work there too. The only difference is that by default mplayer uses dome other audio codec for mp3 which produces integer PCM format instead of float one. Since RPi audio chipset supports most of audio configuration quite well as far as it's 2 channels and uses unsigned 8bit or signed 16 bits LE format, it works out of the box. Probably that's why it's working for most of people.
2. The problem seems to be in snd_pcm_hw_refine function of alsa-lib. And there's where i will be digging some more now.
Re: ALSA on Raspbian
This is quite odd. When I originally tried the above, it worked just fine. Then I tried using MPD to play the file and all I got was garbage for sound. In fact, the system usage was so high, I lost my SSH connection. I was able to get SSH back after the system finished playing the sound file.kadamski wrote:Please try using aplay like this:Code: Select all
aplay - D hw:1,0 FILE.WAV
Now, when I run the above aplay command directly, all I get is the same garbage sound I got through MPD.
I disabled the onboard audio thinking there was a conflict. My USB DAC is now hw:0,0 and the system finds it easily. But the system is not sending the DAC an appropriate bit stream. All I get is garbage sound.
Obviously, since the aplay command worked originally, something messed things up with ALSA and it is not getting re-set properly even after a system reboot.
Anyone know what part of the system determines what kind of stream is sent to the default audio device?
I have set up MPD/ALSA on many systems in the past and have never run into this problem.
Perhaps I'll try uninstalling and re-installing alsa and see if that cleans things up.
- Jim
Re: ALSA on Raspbian
Did you try to turn this card off, wait for a minute, then on again? Normal reboot doesn't have to do the full power-cycle on the USB devices. I don't think reinstalling ALSA will help in any way.
-
- Posts: 33
- Joined: Mon Jul 09, 2012 6:26 pm
Re: ALSA on Raspbian
I am using the hexxeh image and I am able to play with MPD using a USB audio device just fine. With the latest firmware and kernel it is now very usable, although there still are occasional crackles and higher frequency files (> 48kHz) are problematic but that seems related to Pi's usb driver/implementation.