Page 1 of 1

Distortion on audio playback

Posted: 28 Apr 2012 18:18
by PeterMartinez
I am experiencing distortion when playing-back audio with VLC 1.1.11. I am using XP and a Dell laptop. At the start of playback of an internet radio stream, the audio is clean but crackles develope and get worse after a few seconds. Pausing playback stops the crackles for a few seconds. So far I have heard it when playing streams with samplerates of 22050 but not 44100. The crackles are single impulses at random intervals and are most noticable when the audio is high-amplitude low-frequency sound, in which case the crackles are easy to hear at the top end of the audio band. There are no crackles if the stream is quiet.

I found that if I go to Tools/Preferences/Audio and change from the default samplerate (shown as "Audio frequency") to force playback at 44100, the distortion clears almost completely, only reappearing for a second or so every few minutes.

The built-in soundcard in my laptop (Sigma-Tel) has a hardware samplerate of 48kHz. Other rates are achieved by software. Some rates, such as 22050, 11025, 8000, are only approximate (22200, 11100, 8100 ). I think this might be a clue to the problem.

I have a Presonus Firebox, a semi-pro firewire sound box. This too has 48kHz hardware rate and the same problem with the 22050/11025/8000 rates, and playback via VLC is distorted through this too. However I can switch the Firebox to a hardware rate of 44.1 kHz and in this condition the 22050 and 11025 rates are exact. There is NO DISTORTION with VLC playback if it is using 44.1 kHz hardware rate.

All these tests lead me to ask whether there may be a problem with the audio re-sampling in VLC. From my own experience with synchronisation of data streams, I am sure that VLC will need to dynamically re-sample the audio from an externally-timed stream to prevent buffer under/overflow to the local soundcard. Other media players seem to manage this well but for me at least VLC seems to be dropping or padding single audio samples when some internal buffer under or overflows. This will sound worse if there is a large difference between the source and sink samplerates.

I can see from other similar topics that this question has arisen before, but I don't see a solution posted and the topics seem to have died. I don't know whether anyone will read an old topic so I am starting a new one.

Later edit:
It's the same with WaveAudio or DirectX.

Message entries like (I don't show duplicates):
main warning: PTS is out of range (-34920), dropping buffer
main warning: output date isn't PTS date, requesting resampling (-40443)
main warning: buffer is 40444 in advance, triggering downsampling
main warning: timing screwed, stopping resampling

Surprise: the SAME distortion (and messages) when playing-back 22050Hz mp3 files from the hard drive. I would not have expected resampling problems playing from a local file! Surely the program can fetch the file data in sync. with the sink!

With my work-around (force playback to 44100Hz), the following messages every few minutes ..
main warning: output date isn't PTS date, requesting resampling (-40001)
main warning: buffer is 40002 in advance, triggering downsampling
main warning: resampling stopped after 7025562 usec (drift: -451)
While the downsampling is active (for 7 secs), the audio is distorted.

regards
Peter

Re: Distortion on audio playback

Posted: 29 Apr 2012 12:46
by VLC_help
Did you test VLC 2.0.1?

Re: Distortion on audio playback

Posted: 30 Apr 2012 08:26
by PeterMartinez
No I didn't test 2.0.1 yet. If someone can tell me for sure that 1.1.11 has this problem and 2.0.1 fixes it, I will do it.

By the way, I saw in the Tools | Messages | Modules tree screen that there is a module loaded called "ugly-resampler". It is loaded whether I select "high quality audio resampling" or not. Is the high-quality resampler not working? Is my problem due to the ugliness of the resampler? Does 2.0.1 implement the high-Q resampler but 1.11.1 does not?

Sorry for so many questions...

Peter

Re: Distortion on audio playback

Posted: 30 Apr 2012 09:35
by Lotesdelere
We can't be sure so you need to test and trial. Can you try the latest nightly build ? Where VLC 2.0.0 is in fact 2.0.2:
http://nightlies.videolan.org/build/win32/?C=M;O=D

If it still doesn't help then you can also try to:

- Change the audio output module
http://wiki.videolan.org/WindowsFAQ-2.0 ... _anomalies

- Not to use a volume over 100%

- Disable time stretching in the audio preferences
Menu Tools -> Preferences -> Audio

- Force the number of FFmpeg threads to 4 or 2 or even 1
Menu Tools -> Preferences (Show Settings = ALL) -> Input/Codecs -> Video Codecs -> FFmpeg

- Use a faster resampler by setting the Sample Rate Converter type to Zero Holder Hold
Menu Tools -> Preferences (Show Settings = ALL) -> Audio -> SRC Resampler


After the changes save the preferences then exit and restart VLC.
And please be kind enough to report us what worked and what had no effect for you.

Re: Distortion on audio playback

Posted: 30 Apr 2012 10:55
by PeterMartinez
Thank you for replying. First I should say I am only using VLC for audio. I have no experience with video - I was recommended VLC for the ability to stream and convert mp3<>mp4 audio only, and VLC is doing a good job for this - I mention the distortion problem because I want to help. Second I should say I am familiar with writing audio resampling software so I have some ideas where the problem may be - the resampler may be dropping or padding samples instead of interpolating smoothly, and I don't understand why the problem is still present when playback is from a file - there should be no reason to resample.

Please forgive me if I do not upgrade to 2.0.2 yet - it is working fine for the job I want at this moment.

Disabling time-stretch: not a fix. Volume to 100%: not a fix. SRC is not present in 1.1.11. FFmpeg threads: not relevant?

Can I suggest that you may be able to reproduce this effect if you can input from a stream which has a samplerate of 22050 (for example my favourite http://216.249.99.38:8000 Bolivia web radio) and output to a USB soundcard (using Microsoft usbaudio.sys driver) which will implement the 22050 rate as 22200. I think the VLC resampler is struggling to handle this rate change.

regards
Peter

Re: Distortion on audio playback

Posted: 07 May 2012 21:08
by PeterMartinez
I just downloaded 2.0.1. I can see that the Sample Rate Converter in this version is doing a MUCH better job than the one in version 1.1.11 (the "ugly_resampler") which I am sure was not resampling but just dropping/padding randomly at intervals. However, when taking a stream at a samplerate of 22050 and feeding to a soundcard which uses a samplerate of 22200, the 'messages' screen does show that the SRC is struggling, displaying the "timing screwed" message then trying again repeatedly. There are many soundcards with a basic hardware samplerate of 48kHz that implement all lower rates by driver firmware and most of these approximate 11025 samplerate as 11100 and 22050 as 22200 (0.68% fast) so this will be a common set-up.

As I commented before, the SAME behaviour shows when playing back a 22050 Hz MP3 file to a 22200 Hz soundcard. Why is VLC resampling here? Surely it can avoid this by fetching the file stream synchronised to the output?

However, the audio is clean. 2.0.1 has fixed the playback distortion that I reported. Congratulations to the team for a great project.

Peter