We are currently migrating Bugzilla to GitHub issues.
Any changes made to the bug tracker now will be lost, so please do not post new bugs or make changes to them.
When we're done, all bug URLs will redirect to their equivalent location on the new bug tracker.

Bug 698

Summary: PATCH: rewritten pulseaudio support
Product: SDL Reporter: Hans de Goede <jwrdegoede>
Component: audioAssignee: Ryan C. Gordon <icculus>
Status: RESOLVED FIXED QA Contact: Sam Lantinga <slouken>
Severity: normal    
Priority: P2 CC: patmandin, renesd, sezeroz
Version: 1.2.13Keywords: target-1.2.14
Hardware: x86   
OS: Linux   
Attachments: New SDL_pulseaudio.c replacement file
New SDL_pulseaudio.h replacement file
compatibility patch for pulseaudio <= 0.9.10

Description Hans de Goede 2009-02-13 01:10:52 UTC
Created attachment 295 [details]
New SDL_pulseaudio.c replacement file

Since the new "glitch free" version of pulseaudio (used in Fedora 10 amongst others), the sound of SDL using apps (like a simple playmus call) has been crackling.

While looking in to fixing this I noticed that the current pulseaudio code in SDL uses pa_simple. However pa_simple uses a thread to pump pulseaudio events and ipc, given that SDL already has its own thread for audio handling this is clearly suboptimal, leading to unnecessary context switching IPC, etc. Also pa_simple does not allow one to implement the WaitAudio() callback for SDL audiodrivers properly.

Given that my work is mostly a rewrite (although some original pieces remain) I'm attaching the new .c and .h file, as that is easier to review then the huge diff.

Let me know if you also want the diff.

This new version has the following features:
-no longer use an additional thread next to the SDL sound thread
-do not crackle with glitch free audio
-when used with a newer pulse, which does glitch free audio, the total latency is
 the same as with the alsa driver
-proper WaitAudio() implementation, saving another mixlen worth of latency
-adds a WaitDone() implementation

This patch has been written in consultancy with Lennart Poetering (the pulseaudio author) and has been reviewed by him for correct use of the pa API.
Comment 1 Hans de Goede 2009-02-13 01:11:45 UTC
Created attachment 296 [details]
New SDL_pulseaudio.h replacement file
Comment 2 Ozkan Sezer 2009-03-06 10:09:48 UTC
Created attachment 304 [details]
compatibility patch for pulseaudio <= 0.9.10

The attached patch (against the new SDL_pulseaudio.h posted here) is required for compatibility with old pulseaudio versions (<= 0.9.10), such as the one in Fedora 9.
Comment 3 Hans de Goede 2009-03-08 00:30:29 UTC
Compatibility patch looks good to me, thanks.
Comment 4 Ryan C. Gordon 2009-09-13 16:33:28 UTC
Tagging this bug with "target-1.2.14" so we can try to resolve it for SDL 1.2.14.

Please note that we may choose to resolve it as WONTFIX. This tag is largely so we have a comprehensive wishlist of bugs to examine for 1.2.14 (and so we can close bugs that we'll never fix, rather than have them live forever in Bugzilla).

--ryan.
Comment 5 Rene Dudfield 2009-09-17 05:09:15 UTC
I can confirm the crackling.  Haven't tested this patch though.
Comment 6 Patrice Mandin 2009-09-18 08:54:14 UTC
I just tried loopwave with sample.wav, confirms also cracking using current svn. Will try the patch as soon as possible.
Comment 7 Patrice Mandin 2009-09-18 12:14:38 UTC
(In reply to comment #6)
> I just tried loopwave with sample.wav, confirms also cracking using current
> svn. Will try the patch as soon as possible.

I just tried your patch, and at least I did not get any regression. It also seems audio is clearer with it, but I may have a bad ear. I don't know pulse audio enough to know if your patch improves something or not, but I think it's OK, given the improvements you did (if it does not break audio for someone else).
Comment 8 Sam Lantinga 2009-09-21 02:28:05 UTC
This is fixed in subversion, thanks!

Do you give me permission to release your code with SDL 1.3 and future
versions of SDL under both the LGPL and a closed-source commercial
license?
Comment 9 Hans de Goede 2009-09-21 03:32:45 UTC
(In reply to comment #8)
> This is fixed in subversion, thanks!
> 

Great.

> Do you give me permission to release your code with SDL 1.3 and future
> versions of SDL under both the LGPL and a closed-source commercial
> license?

Yes.