]> git.sesse.net Git - vlc/commitdiff
* Fix audio/video synchro bug with esd
authorRenaud Dartus <reno@videolan.org>
Thu, 12 Jul 2001 20:31:33 +0000 (20:31 +0000)
committerRenaud Dartus <reno@videolan.org>
Thu, 12 Jul 2001 20:31:33 +0000 (20:31 +0000)
* Should fix buggy sound due to 44100-48000 Hz conversions

TODO
include/audio_output.h
plugins/esd/aout_esd.c
src/audio_output/aout_s16.c
src/audio_output/aout_u8.c

diff --git a/TODO b/TODO
index 7e360b8438382183d045a2f7e98a2e0c26a09a41..6b60706b384b7c1bc9dda9add862fb563c3aa386 100644 (file)
--- a/TODO
+++ b/TODO
@@ -103,7 +103,7 @@ Urgency: Critical
 Description: Fix AC3 decoder
  The AC3 decoder still has a few quality issues; fix them, and try to add
  MMX support to it as well.
-Status: Todo
+Status: Done 15 June 2001 (reno)
 
 Task: 0x52
 Difficulty: Guru
@@ -193,7 +193,7 @@ Urgency: Critical
 Description: Fix audio synchro
  With some audio plugins, the audio stream is late because of buffer
  sizes. See what's wrong and fix it.
-Status: Todo
+Status: Done 12 July 2001 (reno)
 
 Task: 0x47
 Difficulty: Hard
index a8f1d15ecae9dd05f99ca059e3e0bf8bb81dbea7..23f1e18679fba8392ccfb54348e74c16340123e4 100644 (file)
@@ -2,7 +2,7 @@
  * audio_output.h : audio output thread interface
  *****************************************************************************
  * Copyright (C) 1999, 2000 VideoLAN
- * $Id: audio_output.h,v 1.37 2001/05/30 17:03:11 sam Exp $
+ * $Id: audio_output.h,v 1.38 2001/07/12 20:31:33 reno Exp $
  *
  * Authors: Michel Kaempf <maxx@via.ecp.fr>
  *
@@ -171,6 +171,7 @@ typedef struct aout_thread_s
     /* Rate and gain of the audio output sound (in Hz) */
     long                l_rate;
     long                l_gain;
+    int                 i_latency;
 
     /* there might be some useful private structure, such as audio_buf_info
      * for the OSS output */
index 182fd18afa97f29b09a48b65a56369f500c067af..0a0ecc3ac002fc36b2a21d206e05a2b193482894 100644 (file)
@@ -2,7 +2,7 @@
  * aout_esd.c : Esound functions library
  *****************************************************************************
  * Copyright (C) 2000 VideoLAN
- * $Id: aout_esd.c,v 1.13 2001/05/30 17:03:12 sam Exp $
+ * $Id: aout_esd.c,v 1.14 2001/07/12 20:31:33 reno Exp $
  *
  * Authors: Samuel Hocevar <sam@zoy.org>
  *
@@ -134,7 +134,7 @@ static int aout_Open( aout_thread_t *p_aout )
     /* Initialize some variables */
     p_aout->i_format = AOUT_FORMAT_DEFAULT;
     p_aout->i_channels = 1 + main_GetIntVariable( AOUT_STEREO_VAR, AOUT_STEREO_DEFAULT );
-    p_aout->l_rate     = main_GetIntVariable( AOUT_RATE_VAR, AOUT_RATE_DEFAULT );
+    p_aout->l_rate = esd_audio_rate; /* We use actual esd rate value, not AOUT_RATE_DEFAULT */
 
     i_bits = ESD_BITS16;
     i_mode = ESD_STREAM;
@@ -162,10 +162,6 @@ static int aout_Open( aout_thread_t *p_aout )
         return( -1 );
     }
 
-    intf_ErrMsg( "aout error: you are using the Esound plugin. There is no way yet to get the\n"
-                 "            driver latency because esd_get_latency() hangs, so expect a one\n"
-                 "            second delay with sound. Type `esdctl off' to disable esd." );
-
     return( 0 );
 }
 
@@ -174,6 +170,13 @@ static int aout_Open( aout_thread_t *p_aout )
  *****************************************************************************/
 static int aout_SetFormat( aout_thread_t *p_aout )
 {
+    int i_fd;
+
+    i_fd = esd_open_sound(NULL);
+    p_aout->i_latency = esd_get_latency(i_fd);
+   
+    intf_WarnMsg(2, "aout_esd_latency: %d",p_aout->i_latency);
+
     return( 0 );
 }
 
@@ -194,7 +197,7 @@ static long aout_GetBufInfo( aout_thread_t *p_aout, long l_buffer_limit )
 static void aout_Play( aout_thread_t *p_aout, byte_t *buffer, int i_size )
 {
     int i_amount;
-
+    
     if (p_aout->p_sys->esd_format & ESD_STEREO)
     {
         if (p_aout->p_sys->esd_format & ESD_BITS16)
index ce093ebdf696673526324311b493405e5a105d46..ca82ab02e7645079b02dd07e429801e050b95be3 100644 (file)
@@ -87,37 +87,16 @@ void aout_S16StereoThread( aout_thread_t * p_aout )
         }
 
         l_bytes = p_aout->pf_getbufinfo( p_aout, l_buffer_limit );
-#if 0
-        fprintf(stderr,"l_bytes 1: %li\n",l_bytes);
-        fprintf(stderr,"  playing...\n");
-#endif
 
         /* sizeof(s16) << (p_aout->b_stereo) == 4 */
-        p_aout->date = mdate() + ((((mtime_t)(l_bytes / 4)) * 1000000)
+        p_aout->date = mdate() + ((((mtime_t)((l_bytes + 4 * p_aout->i_latency) / 4)) * 1000000)
                                    / ((mtime_t)p_aout->l_rate));
         p_aout->pf_play( p_aout, (byte_t *)p_aout->buffer,
                          l_buffer_limit * sizeof(s16) );
-#if 0
-        fprintf( stderr,"l_bytes #: %li\n",
-                 p_aout->pf_getbufinfo( p_aout, l_buffer_limit ) );
-#endif
 
         if ( l_bytes > (l_buffer_limit * sizeof(s16)) )
         {
             msleep( p_aout->l_msleep );
-#if 0
-            fprintf(stderr,"  sleeping...\n");
-            msleep( p_aout->l_msleep / 2);
-            l_bytes = p_aout->pf_getbufinfo( p_aout, l_buffer_limit );
-            fprintf(stderr,"l_bytes *: %li\n",l_bytes);
-            msleep( p_aout->l_msleep / 2);
-        }
-        else
-        {
-            fprintf(stderr,"  not sleeping.\n");
-            l_bytes = p_aout->pf_getbufinfo( p_aout, l_buffer_limit );
-            fprintf(stderr,"l_bytes 2: %li\n\n",l_bytes);
-#endif
         }
     }
 
index 209bb235bc49652d3504d32219996061d958d80e..3b47e3d950eb9a41642ccbcce890555bfd20089c 100644 (file)
@@ -2,7 +2,7 @@
  * aout_u8.c: 8 bit unsigned audio output functions
  *****************************************************************************
  * Copyright (C) 1999, 2000, 2001 VideoLAN
- * $Id: aout_u8.c,v 1.5 2001/05/15 16:19:42 sam Exp $
+ * $Id: aout_u8.c,v 1.6 2001/07/12 20:31:33 reno Exp $
  *
  * Authors: Michel Kaempf <maxx@via.ecp.fr>
  *
@@ -82,7 +82,10 @@ void aout_U8MonoThread( aout_thread_t * p_aout )
         }
 
         l_bytes = p_aout->pf_getbufinfo( p_aout, l_buffer_limit );
-        p_aout->date = mdate() + ((((mtime_t)(l_bytes / 1 )) * 1000000) / ((mtime_t)p_aout->l_rate)); /* sizeof(u8) << (p_aout->b_stereo) == 1 */
+        /* sizeof(u8) << (p_aout->b_stereo) == 1 */
+        p_aout->date = mdate() + ((((mtime_t)((l_bytes + 4 * p_aout->i_latency) / 1)) * 1000000)
+                                   / ((mtime_t)p_aout->l_rate));
         p_aout->pf_play( p_aout, (byte_t *)p_aout->buffer, l_buffer_limit * sizeof(u8) );
         if ( l_bytes > (l_buffer_limit * sizeof(u8) * 2) ) /* There are 2 channels (left & right) */
         {
@@ -133,7 +136,10 @@ void aout_U8StereoThread( aout_thread_t * p_aout )
             p_aout->s32_buffer[l_buffer] = 0;
         }
         l_bytes = p_aout->pf_getbufinfo( p_aout, l_buffer_limit );
-        p_aout->date = mdate() + ((((mtime_t)(l_bytes / 2 )) * 1000000) / ((mtime_t)p_aout->l_rate)); /* sizeof(u8) << (p_aout->b_stereo) == 2 */
+        /* sizeof(u8) << (p_aout->b_stereo) == 2 */
+        p_aout->date = mdate() + ((((mtime_t)((l_bytes + 4 * p_aout->i_latency) / 2)) * 1000000)
+                                   / ((mtime_t)p_aout->l_rate));
         p_aout->pf_play( p_aout, (byte_t *)p_aout->buffer, l_buffer_limit * sizeof(u8) );
         if ( l_bytes > (l_buffer_limit * sizeof(u8)) )
         {