esound patch



Hi,

I hope this is the right place to send this...

Anyway, esd was broken on my machine, and I found out why.  I use ALSA,
and esd's alsa_sound.c sets it up in non-blocking mode.  However, it
doesn't check if all of the data was written when writing to the device,
so the first bit of sound gets played, then chop.   There are two
solutions:

1) just use normal non-blocking mode
2) use select(2)

Here's a patch that uses no. 1.  It also fixes various other bugs (like
two error code vars - causes incorrect error msgs)

There are other things I would like to discuss about esound - this the
right place to do it?

Andrew Clausen

-------------------

--- audio_alsa.c Tue Oct 20 18:18:42 1998
+++ audio_alsa.c Wed Oct 21 06:46:29 1998
@@ -20,13 +20,31 @@
 #endif

 #define ARCH_esd_audio_open
+static void
+alsa_print_error (int code, int card, int device) {
+    if( driver_trace ) {
+ perror( "snd_ctl_open" );
+
+ if( device >= 0 ) {
+     fprintf (stderr, "card %d pcm device %d open failed: %s\n",
+           card, device, snd_strerror( code ) );
+ }
+ else {
+     fprintf( stderr, "card %d open failed: %s\n",
+         card, snd_strerror( code ) );
+ }
+    }
+}
+
 int esd_audio_open()
 {
     snd_pcm_format_t format;
     snd_pcm_playback_params_t params;
     int ret, mode = SND_PCM_OPEN_PLAYBACK;
-    int mask=0, card=ALSACARD, device=ALSADEVICE, err=0;
+    int mask, card=ALSACARD, device=ALSADEVICE;
     char buf[256];
+    void *ctl_handle;
+    struct snd_ctl_hw_info hw_info;

     /* if recording, set for full duplex mode */
     if ( (esd_audio_format & ESD_MASK_FUNC) == ESD_RECORD )
@@ -52,30 +70,57 @@
     }

     handle = NULL;
-    for( card=0; (card < SND_CARDS) && (handle == NULL); card++ ) {
- if( mask & (1 << card) ) {
-     err = snd_pcm_open( &handle, card, device, mode );
-     if( ret < 0 ) {
-  if( driver_trace ) {
-      perror( "snd_pcm_open" );
-      fprintf( stderr, "card %d open failed: %s\n",
-        card, snd_strerror( err ) );
-  }
-  handle = NULL;
+    for ( card=0; ( card < SND_CARDS ) && (handle == NULL); card++ ) {
+ if ( mask & (1 << card) ) {
+     /* open sound card */
+     ret = snd_ctl_open( &ctl_handle, card );
+
+     if ( ret < 0 ) {
+  alsa_print_error( ret, card, -1 );
+  continue;
+     }
+
+     if ( driver_trace ) {
+  fprintf( stderr, "opened alsa card %d\n", card );
      }
-     else {
-  if( driver_trace ) {
-      fprintf( stderr, "opened alsa card %d\n", card );
+
+     /* get info on sound card */
+     ret = snd_ctl_hw_info( ctl_handle, &hw_info );
+     if ( ret < 0 ) {
+  alsa_print_error( ret, card, -1 );
+  continue;
+     }
+     ret = snd_ctl_close( ctl_handle );
+     if ( ret < 0 ) {
+  alsa_print_error( ret, card, -1 );
+  continue;
+     }
+



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]