Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 267715 - media-libs/libsdl has poor performance using pulseaudio framework
Summary: media-libs/libsdl has poor performance using pulseaudio framework
Status: RESOLVED WONTFIX
Alias: None
Product: Gentoo Linux
Classification: Unclassified
Component: [OLD] Library (show other bugs)
Hardware: All Linux
: Normal minor
Assignee: Gentoo Games
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2009-04-28 01:52 UTC by Minko Minkov
Modified: 2009-11-23 22:08 UTC (History)
1 user (show)

See Also:
Package list:
Runtime testing required: ---


Attachments
fix to bad audio using pulseaudio plugin in libsdl (libsdl-1.2.13-pulse.patch,3.82 KB, patch)
2009-04-28 01:55 UTC, Minko Minkov
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Minko Minkov 2009-04-28 01:52:32 UTC
I switched to pulseaudio and realized that applications such as frozen-bubble have awful sound using the pulseaudio plugin. I found in another forum that there is a patch for version 1.2.13 that fixes the problem:

https://bugs.launchpad.net/ubuntu/+source/libsdl1.2/+bug/216397

I copied a slightly modified version of the patch to /usr/portage/media-libs/libsdl/files and edited the ebuild to apply the patch. The sound quality improved significantly.

http://0pointer.de/public/sdl-pulse-rework.patch

This is the link to the patch. I'll also paste my modified version.

--- SDL-1.2.13/src/audio/pulse/SDL_pulseaudio.c
+++ SDL-1.2.13/src/audio/pulse/SDL_pulseaudio.c
@@ -1,3 +1,4 @@
+/* -*- Mode: C; c-basic-offset: 8; indent-tabs-mode: t -*- */
 /*
     SDL - Simple DirectMedia Layer
     Copyright (C) 1997-2007 Sam Lantinga
@@ -18,7 +19,7 @@
 
     Stéphan Kochen
     stephan@kochen.nl
-    
+
     Based on parts of the ALSA and ESounD output drivers.
 */
 #include "SDL_config.h"
@@ -78,14 +79,14 @@ static int (*SDL_NAME(pa_simple_write))(
 	pa_simple *s,
 	const void *data,
 	size_t length,
-	int *error 
+	int *error
 );
 static pa_channel_map* (*SDL_NAME(pa_channel_map_init_auto))(
 	pa_channel_map *m,
 	unsigned channels,
 	pa_channel_map_def_t def
 );
-	
+
 
 static struct {
 	const char *name;
@@ -158,16 +159,16 @@ static int Audio_Available(void)
 	if ( LoadPulseLibrary() < 0 ) {
 		return available;
 	}
-	
+
 	/* Connect with a dummy format. */
 	paspec.format = PA_SAMPLE_U8;
 	paspec.rate = 11025;
 	paspec.channels = 1;
 	connection = SDL_NAME(pa_simple_new)(
-		SDL_getenv("PASERVER"),      /* server */
+		NULL,                        /* server */
 		"Test stream",               /* application name */
 		PA_STREAM_PLAYBACK,          /* playback mode */
-		SDL_getenv("PADEVICE"),      /* device on the server */
+		NULL,                        /* device on the server */
 		"Simple DirectMedia Layer",  /* stream description */
 		&paspec,                     /* sample format spec */
 		NULL,                        /* channel map */
@@ -178,7 +179,7 @@ static int Audio_Available(void)
 		available = 1;
 		SDL_NAME(pa_simple_free)(connection);
 	}
-	
+
 	UnloadPulseLibrary();
 	return(available);
 }
@@ -233,7 +234,7 @@ static void PULSE_WaitAudio(_THIS)
 {
 	/* Check to see if the thread-parent process is still alive */
 	{ static int cnt = 0;
-		/* Note that this only works with thread implementations 
+		/* Note that this only works with thread implementations
 		   that use a different process id for each thread.
 		*/
 		if (parent && (((++cnt)%10) == 0)) { /* Check every 10 loops */
@@ -302,7 +303,7 @@ static int PULSE_OpenAudio(_THIS, SDL_Au
 	pa_sample_spec  paspec;
 	pa_buffer_attr  paattr;
 	pa_channel_map  pacmap;
-	
+
 	paspec.format = PA_SAMPLE_INVALID;
 	for ( test_format = SDL_FirstAudioFormat(spec->format); test_format; ) {
 		switch ( test_format ) {
@@ -324,7 +325,7 @@ static int PULSE_OpenAudio(_THIS, SDL_Au
 		return(-1);
 	}
 	spec->format = test_format;
-	
+
 	paspec.channels = spec->channels;
 	paspec.rate = spec->freq;
 
@@ -338,25 +339,24 @@ static int PULSE_OpenAudio(_THIS, SDL_Au
 		return(-1);
 	}
 	SDL_memset(mixbuf, spec->silence, spec->size);
-	
+
 	/* Reduced prebuffering compared to the defaults. */
-	paattr.tlength = mixlen;
+	paattr.tlength = mixlen*2;
 	paattr.minreq = mixlen;
-	paattr.fragsize = mixlen;
-	paattr.prebuf = mixlen;
-	paattr.maxlength = mixlen * 4;
-	
+	paattr.prebuf = mixlen*2;
+	paattr.maxlength = mixlen*2;
+
 	/* The SDL ALSA output hints us that we use Windows' channel mapping */
 	/* http://bugzilla.libsdl.org/show_bug.cgi?id=110 */
 	SDL_NAME(pa_channel_map_init_auto)(
 		&pacmap, spec->channels, PA_CHANNEL_MAP_WAVEEX);
-	
+
 	/* Connect to the PulseAudio server */
 	stream = SDL_NAME(pa_simple_new)(
-		SDL_getenv("PASERVER"),      /* server */
+		NULL,                        /* server */
 		get_progname(),              /* application name */
 		PA_STREAM_PLAYBACK,          /* playback mode */
-		SDL_getenv("PADEVICE"),      /* device on the server */
+		NULL,                        /* device on the server */
 		"Simple DirectMedia Layer",  /* stream description */
 		&paspec,                     /* sample format spec */
 		&pacmap,                     /* channel map */
@@ -371,7 +371,6 @@ static int PULSE_OpenAudio(_THIS, SDL_Au
 
 	/* Get the parent process id (we're the parent of the audio thread) */
 	parent = getpid();
-	
+
 	return(0);
 }
-
Comment 1 Minko Minkov 2009-04-28 01:55:16 UTC
Created attachment 189662 [details, diff]
fix to bad audio using pulseaudio plugin in libsdl

Sorry for pasting the patch. I only now realized how to add attachments.
Comment 2 Rafał Mużyło 2009-04-28 13:40:25 UTC
Could you attach a cleaner patch, one without
all those ""whitespace-only" changes ?
Comment 3 Rafał Mużyło 2009-04-28 13:44:45 UTC
But, as the patch does come from pulseaudio author,
it looks like a good idea.
Comment 4 SpanKY gentoo-dev 2009-04-29 03:22:08 UTC
maybe Diego will have a different opinion, but Rafał's comments look spot on.  the whitespace noise needs to go before committing.
Comment 5 Diego Elio Pettenò (RETIRED) gentoo-dev 2009-04-29 05:12:51 UTC
If I don't remind Lennart to change the original patch to avoid whitespace noise tomorrow, please remind me to remind him, today I'm not at home.

Which is to say, you both are right.
Comment 6 Mr. Bones. (RETIRED) gentoo-dev 2009-07-01 17:19:08 UTC
No reply here.  Reopen with a re-rolled patch please.
Comment 7 Mr. Bones. (RETIRED) gentoo-dev 2009-11-23 22:07:48 UTC
bugzilla
Comment 8 Mr. Bones. (RETIRED) gentoo-dev 2009-11-23 22:08:02 UTC
no reply, closing.