Bug 87202 - Strong noise (unintelligible) when playing through the analog output using mmap
Summary: Strong noise (unintelligible) when playing through the analog output using mmap
Status: RESOLVED NOTOURBUG
Alias: None
Product: PulseAudio
Classification: Unclassified
Component: alsa (show other bugs)
Version: unspecified
Hardware: Other All
: medium normal
Assignee: pulseaudio-bugs
QA Contact: pulseaudio-bugs
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2014-12-10 19:09 UTC by Mario Sanchez Prada
Modified: 2014-12-12 11:18 UTC (History)
3 users (show)

See Also:
i915 platform:
i915 features:


Attachments
Output of alsa-info.sh (26.30 KB, text/plain)
2014-12-10 19:09 UTC, Mario Sanchez Prada
Details
Output of pactl list (17.82 KB, text/plain)
2014-12-10 19:10 UTC, Mario Sanchez Prada
Details
Output of pactl info (466 bytes, text/plain)
2014-12-10 19:10 UTC, Mario Sanchez Prada
Details
Output of dmesg when loading the snd-hda-intel module (1.11 KB, text/plain)
2014-12-11 11:05 UTC, Mario Sanchez Prada
Details

Description Mario Sanchez Prada 2014-12-10 19:09:36 UTC
Created attachment 110686 [details]
Output of alsa-info.sh

In the last few days I've observed the following issue in a Gigabyte BXBT-2807 unit[1] I have using a 5.0-2 release of pulse audio (from debian), but today I could reproduce it as well with the latest code from the master branch, so reporting:

STEPS TO REPRODUCE:

1. Get a GB-BXBT-2807 device or similar. This computer has the analog and HDMI outputs in the same card and a combined Headset+Mic 3.5mm is the only way to use the analog one (not sure if that causes the issue, though)

2. Connect your headphones to the 3.5mm, select them as output device and play some music through them

3. Now repeat one of the following actions several times (or both combined)

  3.a Change the volume up and down continuously (e.g. from 100% to 0% and back, x10-20 times)

  3.b If you have the HDMI cable connected, open gnome-control-center and switch back and forth between the HDMI and the Headphones outputs


EXPECTED OUTCOME:

Repeating (3.a) or (3.b) many times should not result on hearing any noise being heard, just in the volume levels or the output device changing, respectively.


ACTUAL OUTCOME:

Eventually, after repeating 3.a or 3.b (or a combination or both) for a few times, the sound changes into a very weird noise that can or can not resemble the original song being played. Once that happens, you need to either restart pulseaudio or unplug + re-plug the headphones to get back to normal (and even doing that, sometimes you might need to try that "reset sequence" more than once).

I've recorded a video to explain the problem even better:
https://www.youtube.com/watch?v=7qwAdtXtbq8&list=UUtP76gwwFTMmUp8NBhA0FVA 


ADDITIONAL INFORMATION:

Note 1: By hooking some code in mmap_write() I managed to dump to a file the raw data being sent by PA to the sound card, to try to know whether this issue was in PA or somewhere else (e.g. kernel driver). After doing that, I copied that dump file to my personal laptop and played through pacat and could reproduce the noises too, so indeed it seems PA is sending broken data.

Note 2: Following the lead by the previous experiment, I've found that not using mmap in the alsa sink (using unix_write() instead of mmap_write) will NOT produce any noise when changing volume or switching output devices. I did this by commenting the load-module lines for module-udev-detect in /etc/pulse/default.pa, and then explicitly loading module-alsa-card with the parameters shown by pactl list, but setting mmap=no.

Note 3: Following the instructions in https://wiki.ubuntu.com/Audio/PositionReporting, I've already tried loading module-udev-detect with tsched=0 and/or loading the snd-hda-intel module with different values for position_fix, and none of those attempts work.


So, it seems to me that there's something wrong with the mmap path and this device. Now attaching the output of alsa-info.sh, and will follow with a few more attachments (and hopefully more comments) soon.

[1] http://www.gigabyte.com/products/product-page.aspx?pid=5038
Comment 1 Mario Sanchez Prada 2014-12-10 19:10:10 UTC
Created attachment 110687 [details]
Output of pactl list
Comment 2 Mario Sanchez Prada 2014-12-10 19:10:41 UTC
Created attachment 110688 [details]
Output of pactl info
Comment 3 David Henningsson 2014-12-11 01:57:35 UTC
I still have the feeling this is kernel/driver/hw related. At least we have this message in the log:

[  327.857108] hda-intel 0000:00:1b.0: Unstable LPIB (17628 >= 4408); disabling LPIB delay counting

Could you tell if this is related to when the error happens for the first time?

Also, when this error is happening, do you have *constant* entries in the debug log about rewinds? It's natural to have them when you change volume, but not for them to persist after the volume change is completed.
Comment 4 David Henningsson 2014-12-11 02:12:14 UTC
Ah, actually I remember a noise once appearing after changing the volume constantly for a while. This was for an AMD Hudson chip though, so not sure if it is related, but feel free to try 

option snd-hda-intel enable_msi=0

...same procedure as when you tried the position fix stuff (reboot to test).
Comment 5 Mario Sanchez Prada 2014-12-11 11:05:16 UTC
Created attachment 110736 [details]
Output of dmesg when loading the snd-hda-intel module

(In reply to David Henningsson from comment #3)
> I still have the feeling this is kernel/driver/hw related. At least we have
> this message in the log:
> 
> [  327.857108] hda-intel 0000:00:1b.0: Unstable LPIB (17628 >= 4408);
> disabling LPIB delay counting
> 
> Could you tell if this is related to when the error happens for the first
> time?

I can't really tell, as I could not see anymore that message in the output of dmesg after trying this morning (even if I managed to reproduce the noise again).

The only output I can see in dmesg happens at the time of loading the snd-hda-intel module, which I'm attaching right now.

> Also, when this error is happening, do you have *constant* entries in the
> debug log about rewinds? It's natural to have them when you change volume,
> but not for them to persist after the volume change is completed.

No constant entries, only when changing the volume or when switching between output devices (headphones <-> HDMI).

By the way, sometimes it's harder than other times for me to get the noise by simply modifying the volume (although I eventually get the noise anyway), but when that happens just switching to HDMI and then back to headphones usually makes me get the noise easily (after no more than 1-3 attempts, normally).

Not sure how relevant this is to the discussion, but I thought I would mention it because I saw rewinds are also involved when switching between outputs.
Comment 6 Mario Sanchez Prada 2014-12-11 11:20:48 UTC
(In reply to David Henningsson from comment #4)
> Ah, actually I remember a noise once appearing after changing the volume
> constantly for a while. This was for an AMD Hudson chip though, so not sure
> if it is related, but feel free to try 
> 
> option snd-hda-intel enable_msi=0
> 
> ...same procedure as when you tried the position fix stuff (reboot to test).

I've tried that too, but did not work either. Thanks for the tip anyway, that's something I certainly hadn't tried yet.

I'm now in the process of carefully checking the mmap path (down into the kernel if needed too) to see whether I can figure out the culprit at a more fine-grained level.
Comment 7 Mario Sanchez Prada 2014-12-11 16:17:49 UTC
After so much testing and gdb debugging today I finally identified the problem in alsa-lib, after following the lead from the experiment mentioned in "Note 1", and it seems to be caused by the call to snd_pcm_mmap_begin() returning the wrong memory chunks in the areas array, leading to the strange noise mentioned.

With that in mind, I started looking inside of alsa-lib, and found significant differences between the latest code in the 0.28 release and the one I've available in my environment, which is quite older (0.25). And even better, I found that just upgrading to that newer version of alsa-lib would get rid of the noise, so indeed it seems the problem was there!

I've devoted a bit more of time to try to find the specific changeset and it seems that the the fix for bug 64299 is the one fixing this specific:

http://git.alsa-project.org/?p=alsa-lib.git;a=commitdiff;h=f2d39afe6139ab16aa2aeea0f51f32db79ab1262

I found that commit by simply looking at the changelog and looking for things related to either mmap or rewinds, and then applying it locally to my package as a patch on top, so I'm pretty certain that it fixes the problem. Still, I would appreciate if someone (maybe David, as the author) could comment on whether this makes sense, so we can maybe resolve this bug as a duplicate or invalid.
Comment 8 David Henningsson 2014-12-12 11:18:53 UTC
I think this makes sense, yes. Thanks for the follow-up.

I e, the bug starts happening when you switch output or change volume, and in these cases PulseAudio fires one or more rewinds, and the patch fixes an issue that is rewind related.


Use of freedesktop.org services, including Bugzilla, is subject to our Code of Conduct. How we collect and use information is described in our Privacy Policy.