karlkiste
Posts: 184
Joined: Tue Jan 22, 2013 8:50 am
Location: berlin, germany

Click noise when starting analog audio sound playback

Tue Jan 22, 2013 9:43 am

Hi all!

Yes, this topic has been discussed before. I can, however, not find a satisfying solution or workaround.

Let me first start by summing up what I have found out so far on this topic:

The analog audio output is in fact digital PWM. The PWM frequency is around 40MHz, it is low-pass-filtered, DC-decoupled and then fed to the analog plug.

PWM only runs when needed, so when PWM is switched on, the output momentarily jumps from 0V to ~1.65V, and then declines to 0V as the DC decoupling capacitor charges. This is where the noise comes from.

The driver (or firmware, is there a difference?) now does not switch on the PWM just so, but it starts at a duty cycle of 0% and gently ramps it up to 50% to charge the capacitor without making said noise. This solves the problem nicely if you're using e.g. aplay, and the file is 48kHz, 16bit signed little-endian.

If the file is NOT 48kHz, 16bit signed le, the noise reappears.

omxplayer as packaged with recent raspbian gives three clicks when starting to play, even if the sound format is 48kHz s16le.

So far the facts.

The noise to be heard when playing a not 48kHz, s16le file can presumably be blamed to the player software trying to set the soundcard to a mode corresponding to the file to avoid resampling.

What can be done? The performance of omxplayer is great. I'd love to be able to use it for files containing sound, too. The general poor analog quality (like only 10 bit) is no problem for me, just the clicks are not acceptable.

Possible solutions:

A switch (like in config.txt or /sys ) could make PWM run all the time, so the capacitor is always kept charged. If sound is important, the additional CPU load and current consumption could be of lesser concern.

The PWM outputs could be switched to HI-Z instead of driving low when PWM is switched off. So the capacitor would simply keep it's charge (for a while, at least). I don't know, however, if this is possible, and if those outputs do also have digital input buffers which would not like to float around 1.65V.

The dirty external hardware hack: Use a GPIO to drive a relay which shorts the sound outputs whenever sound is starting to be played. The capacitor can then charge through a low-resistance path, and does not propagate the charge to the amplifier.

The smartass way: Plug in a USB sound device. Not my preferred way, as the general quality is OK for me, the sound device costs extra money, and does certainly consume more power than leaving the PWM on all the time.

Has anyone managed to have omxplayer start without clicking?

Thanks for any input!

ski522
Posts: 394
Joined: Sun Sep 30, 2012 2:22 pm

Re: Click noise when starting analog audio sound playback

Tue Jan 22, 2013 12:02 pm

karlkiste wrote: The smartass way: Plug in a USB sound device. Not my preferred way, as the general quality is OK for me, the sound device costs extra money, and does certainly consume more power than leaving the PWM on all the time.
Power is minuscule and cost is minor for a USB sound card. The card I'm using was only $14 (including shipping) and I believe uses around 50mA-75mA although I haven'y measured it; just making an assumption based on data sheets and parts on board.

Good analysis as to what the problem is though, it's ashamed the issue hasn't been resolved. The general "cheese ball" answer is to use HDMI, but how many kids in low income households have access to fancy dancy HDMI LCD tv?!?!? Hell they're lucky if they have access to a TV with a composite input!

I do know that you can keep the sound driver active all time using pulseaudio and in briefly experimenting with this, I did find that to be the case, but I'm not sure omxplayer can take advantage of pulseaudio, although I could be wrong there.

User avatar
RaTTuS
Posts: 10493
Joined: Tue Nov 29, 2011 11:12 am
Location: North West UK

Re: Click noise when starting analog audio sound playback

Tue Jan 22, 2013 12:18 pm

I use HDMI sound
How To ask Questions :- http://www.catb.org/esr/faqs/smart-questions.html
WARNING - some parts of this post may be erroneous YMMV

1QC43qbL5FySu2Pi51vGqKqxy3UiJgukSX
Covfefe

karlkiste
Posts: 184
Joined: Tue Jan 22, 2013 8:50 am
Location: berlin, germany

Re: Click noise when starting analog audio sound playback

Tue Jan 22, 2013 12:57 pm

ski522 wrote:
karlkiste wrote: The smartass way: Plug in a USB sound device. Not my preferred way, as the general quality is OK for me, the sound device costs extra money, and does certainly consume more power than leaving the PWM on all the time.
Power is minuscule and cost is minor for a USB sound card. The card I'm using was only $14 (including shipping) and I believe uses around 50mA-75mA although I haven'y measured it; just making an assumption based on data sheets and parts on board.
Ok, so here a few more arguments: It uses half (Model B) or all (Model A) of the USB ports and about doubles the needed space. In an embedded system, it usually cannot be mounted nicely. I'm trying really hard not to compensate poor software by additional hardware. I strongly prefer to use the existing hardware as good as possible. I could use an HDMI sound deembedder, but for the $$ I could buy five Rpis.

Thank you for your thoughts, but the USB variant stays the very last option for me, even after a self-soldered bugfix ;-)

The system I'm currently working on is all read-only, pulse seems to have some problems with that. And, I have the feeling that omxplayer does initialize sound output multiple times, or tries to change settings. So I fear it won't help at the end to have PWM running while omxplayer opens the sound device, but I'll try with pulse if I find the time.

For the power part: Just made a little measurement. Playing silence at 48kHz, 16bit, 2ch. consumes about 20mA extra [email protected] (389,9 stopped, 408,7 playing)

karlkiste
Posts: 184
Joined: Tue Jan 22, 2013 8:50 am
Location: berlin, germany

Re: Click noise when starting analog audio sound playback

Wed Jan 23, 2013 7:24 am

More curious findings:

aplay clicks on a file which usually doesn't click, if master volume is set low (<85%). Volume must be high for click to disappear.

omxplayer does not respect alsa volume settings.

piepin
Posts: 1
Joined: Wed Jan 23, 2013 8:37 pm

Re: Click noise when starting analog audio sound playback

Wed Jan 23, 2013 8:39 pm

Don't have a solution.

I need a solution. This popping noise defeats the reason I bought the Pi.

:cry:

Skysurfer
Posts: 1
Joined: Tue Jan 29, 2013 6:10 pm

Re: Click noise when starting analog audio sound playback

Tue Jan 29, 2013 6:21 pm

karlkiste wrote:Hi all!

Yes, this topic has been discussed before. I can, however, not find a satisfying solution or workaround
I definitely full agree with you! I also invested many hours to solve this problem. Up to now with no success! With pulseaudio I seemed to be close to the finish. But I couldn't reproduce this solution. If I have a little time, I will try get it. If I suceed, I will tell you.

Best regards,
Skysurfer

sjmurdoch
Posts: 1
Joined: Mon Feb 11, 2013 9:39 am

Re: Click noise when starting analog audio sound playback

Mon Feb 11, 2013 9:46 am

The solution I adopted for avoiding the clicks when playing back differing audio formats was to resample the audio files to 48kHz stereo using mplayer. I'm not sure if this would help solve the problem with omxplayer though, but maybe my blog post will give some ideas: http://www.lightbluetouchpaper.org/2013 ... pberry-pi/

karlkiste
Posts: 184
Joined: Tue Jan 22, 2013 8:50 am
Location: berlin, germany

Re: Click noise when starting analog audio sound playback

Mon Feb 11, 2013 1:35 pm

sjmurdoch wrote: resample the audio files to 48kHz stereo
Yes, in my first posting I wrote that this solves the problem for ALSA output. However, omxplayer clicks, nevermind what sample rate the audio is. I haven't tried the latest release yet (which needs a new firmware, which might be a good omen)

tengil
Posts: 1
Joined: Thu Feb 14, 2013 9:38 am

Re: Click noise when starting analog audio sound playback

Thu Feb 14, 2013 10:00 am

I just upgraded to the latest firmware and software (did an aptitude full-upgrade).

It's a bit better:

- aplay now plays 44.1 audio without click (on high volume)
- omxplayer is down to one click in the beginning (not 3)

Code: Select all

[email protected] ~/tmp $ /opt/vc/bin/vcgencmd version
Feb  7 2013 16:46:17 
Copyright (c) 2012 Broadcom
version 367974 (release)

[email protected] ~/tmp $ uname -a
Linux raspberrypi 3.6.11+ #371 PREEMPT Thu Feb 7 16:31:35 GMT 2013 armv6l GNU/Linux
[email protected] ~/tmp $ 

Gwen
Posts: 7
Joined: Tue Feb 19, 2013 9:39 pm
Location: Glabbeek

Re: Click noise when starting analog audio sound playback

Tue Feb 26, 2013 8:23 pm

I'm using MPD as main sound engine and did enable gapless MP3 playback.
This does not close the output driveer to restart it for the new song
Takes away the popping and clicking

Noise is related to the limited DAC, 11 bit wide, 48ks/s is really limited.
When the volume is full the noise is acceptable, as soon as I reduce it it the noise and bad quality comes in.
Popping comes from the technology used in the DAC.

A potential solution to improve the general sound quality would be to enable a higher sampling rate (88200 ks/s or higher)
Actual driver does not allow this.

Would anyone know where the limitiation comes from?
Hardware or just not implemented as sound quality was assumed not to be important?
Regards,

Gwen

karlkiste
Posts: 184
Joined: Tue Jan 22, 2013 8:50 am
Location: berlin, germany

Re: Click noise when starting analog audio sound playback

Wed Feb 27, 2013 8:04 am

Gwen wrote: A potential solution to improve the general sound quality would be to enable a higher sampling rate (88200 ks/s or higher)
Actual driver does not allow this.

Would anyone know where the limitiation comes from?
Hardware or just not implemented as sound quality was assumed not to be important?
It's partly a hardware problem. The DAC, is in fact no DAC at all, but a PWM module in serializer mode AFAIK. It outputs a frequency of roughly 40MHz (if I want to believe in my very cheap scope). This means, while analog sound is playing, the driver has to generate a data stream of 10MByte/s per channel and feed it to the module. Doubling this would double the CPU load.

This is probably also one of the reasons why the PWM is switched off when not needed, and therefore a direct cause for the annoying clicks.

Anyone with detailed hardware knowledge reading? How about not switching PWM off while idle, but switching from serializer to simple PWM mode? In this way, a 50% duty cycle wave can be generated with no CPU load at all. The additional current consumption is not very high, and there could be a switch (in config.txt or /sys or...) to disable the click-free mode and save the current.

Smcintosh
Posts: 13
Joined: Tue Jul 31, 2012 11:37 am

Re: Click noise when starting analog audio sound playback

Wed Jun 26, 2013 9:16 am

Has anyone found a solution to this? I spent a while sorting an XMBC install and this clicking was a game breaker.

Would love to pick this project up again.

karlkiste
Posts: 184
Joined: Tue Jan 22, 2013 8:50 am
Location: berlin, germany

Re: Click noise when starting analog audio sound playback

Wed Jun 26, 2013 9:43 am

I've come to check again yesterday, and I found that with the latest raspbian image, the problem seems to be solved. Probably the sound module, once used, stays active and therefore the clicking is gone. Only after booting, when sound is used for the first time, there is a single click, which is acceptable for me.

I've tried using omxplayer and aplay.

Thanks to everyone who has contributed to this improvement.

Greets,
Kiste

amith
Posts: 5
Joined: Tue Dec 02, 2014 7:35 pm

Re: Click noise when starting analog audio sound playback

Tue Jan 06, 2015 12:31 pm

I'm confused :?

I understand from the post that a new update should solve the 'clicking' when using Alsa
Unfortunately this seems not to be the case for me.
I still hear ‘clicks’ between two calls to snd_pcm_writei , which are separated in time (if I call it in a for loop no ‘cliks’, but if I execute other code parts and then call the function again, I hear the click)
Any known solution that will enable me to use the Alsa API?

karlkiste
Posts: 184
Joined: Tue Jan 22, 2013 8:50 am
Location: berlin, germany

Re: Click noise when starting analog audio sound playback

Wed Jan 07, 2015 10:26 am

amith wrote:I'm confused :?

I understand from the post that a new update should solve the 'clicking' when using Alsa
Unfortunately this seems not to be the case for me.
I still hear ‘clicks’ between two calls to snd_pcm_writei , which are separated in time (if I call it in a for loop no ‘cliks’, but if I execute other code parts and then call the function again, I hear the click)
Any known solution that will enable me to use the Alsa API?
I have no clue.

Last time I tried it, after booting omxplayer clicks once. The next time omxplayer is started, it does not click anymore. But this is all old, tested with software which was updated half a year ago.

Greets,
Kiste

amith
Posts: 5
Joined: Tue Dec 02, 2014 7:35 pm

Re: Click noise when starting analog audio sound playback

Wed Jan 07, 2015 11:57 am

Thank you for answering.
I'm using Alsa API directly
should I be using a player

billybobischeap
Posts: 1
Joined: Thu Jan 12, 2017 4:29 pm

Re: Click noise when starting analog audio sound playback

Thu Jan 12, 2017 4:32 pm

solved it by removing the bluetooth drivers
Not hearing any clicks or pops anymore.
Also turned off auto-level control for microphone in alsamixer

wga22
Posts: 8
Joined: Tue Mar 07, 2017 2:33 am

Re: Click noise when starting analog audio sound playback

Mon Mar 19, 2018 6:19 pm

to quote from other threadviewtopic.php?t=138610:

Turning off the drivers for bluetooth doesnt seem to help!

/etc/modprobe.d/raspi-blacklist.conf

Code: Select all

#bt
blacklist btbcm
blacklist hci_uart

Return to “Graphics, sound and multimedia”