404e0aa
diff -up allegro-4.2.2/src/unix/alsa9.c.pulse allegro-4.2.2/src/unix/alsa9.c
404e0aa
--- allegro-4.2.2/src/unix/alsa9.c.pulse	2006-03-18 16:05:34.000000000 +0100
404e0aa
+++ allegro-4.2.2/src/unix/alsa9.c	2008-01-21 20:01:18.000000000 +0100
404e0aa
@@ -81,7 +81,7 @@ static double alsa_mixer_allegro_ratio =
404e0aa
 
404e0aa
 static snd_pcm_t *pcm_handle;
404e0aa
 static unsigned char *alsa_bufdata;
404e0aa
-static int alsa_bits, alsa_signed, alsa_stereo;
404e0aa
+static int alsa_bits, alsa_signed, alsa_stereo, alsa_format;
404e0aa
 static unsigned int alsa_rate;
404e0aa
 static unsigned int alsa_fragments;
404e0aa
 static int alsa_sample_size;
404e0aa
@@ -292,7 +292,6 @@ static int alsa_init(int input, int voic
404e0aa
 {
404e0aa
    int ret = 0;
404e0aa
    char tmp1[128], tmp2[128];
404e0aa
-   int format = 0;
404e0aa
    unsigned int numfrags = 0;
404e0aa
    snd_pcm_uframes_t fragsize;
404e0aa
 
404e0aa
@@ -354,29 +353,14 @@ static int alsa_init(int input, int voic
404e0aa
    alsa_stereo = (_sound_stereo) ? 1 : 0;
404e0aa
    alsa_rate = (_sound_freq > 0) ? _sound_freq : 44100;
404e0aa
    alsa_signed = 0;
404e0aa
+   alsa_format = (alsa_bits == 16) ? SND_PCM_FORMAT_U16_NE : SND_PCM_FORMAT_U8;
404e0aa
+   alsa_sample_size = (alsa_bits / 8) * (alsa_stereo ? 2 : 1);
404e0aa
 
404e0aa
-   format = ((alsa_bits == 16) ? SND_PCM_FORMAT_U16_NE : SND_PCM_FORMAT_U8);
404e0aa
-
404e0aa
-   switch (format) {
404e0aa
-
404e0aa
-      case SND_PCM_FORMAT_U8:
404e0aa
-	 alsa_bits = 8;
404e0aa
-	 break;
404e0aa
-
404e0aa
-      case SND_PCM_FORMAT_U16_NE:
404e0aa
-	 if (sizeof(short) != 2) {
404e0aa
-	    ustrzcpy(allegro_error, ALLEGRO_ERROR_SIZE, get_config_text("Unsupported sample format"));
404e0aa
-	    goto Error;
404e0aa
-	 }
404e0aa
-	 break;
404e0aa
-
404e0aa
-      default:
404e0aa
-	 ustrzcpy(allegro_error, ALLEGRO_ERROR_SIZE, get_config_text("Unsupported sample format"));
404e0aa
-	 goto Error;
404e0aa
+   if (alsa_format == SND_PCM_FORMAT_U16_NE && sizeof(short) != 2) {
404e0aa
+      ustrzcpy(allegro_error, ALLEGRO_ERROR_SIZE, get_config_text("Unsupported sample format"));
404e0aa
+      goto Error;
404e0aa
    }
404e0aa
 
404e0aa
-   alsa_sample_size = (alsa_bits / 8) * (alsa_stereo ? 2 : 1);
404e0aa
-
404e0aa
    if (fragsize == 0) {
404e0aa
       unsigned int size = alsa_rate * ALSA_DEFAULT_BUFFER_MS / 1000 / numfrags;
404e0aa
       fragsize = 1;
404e0aa
@@ -389,7 +373,12 @@ static int alsa_init(int input, int voic
404e0aa
 
404e0aa
    ALSA9_CHECK(snd_pcm_hw_params_any(pcm_handle, hwparams));
404e0aa
    ALSA9_CHECK(snd_pcm_hw_params_set_access(pcm_handle, hwparams, SND_PCM_ACCESS_RW_INTERLEAVED));
404e0aa
-   ALSA9_CHECK(snd_pcm_hw_params_set_format(pcm_handle, hwparams, format));
404e0aa
+   if (snd_pcm_hw_params_set_format(pcm_handle, hwparams, alsa_format) < 0) {
404e0aa
+      /* Try again with signed samples (needed atleast for pulseaudio) */
404e0aa
+      alsa_format = (alsa_bits == 16) ? SND_PCM_FORMAT_S16_NE : SND_PCM_FORMAT_S8;
404e0aa
+      alsa_signed = 1;
404e0aa
+      ALSA9_CHECK(snd_pcm_hw_params_set_format(pcm_handle, hwparams, alsa_format));
404e0aa
+   }
404e0aa
    ALSA9_CHECK(snd_pcm_hw_params_set_channels(pcm_handle, hwparams, alsa_stereo + 1));
404e0aa
 
404e0aa
    ALSA9_CHECK(snd_pcm_hw_params_set_rate_near(pcm_handle, hwparams, &alsa_rate, NULL));