dom
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 5284
Joined: Wed Aug 17, 2011 7:41 pm
Location: Cambridge

Re: Popping noise on analog output

Tue Mar 05, 2013 11:53 am

doveman wrote:I wonder if there's any way to make XBMC/RPi normalise everything else then, so that I don't have to crank up the volume on my TV/Amp for it and then risk getting deafened when using iPlayer or another piece of equipment?
You really need to analyse the whole file to do that. It's easy to increase the gain during a quiet bit, and then have the audio blaring (and likely clipping/distorting) when the quiet bit finishes.
You obviously can't normalise every packet of audio, or it would be impossible to represent deliberately quiet sounds, and the discontinuities between packets would be jarring.

doveman
Posts: 174
Joined: Wed Dec 07, 2011 11:52 am

Re: Popping noise on analog output

Tue Mar 05, 2013 12:02 pm

dom wrote:
doveman wrote:I wonder if there's any way to make XBMC/RPi normalise everything else then, so that I don't have to crank up the volume on my TV/Amp for it and then risk getting deafened when using iPlayer or another piece of equipment?
You really need to analyse the whole file to do that. It's easy to increase the gain during a quiet bit, and then have the audio blaring (and likely clipping/distorting) when the quiet bit finishes.
You obviously can't normalise every packet of audio, or it would be impossible to represent deliberately quiet sounds, and the discontinuities between packets would be jarring.
Well the Downmix option is working today, so it's not too bad and I can hear the movies OK now :)

I use ffdshow on my PC with Mediaportal and have it set to Normalise with Max Amplification 200%. I don't know how it works but it seems to do a good job with LiveTV. Whilst it's running, I can watch it dynamically adjust the amplification. Maybe something similar could be done on the RPi?

I don't use it with Movies as I want to maintain the dynamic range but for TV it's nice not to have the adverts blaring much louder than the programme.

Another option would be a limiter (dropping the gain rather than a hard cutoff) to prevent certain things like iPlayer from being much louder than everything else.

User avatar
redhawk
Posts: 3465
Joined: Sun Mar 04, 2012 2:13 pm
Location: ::1

Re: Popping noise on analog output

Tue Mar 05, 2013 1:10 pm

ffmpeg has the option to demux your video clips into separate video and audio files.
Then it should be possible to process only the audio part to make it lounder and remux everything back using the original video data..

First extract audio into wav stereo 16bit little endian format:
ffmpeg video.mp4 -acodec pcm_s16le audio.wav

Normalise your wav data and convert back into aac (or mp3) and remux:
ffmpeg -i video.mp4 -i audio.aac -map 0:0 -map 1:0 -acodec out.mp4

The map options is the tricky part of ffmpeg -map "n:" refers to the input file (0 = video.mp4, 1= audio.aac), the other number ":n" refers to the stream id contained inside the file i.e. video or audio.
The video stream id depends on the encoded video it could be 0 or 1 so try "-map 0:0 -map 1:0" or "-map 0:1 -map 1:0" :)

Richard S.

doveman
Posts: 174
Joined: Wed Dec 07, 2011 11:52 am

Re: Popping noise on analog output

Tue Mar 05, 2013 1:22 pm

I'm talking about an on-the-fly method, not remuxing every file manually, which wouldn't help with streaming video and Live TV anyway.

kalehrl
Posts: 350
Joined: Tue Jul 24, 2012 10:49 am

Re: Popping noise on analog output

Tue Mar 05, 2013 3:58 pm

I can confirm that popping noise is no more but there seems to be another problem introduced with the latest firmware.
Sound is no more working on games started via retroarch.
In the log I get this error:

Code: Select all

RetroArch: ALSA: Using signed 16-bit format.
RetroArch: ALSA: Period size: 1024 frames
RetroArch: ALSA: Buffer size: 1024 frames
RetroArch: Sinc resampler [C]
RetroArch: SINC params (8 phase bits, 16 taps).
RetroArch: RetroArch : FCEUmm 98.13mm (SVN).
RetroArch [ERROR] :: [ALSA]: Unknown error occured (Input/output error).
RetroArch [ERROR] :: Audio backend failed to write. Will continue without sound.
I also tried some advmame games and sound works on some but not in others.

dom
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 5284
Joined: Wed Aug 17, 2011 7:41 pm
Location: Cambridge

Re: Popping noise on analog output

Tue Mar 05, 2013 4:17 pm

kalehrl wrote:I can confirm that popping noise is no more but there seems to be another problem introduced with the latest firmware.
Sound is no more working on games started via retroarch.
In the log I get this error:

Code: Select all

RetroArch: ALSA: Using signed 16-bit format.
RetroArch: ALSA: Period size: 1024 frames
RetroArch: ALSA: Buffer size: 1024 frames
RetroArch: Sinc resampler [C]
RetroArch: SINC params (8 phase bits, 16 taps).
RetroArch: RetroArch : FCEUmm 98.13mm (SVN).
RetroArch [ERROR] :: [ALSA]: Unknown error occured (Input/output error).
RetroArch [ERROR] :: Audio backend failed to write. Will continue without sound.
I also tried some advmame games and sound works on some but not in others.
Can you find the simplest possible example that causes the failure?
Ideally just an "apt-get install <app> && ./<app>". I don't really want to have to go searching for roms and building from source to reproduce this.

kalehrl
Posts: 350
Joined: Tue Jul 24, 2012 10:49 am

Re: Popping noise on analog output

Tue Mar 05, 2013 6:34 pm

The best I can do is attach here the emulators (no ROMs included) and post the command line to start the game (nintendo/famicom super mario bros. 3) because I don't use emulators which can be obtained via apt-get.
The command line is :

Code: Select all

~/Games/RetroPie/emulators/retroarch/retroarch --verbose 2>~/log.txt -L ~/Games/RetroPie/emulators/nes/fceumm_libretro.so --config ~/Games/RetroPie/configs/retroarch.cfg ~/Games/RetroPie/roms/nes/Super_Mario_Bros._3.nes
In retroarch.cfg you will see a line

Code: Select all

audio_out_rate = 32000
No sound is produced with this line active and you will get the output like the one I posted above.
If you comment it out, sound is produced but it is all static.
This didn't happen with older firmware.
I tried using sample rate of 44100 and 48000 but it's the same - static.
It seems like there are some problems with down sampling.
Sound works fine with ioquake and dgen.
Advmame - some games OK, some no sound at all.
https://mega.co.nz/#!M5I3gCoL!Gm1-J0xHA ... a1IC6Xm0Co

User avatar
Toad King
Posts: 157
Joined: Sun Dec 18, 2011 8:03 pm

Re: Popping noise on analog output

Wed Mar 06, 2013 3:44 am

You can just compile the test core in the RetroArch source directory (libretro-test) and run that instead. Just give it any file in place of a ROM, it should just run anyway.

dom
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 5284
Joined: Wed Aug 17, 2011 7:41 pm
Location: Cambridge

Re: Popping noise on analog output

Wed Mar 06, 2013 10:32 am

Toad King wrote:You can just compile the test core in the RetroArch source directory (libretro-test) and run that instead. Just give it any file in place of a ROM, it should just run anyway.
Any chance of posting a prebuilt version?

elbekko
Posts: 5
Joined: Wed Mar 06, 2013 11:39 am

Re: Popping noise on analog output

Wed Mar 06, 2013 12:42 pm

The firmware update fixed my problem, I can live with the initial popping. Thanks a lot!

kalehrl
Posts: 350
Joined: Tue Jul 24, 2012 10:49 am

Re: Popping noise on analog output

Wed Mar 06, 2013 2:30 pm

@dom
Weren't you able to start the emulator with the version I posted?
Here is the compiled libretro-test.
While you're at it, could you investigate why the analogue sound quality is so bad?
Thank you
Attachments
libretro.rar
(4.21 KiB) Downloaded 134 times

dom
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 5284
Joined: Wed Aug 17, 2011 7:41 pm
Location: Cambridge

Re: Popping noise on analog output

Wed Mar 06, 2013 5:00 pm

Is libretro-text typical of how retroarch drives audio?
I find it sends:

Code: Select all

pcm_copy / SNDRV_PCM_TRIGGER_START / SNDRV_PCM_TRIGGER_STOP
pcm_copy / SNDRV_PCM_TRIGGER_START / SNDRV_PCM_TRIGGER_STOP
pcm_copy / SNDRV_PCM_TRIGGER_START /SNDRV_PCM_TRIGGER_STOP
...
With several start/stops a second. Most ALSA code produces:

Code: Select all

pcm_copy (on start of app)
SNDRV_PCM_TRIGGER_START
pcm_copy 
pcm_copy 
pcm_copy 
pcm_copy 
pcm_copy 
pcm_copy 
pcm_copy 
pcm_copy 
...
SNDRV_PCM_TRIGGER_STOP (on on exit)
Any idea why it's doing this? I'm sure this is adding to the audio problems.

kalehrl
Posts: 350
Joined: Tue Jul 24, 2012 10:49 am

Re: Popping noise on analog output

Wed Mar 06, 2013 7:05 pm

I believe retroarch uses alsathread for sound:
https://github.com/Themaister/RetroArch ... sathread.c
There are problems with the sound as stated in the wiki:
https://github.com/petrockblog/RetroPie ... und-Issues
Just to confirm, I went back to https://github.com/Hexxeh/rpi-firmware/ ... 09b25ada12 and sound works so the latest firmware is definitely the culprit. The sound isn't perfect - there is some static but at least it works.

dom
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 5284
Joined: Wed Aug 17, 2011 7:41 pm
Location: Cambridge

Re: Popping noise on analog output

Wed Mar 06, 2013 7:59 pm

kalehrl wrote:I believe retroarch uses alsathread for sound:
https://github.com/Themaister/RetroArch ... sathread.c
There are problems with the sound as stated in the wiki:
https://github.com/petrockblog/RetroPie ... und-Issues
Just to confirm, I went back to https://github.com/Hexxeh/rpi-firmware/ ... 09b25ada12 and sound works so the latest firmware is definitely the culprit. The sound isn't perfect - there is some static but at least it works.
Yes, I've seen the hang with current firmware. Interestingly I've got some local mods to the firmware, and that doesn't hang. I'll need to look through the changes and see which one fixes it.

I suspect that alsathread is continually getting EPIPE (due to underrun) and calling snd_pcm_recover. That is probably making the audio worse.

Now the underrun is likely unavoidable if CPU is >100%.
But it's also possible it is using too small an audio buffer or somehow making the underrun more likely. I'll see if I can spot anything.

doveman
Posts: 174
Joined: Wed Dec 07, 2011 11:52 am

Re: Popping noise on analog output

Thu Mar 07, 2013 10:22 am

For anyone who's still not satisfied with the analog output, perhaps a HDMI->VGA and analog audio converter like this one http://www.amazon.co.uk/Converter-Adapt ... omputers_1 would be a better option than a USB DAC and not much more expensive, as I imagine it should just work for both music and video without needing any special settings or loading the CPU or USB bus.

It's not clear whether it will accept 5.1 and mixdown or if the signal needs to be set to 2.0 on the Pi but that doesn't really matter. I doubt it can convert DTS though, so any decoding would probably have to be done on the Pi still.

Of course, I have no idea what components it uses or what the quality of the output is like.

sej7278
Posts: 249
Joined: Tue Jan 22, 2013 6:43 pm

Re: Popping noise on analog output

Thu Mar 07, 2013 1:05 pm

doveman wrote:For anyone who's still not satisfied with the analog output, perhaps a HDMI->VGA and analog audio converter like this one http://www.amazon.co.uk/Converter-Adapt ... omputers_1 would be a better option than a USB DAC and not much more expensive, as I imagine it should just work for both music and video without needing any special settings or loading the CPU or USB bus.

It's not clear whether it will accept 5.1 and mixdown or if the signal needs to be set to 2.0 on the Pi but that doesn't really matter. I doubt it can convert DTS though, so any decoding would probably have to be done on the Pi still.

Of course, I have no idea what components it uses or what the quality of the output is like.
the problem there is that you need a very expensive receiver to plug into, most of us are talking pc/usb speakers. if you're going to do that you might as well just play it through your hdmi tv.

doveman
Posts: 174
Joined: Wed Dec 07, 2011 11:52 am

Re: Popping noise on analog output

Thu Mar 07, 2013 1:09 pm

sej7278 wrote:the problem there is that you need a very expensive receiver to plug into, most of us are talking pc/usb speakers. if you're going to do that you might as well just play it through your hdmi tv.
Er no, that's the whole point, it has an analog output.

kalehrl
Posts: 350
Joined: Tue Jul 24, 2012 10:49 am

Re: Popping noise on analog output

Fri Mar 08, 2013 7:27 pm

I noticed 2 firmware commits today.
Has the 'game emulators no audio' bug been squashed?
EDIT:
To answer myself - no it hasn't.

limpens
Posts: 38
Joined: Thu Sep 13, 2012 1:15 pm

Re: Popping noise on analog output

Tue Mar 19, 2013 12:16 pm

I still experience a loud plop sound when using mplayer. Is this expected behaviour?
In my use case omxplayer isn't a solution as it by passes alsa mixer and I need to adjust volume etc from software.

This is using the latest firmware and kernel from git. When volume is set very low and mplayer starts I still hear the plopping.

pudding
Posts: 95
Joined: Sat Jan 12, 2013 3:55 pm
Location: UK

Re: Popping noise on analog output

Fri Mar 22, 2013 4:56 pm

dom, I've just updated to the latest firmware version and the sound is very broken with ALSA - bad static, very quiet. My MAME4ALL had pretty much perfect audio (analogue & HDMI) with 2013-02-09-wheezy-raspbian or earlier. My sound code is based on RetroArch but uses quite different ALSA initialisation and buffer settings.

If you want, install MAME4ALL from the Pi Store (or manually here http://code.google.com/p/mame4all-pi/so ... ll_pi.zip) and I'll supply you with ROMS to test with. My source for the ALSA sound code is also here http://code.google.com/p/mame4all-pi/so ... /sound.cpp Run "./mame -log {romname}" to produce an error.log showing underruns, buffer/frame sizes.

Update noticed that with the new kernel ALSA period size is 2048, whereas on previous working kernels the period size is 736 which is what I would expect (frame size 44100khz/60fps), it matches the "samples per frame" based on latency of 1/60 of a second passed to snd_pcm_set_params. I also put a usleep in to reduce cpu usage below 70% but there was no difference to the sound.
Last edited by pudding on Mon Mar 25, 2013 11:05 am, edited 2 times in total.
Author of MAME4ALL for Pi, PiSNES, PiFBA & PiMenu

User avatar
Toad King
Posts: 157
Joined: Sun Dec 18, 2011 8:03 pm

Re: Popping noise on analog output

Sat Mar 23, 2013 6:13 pm

dom wrote:
kalehrl wrote:I believe retroarch uses alsathread for sound:
https://github.com/Themaister/RetroArch ... sathread.c
There are problems with the sound as stated in the wiki:
https://github.com/petrockblog/RetroPie ... und-Issues
Just to confirm, I went back to https://github.com/Hexxeh/rpi-firmware/ ... 09b25ada12 and sound works so the latest firmware is definitely the culprit. The sound isn't perfect - there is some static but at least it works.
Yes, I've seen the hang with current firmware. Interestingly I've got some local mods to the firmware, and that doesn't hang. I'll need to look through the changes and see which one fixes it.

I suspect that alsathread is continually getting EPIPE (due to underrun) and calling snd_pcm_recover. That is probably making the audio worse.

Now the underrun is likely unavoidable if CPU is >100%.
But it's also possible it is using too small an audio buffer or somehow making the underrun more likely. I'll see if I can spot anything.
If the issue is the audio buffer being too small, you can increase it by setting the "audio_latency" value in retroarch.cfg (by default at ~/.retroarch.cfg). It's in milliseconds and is normally 64 by default, but might need to be bumped higher for the Raspberry Pi.

dom
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 5284
Joined: Wed Aug 17, 2011 7:41 pm
Location: Cambridge

Re: Popping noise on analog output

Sun Mar 24, 2013 8:27 pm

kalehrl wrote:I noticed 2 firmware commits today.
Has the 'game emulators no audio' bug been squashed?
Try now (after rpi-update)
The hang in libretro test doesn't occur for me. It still clicks due to underrun, so may be worth increasing the "audio_latency" suggest by Toad King.

kalehrl
Posts: 350
Joined: Tue Jul 24, 2012 10:49 am

Re: Popping noise on analog output

Mon Mar 25, 2013 11:06 pm

Tested and it works now.
However, there is an issue when using any sample rate lower than the, possibly default, 44100.
I'm using analogue out and I found out that by lowering the sample rate to 22050, I can eke out a bit more emulation speed. The sound quality remained the same to my ears.
Now, when I lower it to 22050 in mame4all for example, I get something that seems to me as slightly intermittent sound with scratches.
Bottom line is, there seem to be some issues with down sampling.

Jokke
Posts: 11
Joined: Tue Jul 03, 2012 3:50 pm

Re: Popping noise on analog output

Tue Mar 26, 2013 12:59 am

Well done!!

You made something that sounded close to impossible looking the earlier posts. Thanks for taking the time to dig into this dom. I can live with the initial pop as long as I know I do not have pop every single time some app is giving audio out or ending the playback.

kalehrl
Posts: 350
Joined: Tue Jul 24, 2012 10:49 am

Re: Popping noise on analog output

Sat Mar 30, 2013 1:36 pm

It fixed one thing and broke another so it's not much of a progress.
I'd rather audio pop was still there because now I wouldn't be having game emulator audio problems.

Return to “Troubleshooting”