ALSA on Raspbian


168 posts   Page 7 of 7   1 ... 3, 4, 5, 6, 7
by kadamski » Fri Sep 14, 2012 12:08 pm
Unfortunately I don't know anything about espeak or using microphone. It seems to me that it first tries using ALSA, then jack, then PulseAudio but all fails. But I don't know why ALSA fails. For some reason it seems that it is trying to use dmix for capture stream which is not supported.
Posts: 187
Joined: Fri Jun 08, 2012 10:56 pm
by Licaon_Kter » Fri Sep 14, 2012 1:40 pm
av2kk wrote:By the way the fiq update seems to reduce the number of interrupts and improve the speed by 10%. Does it really address my problem?

updated yet?
BFQ+BFS or RT on a RPi? 4'real: https://github.com/licaon-kter/ (source and compiled!)
User avatar
Posts: 240
Joined: Wed Sep 05, 2012 10:12 am
Location: Between the keyboard and the chair.
by jlongstreet » Fri Sep 14, 2012 11:11 pm
I'm able to play sounds over the analog audio jack with aplay, but sound won't work in RetroArch (a multi-system emulator frontend).

Code: Select all
$ retroarch -L <path-to-core> <path-to-rom>
RetroArch [WARN] :: XDG_CONFIG_HOME is not defined. Will look for config in $HOME/.retroarch.cfg ...
RetroArch [ERROR] :: [ALSA]: Unknown error occured (Resource temporarily unavailable).
RetroArch [ERROR]: Audio backend failed to write. Will continue without sound.
Posts: 31
Joined: Wed Sep 05, 2012 2:59 am
by GeekTeacher » Sat Sep 15, 2012 9:42 am
@kadamski @everyone

I've just noticed that in spite of the ALSA errors I mentioned in my previous post, the Espeak text-to-speech synth does actually work, by which I mean it outputs audio through the analogue jack. It will read out text files in a voice like Stephen Hawking's or read out text lines fed directly to it. However, every now and then it does crash, requiring the terminal window to be restarted.

Anyone else got any ideas about how to resolve the error messages I get and displayed a few posts earlier please?
Posts: 16
Joined: Sun Jun 24, 2012 1:13 pm
by grrrz » Mon Sep 17, 2012 10:35 am
Hi,
recenlty tried my raspi, installed the last wheezy,
my goal would be to run pure data, including sound and midi or gpio if I can get it working.
Right now i'm a little frustrated because I have no luck with the sound.
tried almost everything in the topic, ans somewhere else, and so far:
-vlc, mplayer, lxplayer, puredata don't work either in lxde or in command line
(pure data gives me a red "audio I/o error" in the interface)
-omxplayer and aplay do work in command line
From the last wheezy version I installed, I upgraded debian and the firmware,
tried the first solution in this topic for asound.conf before noticing the second one was the one already included from the start, tried no asound file at all, tried pulseaudio (and removed it, but there are still traces of it somehow)
still the same.
Every soft mention detects correctly the interface in the menu but I get no sound at all (from hdmi or phones). If I try the "plug" option in puredata it shows a lot of errors in the console and shuts itself.
By the way MIDI seems to be correctly working using UM3-EX (but the "new patcher" option is buggy)

here is the output from vlc:

pi@raspberrypi ~/tests/taxidermia $ cvlc 1.mp3
VLC media player 2.0.3 Twoflower (revision 2.0.2-93-g77aa89e)
[0x259708] inhibit interface error: Failed to connect to the D-Bus session daemon: Unable to autolaunch a dbus-daemon without a $DISPLAY for X11
[0x259708] main interface error: no suitable interface module
[0x259fa0] main interface error: no suitable interface module
[0xe08f0] main libvlc error: interface "globalhotkeys,none" initialization failed
[0x256048] dummy interface: using the dummy interface module...
ALSA lib conf.c:4687:(snd_config_expand) Unknown parameters CARD=ALSA
ALSA lib pcm.c:2217:(snd_pcm_open_noupdate) Unknown PCM default:CARD=ALSA
[0x101398] alsa audio output error: cannot open ALSA device "default:CARD=ALSA": Invalid argument
[0x101398] main audio output error: Audio output failed
[0x101398] main audio output error: The audio device "default:CARD=ALSA" could not be used:
Invalid argument.
[0x101398] pulse audio output error: PulseAudio server connection failure: Connection refused
[0x101398] oss audio output error: cannot open audio device (/dev/dsp)
[0x101398] main audio output error: no suitable audio output module
[0x248ce0] main decoder error: failed to create audio output

any help is appreciated.
Posts: 15
Joined: Mon Sep 17, 2012 10:21 am
by GeekTeacher » Mon Sep 17, 2012 8:35 pm
Desperately seeking an ALSA Guru to sort USB microphone problem

OK, so I've made a fresh Raspian image and updated my firmware. I've installed python-alsaaudio, set 'amixer cset numid=3 2' for analogue audio out. The sample files all play (with 'aplay /usr/share/sounds/alsa/Front_Right.wav' etc) and I can record and playback using a USB microphone with Audacity. This part is working fine. The aplay commands give the following results:

Code: Select all
pi@raspberrypi /usr/share/doc/python-alsaaudio/examples $ aplay -l
**** List of PLAYBACK Hardware Devices ****
card 0: ALSA [bcm2835 ALSA], device 0: bcm2835 ALSA [bcm2835 ALSA]
  Subdevices: 8/8
  Subdevice #0: subdevice #0
  Subdevice #1: subdevice #1
  Subdevice #2: subdevice #2
  Subdevice #3: subdevice #3
  Subdevice #4: subdevice #4
  Subdevice #5: subdevice #5
  Subdevice #6: subdevice #6
  Subdevice #7: subdevice #7
pi@raspberrypi /usr/share/doc/python-alsaaudio/examples $ aplay -L
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


What I want to do is read the USB mic input pitch and volume using Python, but for now I'll just settle for recording and playing back with Python. I've run the sample files with the following results:

python mixertest.py - which only displays PCM and an available mixer control (I think possibly the mic should also be there)
python recordtest.py testfile - no recording and the following error message:

Code: Select all
Traceback (most recent call last):
  File "recordtest.py", line 46, in <module>
    inp = alsaaudio.PCM(alsaaudio.PCM_CAPTURE, alsaaudio.PCM_NONBLOCK, card)
alsaaudio.ALSAAudioError: No such file or directory


python playbacktest.py - no errors, but obviously no sound has been recorded to playback
python mixertest.py Master - 'no such mixer' error
python mixertest.py Capture rec - 'no such mixer' error

However, if I run these Python commands, I get the following results:

Code: Select all
>>> import alsaaudio
>>> alsaaudio.mixers( )
[u'PCM']                                       # I think this should list all of the mixers
>>> alsaaudio.mixers(1)
[u'PCM']
>>> alsaaudio.mixers(2)
[u'Mic']

which looks to me as if my mic is actually being recognised in Python.
So am I doing something wrong or is there a problem with ALSA on RPi?
Any help for getting recording to work in this way will be most gratefully received.
Posts: 16
Joined: Sun Jun 24, 2012 1:13 pm
by cefn » Tue Sep 25, 2012 12:32 am
@GeekTeacher Depending what you're trying to do, have you tried using Gstreamer or PACat?

I suggest these out of very little knowledge of the full situation on Raspbian, but I've used Gstreamer for pulseaudio and alsa wrangling before on low spec machines...
http://blog.safaribooksonline.com/2012/ ... the-music/

...and used pacat on Arm to literally write the wav sample numbers from a pulseaudio device into a stream...
http://forum.doozan.com/read.php?2,8088,8120#msg-8120

...so they might turn out to be relevant ingredients of a solution and could avoid whatever limitation you're hitting right now.
Posts: 4
Joined: Wed May 30, 2012 7:23 am
by mba » Thu Sep 27, 2012 7:00 pm
Hi,

just wondering if work is still being done on the alsa driver? I think I am seeing some of the problems discussed earlier in this thread. I am trying to get SqueezePlay to work on the latest raspbian (18-09-2012), but using the default asound.conf results in dropouts in audio. Looking at syslog its getting filled with:
Code: Select all
Sep 27 18:52:17 raspberrypi squeezeplay: audio_thread_execute:831 underrun!!! (at least -1348769233777.045 ms long)
Sep 27 18:52:19 raspberrypi kernel: [ 2704.343043] vcos: [8681]: bcm2835_audio_write:794 bcm2835_audio_write: failed on vchi_bulk_queue_transmit (status=-1)
Sep 27 18:52:19 raspberrypi squeezeplay: audio_thread_execute:877 xrun (snd_pcm_wait)
Sep 27 18:52:19 raspberrypi squeezeplay: audio_thread_execute:879 PCM wait failed: Unknown error 372
Sep 27 18:52:19 raspberrypi squeezeplay: audio_thread_execute:831 underrun!!! (at least -1348769235750.957 ms long)
Sep 27 18:52:21 raspberrypi kernel: [ 2706.383062] vcos: [8681]: bcm2835_audio_write:794 bcm2835_audio_write: failed on vchi_bulk_queue_transmit (status=-1)
Sep 27 18:52:21 raspberrypi squeezeplay: audio_thread_execute:831 underrun!!! (at least -1348769233792.347 ms long)

every time the sounds stutter.
I have tried using
Code: Select all
pcm.!default {
   type hw
   card 0
}

ctl.!default {
   type hw
   card 0
}

this made audio play without dropouts but unfortunately freezes the pi completely after a while. I haven't had time to gather logs from this freeze, but I am working on it.

Best regards
Martin
AMOTE - a LIRC client for Android. Build your own Android-based universal remote.
Posts: 110
Joined: Fri Jun 08, 2012 7:05 pm
Location: Denmark
by mba » Sat Sep 29, 2012 6:39 pm
I am guessing that a call to snd_pcm_wait waits the full length of the timeout without the sound driver reports that it is ready. Maybe the driver was ready for data but didn't report it? As it also reports underrun error.
AMOTE - a LIRC client for Android. Build your own Android-based universal remote.
Posts: 110
Joined: Fri Jun 08, 2012 7:05 pm
Location: Denmark
by GeekTeacher » Sat Sep 29, 2012 8:44 pm
Thanks to all who replied to my post seeking help for reading the input from a USB mic. The best solution I had was from Adam Bialas via a PM, who suggested the following for the asound.conf file:

Code: Select all
ctl.!default {
type hw
card 0
}
pcm.usb
{
type hw
card "U012529205"
format S16_LE
}

pcm.!default {
type asym
playback.pcm
{
type plug
slave {
pcm "hw:0"
format S16_LE
}
}
capture.pcm
{
type plug
slave.pcm "usb"
}
}

This enabled me to at least record from my mic. I went on to talk to Nathan Whitehead about using his SoundAnalyse module for reading the pitch and volume of the mic - the problems I was having turned out to be with the PyAudio module rather than his module. It seems the RPi doesn't like to sample sound in 'chunks' larger than about 512k, probably due to it's memory size. Reducing the chunk size has got me going in the right direction for making some sound activated devices for the RPi to control. Thanks again folks, Martyn.
Posts: 16
Joined: Sun Jun 24, 2012 1:13 pm
by iudas » Wed Oct 03, 2012 4:42 pm
@GeekTeacher

i am also trying to record audio with alsaaudio and a USB sound-card and got stuck with the same error message:
"alsaaudio.ALSAAudioError: No such file or directory"

did u manage to come over this, or you changed your approach?
any help is appriciated
Posts: 2
Joined: Wed Oct 03, 2012 4:29 pm
by iudas » Thu Oct 04, 2012 1:51 pm
Hi,

just for archiving, after some further investigation i managed to record with a
usb microphone with alsaaudio. the following python code will do an ~5sec recording and
save it to the "out.wav".

some notes:
- i=250 will give u ~5sec sample
- i got the value for card='sysdefault:CARD=Microphone' by running 'arecord -L'
- the "out.wav" is not a "real" wav file, it looks more like a raw byte-stream

Code: Select all
import alsaaudio

card = 'sysdefault:CARD=Microphone'
f = open('out.wav', 'wb')
inp = alsaaudio.PCM(alsaaudio.PCM_CAPTURE, alsaaudio.PCM_NORMAL, card)
inp.setchannels(1)
inp.setrate(48000)
inp.setformat(alsaaudio.PCM_FORMAT_S16_LE)

i=250
while i > 0:
  length,data = inp.read()
  f.write(data)
  i-=1
Posts: 2
Joined: Wed Oct 03, 2012 4:29 pm
by mrraspberrypi » Tue Oct 09, 2012 12:15 am
I can get mp3 playing on my USB audio with mplayer. But I cant get the USB audio recording from the mic input (hw:1,0) into wav/mp3 - its just purely heavy static noise.

Here's what alsa -L gives me

Code: Select all
pi@raspberrypi ~ $ aplay -L
null
    Discard all samples (playback) or generate zero samples (capture)
sysdefault:CARD=ALSA
    bcm2835 ALSA, bcm2835 ALSA
    Default Audio Device
sysdefault:CARD=Device
    Generic USB Audio Device, USB Audio
    Default Audio Device
front:CARD=Device,DEV=0
    Generic USB Audio Device, USB Audio
    Front speakers
surround40:CARD=Device,DEV=0
    Generic USB Audio Device, USB Audio
    4.0 Surround output to Front and Rear speakers
surround41:CARD=Device,DEV=0
    Generic USB Audio Device, USB Audio
    4.1 Surround output to Front, Rear and Subwoofer speakers
surround50:CARD=Device,DEV=0
    Generic USB Audio Device, USB Audio
    5.0 Surround output to Front, Center and Rear speakers
surround51:CARD=Device,DEV=0
    Generic USB Audio Device, USB Audio
    5.1 Surround output to Front, Center, Rear and Subwoofer speakers
surround71:CARD=Device,DEV=0
    Generic USB Audio Device, USB Audio
    7.1 Surround output to Front, Center, Side, Rear and Woofer speakers
iec958:CARD=Device,DEV=0
    Generic USB Audio Device, USB Audio
    IEC958 (S/PDIF) Digital Audio Output


Here's what my asound.conf looks like:

Code: Select all
pcm.mmap0 {
    type mmap_emul;
    slave {
      pcm "hw:0,0";
    }
}

pcm.!default {
  type plug;
  slave {
    pcm mmap0;
  }
}


What do I do to get mic recording nice and clearly so darkice can stream it to my icecast server online??? :(
Posts: 10
Joined: Tue Sep 25, 2012 2:37 am
by andig2 » Mon Dec 17, 2012 10:03 am
@GeekTeacher: same problem here. Did you manage to record anything using python?
Posts: 46
Joined: Wed Oct 31, 2012 9:34 pm
by dextrus » Sat Jan 26, 2013 6:30 pm
I can record and playback using python or C++ just fine with the latest Raspbian. Ask if you want code.

However, I do want to playback multiple sounds. I noticed that Raspbian creates 8 ALSA playback subdevices on boot, yet I am unable to access these (presumably I access these with hw:0,x where x is the subdevice).

Why does the recent image create 8 ALSA playback subdevices then?

/Dextrus
Have more FUN with your Pi. Visit www.pi-fun.com
Posts: 119
Joined: Tue Jan 24, 2012 10:10 pm
Location: Eastleigh, Hampshire
by basj » Wed Mar 04, 2015 10:00 pm
I have similar problem when trying to list audio devices on my RPi B + Raspbian with Python + PyAudio.

This Python code:
Code: Select all
import pyaudio
p = pyaudio.PyAudio()
for i in range(p.get_device_count()):
    print p.get_device_info_by_index(i)


produces this dirty error. Do you know how to solve it? Any idea @dextrus?

Code: Select all
ALSA lib confmisc.c:1286:(snd_func_refer) Unable to find definition 'cards.bcm2835.pcm.front.0:CARD=0'
ALSA lib conf.c:4241:(_snd_config_evaluate) function snd_func_refer returned error: No such file or directory
ALSA lib conf.c:4720:(snd_config_expand) Evaluate error: No such file or directory
ALSA lib pcm.c:2217:(snd_pcm_open_noupdate) Unknown PCM front
ALSA lib pcm.c:2217:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.rear
ALSA lib pcm.c:2217:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.center_lfe
ALSA lib pcm.c:2217:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.side
ALSA lib confmisc.c:1286:(snd_func_refer) Unable to find definition 'cards.bcm2835.pcm.surround40.0:CARD=0'
ALSA lib conf.c:4241:(_snd_config_evaluate) function snd_func_refer returned error: No such file or directory
ALSA lib conf.c:4720:(snd_config_expand) Evaluate error: No such file or directory
ALSA lib pcm.c:2217:(snd_pcm_open_noupdate) Unknown PCM surround40
ALSA lib confmisc.c:1286:(snd_func_refer) Unable to find definition 'cards.bcm2835.pcm.surround51.0:CARD=0'
ALSA lib conf.c:4241:(_snd_config_evaluate) function snd_func_refer returned error: No such file or directory
ALSA lib conf.c:4720:(snd_config_expand) Evaluate error: No such file or directory
ALSA lib pcm.c:2217:(snd_pcm_open_noupdate) Unknown PCM surround41
ALSA lib confmisc.c:1286:(snd_func_refer) Unable to find definition 'cards.bcm2835.pcm.surround51.0:CARD=0'
ALSA lib conf.c:4241:(_snd_config_evaluate) function snd_func_refer returned error: No such file or directory
ALSA lib conf.c:4720:(snd_config_expand) Evaluate error: No such file or directory
ALSA lib pcm.c:2217:(snd_pcm_open_noupdate) Unknown PCM surround50
ALSA lib confmisc.c:1286:(snd_func_refer) Unable to find definition 'cards.bcm2835.pcm.surround51.0:CARD=0'
ALSA lib conf.c:4241:(_snd_config_evaluate) function snd_func_refer returned error: No such file or directory
ALSA lib conf.c:4720:(snd_config_expand) Evaluate error: No such file or directory
ALSA lib pcm.c:2217:(snd_pcm_open_noupdate) Unknown PCM surround51
ALSA lib confmisc.c:1286:(snd_func_refer) Unable to find definition 'cards.bcm2835.pcm.surround71.0:CARD=0'
ALSA lib conf.c:4241:(_snd_config_evaluate) function snd_func_refer returned error: No such file or directory
ALSA lib conf.c:4720:(snd_config_expand) Evaluate error: No such file or directory
ALSA lib pcm.c:2217:(snd_pcm_open_noupdate) Unknown PCM surround71
ALSA lib confmisc.c:1286:(snd_func_refer) Unable to find definition 'cards.bcm2835.pcm.iec958.0:CARD=0,AES0=4,AES1=130,AES2=0,AES3=2'
ALSA lib conf.c:4241:(_snd_config_evaluate) function snd_func_refer returned error: No such file or directory
ALSA lib conf.c:4720:(snd_config_expand) Evaluate error: No such file or directory
ALSA lib pcm.c:2217:(snd_pcm_open_noupdate) Unknown PCM iec958
ALSA lib confmisc.c:1286:(snd_func_refer) Unable to find definition 'cards.bcm2835.pcm.iec958.0:CARD=0,AES0=4,AES1=130,AES2=0,AES3=2'
ALSA lib conf.c:4241:(_snd_config_evaluate) function snd_func_refer returned error: No such file or directory
ALSA lib conf.c:4720:(snd_config_expand) Evaluate error: No such file or directory
ALSA lib pcm.c:2217:(snd_pcm_open_noupdate) Unknown PCM spdif
ALSA lib confmisc.c:1286:(snd_func_refer) Unable to find definition 'cards.bcm2835.pcm.iec958.0:CARD=0,AES0=4,AES1=130,AES2=0,AES3=2'
ALSA lib conf.c:4241:(_snd_config_evaluate) function snd_func_refer returned error: No such file or directory
ALSA lib conf.c:4720:(snd_config_expand) Evaluate error: No such file or directory
ALSA lib pcm.c:2217:(snd_pcm_open_noupdate) Unknown PCM spdif
ALSA lib pcm.c:2217:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.hdmi
ALSA lib pcm.c:2217:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.hdmi
ALSA lib pcm.c:2217:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.modem
ALSA lib pcm.c:2217:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.modem
ALSA lib pcm.c:2217:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.phoneline
ALSA lib pcm.c:2217:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.phoneline
ALSA lib pcm_dmix.c:957:(snd_pcm_dmix_open) The dmix plugin supports only playback stream
ALSA lib pcm_dmix.c:1018:(snd_pcm_dmix_open) unable to open slave
Cannot connect to server socket err = No such file or directory
Cannot connect to server request channel
jack server is not running or cannot be started
{'defaultSampleRate': 44100.0, 'defaultLowOutputLatency': 0.011609977324263039, 'defaultLowInputLatency': -1.0, 'maxInputChannels': 0, 'structVersion': 2, 'hostApi': 0, 'index': 0, 'defaultHighOutputLatency': 0.046439909297052155, 'maxOutputChannels': 2, 'name': 'bcm2835 ALSA: bcm2835 ALSA (hw:0,0)', 'defaultHighInputLatency': -1.0}
{'defaultSampleRate': 44100.0, 'defaultLowOutputLatency': 0.011609977324263039, 'defaultLowInputLatency': -1.0, 'maxInputChannels': 0, 'structVersion': 2, 'hostApi': 0, 'index': 1, 'defaultHighOutputLatency': 0.046439909297052155, 'maxOutputChannels': 128, 'name': 'sysdefault', 'defaultHighInputLatency': -1.0}
{'defaultSampleRate': 44100.0, 'defaultLowOutputLatency': 0.011609977324263039, 'defaultLowInputLatency': -1.0, 'maxInputChannels': 0, 'structVersion': 2, 'hostApi': 0, 'index': 2, 'defaultHighOutputLatency': 0.046439909297052155, 'maxOutputChannels': 128, 'name': 'default', 'defaultHighInputLatency': -1.0}
Posts: 14
Joined: Tue Mar 03, 2015 1:37 pm
by x4dr » Fri Feb 19, 2016 3:53 pm
I aswell have a problem that was earlier described in this thread:
sometimes playback with alsa (or pulseaudio) just freezes and the application that is playing the sound is blocking, does not react to ctrl C, but only to ctrl Z and has to be killed with -9
UNLESS i play around with the volume for a bit.
The start_alsa.elf that was posted 3 years ago leads to no output from the pi and it just staying dead when powered up
Posts: 7
Joined: Fri Feb 05, 2016 1:23 pm
by ShunJianLee » Wed May 11, 2016 5:54 am
May i know should i add this into pi terminal?

pi@raspberrypi:~ $ sudo nano /etc/asound.conf

pcm.mmap0 {
type mmap_emul;
slave {
pcm "hw:0,0";
}
}

pcm.!default {
type plug;
slave {
pcm mmap0;
}
}
Posts: 70
Joined: Wed Nov 25, 2015 4:43 am