[uae] Re: Bloody ALSA (was Re: Re: Source code snapshot)

  • From: Richard Drummond <evilrich@xxxxxxxxxxxxxx>
  • To: uae@xxxxxxxxxxxxx
  • Date: Sun, 26 Mar 2006 10:29:57 -0500

Hi Giulio

On Sunday 26 March 2006 03:28, Giulio Canevari wrote:
> Situation don't change here this way.

Try the attached patch.

Cheers,
Rich
Index: sd-alsa/sound.c
===================================================================
RCS file: /cvsroot/uaedev/uae/src/sd-alsa/sound.c,v
retrieving revision 1.2
diff -u -r1.2 sound.c
--- sd-alsa/sound.c     28 Feb 2006 08:15:37 -0000      1.2
+++ sd-alsa/sound.c     26 Mar 2006 15:22:02 -0000
@@ -5,6 +5,7 @@
   * 
   * Copyright 1997 Bernd Schmidt
   * Copyright 2004 Heikki Orsila
+  * Copyright 2006 Richard Drummond
   *
   * BUGS: certainly
   * TODO:
@@ -91,14 +92,14 @@
 
 int init_sound (void)
 {
-  int tmp;
-  int rate;
-  int dspbits;
-  int alsamode;
-  int channels;
+  unsigned int rate;
+  unsigned int dspbits;
+  snd_pcm_format_t alsamode;
+  unsigned int channels;
   int err;
   snd_pcm_hw_params_t *hw_params;
-  snd_pcm_uframes_t buffer_frames;
+  snd_pcm_uframes_t period_frames;
+  unsigned int periods;
 
   dspbits = currprefs.sound_bits;
   channels = currprefs.sound_stereo ? 2 : 1;
@@ -166,11 +167,18 @@
   }
       
   alsa_to_frames_divisor = channels * dspbits / 8;
-  buffer_frames = sndbufsize / alsa_to_frames_divisor;
-  if ((err = snd_pcm_hw_params_set_period_size_near(alsa_playback_handle, 
hw_params, &buffer_frames, 0)) < 0) {
+  period_frames = sndbufsize / alsa_to_frames_divisor;
+  if ((err = snd_pcm_hw_params_set_period_size_near (alsa_playback_handle, 
hw_params, &period_frames, 0)) < 0) {
     fprintf (stderr, "cannot set period size near (%s)\n", snd_strerror (err));
     goto nosound;
   }
+  sndbufsize = period_frames * alsa_to_frames_divisor;
+
+  periods = 2;
+  if ((err = snd_pcm_hw_params_set_periods_near (alsa_playback_handle, 
hw_params, &periods, 0)) < 0) {
+    fprintf (stderr, "cannot set periods near (%)\n", snd_strerror (err));
+    goto nosound;
+  }
 
   if ((err = snd_pcm_hw_params (alsa_playback_handle, hw_params)) < 0) {
     fprintf (stderr, "cannot set parameters (%s)\n",

Other related posts: