Karloch
Posts: 5
Joined: Sun Jun 26, 2016 11:20 am

ALSA not working properly: aplay: pcm_write:1939: write erro

Sun Jun 26, 2016 11:29 am

I'm setting up my Raspberry Pi 3B to play several sounds on determinate events through a speaker connected to the analog 3'5mm output (already forced 3'5mm output through raspi-config and it sounds OK). After the Raspbian boots, sounds works like a charm, but after several plays using aplay it will stop working and return the following error:

Code: Select all

user@raspi:~$ aplay cartoon001.wav
Playing WAVE 'cartoon001.wav' : Signed 16 bit Little Endian, Rate 11025 Hz, Mono
aplay: pcm_write:1939: write error: Input/output error
It will only work again after a restart, repeating the symptoms. Playing the sound as root gives same result.

Several data from my setup:

Code: Select all

user@raspi:~$ uname -a
Linux raspi 4.4.13-v7+ #894 SMP Mon Jun 13 13:13:27 BST 2016 armv7l GNU/Linux

user@raspi:~$ 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
dmix:CARD=ALSA,DEV=0
    bcm2835 ALSA, bcm2835 ALSA
    Direct sample mixing device
dmix:CARD=ALSA,DEV=1
    bcm2835 ALSA, bcm2835 IEC958/HDMI
    Direct sample mixing device
dsnoop:CARD=ALSA,DEV=0
    bcm2835 ALSA, bcm2835 ALSA
    Direct sample snooping device
dsnoop:CARD=ALSA,DEV=1
    bcm2835 ALSA, bcm2835 IEC958/HDMI
    Direct sample snooping device
hw:CARD=ALSA,DEV=0
    bcm2835 ALSA, bcm2835 ALSA
    Direct hardware device without any conversions
hw:CARD=ALSA,DEV=1
    bcm2835 ALSA, bcm2835 IEC958/HDMI
    Direct hardware device without any conversions
plughw:CARD=ALSA,DEV=0
    bcm2835 ALSA, bcm2835 ALSA
    Hardware device with all software conversions
plughw:CARD=ALSA,DEV=1
    bcm2835 ALSA, bcm2835 IEC958/HDMI
    Hardware device with all software conversions

user@raspi:~$ lsmod
Module                  Size  Used by
xt_multiport            1756  1
iptable_filter          1409  1
ip_tables              11637  1 iptable_filter
x_tables               12507  3 ip_tables,xt_multiport,iptable_filter
arc4                    1958  0
ecb                     2127  0
md4                     3615  0
md5                     2039  1
hmac                    2959  1
nls_utf8                1318  1
cifs                  382801  2
bnep                   10340  2
hci_uart               17943  1
btbcm                   5929  1 hci_uart
bluetooth             326105  22 bnep,btbcm,hci_uart
brcmfmac              186343  0
brcmutil                5661  1 brcmfmac
cfg80211              427855  1 brcmfmac
rfkill                 16037  4 cfg80211,bluetooth
snd_bcm2835            20511  0
snd_pcm                75698  1 snd_bcm2835
snd_timer              19160  1 snd_pcm
snd                    51844  3 snd_bcm2835,snd_timer,snd_pcm
bcm2835_gpiomem         3040  0
spi_bcm2835             7286  0
bcm2835_wdt             3225  0
uio_pdrv_genirq         3164  0
uio                     8000  1 uio_pdrv_genirq
ipv6                  347530  34

user@raspi:~$ amixer
Simple mixer control 'PCM',0
  Capabilities: pvolume pvolume-joined pswitch pswitch-joined
  Playback channels: Mono
  Limits: Playback -10239 - 400
  Mono: Playback 400 [100%] [4.00dB] [on]

sash_b
Posts: 1
Joined: Sun Aug 21, 2016 7:28 pm

Re: ALSA not working properly: aplay: pcm_write:1939: write

Sun Aug 21, 2016 7:31 pm

Hi Karloch,

I am seeing the same issue.
Did you get over this issue yet?

Karloch
Posts: 5
Joined: Sun Jun 26, 2016 11:20 am

Re: ALSA not working properly: aplay: pcm_write:1939: write

Mon Aug 22, 2016 10:21 am

I'm afraid not, I keep with the same problem :(

User avatar
flatmax
Posts: 346
Joined: Thu May 26, 2016 10:36 pm

Re: ALSA not working properly: aplay: pcm_write:1939: write

Mon Aug 22, 2016 10:43 am

Can you rmmod and modprobe the snd_bcm2835 module ?
Does the sound come back ?

Matt
Discuss hearing, acoustics, audio injector products, - https://lists.audioinjector.net/mailman/listinfo/people
Sound card for the Raspberry Pi with inbuilt microphone : www.audioinjector.net
Audio Inector Octo multitrack GPIO sound card

Karloch
Posts: 5
Joined: Sun Jun 26, 2016 11:20 am

Re: ALSA not working properly: aplay: pcm_write:1939: write

Mon Aug 22, 2016 10:03 pm

Same result:

Code: Select all

~$ sudo rmmod snd_bcm2835
~$ sudo modprobe snd_bcm2835
~$ aplay cartoon001.wav
Playing WAVE 'cartoon001.wav' : Signed 16 bit Little Endian, Rate 11025 Hz, Mono
aplay: pcm_write:1939: write error: Error de entrada/salida

hal8000
Posts: 265
Joined: Fri Oct 04, 2013 5:22 pm

Re: ALSA not working properly: aplay: pcm_write:1939: write

Mon Aug 22, 2016 10:12 pm

When sound stops anything unusual in system log?

Code: Select all

dmesg | tail -n 10

Karloch
Posts: 5
Joined: Sun Jun 26, 2016 11:20 am

Re: ALSA not working properly: aplay: pcm_write:1939: write

Tue Aug 23, 2016 1:09 am

Nothing is reported to the kernel log when the error happens:

Code: Select all

~$ dmesg | tail -n 10
[   13.990801] Bluetooth: HCI UART protocol BCM registered
[   14.235080] Bluetooth: BNEP (Ethernet Emulation) ver 1.3
[   14.235100] Bluetooth: BNEP filters: protocol multicast
[   14.235125] Bluetooth: BNEP socket layer initialized
[   15.950226] FS-Cache: Netfs 'cifs' registered for caching
[   15.950978] Key type cifs.spnego registered
[   15.951038] Key type cifs.idmap registered
[   16.375080] systemd-journald[134]: Received request to flush runtime journal from PID 1
[   16.725662] Adding 102396k swap on /var/swap.  Priority:-1 extents:3 across:200700k SSFS
[   21.055153] ip_tables: (C) 2000-2006 Netfilter Core Team

marvinsuess
Posts: 2
Joined: Tue Oct 18, 2016 9:31 pm

Re: ALSA not working properly: aplay: pcm_write:1939: write

Tue Oct 18, 2016 10:10 pm

Hey,

I have the same problem with my RPi 3B. Maybe there is something wrong with the PWM.

My original problem was that I couldn't write the data for my Neopixel WS2812b LED strip which is usually done via PWM on a GPIO Pin. It worked a while but suddenly it just wrote garbage data (without changes in my code). I tested a different strip, different cables and so on and now I think it has to be something wrong with the PWM. I googled and found that audio is also using PWM so I tried to play audio. I get silence and the same errors as you do:

If I use mpg123:

Code: Select all

[...]

[alsa.c:230] error: Fatal problem with alsa output, error -5.

[audio.c:614] error: Error in writing audio (Input/output error?)!

[mpg123.c:681] error: Deep trouble! Cannot flush to my output anymore!
If I try aplay:

Code: Select all

aplay: pcm_write:1939: Schreibfehler: Eingabe-/Ausgabefehler
Also nothing interesting in syslog.

So maybe you can test the PWM on your Raspberry?

It will be interesting to see if we share the same problem or not.

Karloch
Posts: 5
Joined: Sun Jun 26, 2016 11:20 am

Re: ALSA not working properly: aplay: pcm_write:1939: write

Sun Oct 23, 2016 10:43 pm

So maybe you can test the PWM on your Raspberry?
That's really interesting because I'm using PWM via GPIO in order to perform some beeping through a PC Speaker. Maybe this has something to do with the ALSA failing to play sound?

User avatar
rpdom
Posts: 21823
Joined: Sun May 06, 2012 5:17 am
Location: Chelmsford, Essex, UK

Re: ALSA not working properly: aplay: pcm_write:1939: write

Mon Oct 24, 2016 5:09 am

Karloch wrote:
So maybe you can test the PWM on your Raspberry?
That's really interesting because I'm using PWM via GPIO in order to perform some beeping through a PC Speaker. Maybe this has something to do with the ALSA failing to play sound?
You can't use hardware PWM via GPIO at the same time as audio via the A/V jack. Analogue audio uses both of the hardware PWM channels.

marvinsuess
Posts: 2
Joined: Tue Oct 18, 2016 9:31 pm

Re: ALSA not working properly: aplay: pcm_write:1939: write

Mon Nov 07, 2016 12:44 am

You can't use hardware PWM via GPIO at the same time as audio via the A/V jack. Analogue audio uses both of the hardware PWM channels.
This is what I found out before I had the problem I described above. I tried to play music while sending data to my LED strip. What I saw was that the LEDs were not doing what I told them to do but showing some random colours somehow in sync with the music. Even when I turned off the music the effect of just showing random colours remained. At this time I became aware that the PWM channels are also used for audio. But I was able to fix it every time I tried by turning the Raspberry off and on again (and if I had read the original post carefully enough I would have seen that this is what Karloch wrote).

So my situation is different. I didn't play music when my current problem first occurred, I just sent data to the LED strip. And the turn-off-and-on-fix doesn't work anymore :( This and the disability to play music lead me to the conclusion that the PWM may be broken in some way.

Edit: I solved my problem by simply not loading the snd_bcm2835 module. Just go to /etc/modprobe.d and create a file "alsa-blacklist.conf" (with sudo) containing just the line "blacklist snd_bcm2835". Reboot the Raspberry and the problem is gone. I know this doesn't solve Karloch's problem or the problems of anyone who needs sound but I wrote this anyway because someone with the same problem as me may find this post and I don't want to hide the solution.

User avatar
jefferson_palheta
Posts: 10
Joined: Thu Apr 27, 2017 8:22 pm

Re: ALSA not working properly: aplay: pcm_write:1939: write erro

Mon Oct 23, 2017 6:08 pm

did someone get some solution? I get the same problem because I'm using PWM to control IR transmitter so I can play my sound with sox (play my_song.wav) and it works well but when a run my code that uses pwm then the sound stop and doesn't come back until I restart my RP3.

Return to “Troubleshooting”