Fixed bug #572 SDL-1.2
authorSam Lantinga
Mon, 21 Sep 2009 08:03:00 +0000
branchSDL-1.2
changeset 42113ce5bfddbaf6
parent 4210 8f501bbc3bf1
child 4212 0794718a428c
Fixed bug #572

Please merge this patch for the PA driver in SDL.

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

This patch:
- fixes buffering (i.e. reduces number of "fragments" to 2, doesn't defer
filling up of the buffer until the entire buffer ran completely empty.)
- drops $PASERVER and $PADEVICE env var support, since this is a duplication of
$PULSE_SERVER and $PULSE_SINK which the PA libs honor anyway.

This fixes the sound issues in all games I tested.
src/audio/pulse/SDL_pulseaudio.c
     1.1 --- a/src/audio/pulse/SDL_pulseaudio.c	Mon Sep 21 07:59:44 2009 +0000
     1.2 +++ b/src/audio/pulse/SDL_pulseaudio.c	Mon Sep 21 08:03:00 2009 +0000
     1.3 @@ -1,3 +1,4 @@
     1.4 +/* -*- Mode: C; c-basic-offset: 8; indent-tabs-mode: t -*- */
     1.5  /*
     1.6      SDL - Simple DirectMedia Layer
     1.7      Copyright (C) 1997-2009 Sam Lantinga
     1.8 @@ -18,7 +19,7 @@
     1.9  
    1.10      St├ęphan Kochen
    1.11      stephan@kochen.nl
    1.12 -    
    1.13 +
    1.14      Based on parts of the ALSA and ESounD output drivers.
    1.15  */
    1.16  #include "SDL_config.h"
    1.17 @@ -78,14 +79,14 @@
    1.18  	pa_simple *s,
    1.19  	const void *data,
    1.20  	size_t length,
    1.21 -	int *error 
    1.22 +	int *error
    1.23  );
    1.24  static pa_channel_map* (*SDL_NAME(pa_channel_map_init_auto))(
    1.25  	pa_channel_map *m,
    1.26  	unsigned channels,
    1.27  	pa_channel_map_def_t def
    1.28  );
    1.29 -	
    1.30 +
    1.31  
    1.32  static struct {
    1.33  	const char *name;
    1.34 @@ -158,16 +159,16 @@
    1.35  	if ( LoadPulseLibrary() < 0 ) {
    1.36  		return available;
    1.37  	}
    1.38 -	
    1.39 +
    1.40  	/* Connect with a dummy format. */
    1.41  	paspec.format = PA_SAMPLE_U8;
    1.42  	paspec.rate = 11025;
    1.43  	paspec.channels = 1;
    1.44  	connection = SDL_NAME(pa_simple_new)(
    1.45 -		SDL_getenv("PASERVER"),      /* server */
    1.46 +		NULL,                        /* server */
    1.47  		"Test stream",               /* application name */
    1.48  		PA_STREAM_PLAYBACK,          /* playback mode */
    1.49 -		SDL_getenv("PADEVICE"),      /* device on the server */
    1.50 +		NULL,                        /* device on the server */
    1.51  		"Simple DirectMedia Layer",  /* stream description */
    1.52  		&paspec,                     /* sample format spec */
    1.53  		NULL,                        /* channel map */
    1.54 @@ -178,7 +179,7 @@
    1.55  		available = 1;
    1.56  		SDL_NAME(pa_simple_free)(connection);
    1.57  	}
    1.58 -	
    1.59 +
    1.60  	UnloadPulseLibrary();
    1.61  	return(available);
    1.62  }
    1.63 @@ -233,7 +234,7 @@
    1.64  {
    1.65  	/* Check to see if the thread-parent process is still alive */
    1.66  	{ static int cnt = 0;
    1.67 -		/* Note that this only works with thread implementations 
    1.68 +		/* Note that this only works with thread implementations
    1.69  		   that use a different process id for each thread.
    1.70  		*/
    1.71  		if (parent && (((++cnt)%10) == 0)) { /* Check every 10 loops */
    1.72 @@ -302,7 +303,7 @@
    1.73  	pa_sample_spec  paspec;
    1.74  	pa_buffer_attr  paattr;
    1.75  	pa_channel_map  pacmap;
    1.76 -	
    1.77 +
    1.78  	paspec.format = PA_SAMPLE_INVALID;
    1.79  	for ( test_format = SDL_FirstAudioFormat(spec->format); test_format; ) {
    1.80  		switch ( test_format ) {
    1.81 @@ -324,7 +325,7 @@
    1.82  		return(-1);
    1.83  	}
    1.84  	spec->format = test_format;
    1.85 -	
    1.86 +
    1.87  	paspec.channels = spec->channels;
    1.88  	paspec.rate = spec->freq;
    1.89  
    1.90 @@ -338,25 +339,24 @@
    1.91  		return(-1);
    1.92  	}
    1.93  	SDL_memset(mixbuf, spec->silence, spec->size);
    1.94 -	
    1.95 +
    1.96  	/* Reduced prebuffering compared to the defaults. */
    1.97 -	paattr.tlength = mixlen;
    1.98 +	paattr.tlength = mixlen*2;
    1.99  	paattr.minreq = mixlen;
   1.100 -	paattr.fragsize = mixlen;
   1.101 -	paattr.prebuf = mixlen;
   1.102 -	paattr.maxlength = mixlen * 4;
   1.103 -	
   1.104 +	paattr.prebuf = mixlen*2;
   1.105 +	paattr.maxlength = mixlen*2;
   1.106 +
   1.107  	/* The SDL ALSA output hints us that we use Windows' channel mapping */
   1.108  	/* http://bugzilla.libsdl.org/show_bug.cgi?id=110 */
   1.109  	SDL_NAME(pa_channel_map_init_auto)(
   1.110  		&pacmap, spec->channels, PA_CHANNEL_MAP_WAVEEX);
   1.111 -	
   1.112 +
   1.113  	/* Connect to the PulseAudio server */
   1.114  	stream = SDL_NAME(pa_simple_new)(
   1.115 -		SDL_getenv("PASERVER"),      /* server */
   1.116 +		NULL,                        /* server */
   1.117  		get_progname(),              /* application name */
   1.118  		PA_STREAM_PLAYBACK,          /* playback mode */
   1.119 -		SDL_getenv("PADEVICE"),      /* device on the server */
   1.120 +		NULL,                        /* device on the server */
   1.121  		"Simple DirectMedia Layer",  /* stream description */
   1.122  		&paspec,                     /* sample format spec */
   1.123  		&pacmap,                     /* channel map */
   1.124 @@ -371,7 +371,6 @@
   1.125  
   1.126  	/* Get the parent process id (we're the parent of the audio thread) */
   1.127  	parent = getpid();
   1.128 -	
   1.129 +
   1.130  	return(0);
   1.131  }
   1.132 -