bcm2835 ALSA sound: pop on sound playback start/completion
Hello
After doing some testing with sound onboard the Rpi, I can characterize (via oscilloscope) the conditions that result in a rather jarring click on start of playback and pop on completion of playback
Running FW 339137 Kernel Linux raspberrypi 3.2.27+ #174 PREEMPT Wed Sep 26 14:09:47
Sample command: mpg321blah.mp3 (sound plays) ^C (pop)
The rpi schematic details use of PWM channels for audio carrier generation - having read some other information on improving the rpi's sound quality, I can offer insight on to what happens when the PWM is initiated/released in playback.
On boot and in an "idle" state, the PWM output is 0V (disabled). When playback commences, the voltage measured at C20/C26 pin "2" ramps to +0.56V quite quickly, causing an audible click. This is because the output 10u AC coupling capacitor C34/C48 passes this ramp, which then saturates any input stage in a downstream amp expecting a ~700mV rms AC signal. The effect is variable depending on the input coupling used on the downstream amp.
A similar but more complex effect happens when the audio playback is interrupted or completes. On measuring C20 pin "2" the +0.56V DC biased audio signal has a brief pulse at +1.8V for 6.5ms, then 0V for 16.5ms, then a pulse back to 0.56V for 4ms, then 0V idle state [a fat pair of square pulses]. Similar to the start of playback case, this causes the pop sound on playback.
Maybe the open/close functions in ALSA need to be set so that they preserve PWM at 50% duty cycle on a) driver loading and b) start/finish of playback
Works fine for me, but only for mpd. I also installed Shairport and changed /etc/libao.conf to "default_driver=pulse", rebooted my Pi, but still no sound from Shairport... Any thoughts?
Note that launching PulseAudio (which is not recommended) in system mode avoid the problem with suspended input. You can do so by adapting the pulseaudio initscript, and adding the mpd user to the group pulse-access.
@JstNnyms @skipper79 I've described the necessary steps in more detail on my blog: https://dbader.org/blog/crackle-free-audio-on-the-raspberry-pi-with-mpd-and-pulseaudio
workaround ain't good enough for openelec and friends :-( is there a known setting in the firmware to fix the pops/clicks?
Also, note that by setting your RPi's volume to the maximum (by default mine is at 40%...), the pops volume is acceptable (compared to the video/audio volume).
Think Mr. Upton knows about the problems with the als driver: http://permalink.gmane.org/gmane.linux.alsa.devel/104114
uname -a Linux raspberrypi 3.6.11+ #348 PREEMPT Tue Jan 1 16:33:22 GMT 2013 armv6l GNU/Linux /opt/vc/bin/vcgencmd version Jan 2 2013 23:40:34 Copyright (c) 2012 Broadcom version 360331 (release)
still pops at the beginning and end of each audio sample (I am using espeak)
Dear Experts, As far as I can see, you are very knowledgeable about how the sound system using pulse audio works on the raspbian.
I have 2 questions:
- How can I avoid such "clicks" when using omxplayer ? They happen at the start and the end of a track when using the analog output (e.g. omxplayer -o local anyfile.mp3).
- I have tried to obtain an output from the 3.5 mm jack local headphone output using mplayer and the pulse audio / alsa mixer. However, I didi not succeed on getting any output at all, always silent. However, on the HDMI output it works fine. I know that in ancient raspbian images the command sudo amixer cset numid=3 1 was supossed to redirect ALSA output to the headphone local jack, but I read somewhere that in the latest raspbian releases this no longer works. Actaully this command refers to the Master Playback Volume control and this only reduces the volume to an unaudible level. Does any of you know how can one redirect the alsa mixer output to the local headphone jack in the latest raspbian releases?
Mine is actually as follows;
pi@raspberrypi ~ $ uname -a
Linux raspberrypi 3.2.27+ #250 PREEMPT Thu Oct 18 19:03:02 BST 2012 armv6l GNU/Linux
pi@raspberrypi ~ $ sudo amixer controls
numid=4,iface=MIXER,name='Master Playback Switch'
numid=3,iface=MIXER,name='Master Playback Volume'
numid=2,iface=MIXER,name='Capture Switch'
numid=1,iface=MIXER,name='Capture Volume'
pi@raspberrypi ~ $ sudo amixer cset numid=3 1
numid=3,iface=MIXER,name='Master Playback Volume'
; type=INTEGER,access=rw------,values=2,min=0,max=65536,step=1
: values=1,1
(... the only difference when doing this is that the volume is practically unadible, but it is still going to the HDMI output and not to the local headphone oputput).
pi@raspberrypi ~ $ sudo amixer cset numid=3 65536
numid=3,iface=MIXER,name='Master Playback Volume'
; type=INTEGER,access=rw------,values=2,min=0,max=65536,step=1
: values=65536,65536
(... previous command resumes normal volume to the HDMI output).
pi@raspberrypi ~ $ aplay -L
null
Discard all samples (playback) or generate zero samples (capture)
pulse
Playback/recording through the PulseAudio sound server
sysdefault:CARD=ALSA
bcm2835 ALSA, bcm2835 ALSA
Default Audio Device
Many thanks in advance!
Bob.
uname -a Linux raspberrypi 3.6.11+ #358 PREEMPT Tue Jan 15 00:45:33 GMT 2013 armv6l GNU/Linux /opt/vc/bin/vcgencmd version Jan 15 2013 12:54:01 Copyright (c) 2012 Broadcom version 362704 (release)
still pops at the beginning and end of each audio sample (I am using espeak)
Same problem here Linux raspberrypi 3.6.11-4-ARCH+ #1 PREEMPT Wed Jan 16 19:06:54 UTC 2013 armv6l GNU/Linux
Isn't there any way to disable alsa power saving mode so the sound card is constantly on?
sudo echo "performance" > /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor ?
sudo echo "performance" > /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor ?
no change, still pops at the beginning and end of each audio sample
Someone's written a blog post about pop-free audio for XBMC using the analog jack: http://www.oxymoronical.com/blog/2013/01/Pop-free-sound-from-a-Raspberry-Pi-running-XBMC
Yeah but that requires pulseaudio, which for example OpenELEC doesn't have by default. And it's a hack anyway, not a real solution.
Seeing this issue is like 4 months old, would be really nice to see a fix soon...
Agreed. The problem has existed since the beginning so just thought I'd post one workaround in case it helps someone...
I've put some more detail in my blog post, along with a work-around suitable for playing back sound with varying sample rate: http://www.lightbluetouchpaper.org/2013/02/10/fixing-poppingclicking-audio-on-raspberry-pi/
The workaround only fixes the stop pop not the start pop. related: https://github.com/OpenELEC/OpenELEC.tv/issues/923
A recent firmware update should have fixed some of these issues - the GPU firmware now doesn't switch off the PWM after the device is released.
Awesome. The click is here at first play, but then never happens again.
uname -a Linux raspberrypi 3.6.11+ #389 PREEMPT Wed Mar 6 12:43:30 GMT 2013 armv6l GNU/Linux /opt/vc/bin/vcgencmd version Mar 4 2013 22:02:46 Copyright (c) 2012 Broadcom version 374489 (release)
Pop is on first audio use, clear until next reboot, HUGE improvement, Many Thanks!