Bug 537378 - tsched=0 is unusable, makes sound heavily distorted
Summary: tsched=0 is unusable, makes sound heavily distorted
Keywords:
Status: CLOSED WONTFIX
Alias: None
Product: Fedora
Classification: Fedora
Component: pulseaudio
Version: 14
Hardware: All
OS: Linux
low
medium
Target Milestone: ---
Assignee: Lennart Poettering
QA Contact: Fedora Extras Quality Assurance
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2009-11-13 12:06 UTC by Michal Schmidt
Modified: 2012-08-16 18:56 UTC (History)
9 users (show)

Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Clone Of:
Environment:
Last Closed: 2012-08-16 18:56:23 UTC
Type: ---
Embargoed:


Attachments (Terms of Use)
pulseaudio -vvvvv (99.96 KB, text/plain)
2009-11-13 12:06 UTC, Michal Schmidt
no flags Details
alsa-info.sh --no-upload (18.26 KB, text/plain)
2009-11-13 12:07 UTC, Michal Schmidt
no flags Details
Testcase for mixing in PA (402 bytes, application/x-sh)
2009-11-18 17:29 UTC, Michal Schmidt
no flags Details

Description Michal Schmidt 2009-11-13 12:06:52 UTC
Created attachment 369413 [details]
pulseaudio -vvvvv

Description of problem:
While helping someone with their sound-related issues, I decided that their combination of the sound card and ALSA driver is buggy, making it impossible for glitch-free PA to work right. So I suggested tsched=0 as a workaround. To my surprise this made the sound even worse.

Then I tried setting tsched=0 on my own laptop, which otherwise works fine with glitch-free. I reproduced the horrible sound distortion too.

Version-Release number of selected component (if applicable):
pulseaudio-libs-glib2-0.9.20-1.fc12.x86_64
pulseaudio-libs-0.9.20-1.fc12.x86_64
pulseaudio-esound-compat-0.9.20-1.fc12.x86_64
pulseaudio-gdm-hooks-0.9.20-1.fc12.x86_64
pulseaudio-module-bluetooth-0.9.20-1.fc12.x86_64
pulseaudio-0.9.20-1.fc12.x86_64
pulseaudio-module-x11-0.9.20-1.fc12.x86_64
pulseaudio-libs-zeroconf-0.9.20-1.fc12.x86_64
pulseaudio-utils-0.9.20-1.fc12.x86_64
pulseaudio-module-gconf-0.9.20-1.fc12.x86_64
pulseaudio-module-zeroconf-0.9.20-1.fc12.x86_64
alsa-lib-1.0.21-3.fc12.x86_64
kernel-2.6.31.5-127.fc12.x86_64

How reproducible:
almost always

Steps to Reproduce:
0. Prepare a wav file with a test sound (a 23.2s long sine wave):
gst-launch-0.10 audiotestsrc freq=440 num-buffers=1000 ! 'audio/x-raw-int,rate=44100,channels=1,width=16,depth=16' ! wavenc ! filesink location=/tmp/sine.wav
1. Set tsched=0 in /etc/pulse/default.pa:
load-module module-udev-detect tsched=0
2. Restart PA: pulseaudio -k; sleep 1; pulseaudio -vvvvv
3. Play the sine wave: paplay /tmp/sine.wav

Actual results:
You'll hear an ugly sound, like a helicopter.

Expected results:
I'd like to hear a plain concert A tone without distortion.

Additional info:
I'll attach the output of pulseaudio -vvvvv and alsa-info.sh for hw information.

Comment 1 Michal Schmidt 2009-11-13 12:07:33 UTC
Created attachment 369414 [details]
alsa-info.sh --no-upload

Comment 2 Michal Schmidt 2009-11-18 17:29:38 UTC
Created attachment 370142 [details]
Testcase for mixing in PA

Attached is a simple script to test mixing of multiple sources in PA.

It seems to be a very reliable trigger for the bug. With glitch-free it works fine for me. With tsched=0 it causes heavy distortion or complete silence with lots of rewinding in PA.

The behaviour is the same on two very different systems:
 - my laptop with HDA ATI (Realtek ALC268), Fedora 12, PA 0.9.20.
 - a desktop with PCI Creative SB Live! (emu10k1), Fedora 11, PA 0.9.15

I'm surprised that tsched=0 works so badly, because I thought it was supposed to be the safe fallback which would use only basic functionality of the ALSA drivers.

Comment 3 Michal Schmidt 2009-11-23 15:57:23 UTC
Ubuntu developer Daniel T. Chen reproduced it too. From #pulseaudio:
<dtchen> michich: yes, that symptom is reproducible since 0.9.19, it seems
<dtchen> michich: (just tested from 0.9.19 forward through 0.9.21)
<dtchen> haven't tested earlier versions, don't have them lying around
<dtchen> michich: also reproducible in Debian unstable and Ubuntu 9.04 and 9.10

Comment 4 Michal Schmidt 2009-11-24 13:51:49 UTC
Tested with pulseaudio-0.9.21-1.fc12.x86_64: no change.

Comment 5 Michal Schmidt 2009-11-24 17:28:00 UTC
PA developer Colin Guthrie reproduced it and will look into it.
Lennart is away for the next 3 weeks (https://tango.0pointer.de/pipermail/pulseaudio-discuss/2009-November/005603.html).

Comment 6 Petr Mensik 2009-11-25 09:51:01 UTC
I tested chordtest on all 4 my machines, some intel HDA with sigmatel codec, some intel integrated sound cards based on ac97. All behaved the same, with tsched=0 it did fail on all computers. All cards played with tsched=1 fine, with tsched=0 there was problem. 

Only case it did not fail was au8830 driver for vortex2, which does not support all features. But it had problems with tsched=0 anyway, propably due to bug in alsa itself (card has hw mixing, which could not play well simultaneously however).

Comment 7 Lennart Poettering 2010-02-23 02:17:57 UTC
This script from comment 3 runs very robust on my machine here.

Does this problem still exist?

Comment 8 Colin Guthrie 2010-02-23 11:00:54 UTC
I can still reproduce the issue with fully up to date stable-queue (obviously I have to set tsched=0 to trigger it).

I've not tried with your git master patch:
 d11cd33 alsa: don't make use of tsched related variables when tsched is disabled

Which would seem a likely candidate for fixing. I'll try that next.

Comment 9 Colin Guthrie 2010-02-23 11:10:52 UTC
Nope even with that patch applied, the problem still surfaced. I got one clean run this time (which I've not seen before), but the second run bombed out with the ear bleeding etc. :p

Comment 10 Michal Schmidt 2010-02-23 12:51:35 UTC
It is still reproducible for me too. I am now running the latest packages from the branched F-13.

Comment 11 Lennart Poettering 2010-02-23 17:53:27 UTC
Hmm, so is this accompanied by any specific output when run with -vvvv?

When exactly does this happen? when a new stream is about to start? might this be related to rewinding?

Could somebody try to reproduce this with a PA run in valgrind? "VALGRIND=1 valgrind pulseaudio -vvvvv". Does this show anything?

Comment 12 Michal Schmidt 2010-02-24 21:45:16 UTC
pulseaudio-0.9.21-6.fc13.x86_64 ignores VALGRIND=1 because it's built without valgrind support (the packages does not BuildRequire valgrind-devel).

I ran it anyway. I used 'ts' to add timestamps to each line:
pulseaudio -k; VALGRIND=1 valgrind pulseaudio -vvvvv 2>&1 | ts '%H:%M:%.S' > /tmp/pa.log

I used chordtest.sh for the test, just modified it to wait 10 seconds before starting another tone generator instead of 2 seconds.

The result (9 MB) is here:
http://michich.fedorapeople.org/pa-chordtest-tsched0.log

Some notable events:
19:01:25 - pulseaudio started
19:01:31 - module-suspend-on-idle kicked in, suspended the output device.
19:01:40 - chordtest.sh was started and the 1st tone generator connected to PA.
           There were some rewinds logged, but there were not too many of them.
           For some reason pulseaudio consumed about 30 % CPU time already
           (observed by top). And the sound was already distorted.
           In fact the tone was not even once clear during the whole test.
19:01:50 - 2nd client connected. Again a few rewinds were logged.
           Also some 'memblock.c: Pool full' messages.
           pulseaudio CPU usage has risen to 50 - 60 % now.
19:02:00 - 3rd client connected. pulseaudio now uses around 90 % CPU.
19:02:10 - 4th client connected.
19:02:20 - 5th client connected. Lots of rewinds.
19:02:31 - 6th client connected. So many rewinds and a flood of logs that even
           the 'ts' process starts to take considerable amount of CPU time.

Comment 13 Raymond 2010-03-29 11:16:21 UTC
(In reply to comment #12)

> 
> The result (9 MB) is here:
> http://michich.fedorapeople.org/pa-chordtest-tsched0.log
> 
> Some notable events:
> 19:01:25 - pulseaudio started
> 19:01:31 - module-suspend-on-idle kicked in, suspended the output device.
> 19:01:40 - chordtest.sh was started and the 1st tone generator connected to PA.
>            There were some rewinds logged, but there were not too many of them.
>            For some reason pulseaudio consumed about 30 % CPU time already
>            (observed by top). And the sound was already distorted.
>            In fact the tone was not even once clear during the whole test.
> 19:01:50 - 2nd client connected. Again a few rewinds were logged.
>            Also some 'memblock.c: Pool full' messages.
>            pulseaudio CPU usage has risen to 50 - 60 % now.
> 19:02:00 - 3rd client connected. pulseaudio now uses around 90 % CPU.
> 19:02:10 - 4th client connected.
> 19:02:20 - 5th client connected. Lots of rewinds.
> 19:02:31 - 6th client connected. So many rewinds and a flood of logs that even
>            the 'ts' process starts to take considerable amount of CPU time.    



19:02:11.083448 D: source.c: Processing rewind...
19:02:11.083565 D: protocol-native.c: Underrun on 'audiotest wave', 0 bytes in queue.

Comment 14 Raymond 2010-03-30 01:50:01 UTC
(In reply to comment #6)
> I tested chordtest on all 4 my machines, some intel HDA with sigmatel codec,
> some intel integrated sound cards based on ac97. All behaved the same, with
> tsched=0 it did fail on all computers. All cards played with tsched=1 fine,
> with tsched=0 there was problem. 
> 
> Only case it did not fail was au8830 driver for vortex2, which does not support
> all features. But it had problems with tsched=0 anyway, propably due to bug in
> alsa itself (card has hw mixing, which could not play well simultaneously
> however).    

what problem do your au8830 have ? 

I can run ,/chordtest.sh on pulseaudio-0.9.13 Fedora 10 using pulsesink or 'alsasink device=hw:0,0" or 'alsasink device=pulse'

The only problem of au8830 is missing a constraint to allow alsa-lib for those functions snd_pcm_hw_params_set_period_time_near() and snd_pcm_hw_params_set_buffer_time_near() to return period_time and buffer_time since the current constraint period_size must be power of two is not sufficient for alsa-lib to evalaute an feasible value

so you will get some message when using gstreamer which use buffer time but it still continue to play nicely on fedora 10


 ./chordtest.sh
Running sine at 440 kHz
Setting pipeline to PAUSED ...
Pipeline is PREROLLING ...
WARNING: from element /GstPipeline:pipeline0/GstAlsaSink:alsasink0: Could not get/set settings from/on resource.
Additional debug info:
gstalsasink.c(404): set_hwparams (): /GstPipeline:pipeline0/GstAlsaSink:alsasink0:
Unable to set buffer time 200000 for playback: Invalid argument
Pipeline is PREROLLED ...
Setting pipeline to PLAYING ...
New clock: GstAudioSinkClock
Running sine at 554.37 kHz
Setting pipeline to PAUSED ...
Pipeline is PREROLLING ...
WARNING: from element /GstPipeline:pipeline0/GstAlsaSink:alsasink0: Could not get/set settings from/on resource.
Additional debug info:
gstalsasink.c(404): set_hwparams (): /GstPipeline:pipeline0/GstAlsaSink:alsasink0:
Unable to set buffer time 200000 for playback: Invalid argument
Pipeline is PREROLLED ...
Setting pipeline to PLAYING ...
New clock: GstAudioSinkClock
Running sine at 659.26 kHz
Setting pipeline to PAUSED ...
Pipeline is PREROLLING ...
WARNING: from element /GstPipeline:pipeline0/GstAlsaSink:alsasink0: Could not get/set settings from/on resource.
Additional debug info:
gstalsasink.c(404): set_hwparams (): /GstPipeline:pipeline0/GstAlsaSink:alsasink0:
Unable to set buffer time 200000 for playback: Invalid argument
Pipeline is PREROLLED ...
Setting pipeline to PLAYING ...
New clock: GstAudioSinkClock
Running sine at 783.99 kHz
Setting pipeline to PAUSED ...
Pipeline is PREROLLING ...
WARNING: from element /GstPipeline:pipeline0/GstAlsaSink:alsasink0: Could not get/set settings from/on resource.
Additional debug info:
gstalsasink.c(404): set_hwparams (): /GstPipeline:pipeline0/GstAlsaSink:alsasink0:
Unable to set buffer time 200000 for playback: Invalid argument
Pipeline is PREROLLED ...
Setting pipeline to PLAYING ...
New clock: GstAudioSinkClock
Running sine at 987.77 kHz
Setting pipeline to PAUSED ...
Pipeline is PREROLLING ...
WARNING: from element /GstPipeline:pipeline0/GstAlsaSink:alsasink0: Could not get/set settings from/on resource.
Additional debug info:
gstalsasink.c(404): set_hwparams (): /GstPipeline:pipeline0/GstAlsaSink:alsasink0:
Unable to set buffer time 200000 for playback: Invalid argument
Pipeline is PREROLLED ...
Setting pipeline to PLAYING ...
New clock: GstAudioSinkClock
Running sine at 1318.5 kHz
Setting pipeline to PAUSED ...
Pipeline is PREROLLING ...
WARNING: from element /GstPipeline:pipeline0/GstAlsaSink:alsasink0: Could not get/set settings from/on resource.
Additional debug info:
gstalsasink.c(404): set_hwparams (): /GstPipeline:pipeline0/GstAlsaSink:alsasink0:
Unable to set buffer time 200000 for playback: Invalid argument
Pipeline is PREROLLED ...
Setting pipeline to PLAYING ...
New clock: GstAudioSinkClock
killing generator 1
killing generator 2
killing generator 3
killing generator 4
killing generator 5
killing generator 6

Comment 15 Raymond 2010-03-30 05:43:01 UTC
(In reply to comment #0)

> 
> Steps to Reproduce:
> 0. Prepare a wav file with a test sound (a 23.2s long sine wave):
> gst-launch-0.10 audiotestsrc freq=440 num-buffers=1000 !
> 'audio/x-raw-int,rate=44100,channels=1,width=16,depth=16' ! wavenc ! filesink
> location=/tmp/sine.wav
> 1. Set tsched=0 in /etc/pulse/default.pa:
> load-module module-udev-detect tsched=0
> 2. Restart PA: pulseaudio -k; sleep 1; pulseaudio -vvvvv
> 3. Play the sine wave: paplay /tmp/sine.wav
> 
> Actual results:
> You'll hear an ugly sound, like a helicopter.
> 
> Expected results:
> I'd like to hear a plain concert A tone without distortion.
> 

I can hear the tone without distortion using paplay or aplay ( i.e. Traditional mode or Early Requests mode ) with pulseaudio-0.9.13 on Fedora 10

Comment 16 Raymond 2010-03-30 11:54:56 UTC
(In reply to comment #11)
> Hmm, so is this accompanied by any specific output when run with -vvvv?
> 
> When exactly does this happen? when a new stream is about to start? might this
> be related to rewinding?
> 
> Could somebody try to reproduce this with a PA run in valgrind? "VALGRIND=1
> valgrind pulseaudio -vvvvv". Does this show anything?    

https://bugs.launchpad.net/ubuntu/+source/linux/+bug/475355

http://launchpadlibrarian.net/35218869/pulseverbose.log

The message common in both logs ( Michal Schmidt 's log and daniq 's log ) is

D: source.c: Processing rewind...
D: protocol-native.c: Underrun on ''Surrogates (2009)' by 'ELEKTRI4KA [uniongang.ru]'', 0 bytes in queue.
D: protocol-native.c: Requesting rewind due to rewrite.

Comment 17 Raymond 2010-07-23 02:13:42 UTC
(In reply to comment #6)

> Only case it did not fail was au8830 driver for vortex2, which does not support
> all features. But it had problems with tsched=0 anyway, propably due to bug in
> alsa itself (card has hw mixing, which could not play well simultaneously
> however).    

The patch should fix the snd_pcm_period_elapsed when multiple streams are playing 

http://git.alsa-project.org/?p=alsa-kernel.git;a=commitdiff;h=e9ab33d03eb721a632214c0bbaa18652de88aa2d;hp=3fd43858c7937801134bd70ef1d411e44f9c0c1c

what's your au8830 problem with tsched=0 ?

so far , my au8830 run quite well on Fedora 10

Comment 18 Colin Guthrie 2010-08-17 18:15:52 UTC
This problem is fixed (according to my tests) by the patch posted today by David Henningsson of Canonical to the PA mailing list:
http://thread.gmane.org/gmane.comp.audio.pulseaudio.general/7286

Lennart, is this OK as it stands to be committed to master+s-q or do you want to tweak the values etc?

Comment 19 Raymond 2010-08-18 02:57:03 UTC
(In reply to comment #18)
> This problem is fixed (according to my tests) by the patch posted today by
> David Henningsson of Canonical to the PA mailing list:
> http://thread.gmane.org/gmane.comp.audio.pulseaudio.general/7286
> 
> Lennart, is this OK as it stands to be committed to master+s-q or do you want
> to tweak the values etc?

If the main objective of timer scheduling is power saving , the non timer scheduling (traditional mode ) should fill up the sound card whenever the sound card process a period (i.e. not as same as timer scheduling and write at the last 20ms ) to prevent underrun

BTW , David 's patch seem not against the latest git version and override 

http://git.0pointer.de/?p=pulseaudio.git;a=commitdiff;h=4df443bbe682055a41e7c2248877dcc7682a69b8;hp=f081c152f3d5f6a70edc6b7369445229b4f6a1b8

Comment 20 Michal Schmidt 2010-09-16 20:14:03 UTC
I made a scratch build for F-13 from the current stable-queue:
https://koji.fedoraproject.org/koji/taskinfo?taskID=2471790

It seems the rewind safeguard helped indeed.
With it I have to try much harder to confuse pulseaudio - when I change the volume like mad with gnome-volume-control-applet while all the 6 tones of chordtest are playing, I can make pulseaudio consume a lot of CPU time and get it killed.
Definitely an improvement over 0.9.21 which had problems with only 3 tones and no volume changes.

Comment 21 Bug Zapper 2010-11-04 06:26:37 UTC
This message is a reminder that Fedora 12 is nearing its end of life.
Approximately 30 (thirty) days from now Fedora will stop maintaining
and issuing updates for Fedora 12.  It is Fedora's policy to close all
bug reports from releases that are no longer maintained.  At that time
this bug will be closed as WONTFIX if it remains open with a Fedora 
'version' of '12'.

Package Maintainer: If you wish for this bug to remain open because you
plan to fix it in a currently maintained version, simply change the 'version' 
to a later Fedora version prior to Fedora 12's end of life.

Bug Reporter: Thank you for reporting this issue and we are sorry that 
we may not be able to fix it before Fedora 12 is end of life.  If you 
would still like to see this bug fixed and are able to reproduce it 
against a later version of Fedora please change the 'version' of this 
bug to the applicable version.  If you are unable to change the version, 
please add a comment here and someone will do it for you.

Although we aim to fix as many bugs as possible during every release's 
lifetime, sometimes those efforts are overtaken by events.  Often a 
more recent Fedora release includes newer upstream software that fixes 
bugs or makes them obsolete.

The process we are following is described here: 
http://fedoraproject.org/wiki/BugZappers/HouseKeeping

Comment 22 Oliver Henshaw 2010-12-02 10:36:46 UTC
The rewind safeguard is only in 0.9.22 afaik, and that is only built for F15 currently. So this bug should still be valid in F14.

Comment 23 Colin Guthrie 2010-12-02 10:58:40 UTC
I would generally recommend pushing 0.9.22 to F14 as it's really just a bugfix update, but I don't know if this will be allowed to get through the update policy. The only patch that may introduce a problem in an older distro is the one that updates the rygel module to use the newer version of it's dbus spec. I'm not sure what version of Rygel is in F14 and thus that particular patch may want to be reverted.

Comment 24 Michal Schmidt 2010-12-03 14:37:39 UTC
Colin,

F-14 has rygel-0.8.3-1.fc14.

I assume the patch you are talking about is this one:

  commit 803659883decc539dabedd6359238a43fd12a039
  Author: Stephen Moehle <stephen.moehle>
  Date:   Sun Nov 14 12:31:15 2010 -0800

    upnp: Implement the MediaServer2 D-Bus interface
    
    This allows PulseAudio to work with versions of Rygel 0.7.1 and higher
    which only support MediaServer2:
     http://live.gnome.org/Rygel/MediaServer2Spec

I don't really know what Rygel is, but since 0.8.3 > 0.7.1, this looks like another argument for pushing a pulseaudio-0.9.22 update to F-14.

Comment 25 Colin Guthrie 2010-12-03 14:51:29 UTC
(In reply to comment #24)
> I don't really know what Rygel is, but since 0.8.3 > 0.7.1, this looks like
> another argument for pushing a pulseaudio-0.9.22 update to F-14.

Yeah, sounds like another reason to push the newer version (after suitable testing).

FWIW, Rygel is a UPnP framework and PA integration lets you output the sound from your computer via a compatible device (e.g. PS3 etc. - although I never got it to work on my PS3 but meh!)

Comment 26 Rex Dieter 2010-12-03 18:58:21 UTC
Rebasing bug to F14, based on the last few comments.

Seems 0.9.22 is a good update candidate for both f13, f14

Comment 27 Rex Dieter 2010-12-03 21:28:58 UTC
0.9.22 scratch builds for testing:
F-14: http://koji.fedoraproject.org/koji/taskinfo?taskID=2642505
F-13: http://koji.fedoraproject.org/koji/taskinfo?taskID=2642502

and a yum repo for your testing pleasure,
http://repos.fedorapeople.org/repos/rdieter/pulseaudio-backport/

Comment 28 Fedora End Of Life 2012-08-16 18:56:26 UTC
This message is a notice that Fedora 14 is now at end of life. Fedora 
has stopped maintaining and issuing updates for Fedora 14. It is 
Fedora's policy to close all bug reports from releases that are no 
longer maintained.  At this time, all open bugs with a Fedora 'version'
of '14' have been closed as WONTFIX.

(Please note: Our normal process is to give advanced warning of this 
occurring, but we forgot to do that. A thousand apologies.)

Package Maintainer: If you wish for this bug to remain open because you
plan to fix it in a currently maintained version, feel free to reopen 
this bug and simply change the 'version' to a later Fedora version.

Bug Reporter: Thank you for reporting this issue and we are sorry that 
we were unable to fix it before Fedora 14 reached end of life. If you 
would still like to see this bug fixed and are able to reproduce it 
against a later version of Fedora, you are encouraged to click on 
"Clone This Bug" (top right of this page) and open it against that 
version of Fedora.

Although we aim to fix as many bugs as possible during every release's 
lifetime, sometimes those efforts are overtaken by events.  Often a 
more recent Fedora release includes newer upstream software that fixes 
bugs or makes them obsolete.

The process we are following is described here: 
http://fedoraproject.org/wiki/BugZappers/HouseKeeping


Note You need to log in before you can comment on or make changes to this bug.