]> git.sesse.net Git - vlc/commitdiff
* Fixed a quite old bug in the audio output which made the sound stutter
authorSam Hocevar <sam@videolan.org>
Sun, 24 Feb 2002 22:06:50 +0000 (22:06 +0000)
committerSam Hocevar <sam@videolan.org>
Sun, 24 Feb 2002 22:06:50 +0000 (22:06 +0000)
    when wrapping around the audio output fifo.
  * Lots of simplifications in the audio output, got rid of b_stereo.

33 files changed:
Makefile
include/audio_output.h
include/common.h
include/defs.h.in
include/modules.h
plugins/a52/a52.c
plugins/ac3_adec/ac3_adec.c
plugins/ac3_spdif/ac3_spdif.c
plugins/alsa/aout_alsa.c
plugins/arts/aout_arts.c
plugins/beos/aout_beos.cpp
plugins/directx/aout_directx.c
plugins/dsp/aout_dsp.c
plugins/dummy/aout_dummy.c
plugins/esd/aout_esd.c
plugins/lpcm_adec/lpcm_adec.c
plugins/macosx/aout_macosx.c
plugins/mad/mad_libmad.c
plugins/mpeg_adec/adec_layer1.c
plugins/mpeg_adec/adec_layer2.c
plugins/mpeg_adec/adec_math.c
plugins/mpeg_adec/adec_math.h
plugins/mpeg_adec/mpeg_adec.c
plugins/qnx/aout_qnx.c
plugins/sdl/aout_sdl.c
plugins/win32/waveout.c
src/audio_output/aout_common.c [deleted file]
src/audio_output/aout_common.h [deleted file]
src/audio_output/aout_ext-dec.c
src/audio_output/aout_pcm.c [new file with mode: 0644]
src/audio_output/aout_pcm.h [new file with mode: 0644]
src/audio_output/aout_spdif.c
src/audio_output/audio_output.c

index 553928685a16b2ae4a6b6f1af683541af59f8400..561c0bcd325e1e44b5d3c787914b83171618f1a4 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -136,7 +136,7 @@ PLUGINS_TARGETS := ac3_adec/ac3_adec \
 INTERFACE := main interface intf_msg intf_playlist intf_eject
 INPUT := input input_ext-dec input_ext-intf input_dec input_programs input_clock mpeg_system
 VIDEO_OUTPUT := video_output video_text vout_pictures vout_subpictures
-AUDIO_OUTPUT := audio_output aout_common aout_ext-dec aout_spdif
+AUDIO_OUTPUT := audio_output aout_ext-dec aout_pcm aout_spdif
 MISC := mtime modules configuration netutils iso_lang
 
 C_OBJ :=       $(INTERFACE:%=src/interface/%.o) \
index d61c51ea32f6b5afd80dcb09b2789445ce22d92a..63134cf88c49a65adbb1abfde359cde344623a6c 100644 (file)
@@ -2,7 +2,7 @@
  * audio_output.h : audio output thread interface
  *****************************************************************************
  * Copyright (C) 1999, 2000 VideoLAN
- * $Id: audio_output.h,v 1.42 2002/02/24 20:51:09 gbazin Exp $
+ * $Id: audio_output.h,v 1.43 2002/02/24 22:06:50 sam Exp $
  *
  * Authors: Michel Kaempf <maxx@via.ecp.fr>
  *          Cyril Deguet <asmax@via.ecp.fr>
@@ -54,20 +54,18 @@ typedef struct aout_increment_s
 {
     /* The remainder is used to keep track of the fractional part of the
      * index. */
-    long                l_remainder;
+    int i_r;
 
     /*
      * The increment structure is initialized with the result of an euclidean
      * division :
      *
-     *  l_euclidean_numerator                           l_euclidean_remainder
-     * ----------------------- = l_euclidean_integer + -----------------------
-     * l_euclidean_denominator                         l_euclidean_denominator
+     *  i_x           i_b
+     * ----- = i_a + -----
+     *  i_y           i_c
      *
      */
-    long                l_euclidean_integer;
-    long                l_euclidean_remainder;
-    long                l_euclidean_denominator;
+    int i_a, i_b, i_c;
 
 } aout_increment_t;
 
@@ -76,53 +74,61 @@ typedef struct aout_increment_s
  *****************************************************************************/
 typedef struct aout_fifo_s
 {
-    /* See the fifo types below */
-    int                 i_type;
+    /* See the fifo formats below */
+    int                 i_format;
+    int                 i_channels;
+    int                 i_rate;
+    int                 i_frame_size;
+
     boolean_t           b_die;
     int                 i_fifo;      /* Just to keep track of the fifo index */
 
-    int                 i_channels;
-    boolean_t           b_stereo;
-    long                l_rate;
-
     vlc_mutex_t         data_lock;
     vlc_cond_t          data_wait;
 
-    long                l_frame_size;
     void *              buffer;
     mtime_t *           date;
+
     /* The start frame is the first frame in the buffer that contains decoded
      * audio data. It it also the first frame in the current timestamped frame
      * area, ie the first dated frame in the decoded part of the buffer. :-p */
-    long                l_start_frame;
+    int                 i_start_frame;
     boolean_t           b_start_frame;
     /* The next frame is the end frame of the current timestamped frame area,
      * ie the first dated frame after the start frame. */
-    long                l_next_frame;
+    int                 i_next_frame;
     boolean_t           b_next_frame;
     /* The end frame is the first frame, after the start frame, that doesn't
      * contain decoded audio data. That's why the end frame is the first frame
      * where the audio decoder can store its decoded audio frames. */
-    long                l_end_frame;
+    int                 i_end_frame;
 
-    long                l_unit;
+    /* Current index in p_aout->buffer */
+    int                 i_unit;
+    /* Max index in p_aout->buffer */
+    int                 i_unit_limit;
+    /* Structure used to calculate i_unit with a Bresenham algorithm */
     aout_increment_t    unit_increment;
+
     /* The following variable is used to store the number of remaining audio
      * units in the current timestamped frame area. */
-    long                l_units;
+    int                 i_units;
 
 } aout_fifo_t;
 
 #define AOUT_FIFO_ISEMPTY( fifo ) \
-  ( (fifo).l_end_frame == (fifo).l_start_frame )
+  ( (fifo).i_end_frame == (fifo).i_start_frame )
 
 #define AOUT_FIFO_ISFULL( fifo ) \
-  ( ((((fifo).l_end_frame + 1) - (fifo).l_start_frame) & AOUT_FIFO_SIZE) == 0 )
+  ( ((((fifo).i_end_frame + 1) - (fifo).i_start_frame) & AOUT_FIFO_SIZE) == 0 )
+
+#define AOUT_FIFO_INC( i_index ) \
+  ( ((i_index) + 1) & AOUT_FIFO_SIZE )
 
-#define AOUT_EMPTY_FIFO         0
-#define AOUT_ADEC_MONO_FIFO     1
-#define AOUT_ADEC_STEREO_FIFO   2
-#define AOUT_ADEC_SPDIF_FIFO    3
+/* List of known fifo formats */
+#define AOUT_FIFO_NONE    0
+#define AOUT_FIFO_PCM     1
+#define AOUT_FIFO_SPDIF   2
 
 /*****************************************************************************
  * aout_thread_t : audio output thread descriptor
@@ -140,7 +146,7 @@ typedef struct aout_thread_s
     struct module_s *   p_module;
     int              ( *pf_open )       ( p_aout_thread_t );
     int              ( *pf_setformat )  ( p_aout_thread_t );
-    long             ( *pf_getbufinfo ) ( p_aout_thread_t, long );
+    int              ( *pf_getbufinfo ) ( p_aout_thread_t, int );
     void             ( *pf_play )       ( p_aout_thread_t, byte_t *, int );
     void             ( *pf_close )      ( p_aout_thread_t );
 
@@ -151,8 +157,8 @@ typedef struct aout_thread_s
 
     /* The size of the audio output buffer is kept in audio units, as this is
      * the only unit that is common with every audio decoder and audio fifo */
-    long                l_units;
-    long                l_msleep;
+    int                 i_units;
+    int                 i_msleep;
 
     /* date is the moment where the first audio unit of the output buffer
      * will be played */
@@ -161,15 +167,14 @@ typedef struct aout_thread_s
     /* The current volume */
     int                 i_volume;
     int                 i_savedvolume;
-    /* Format of the audio output samples */
+
+    /* Format of the audio output samples, number of channels, and
+     * rate and gain (in Hz) of the audio output sound */
     int                 i_format;
-    /* Number of channels */
     int                 i_channels;
-    /* Mono or Stereo sound */
-    boolean_t           b_stereo;
-    /* Rate and gain of the audio output sound (in Hz) */
-    long                l_rate;
-    long                l_gain;
+    int                 i_rate;
+
+    /* Latency of the audio output plugin, in bytes */
     int                 i_latency;
 
     /* there might be some useful private structure, such as audio_buf_info
@@ -207,11 +212,10 @@ typedef struct aout_thread_s
 void            aout_InitBank           ( void );
 void            aout_EndBank            ( void );
 
-aout_thread_t * aout_CreateThread       ( int *pi_status, int i_channels, 
-    long l_rate );
+aout_thread_t * aout_CreateThread       ( int *, int, int );
 void            aout_DestroyThread      ( aout_thread_t *, int * );
 
-aout_fifo_t *   aout_CreateFifo         ( int, int, long, long, long, void * );
+aout_fifo_t *   aout_CreateFifo         ( int, int, int, int, void * );
 void            aout_DestroyFifo        ( aout_fifo_t *p_fifo );
 void            aout_FreeFifo           ( aout_fifo_t *p_fifo );
 #else
index 84063a1dccc4c0566761d32cfa1b1f3c0cb52106..a0ff5a4e774e2b9713b9d5a7252e194bc9a9ffa2 100644 (file)
@@ -3,7 +3,7 @@
  * Collection of useful common types and macros definitions
  *****************************************************************************
  * Copyright (C) 1998, 1999, 2000 VideoLAN
- * $Id: common.h,v 1.77 2002/02/24 21:36:20 jobi Exp $
+ * $Id: common.h,v 1.78 2002/02/24 22:06:50 sam Exp $
  *
  * Authors: Samuel Hocevar <sam@via.ecp.fr>
  *          Vincent Seguin <seguin@via.ecp.fr>
@@ -542,8 +542,7 @@ typedef struct module_symbols_s
                                            struct pgrm_descriptor_s *,
                                            mtime_t );
 
-    struct aout_fifo_s * ( * aout_CreateFifo ) 
-                                       ( int, int, long, long, long, void * );
+    struct aout_fifo_s * ( * aout_CreateFifo ) ( int, int, int, int, void * );
     void ( * aout_DestroyFifo )     ( struct aout_fifo_s * );
 
     struct vout_thread_s * (* vout_CreateThread) ( int *, int, int, u32, int );
index 282589ad8c9b2492e27e89394d9414133d608d1e..95b04374f1fa585b44dde4339f0e91f56a193192 100644 (file)
@@ -1,4 +1,4 @@
-/* include/defs.h.in.  Generated automatically from configure.in by autoheader.  */
+/* include/defs.h.in.  Generated automatically from configure.in by autoheader 2.13.  */
 
 /* Define if using alloca.c.  */
 #undef C_ALLOCA
index 230c400990568612489d62970394a88e0a252023..4f806fc3e39cbbedcdf8eb149c9372086edf9637 100644 (file)
@@ -2,7 +2,7 @@
  * modules.h : Module management functions.
  *****************************************************************************
  * Copyright (C) 2001 VideoLAN
- * $Id: modules.h,v 1.42 2002/02/24 20:51:09 gbazin Exp $
+ * $Id: modules.h,v 1.43 2002/02/24 22:06:50 sam Exp $
  *
  * Authors: Samuel Hocevar <sam@zoy.org>
  *
@@ -212,7 +212,7 @@ typedef struct function_list_s
         {
             int  ( * pf_open )       ( struct aout_thread_s * );
             int  ( * pf_setformat )  ( struct aout_thread_s * );
-            long ( * pf_getbufinfo ) ( struct aout_thread_s *, long );
+            int  ( * pf_getbufinfo ) ( struct aout_thread_s *, int );
             void ( * pf_play )       ( struct aout_thread_s *, byte_t *, int );
             void ( * pf_close )      ( struct aout_thread_s * );
         } aout;
index 2b918da568b90217c37a4e6391a29f0b8fcdb51d..794b2ef53e1a957edc36be39336681661c2ab79d 100644 (file)
@@ -4,7 +4,7 @@
  *   (http://liba52.sf.net/).
  *****************************************************************************
  * Copyright (C) 2001 VideoLAN
- * $Id: a52.c,v 1.4 2002/02/24 20:51:09 gbazin Exp $
+ * $Id: a52.c,v 1.5 2002/02/24 22:06:50 sam Exp $
  *
  * Authors: Gildas Bazin <gbazin@netcourrier.com>
  *      
@@ -213,7 +213,7 @@ static int DecodeFrame( a52_adec_thread_t * p_a52_adec )
     int i;
 
     if( ( p_a52_adec->p_aout_fifo != NULL ) &&
-        ( p_a52_adec->p_aout_fifo->l_rate != p_a52_adec->sample_rate ) )
+        ( p_a52_adec->p_aout_fifo->i_rate != p_a52_adec->sample_rate ) )
     {
         /* Make sure the output thread leaves the NextFrame() function */
         vlc_mutex_lock (&(p_a52_adec->p_aout_fifo->data_lock));
@@ -227,9 +227,9 @@ static int DecodeFrame( a52_adec_thread_t * p_a52_adec )
     /* Creating the audio output fifo if not created yet */
     if (p_a52_adec->p_aout_fifo == NULL )
     {
-        p_a52_adec->p_aout_fifo = aout_CreateFifo( AOUT_ADEC_STEREO_FIFO
+        p_a52_adec->p_aout_fifo = aout_CreateFifo( AOUT_FIFO_PCM
                                     p_a52_adec->i_channels,
-                                    p_a52_adec->sample_rate, 0,
+                                    p_a52_adec->sample_rate,
                                     AC3DEC_FRAME_SIZE * p_a52_adec->i_channels,
                                     NULL );
 
@@ -242,20 +242,20 @@ static int DecodeFrame( a52_adec_thread_t * p_a52_adec )
     /* Set the Presentation Time Stamp */
     CurrentPTS( &p_a52_adec->bit_stream,
                 &p_a52_adec->p_aout_fifo->date[
-                    p_a52_adec->p_aout_fifo->l_end_frame],
+                    p_a52_adec->p_aout_fifo->i_end_frame],
                 NULL );
 
     if( !p_a52_adec->p_aout_fifo->date[
-            p_a52_adec->p_aout_fifo->l_end_frame] )
+            p_a52_adec->p_aout_fifo->i_end_frame] )
     {
         p_a52_adec->p_aout_fifo->date[
-            p_a52_adec->p_aout_fifo->l_end_frame] = LAST_MDATE;
+            p_a52_adec->p_aout_fifo->i_end_frame] = LAST_MDATE;
     }
 
 
 
     p_buffer = ((byte_t *)p_a52_adec->p_aout_fifo->buffer) +
-        ( p_a52_adec->p_aout_fifo->l_end_frame * AC3DEC_FRAME_SIZE *
+        ( p_a52_adec->p_aout_fifo->i_end_frame * AC3DEC_FRAME_SIZE *
           p_a52_adec->i_channels * sizeof(s16) );
 
     /* FIXME */
@@ -280,8 +280,8 @@ static int DecodeFrame( a52_adec_thread_t * p_a52_adec )
 
 
     vlc_mutex_lock( &p_a52_adec->p_aout_fifo->data_lock );
-    p_a52_adec->p_aout_fifo->l_end_frame = 
-      (p_a52_adec->p_aout_fifo->l_end_frame + 1) & AOUT_FIFO_SIZE;
+    p_a52_adec->p_aout_fifo->i_end_frame = 
+      (p_a52_adec->p_aout_fifo->i_end_frame + 1) & AOUT_FIFO_SIZE;
     vlc_cond_signal (&p_a52_adec->p_aout_fifo->data_wait);
     vlc_mutex_unlock (&p_a52_adec->p_aout_fifo->data_lock);
 
index feeca004b20c868941f933ee1c8ed55b64b7c8f5..4d271b18320c4ac14b164262e46630429050542c 100644 (file)
@@ -2,7 +2,7 @@
  * ac3_adec.c: ac3 decoder module main file
  *****************************************************************************
  * Copyright (C) 1999-2001 VideoLAN
- * $Id: ac3_adec.c,v 1.21 2002/02/24 20:51:09 gbazin Exp $
+ * $Id: ac3_adec.c,v 1.22 2002/02/24 22:06:50 sam Exp $
  *
  * Authors: Michel Lespinasse <walken@zoy.org>
  *
@@ -279,7 +279,7 @@ static int decoder_Run ( decoder_config_t * p_config )
         }
 
         if( ( p_ac3thread->p_aout_fifo != NULL ) &&
-            ( p_ac3thread->p_aout_fifo->l_rate != sync_info.sample_rate ) )
+            ( p_ac3thread->p_aout_fifo->i_rate != sync_info.sample_rate ) )
         {
             /* Make sure the output thread leaves the NextFrame() function */
             vlc_mutex_lock (&(p_ac3thread->p_aout_fifo->data_lock));
@@ -292,8 +292,8 @@ static int decoder_Run ( decoder_config_t * p_config )
 
         /* Creating the audio output fifo if not created yet */
         if (p_ac3thread->p_aout_fifo == NULL ) {
-            p_ac3thread->p_aout_fifo = aout_CreateFifo( AOUT_ADEC_STEREO_FIFO, 
-                    2, sync_info.sample_rate, 0, AC3DEC_FRAME_SIZE, NULL  );
+            p_ac3thread->p_aout_fifo = aout_CreateFifo( AOUT_FIFO_PCM, 2,
+                           sync_info.sample_rate, AC3DEC_FRAME_SIZE, NULL  );
             if ( p_ac3thread->p_aout_fifo == NULL )
             {
                 free( IMDCT->w_1 );
@@ -326,17 +326,17 @@ static int decoder_Run ( decoder_config_t * p_config )
         }
 
         CurrentPTS( &p_ac3thread->ac3_decoder->bit_stream,
-            &p_ac3thread->p_aout_fifo->date[p_ac3thread->p_aout_fifo->l_end_frame],
+            &p_ac3thread->p_aout_fifo->date[p_ac3thread->p_aout_fifo->i_end_frame],
             NULL );
-        if( !p_ac3thread->p_aout_fifo->date[p_ac3thread->p_aout_fifo->l_end_frame] )
+        if( !p_ac3thread->p_aout_fifo->date[p_ac3thread->p_aout_fifo->i_end_frame] )
         {
             p_ac3thread->p_aout_fifo->date[
-                p_ac3thread->p_aout_fifo->l_end_frame] =
+                p_ac3thread->p_aout_fifo->i_end_frame] =
                 LAST_MDATE;
         }
     
         buffer = ((s16 *)p_ac3thread->p_aout_fifo->buffer) + 
-            (p_ac3thread->p_aout_fifo->l_end_frame * AC3DEC_FRAME_SIZE);
+            (p_ac3thread->p_aout_fifo->i_end_frame * AC3DEC_FRAME_SIZE);
 
         if (ac3_decode_frame (p_ac3thread->ac3_decoder, buffer))
         {
@@ -345,8 +345,8 @@ static int decoder_Run ( decoder_config_t * p_config )
         }
         
         vlc_mutex_lock (&p_ac3thread->p_aout_fifo->data_lock);
-        p_ac3thread->p_aout_fifo->l_end_frame = 
-            (p_ac3thread->p_aout_fifo->l_end_frame + 1) & AOUT_FIFO_SIZE;
+        p_ac3thread->p_aout_fifo->i_end_frame = 
+            (p_ac3thread->p_aout_fifo->i_end_frame + 1) & AOUT_FIFO_SIZE;
         vlc_cond_signal (&p_ac3thread->p_aout_fifo->data_wait);
         vlc_mutex_unlock (&p_ac3thread->p_aout_fifo->data_lock);
 
index 01b8c913bd86dcc7caf44a687e42cf78d06d7954..94ebb2ab3a7b3f21c38748eae3b1096b78cc33e0 100644 (file)
@@ -2,7 +2,7 @@
  * ac3_spdif.c: ac3 pass-through to external decoder with enabled soundcard
  *****************************************************************************
  * Copyright (C) 2001 VideoLAN
- * $Id: ac3_spdif.c,v 1.15 2002/02/24 20:51:09 gbazin Exp $
+ * $Id: ac3_spdif.c,v 1.16 2002/02/24 22:06:50 sam Exp $
  *
  * Authors: Stéphane Borel <stef@via.ecp.fr>
  *          Juha Yrjola <jyrjola@cc.hut.fi>
@@ -157,19 +157,19 @@ static int decoder_Run( decoder_config_t * p_config )
         /* if we're late here the output won't have to play the frame */
         if( i_current_pts > mdate() )
         {
-            p_spdif->p_aout_fifo->date[p_spdif->p_aout_fifo->l_end_frame] =
+            p_spdif->p_aout_fifo->date[p_spdif->p_aout_fifo->i_end_frame] =
                 i_current_pts;
     
             /* Write in the first free packet of aout fifo */
             p_spdif->p_iec = ((u8*)(p_spdif->p_aout_fifo->buffer) + 
-                (p_spdif->p_aout_fifo->l_end_frame * SPDIF_FRAME_SIZE ));
+                (p_spdif->p_aout_fifo->i_end_frame * SPDIF_FRAME_SIZE ));
     
             /* Build burst to be sent to hardware decoder */
             ac3_iec958_build_burst( p_spdif );
     
             vlc_mutex_lock (&p_spdif->p_aout_fifo->data_lock);
-            p_spdif->p_aout_fifo->l_end_frame = 
-                    (p_spdif->p_aout_fifo->l_end_frame + 1 ) & AOUT_FIFO_SIZE;
+            p_spdif->p_aout_fifo->i_end_frame = 
+                    (p_spdif->p_aout_fifo->i_end_frame + 1 ) & AOUT_FIFO_SIZE;
             vlc_mutex_unlock (&p_spdif->p_aout_fifo->data_lock);
         }
 
@@ -265,9 +265,9 @@ static int InitThread( ac3_spdif_thread_t * p_spdif )
     }
     
     /* Creating the audio output fifo */
-    p_spdif->p_aout_fifo = aout_CreateFifo( AOUT_ADEC_SPDIF_FIFO, 1,
+    p_spdif->p_aout_fifo = aout_CreateFifo( AOUT_FIFO_SPDIF, 1,
                                             p_spdif->ac3_info.i_sample_rate,
-                                            0, SPDIF_FRAME_SIZE, NULL );
+                                            SPDIF_FRAME_SIZE, NULL );
 
     if( p_spdif->p_aout_fifo == NULL )
     {
index 3ec44e0f332049c6acf4a41183e09e232952cc81..50e58f3f673417974daa6eac8c4c0b8e20b50ca8 100644 (file)
@@ -2,7 +2,7 @@
  * aout_alsa.c : Alsa functions library
  *****************************************************************************
  * Copyright (C) 2000-2001 VideoLAN
- * $Id: aout_alsa.c,v 1.27 2002/02/19 00:50:19 sam Exp $
+ * $Id: aout_alsa.c,v 1.28 2002/02/24 22:06:50 sam Exp $
  *
  * Authors: Henri Fallon <henri@videolan.org> - Original Author
  *          Jeffrey Baker <jwbaker@acm.org> - Port to ALSA 1.0 API
@@ -162,7 +162,7 @@ static int aout_SetFormat( aout_thread_t *p_aout )
     }
 
     i_rv = snd_pcm_hw_params_set_rate_near( p_aout->p_sys->p_alsa_handle, p_hw,
-                                            p_aout->l_rate, 0 );
+                                            p_aout->i_rate, 0 );
     if( i_rv < 0 )
     {
         intf_ErrMsg( "aout error: unable to set sample rate" );
@@ -253,7 +253,7 @@ static void aout_HandleXrun(aout_thread_t *p_aout)
  * of data to play, it switches to the "underrun" status. It has to
  * be flushed and re-prepared
  *****************************************************************************/
-static long aout_GetBufInfo( aout_thread_t *p_aout, long l_buffer_limit )
+static long aout_GetBufInfo( aout_thread_t *p_aout, int i_buffer_limit )
 {
     snd_pcm_status_t *p_status;
     int i_alsa_get_status_returns;
index 308e2d2446a508476c0e705b19368786c2471e35..4e02122aaaa1cd2105deb294f5f2da5e4b16bf27 100644 (file)
@@ -53,7 +53,7 @@ typedef struct aout_sys_s
  *****************************************************************************/
 static int     aout_Open        ( aout_thread_t *p_aout );
 static int     aout_SetFormat   ( aout_thread_t *p_aout );
-static long    aout_GetBufInfo  ( aout_thread_t *p_aout, long l_buffer_info );
+static int     aout_GetBufInfo  ( aout_thread_t *p_aout, int i_buffer_info );
 static void    aout_Play        ( aout_thread_t *p_aout,
                                   byte_t *buffer, int i_size );
 static void    aout_Close       ( aout_thread_t *p_aout );
@@ -96,7 +96,7 @@ static int aout_Open( aout_thread_t *p_aout )
     }
 
     p_aout->p_sys->stream =
-        arts_play_stream( p_aout->l_rate, 16, p_aout->i_channels, "vlc" );
+        arts_play_stream( p_aout->i_rate, 16, p_aout->i_channels, "vlc" );
 
     return( 0 );
 }
@@ -118,10 +118,10 @@ static int aout_SetFormat( aout_thread_t *p_aout )
 /*****************************************************************************
  * aout_GetBufInfo: buffer status query
  *****************************************************************************/
-static long aout_GetBufInfo( aout_thread_t *p_aout, long l_buffer_limit )
+static int aout_GetBufInfo( aout_thread_t *p_aout, int i_buffer_limit )
 {
     /* arbitrary value that should be changed */
-    return( l_buffer_limit );
+    return( i_buffer_limit );
 }
 
 /*****************************************************************************
index 35ab10523e00d5894c55808ee5bbffdecf207a22..29d71565959b51094926fde53ac489a944670d7e 100644 (file)
@@ -2,7 +2,7 @@
  * aout_beos.cpp: BeOS audio output
  *****************************************************************************
  * Copyright (C) 1999, 2000, 2001 VideoLAN
- * $Id: aout_beos.cpp,v 1.22 2002/02/24 20:51:09 gbazin Exp $
+ * $Id: aout_beos.cpp,v 1.23 2002/02/24 22:06:50 sam Exp $
  *
  * Authors: Jean-Marc Dressler <polux@via.ecp.fr>
  *          Samuel Hocevar <sam@zoy.org>
@@ -55,8 +55,8 @@ typedef struct aout_sys_s
     BPushGameSound * p_sound;
     gs_audio_format * p_format;
     void * p_buffer;
-    long i_buffer_size;
-    long i_buffer_pos;
+    int i_buffer_size;
+    int i_buffer_pos;
 
 } aout_sys_t;
 
@@ -68,7 +68,7 @@ extern "C"
  *****************************************************************************/
 static int     aout_Open        ( aout_thread_t *p_aout );
 static int     aout_SetFormat   ( aout_thread_t *p_aout );
-static long    aout_GetBufInfo  ( aout_thread_t *p_aout, long l_buffer_info );
+static int     aout_GetBufInfo  ( aout_thread_t *p_aout, int i_buffer_info );
 static void    aout_Play        ( aout_thread_t *p_aout,
                                   byte_t *buffer, int i_size );
 static void    aout_Close       ( aout_thread_t *p_aout );
@@ -155,10 +155,10 @@ static int aout_SetFormat( aout_thread_t *p_aout )
 /*****************************************************************************
  * aout_GetBufInfo: buffer status query
  *****************************************************************************/
-static long aout_GetBufInfo( aout_thread_t *p_aout, long l_buffer_limit )
+static int aout_GetBufInfo( aout_thread_t *p_aout, int i_buffer_limit )
 {
     /* Each value is 4 bytes long (stereo signed 16 bits) */
-    long i_hard_pos = 4 * p_aout->p_sys->p_sound->CurrentPosition();
+    int i_hard_pos = 4 * p_aout->p_sys->p_sound->CurrentPosition();
 
     i_hard_pos = p_aout->p_sys->i_buffer_pos - i_hard_pos;
     if( i_hard_pos < 0 )
@@ -176,7 +176,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 )
 {
-    long i_newbuf_pos;
+    int i_newbuf_pos;
 
     if( (i_newbuf_pos = p_aout->p_sys->i_buffer_pos + i_size)
               > p_aout->p_sys->i_buffer_size )
index 98e84ea0226ef2da91fbd82cbbed27960f29947e..fb0c6fc8fec1480f90aab467b6121ae9fa7ca5a0 100644 (file)
@@ -2,7 +2,7 @@
  * aout_directx.c: Windows DirectX audio output method
  *****************************************************************************
  * Copyright (C) 2001 VideoLAN
- * $Id: aout_directx.c,v 1.19 2002/02/24 20:51:09 gbazin Exp $
+ * $Id: aout_directx.c,v 1.20 2002/02/24 22:06:50 sam Exp $
  *
  * Authors: Gildas Bazin <gbazin@netcourrier.com>
  *
@@ -68,12 +68,12 @@ typedef struct aout_sys_s
 
     HINSTANCE           hdsound_dll;      /* handle of the opened dsound dll */
 
-    long l_buffer_size;                       /* secondary sound buffer size */
-    long l_write_position;             /* next write position for the buffer */
+    int i_buffer_size;                        /* secondary sound buffer size */
+    int i_write_position;              /* next write position for the buffer */
 
     volatile boolean_t b_buffer_underflown;    /* buffer underflow detection */
-    volatile long l_data_played_from_beginning;   /* for underflow detection */
-    volatile long l_data_written_from_beginning;  /* for underflow detection */
+    volatile int i_data_played_from_beginning;    /* for underflow detection */
+    volatile int i_data_written_from_beginning;   /* for underflow detection */
 
     vlc_mutex_t buffer_lock;                            /* audio buffer lock */
 
@@ -90,7 +90,7 @@ typedef struct aout_sys_s
  *****************************************************************************/
 static int     aout_Open        ( aout_thread_t *p_aout );
 static int     aout_SetFormat   ( aout_thread_t *p_aout );
-static long    aout_GetBufInfo  ( aout_thread_t *p_aout, long l_buffer_info );
+static int     aout_GetBufInfo  ( aout_thread_t *p_aout, int i_buffer_info );
 static void    aout_Play        ( aout_thread_t *p_aout,
                                   byte_t *buffer, int i_size );
 static void    aout_Close       ( aout_thread_t *p_aout );
@@ -141,8 +141,8 @@ static int aout_Open( aout_thread_t *p_aout )
     p_aout->p_sys->p_dsbuffer = NULL;
     p_aout->p_sys->p_dsnotify = NULL;
     p_aout->p_sys->b_notification_thread_die = 0;
-    p_aout->p_sys->l_data_written_from_beginning = 0;
-    p_aout->p_sys->l_data_played_from_beginning = 0;
+    p_aout->p_sys->i_data_written_from_beginning = 0;
+    p_aout->p_sys->i_data_played_from_beginning = 0;
     vlc_mutex_init( &p_aout->p_sys->buffer_lock );
 
 
@@ -205,7 +205,7 @@ static int aout_SetFormat( aout_thread_t *p_aout )
 {
     HRESULT       dsresult;
     WAVEFORMATEX  *p_waveformat;
-    unsigned long i_size_struct;
+    unsigned int  i_size_struct;
 
     intf_WarnMsg( 3, "aout: DirectX aout_SetFormat ");
 
@@ -227,8 +227,8 @@ static int aout_SetFormat( aout_thread_t *p_aout )
     {
         /* Here we'll change the format */
         p_waveformat->nChannels        = 2; 
-        p_waveformat->nSamplesPerSec   = (p_aout->l_rate < 44100) ? 44100
-                                             : p_aout->l_rate; 
+        p_waveformat->nSamplesPerSec   = (p_aout->i_rate < 44100) ? 44100
+                                             : p_aout->i_rate; 
         p_waveformat->wBitsPerSample   = 16; 
         p_waveformat->nBlockAlign      = p_waveformat->wBitsPerSample / 8 *
                                              p_waveformat->nChannels;
@@ -271,34 +271,34 @@ static int aout_SetFormat( aout_thread_t *p_aout )
  * returns the number of bytes in the audio buffer that have not yet been
  * sent to the sound device.
  *****************************************************************************/
-static long aout_GetBufInfo( aout_thread_t *p_aout, long l_buffer_limit )
+static int aout_GetBufInfo( aout_thread_t *p_aout, int i_buffer_limit )
 {
-    long l_play_position, l_notused, l_result;
+    int i_play_position, i_notused, i_result;
     HRESULT dsresult;
 
     if( p_aout->p_sys->b_buffer_underflown )
     {
         intf_WarnMsg( 3, "aout: DirectX aout_GetBufInfo underflow");
-        return( l_buffer_limit );
+        return( i_buffer_limit );
     }
 
     dsresult = IDirectSoundBuffer_GetCurrentPosition(p_aout->p_sys->p_dsbuffer,
-                                                 &l_play_position, &l_notused);
+                                                 &i_play_position, &i_notused);
     if( dsresult != DS_OK )
     {
         intf_WarnMsg(3,"aout: DirectX aout_GetBufInfo cannot get current pos");
-        return( l_buffer_limit );
+        return( i_buffer_limit );
     }
 
-    l_result = (p_aout->p_sys->l_write_position >= l_play_position) ?
-      (p_aout->p_sys->l_write_position - l_play_position)
-               : (p_aout->p_sys->l_buffer_size - l_play_position
-                  + p_aout->p_sys->l_write_position);
+    i_result = (p_aout->p_sys->i_write_position >= i_play_position) ?
+      (p_aout->p_sys->i_write_position - i_play_position)
+               : (p_aout->p_sys->i_buffer_size - i_play_position
+                  + p_aout->p_sys->i_write_position);
 
 #if 0
-    intf_WarnMsg( 3, "aout: DirectX aout_GetBufInfo: %li", l_result);
+    intf_WarnMsg( 3, "aout: DirectX aout_GetBufInfo: %i", i_result);
 #endif
-    return l_result;
+    return i_result;
 }
 
 /*****************************************************************************
@@ -310,7 +310,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 )
 {
     VOID            *p_write_position, *p_start_buffer;
-    long            l_bytes1, l_bytes2, l_play_position;
+    int             i_bytes1, i_bytes2, i_play_position;
     HRESULT         dsresult;
 
     /* protect buffer access (because of DirectSoundThread) */
@@ -322,30 +322,30 @@ static void aout_Play( aout_thread_t *p_aout, byte_t *buffer, int i_size )
          *  as soon as possible. This is why we query the play position */
         dsresult = IDirectSoundBuffer_GetCurrentPosition(
                                             p_aout->p_sys->p_dsbuffer,
-                                            &l_play_position,
-                                            &p_aout->p_sys->l_write_position );
+                                            &i_play_position,
+                                            &p_aout->p_sys->i_write_position );
         if( dsresult != DS_OK )
         {
             intf_WarnMsg( 3, "aout: aout_Play can'get buffer position");
-            p_aout->p_sys->l_write_position = 0; 
+            p_aout->p_sys->i_write_position = 0; 
         }
 
         intf_WarnMsg( 3, "aout: aout_Play underflow");
         /* reinitialise the underflow detection counters */
         p_aout->p_sys->b_buffer_underflown = 0;
-        p_aout->p_sys->l_data_written_from_beginning = 0;
+        p_aout->p_sys->i_data_written_from_beginning = 0;
 
-#define WRITE_P  p_aout->p_sys->l_write_position
-#define PLAY_P   l_play_position
-#define BUF_SIZE p_aout->p_sys->l_buffer_size
-        p_aout->p_sys->l_data_played_from_beginning = -(WRITE_P %(BUF_SIZE/2));
+#define WRITE_P  p_aout->p_sys->i_write_position
+#define PLAY_P   i_play_position
+#define BUF_SIZE p_aout->p_sys->i_buffer_size
+        p_aout->p_sys->i_data_played_from_beginning = -(WRITE_P %(BUF_SIZE/2));
         if( PLAY_P < BUF_SIZE/2 && WRITE_P > BUF_SIZE/2 )
         {
-            p_aout->p_sys->l_data_played_from_beginning -= (BUF_SIZE/2);
+            p_aout->p_sys->i_data_played_from_beginning -= (BUF_SIZE/2);
         }
         if( PLAY_P > BUF_SIZE/2 && WRITE_P < BUF_SIZE/2 )
         {
-            p_aout->p_sys->l_data_played_from_beginning -= (BUF_SIZE/2);
+            p_aout->p_sys->i_data_played_from_beginning -= (BUF_SIZE/2);
         }        
 #undef WRITE_P
 #undef PLAY_P
@@ -354,23 +354,23 @@ static void aout_Play( aout_thread_t *p_aout, byte_t *buffer, int i_size )
 
     /* Before copying anything, we have to lock the buffer */
     dsresult = IDirectSoundBuffer_Lock( p_aout->p_sys->p_dsbuffer,
-                   p_aout->p_sys->l_write_position,  /* Offset of lock start */
+                   p_aout->p_sys->i_write_position,  /* Offset of lock start */
                    i_size,                        /* Number of bytes to lock */
                    &p_write_position,               /* Address of lock start */
-                   &l_bytes1,    /* Count of bytes locked before wrap around */
+                   &i_bytes1,    /* Count of bytes locked before wrap around */
                    &p_start_buffer,        /* Buffer adress (if wrap around) */
-                   &l_bytes2,            /* Count of bytes after wrap around */
+                   &i_bytes2,            /* Count of bytes after wrap around */
                    0);                                              /* Flags */
     if( dsresult == DSERR_BUFFERLOST )
     {
         IDirectSoundBuffer_Restore( p_aout->p_sys->p_dsbuffer );
         dsresult = IDirectSoundBuffer_Lock( p_aout->p_sys->p_dsbuffer,
-                                            p_aout->p_sys->l_write_position,
+                                            p_aout->p_sys->i_write_position,
                                             i_size,
                                             &p_write_position,
-                                            &l_bytes1,
+                                            &i_bytes1,
                                             &p_start_buffer,
-                                            &l_bytes2,
+                                            &i_bytes2,
                                             0);
 
     }
@@ -382,20 +382,20 @@ static void aout_Play( aout_thread_t *p_aout, byte_t *buffer, int i_size )
     }
 
     /* Now do the actual memcpy (two memcpy because the buffer is circular) */
-    memcpy( p_write_position, buffer, l_bytes1 );
+    memcpy( p_write_position, buffer, i_bytes1 );
     if( p_start_buffer != NULL )
     {
-        memcpy( p_start_buffer, buffer + l_bytes1, l_bytes2 );
+        memcpy( p_start_buffer, buffer + i_bytes1, i_bytes2 );
     }
 
     /* Now the data has been copied, unlock the buffer */
     IDirectSoundBuffer_Unlock( p_aout->p_sys->p_dsbuffer, 
-            p_write_position, l_bytes1, p_start_buffer, l_bytes2 );
+            p_write_position, i_bytes1, p_start_buffer, i_bytes2 );
 
     /* Update the write position index of the buffer*/
-    p_aout->p_sys->l_write_position += i_size;
-    p_aout->p_sys->l_write_position %= p_aout->p_sys->l_buffer_size;
-    p_aout->p_sys->l_data_written_from_beginning += i_size;
+    p_aout->p_sys->i_write_position += i_size;
+    p_aout->p_sys->i_write_position %= p_aout->p_sys->i_buffer_size;
+    p_aout->p_sys->i_data_written_from_beginning += i_size;
 
     vlc_mutex_unlock( &p_aout->p_sys->buffer_lock );
 
@@ -544,7 +544,7 @@ static int DirectxCreateSecondaryBuffer( aout_thread_t *p_aout )
     memset(&waveformat, 0, sizeof(WAVEFORMATEX)); 
     waveformat.wFormatTag      = WAVE_FORMAT_PCM; 
     waveformat.nChannels       = p_aout->i_channels; 
-    waveformat.nSamplesPerSec  = p_aout->l_rate; 
+    waveformat.nSamplesPerSec  = p_aout->i_rate; 
     waveformat.wBitsPerSample  = 16; 
     waveformat.nBlockAlign     = waveformat.wBitsPerSample / 8 *
                                  waveformat.nChannels;
@@ -574,11 +574,11 @@ static int DirectxCreateSecondaryBuffer( aout_thread_t *p_aout )
     memset(&dsbcaps, 0, sizeof(DSBCAPS)); 
     dsbcaps.dwSize = sizeof(DSBCAPS);
     IDirectSoundBuffer_GetCaps( p_aout->p_sys->p_dsbuffer, &dsbcaps  );
-    p_aout->p_sys->l_buffer_size = dsbcaps.dwBufferBytes;
-    p_aout->p_sys->l_write_position = 0;
+    p_aout->p_sys->i_buffer_size = dsbcaps.dwBufferBytes;
+    p_aout->p_sys->i_write_position = 0;
 
-    intf_WarnMsg( 3, "aout: DirectX DirectxCreateSecondaryBuffer: %li",
-                  p_aout->p_sys->l_buffer_size);
+    intf_WarnMsg( 3, "aout: DirectX DirectxCreateSecondaryBuffer: %i",
+                  p_aout->p_sys->i_buffer_size);
 
     /* Now the secondary buffer is created, we need to setup its position
      * notification */
@@ -646,9 +646,9 @@ static void DirectSoundThread( aout_thread_t *p_aout )
 {
     HANDLE  notification_events[2];
     VOID    *p_write_position, *p_start_buffer;
-    long    l_bytes1, l_bytes2;
+    int     i_bytes1, i_bytes2;
     HRESULT dsresult;
-    long    l_buffer_size, l_play_position, l_data_in_buffer;
+    int     i_buffer_size, i_play_position, i_data_in_buffer;
 
     notification_events[0]=p_aout->p_sys->notification_events[0].hEventNotify;
     notification_events[1]=p_aout->p_sys->notification_events[1].hEventNotify;
@@ -665,7 +665,7 @@ static void DirectSoundThread( aout_thread_t *p_aout )
     while( !p_aout->p_sys->b_notification_thread_die )
     {
         /* wait for the position notification */
-        l_play_position = WaitForMultipleObjects( 2, notification_events,
+        i_play_position = WaitForMultipleObjects( 2, notification_events,
                                                   0, INFINITE ); 
         vlc_mutex_lock( &p_aout->p_sys->buffer_lock );
 
@@ -675,28 +675,28 @@ static void DirectSoundThread( aout_thread_t *p_aout )
         }
 
         /* check for buffer underflow (bodge for wrap around) */
-        l_buffer_size = p_aout->p_sys->l_buffer_size;
-        l_play_position = (l_play_position - WAIT_OBJECT_0) * l_buffer_size/2;
-        p_aout->p_sys->l_data_played_from_beginning += (l_buffer_size/2);
-        l_data_in_buffer = p_aout->p_sys->l_data_written_from_beginning -
-                               p_aout->p_sys->l_data_played_from_beginning; 
+        i_buffer_size = p_aout->p_sys->i_buffer_size;
+        i_play_position = (i_play_position - WAIT_OBJECT_0) * i_buffer_size/2;
+        p_aout->p_sys->i_data_played_from_beginning += (i_buffer_size/2);
+        i_data_in_buffer = p_aout->p_sys->i_data_written_from_beginning -
+                               p_aout->p_sys->i_data_played_from_beginning; 
 
         /* detect wrap-around */
-        if( l_data_in_buffer < (-l_buffer_size/2) )
+        if( i_data_in_buffer < (-i_buffer_size/2) )
         {
-            intf_WarnMsg(3,"aout: DirectSoundThread wrap around: %li", l_data_in_buffer);
-            l_data_in_buffer += l_buffer_size;
+            intf_WarnMsg(3,"aout: DirectSoundThread wrap around: %i", i_data_in_buffer);
+            i_data_in_buffer += i_buffer_size;
         }
 
         /* detect underflow */
-        if( l_data_in_buffer <= 0 )
+        if( i_data_in_buffer <= 0 )
         {
-            intf_WarnMsg(3,"aout: DirectSoundThread underflow: %li", l_data_in_buffer);
+            intf_WarnMsg(3,"aout: DirectSoundThread underflow: %li", i_data_in_buffer);
             p_aout->p_sys->b_buffer_underflown = 1;
-            p_aout->p_sys->l_write_position =
-                  (l_play_position + l_buffer_size/2) % l_buffer_size;
-            l_data_in_buffer = l_buffer_size / 2;
-            p_aout->p_sys->l_data_played_from_beginning -= (l_buffer_size/2);
+            p_aout->p_sys->i_write_position =
+                  (i_play_position + i_buffer_size/2) % i_buffer_size;
+            i_data_in_buffer = i_buffer_size / 2;
+            p_aout->p_sys->i_data_played_from_beginning -= (i_buffer_size/2);
         }
 
 
@@ -704,23 +704,23 @@ static void DirectSoundThread( aout_thread_t *p_aout )
 
         /* Before copying anything, we have to lock the buffer */
         dsresult = IDirectSoundBuffer_Lock( p_aout->p_sys->p_dsbuffer,
-                   p_aout->p_sys->l_write_position,  /* Offset of lock start */
-                   l_buffer_size - l_data_in_buffer,      /* Number of bytes */
+                   p_aout->p_sys->i_write_position,  /* Offset of lock start */
+                   i_buffer_size - i_data_in_buffer,      /* Number of bytes */
                    &p_write_position,               /* Address of lock start */
-                   &l_bytes1,    /* Count of bytes locked before wrap around */
+                   &i_bytes1,    /* Count of bytes locked before wrap around */
                    &p_start_buffer,        /* Buffer adress (if wrap around) */
-                   &l_bytes2,            /* Count of bytes after wrap around */
+                   &i_bytes2,            /* Count of bytes after wrap around */
                    0);                                              /* Flags */
         if( dsresult == DSERR_BUFFERLOST )
         {
             IDirectSoundBuffer_Restore( p_aout->p_sys->p_dsbuffer );
             dsresult = IDirectSoundBuffer_Lock( p_aout->p_sys->p_dsbuffer,
-                                          p_aout->p_sys->l_write_position,
-                                          l_buffer_size - l_data_in_buffer,
+                                          p_aout->p_sys->i_write_position,
+                                          i_buffer_size - i_data_in_buffer,
                                           &p_write_position,
-                                          &l_bytes1,
+                                          &i_bytes1,
                                           &p_start_buffer,
-                                          &l_bytes2,
+                                          &i_bytes2,
                                           0);
         }
         if( dsresult != DS_OK )
@@ -731,15 +731,15 @@ static void DirectSoundThread( aout_thread_t *p_aout )
         }
 
         /* Now do the actual memcpy (two because the buffer is circular) */
-        memset( p_write_position, 0, l_bytes1 );
+        memset( p_write_position, 0, i_bytes1 );
         if( p_start_buffer != NULL )
         {
-            memset( p_start_buffer, 0, l_bytes2 );
+            memset( p_start_buffer, 0, i_bytes2 );
         }
 
         /* Now the data has been copied, unlock the buffer */
         IDirectSoundBuffer_Unlock( p_aout->p_sys->p_dsbuffer, 
-                        p_write_position, l_bytes1, p_start_buffer, l_bytes2 );
+                        p_write_position, i_bytes1, p_start_buffer, i_bytes2 );
 
         vlc_mutex_unlock( &p_aout->p_sys->buffer_lock );
 
index ec9e2e7b64936faa2670fe1c0e2149fbc9d4a276..c2260072d9549bc05e65c7a6f1f97f877c4c9245 100644 (file)
@@ -2,7 +2,7 @@
  * aout_dsp.c : dsp functions library
  *****************************************************************************
  * Copyright (C) 1999-2001 VideoLAN
- * $Id: aout_dsp.c,v 1.22 2002/02/24 20:51:09 gbazin Exp $
+ * $Id: aout_dsp.c,v 1.23 2002/02/24 22:06:50 sam Exp $
  *
  * Authors: Michel Kaempf <maxx@via.ecp.fr>
  *          Samuel Hocevar <sam@zoy.org>
@@ -75,7 +75,7 @@ typedef struct aout_sys_s
  *****************************************************************************/
 static int     aout_Open        ( aout_thread_t *p_aout );
 static int     aout_SetFormat   ( aout_thread_t *p_aout );
-static long    aout_GetBufInfo  ( aout_thread_t *p_aout, long l_buffer_info );
+static int     aout_GetBufInfo  ( aout_thread_t *p_aout, int i_buffer_info );
 static void    aout_Play        ( aout_thread_t *p_aout,
                                   byte_t *buffer, int i_size );
 static void    aout_Close       ( aout_thread_t *p_aout );
@@ -142,8 +142,8 @@ static int aout_Open( aout_thread_t *p_aout )
 static int aout_SetFormat( aout_thread_t *p_aout )
 {
     int i_format;
-    long l_rate;
-    boolean_t b_stereo = p_aout->b_stereo;
+    int i_rate;
+    boolean_t b_stereo;
 
     /* Reset the DSP device */
     if( ioctl( p_aout->p_sys->i_fd, SNDCTL_DSP_RESET, NULL ) < 0 )
@@ -170,6 +170,8 @@ static int aout_SetFormat( aout_thread_t *p_aout )
     }
 
     /* Set the number of channels */
+    b_stereo = ( p_aout->i_channels >= 2 );
+
     if( ioctl( p_aout->p_sys->i_fd, SNDCTL_DSP_STEREO, &b_stereo ) < 0 )
     {
         intf_ErrMsg( "aout error: can't set number of audio channels (%i)",
@@ -177,28 +179,27 @@ static int aout_SetFormat( aout_thread_t *p_aout )
         return( -1 );
     }
 
-    if( b_stereo != p_aout->b_stereo )
+    if( (1 + b_stereo) != p_aout->i_channels )
     {
-        intf_WarnMsg( 2, "aout warning: number of audio channels not supported"
-                      " (%i)", p_aout->i_channels );
-        p_aout->b_stereo = b_stereo;
+        intf_WarnMsg( 2, "aout warning: %i audio channels not supported",
+                      p_aout->i_channels );
         p_aout->i_channels = 1 + b_stereo;
     }
 
     /* Set the output rate */
-    l_rate = p_aout->l_rate;
+    i_rate = p_aout->i_rate;
     if( ioctl( p_aout->p_sys->i_fd, SNDCTL_DSP_SPEED, &l_rate ) < 0 )
     {
-        intf_ErrMsg( "aout error: can't set audio output rate (%li)",
-                     p_aout->l_rate );
+        intf_ErrMsg( "aout error: can't set audio output rate (%i)",
+                     p_aout->i_rate );
         return( -1 );
     }
 
-    if( l_rate != p_aout->l_rate )
+    if( i_rate != p_aout->i_rate )
     {
         intf_WarnMsg( 1, "aout warning: audio output rate not supported (%li)",
-                      p_aout->l_rate );
-        p_aout->l_rate = l_rate;
+                      p_aout->i_rate );
+        p_aout->i_rate = i_rate;
     }
 
     return( 0 );
@@ -208,14 +209,13 @@ static int aout_SetFormat( aout_thread_t *p_aout )
  * aout_GetBufInfo: buffer status query
  *****************************************************************************
  * This function fills in the audio_buf_info structure :
- * - int fragments : number of available fragments (partially usend ones not
- *   counted)
+ * - returns : number of available fragments (not partially used ones)
  * - int fragstotal : total number of fragments allocated
  * - int fragsize : size of a fragment in bytes
  * - int bytes : available space in bytes (includes partially used fragments)
  * Note! 'bytes' could be more than fragments*fragsize
  *****************************************************************************/
-static long aout_GetBufInfo( aout_thread_t *p_aout, long l_buffer_limit )
+static int aout_GetBufInfo( aout_thread_t *p_aout, int i_buffer_limit )
 {
     ioctl( p_aout->p_sys->i_fd, SNDCTL_DSP_GETOSPACE,
            &p_aout->p_sys->audio_buf );
index d27dc1ee1f9331a2ca7f7462ae2d61596f4300f1..ffc6d100c26fb8e4f04b7574bb7fb04f5987e215 100644 (file)
@@ -2,7 +2,7 @@
  * aout_dummy.c : dummy audio output plugin
  *****************************************************************************
  * Copyright (C) 2000, 2001 VideoLAN
- * $Id: aout_dummy.c,v 1.19 2002/02/15 13:32:53 sam Exp $
+ * $Id: aout_dummy.c,v 1.20 2002/02/24 22:06:50 sam Exp $
  *
  * Authors: Samuel Hocevar <sam@zoy.org>
  *
@@ -48,7 +48,7 @@ typedef struct aout_sys_s
  *****************************************************************************/
 static int     aout_Open        ( aout_thread_t *p_aout );
 static int     aout_SetFormat   ( aout_thread_t *p_aout );
-static long    aout_GetBufInfo  ( aout_thread_t *p_aout, long l_buffer_info );
+static int     aout_GetBufInfo  ( aout_thread_t *p_aout, int i_buffer_info );
 static void    aout_Play        ( aout_thread_t *p_aout,
                                   byte_t *buffer, int i_size );
 static void    aout_Close       ( aout_thread_t *p_aout );
@@ -85,9 +85,9 @@ static int aout_SetFormat( aout_thread_t *p_aout )
 /*****************************************************************************
  * aout_GetBufInfo: returns available bytes in buffer
  *****************************************************************************/
-static long aout_GetBufInfo( aout_thread_t *p_aout, long l_buffer_limit )
+static int aout_GetBufInfo( aout_thread_t *p_aout, int i_buffer_limit )
 {
-    return( sizeof(s16) * l_buffer_limit + 1 ); /* value big enough to sleep */
+    return( sizeof(s16) * i_buffer_limit + 1 ); /* value big enough to sleep */
 }
 
 /*****************************************************************************
index adc21206b43f194f439aea64698b66fc93d4b8d8..014a20385d3a423a106851ecc742c998855caee6 100644 (file)
@@ -2,7 +2,7 @@
  * aout_esd.c : Esound functions library
  *****************************************************************************
  * Copyright (C) 2000-2001 VideoLAN
- * $Id: aout_esd.c,v 1.20 2002/02/24 20:51:09 gbazin Exp $
+ * $Id: aout_esd.c,v 1.21 2002/02/24 22:06:50 sam Exp $
  *
  * Authors: Samuel Hocevar <sam@zoy.org>
  *
@@ -61,7 +61,7 @@ typedef struct aout_sys_s
  *****************************************************************************/
 static int     aout_Open        ( aout_thread_t *p_aout );
 static int     aout_SetFormat   ( aout_thread_t *p_aout );
-static long    aout_GetBufInfo  ( aout_thread_t *p_aout, long l_buffer_info );
+static int     aout_GetBufInfo  ( aout_thread_t *p_aout, int i_buffer_info );
 static void    aout_Play        ( aout_thread_t *p_aout,
                                   byte_t *buffer, int i_size );
 static void    aout_Close       ( aout_thread_t *p_aout );
@@ -98,8 +98,8 @@ static int aout_Open( aout_thread_t *p_aout )
     }
 
     /* Initialize some variables */
-    p_aout->l_rate = esd_audio_rate; /* We use actual esd rate value, not
-                                     * initial value */
+    p_aout->i_rate = esd_audio_rate; /* We use actual esd rate value, not
+                                      * initial value */
 
     i_bits = ESD_BITS16;
     i_mode = ESD_STREAM;
@@ -119,11 +119,11 @@ static int aout_Open( aout_thread_t *p_aout )
      * and try to open /dev/dsp if there's no EsounD */
     if ( (p_aout->p_sys->i_fd
             = esd_play_stream_fallback(p_aout->p_sys->esd_format,
-                p_aout->l_rate, NULL, "vlc")) < 0 )
+                p_aout->i_rate, NULL, "vlc")) < 0 )
     {
         intf_ErrMsg( "aout error: can't open esound socket"
                      " (format 0x%08x at %ld Hz)",
-                     p_aout->p_sys->esd_format, p_aout->l_rate );
+                     p_aout->p_sys->esd_format, p_aout->i_rate );
         return( -1 );
     }
 
@@ -148,10 +148,10 @@ static int aout_SetFormat( aout_thread_t *p_aout )
 /*****************************************************************************
  * aout_GetBufInfo: buffer status query
  *****************************************************************************/
-static long aout_GetBufInfo( aout_thread_t *p_aout, long l_buffer_limit )
+static int aout_GetBufInfo( aout_thread_t *p_aout, int i_buffer_limit )
 {
     /* arbitrary value that should be changed */
-    return( l_buffer_limit );
+    return( i_buffer_limit );
 }
 
 /*****************************************************************************
@@ -167,22 +167,22 @@ static void aout_Play( aout_thread_t *p_aout, byte_t *buffer, int i_size )
     {
         if (p_aout->p_sys->esd_format & ESD_BITS16)
         {
-            i_amount = (44100 * (ESD_BUF_SIZE + 64)) / p_aout->l_rate;
+            i_amount = (44100 * (ESD_BUF_SIZE + 64)) / p_aout->i_rate;
         }
         else
         {
-            i_amount = (44100 * (ESD_BUF_SIZE + 128)) / p_aout->l_rate;
+            i_amount = (44100 * (ESD_BUF_SIZE + 128)) / p_aout->i_rate;
         }
     }
     else
     {
         if (p_aout->p_sys->esd_format & ESD_BITS16)
         {
-            i_amount = (2 * 44100 * (ESD_BUF_SIZE + 128)) / p_aout->l_rate;
+            i_amount = (2 * 44100 * (ESD_BUF_SIZE + 128)) / p_aout->i_rate;
         }
         else
         {
-            i_amount = (2 * 44100 * (ESD_BUF_SIZE + 256)) / p_aout->l_rate;
+            i_amount = (2 * 44100 * (ESD_BUF_SIZE + 256)) / p_aout->i_rate;
         }
     }
 
index 7b6f6f1f3eb4ebdf05e46f9bedaff23a721d101f..82f0689d2210618aa50ae0a0007cd905bd11f814 100644 (file)
@@ -2,7 +2,7 @@
  * lpcm_decoder_thread.c: lpcm decoder thread
  *****************************************************************************
  * Copyright (C) 1999-2001 VideoLAN
- * $Id: lpcm_adec.c,v 1.12 2002/02/19 00:50:19 sam Exp $
+ * $Id: lpcm_adec.c,v 1.13 2002/02/24 22:06:50 sam Exp $
  *
  * Authors: Samuel Hocevar <sam@zoy.org>
  *          Henri Fallon <henri@videolan.org>
@@ -145,8 +145,8 @@ static int InitThread (lpcmdec_thread_t * p_lpcmdec)
                    NULL, NULL);
 
     /* Creating the audio output fifo */
-    p_lpcmdec->p_aout_fifo = aout_CreateFifo( AOUT_ADEC_STEREO_FIFO, 2, 48000,
-                                            0, LPCMDEC_FRAME_SIZE/2, NULL  );
+    p_lpcmdec->p_aout_fifo = aout_CreateFifo( AOUT_FIFO_PCM, 2, 48000,
+                                              LPCMDEC_FRAME_SIZE/2, NULL  );
     if ( p_lpcmdec->p_aout_fifo == NULL )
     {
         return( -1 );
@@ -164,16 +164,16 @@ void DecodeFrame( lpcmdec_thread_t * p_lpcmdec )
     byte_t byte1, byte2;
 
     CurrentPTS( &p_lpcmdec->bit_stream,
-        &p_lpcmdec->p_aout_fifo->date[p_lpcmdec->p_aout_fifo->l_end_frame],
+        &p_lpcmdec->p_aout_fifo->date[p_lpcmdec->p_aout_fifo->i_end_frame],
         NULL );
-    if( !p_lpcmdec->p_aout_fifo->date[p_lpcmdec->p_aout_fifo->l_end_frame] )
+    if( !p_lpcmdec->p_aout_fifo->date[p_lpcmdec->p_aout_fifo->i_end_frame] )
     {
-        p_lpcmdec->p_aout_fifo->date[p_lpcmdec->p_aout_fifo->l_end_frame] =
+        p_lpcmdec->p_aout_fifo->date[p_lpcmdec->p_aout_fifo->i_end_frame] =
             LAST_MDATE;
     }
 
     buffer = ((byte_t *)p_lpcmdec->p_aout_fifo->buffer) + 
-              (p_lpcmdec->p_aout_fifo->l_end_frame * LPCMDEC_FRAME_SIZE);
+              (p_lpcmdec->p_aout_fifo->i_end_frame * LPCMDEC_FRAME_SIZE);
 
     RemoveBits32(&p_lpcmdec->bit_stream);
     byte1 = GetBits(&p_lpcmdec->bit_stream, 8) ;
@@ -199,8 +199,8 @@ void DecodeFrame( lpcmdec_thread_t * p_lpcmdec )
     }
     
     vlc_mutex_lock (&p_lpcmdec->p_aout_fifo->data_lock);
-    p_lpcmdec->p_aout_fifo->l_end_frame = 
-        (p_lpcmdec->p_aout_fifo->l_end_frame + 1) & AOUT_FIFO_SIZE;
+    p_lpcmdec->p_aout_fifo->i_end_frame = 
+        (p_lpcmdec->p_aout_fifo->i_end_frame + 1) & AOUT_FIFO_SIZE;
     vlc_cond_signal (&p_lpcmdec->p_aout_fifo->data_wait);
     vlc_mutex_unlock (&p_lpcmdec->p_aout_fifo->data_lock);
 }
index 4cc99176900304566795bf8cf452705a3a093816..47b25eb8749d39d7649d0b5a108785ca9195a378 100644 (file)
@@ -2,7 +2,7 @@
  * aout_darwin.c : Darwin audio output plugin
  *****************************************************************************
  * Copyright (C) 2001 VideoLAN
- * $Id: aout_macosx.c,v 1.13 2002/02/19 00:50:19 sam Exp $
+ * $Id: aout_macosx.c,v 1.14 2002/02/24 22:06:50 sam Exp $
  *
  * Authors: Colin Delacroix <colin@zoy.org>
  *
@@ -78,7 +78,7 @@ typedef struct aout_sys_s
  *****************************************************************************/
 static int     aout_Open        ( aout_thread_t *p_aout );
 static int     aout_SetFormat   ( aout_thread_t *p_aout );
-static long    aout_GetBufInfo  ( aout_thread_t *p_aout, long l_buffer_info );
+static int     aout_GetBufInfo  ( aout_thread_t *p_aout, int i_buffer_info );
 static void    aout_Play        ( aout_thread_t *p_aout,
                                   byte_t *buffer, int i_size );
 static void    aout_Close       ( aout_thread_t *p_aout );
@@ -178,7 +178,7 @@ static int aout_Open( aout_thread_t *p_aout )
      * not be forced to compute the same value twice
      */
     p_aout->p_sys->ui_deviceBufferSize = 
-      2 * 2 * sizeof(s16) * ((s64)p_aout->l_rate * AOUT_BUFFER_DURATION) / 1000000; 
+      2 * 2 * sizeof(s16) * ((s64)p_aout->i_rate * AOUT_BUFFER_DURATION) / 1000000; 
  
     /* Allocate memory for audio */
     p_aout->p_sys->p_Data = NewPtrClear( p_aout->p_sys->ui_deviceBufferSize );
@@ -280,7 +280,7 @@ static int aout_SetFormat( aout_thread_t *p_aout )
             // format.mFormatFlags |= kLinearPCMFormatFlagIsFloat;
             // format.mFormatFlags |= kLinearPCMFormatFlagIsSignedInteger;
 
-            format.mSampleRate       = p_aout->l_rate;
+            format.mSampleRate       = p_aout->i_rate;
             format.mChannelsPerFrame = p_aout->i_channels;
 
             err = AudioDeviceSetProperty( p_aout->p_sys->device, 0, 0, false, 
@@ -312,7 +312,7 @@ static int aout_SetFormat( aout_thread_t *p_aout )
 /*****************************************************************************
  * aout_GetBufInfo: returns available bytes in buffer
  *****************************************************************************/
-static long aout_GetBufInfo( aout_thread_t *p_aout, long l_buffer_limit )
+static int aout_GetBufInfo( aout_thread_t *p_aout, int i_buffer_limit )
 {
     return( 0 ); // Send data as soon as possible
 
index f0d7dafd31929c02d2a7f655df9c64d29d4e93bd..9bd34295b2dee66a5517a84622d0b0fc90248380 100644 (file)
@@ -155,7 +155,7 @@ enum mad_flow libmad_input(void *data, struct mad_stream *p_libmad_stream)
  *
  *   intf_ErrMsg( "mad_adec: libmad_header samplerate %d", p_libmad_header->samplerate);
  *
- *   p_mad_adec->p_aout_fifo->l_rate = p_libmad_header->samplerate;
+ *   p_mad_adec->p_aout_fifo->i_rate = p_libmad_header->samplerate;
  *   mad_timer_add(&p_mad_adec->libmad_timer,p_libmad_header->duration);
  *
  *   return MAD_FLOW_CONTINUE;
@@ -300,12 +300,11 @@ enum mad_flow libmad_output(void *data, struct mad_header const *p_libmad_header
     if (p_mad_adec->p_aout_fifo==NULL)
     {
        p_mad_adec->p_aout_fifo = aout_CreateFifo(
-               AOUT_ADEC_STEREO_FIFO,          /* fifo type */
-               p_libmad_pcm->channels,         /* nr. of channels */
-               p_libmad_pcm->samplerate,       /* frame rate in Hz ?*/
-               0,                              /* units */
-                ADEC_FRAME_SIZE,               /* frame size */
-               NULL  );                        /* buffer */
+                AOUT_FIFO_PCM,              /* fifo type */
+                p_libmad_pcm->channels,     /* nr. of channels */
+                p_libmad_pcm->samplerate,   /* frame rate in Hz ?*/
+                ADEC_FRAME_SIZE,            /* frame size */
+                NULL  );                    /* buffer */
 
        if ( p_mad_adec->p_aout_fifo == NULL )
        {
@@ -315,27 +314,27 @@ enum mad_flow libmad_output(void *data, struct mad_header const *p_libmad_header
         intf_ErrMsg("mad_adec debug: in libmad_output aout fifo created");
     }
 
-    if (p_mad_adec->p_aout_fifo->l_rate != p_libmad_pcm->samplerate)
+    if (p_mad_adec->p_aout_fifo->i_rate != p_libmad_pcm->samplerate)
     {
        intf_ErrMsg( "mad_adec: libmad_output samplerate is changing from [%d] Hz to [%d] Hz, sample size [%d], error_code [%0x]",
-                   p_mad_adec->p_aout_fifo->l_rate, p_libmad_pcm->samplerate,
+                   p_mad_adec->p_aout_fifo->i_rate, p_libmad_pcm->samplerate,
                     p_libmad_pcm->length, p_mad_adec->libmad_decoder->sync->stream.error);
-       p_mad_adec->p_aout_fifo->l_rate = p_libmad_pcm->samplerate;
+       p_mad_adec->p_aout_fifo->i_rate = p_libmad_pcm->samplerate;
     }
 
     if( p_mad_adec->i_current_pts )
     {
-        p_mad_adec->p_aout_fifo->date[p_mad_adec->p_aout_fifo->l_end_frame]
+        p_mad_adec->p_aout_fifo->date[p_mad_adec->p_aout_fifo->i_end_frame]
                 = p_mad_adec->i_current_pts;
     }
     else
     {
-        p_mad_adec->p_aout_fifo->date[p_mad_adec->p_aout_fifo->l_end_frame]
+        p_mad_adec->p_aout_fifo->date[p_mad_adec->p_aout_fifo->i_end_frame]
                 = LAST_MDATE;
     }
     mad_timer_add(&p_mad_adec->libmad_timer,p_libmad_header->duration);
 
-    buffer = ((byte_t *)p_mad_adec->p_aout_fifo->buffer) + (p_mad_adec->p_aout_fifo->l_end_frame * MAD_OUTPUT_SIZE);
+    buffer = ((byte_t *)p_mad_adec->p_aout_fifo->buffer) + (p_mad_adec->p_aout_fifo->i_end_frame * MAD_OUTPUT_SIZE);
 
     while (nsamples--)
     {
@@ -384,7 +383,7 @@ enum mad_flow libmad_output(void *data, struct mad_header const *p_libmad_header
     }
 
     vlc_mutex_lock (&p_mad_adec->p_aout_fifo->data_lock);
-    p_mad_adec->p_aout_fifo->l_end_frame = (p_mad_adec->p_aout_fifo->l_end_frame + 1) & AOUT_FIFO_SIZE;
+    p_mad_adec->p_aout_fifo->i_end_frame = (p_mad_adec->p_aout_fifo->i_end_frame + 1) & AOUT_FIFO_SIZE;
     vlc_cond_signal (&p_mad_adec->p_aout_fifo->data_wait);
     vlc_mutex_unlock (&p_mad_adec->p_aout_fifo->data_lock);
 
index a66600c154fbf74cfa3ca9b41558dd5848986cf7..55e7fe4e849c3fb580d72d9755d03a36a5849fb1 100644 (file)
@@ -2,7 +2,7 @@
  * adec_layer1.c: MPEG Layer I audio decoder
  *****************************************************************************
  * Copyright (C) 1999-2001 VideoLAN
- * $Id: adec_layer1.c,v 1.5 2001/12/30 07:09:55 sam Exp $
+ * $Id: adec_layer1.c,v 1.6 2002/02/24 22:06:50 sam Exp $
  *
  * Authors: Michel Kaempf <maxx@via.ecp.fr>
  *          Michel Lespinasse <walken@via.ecp.fr>
@@ -155,8 +155,6 @@ int adec_layer1_mono( adec_thread_t * p_adec, s16 * buffer )
 
     for ( s = 0 ; s < 12; s++)
     {
-        s16 * XXX_buf;
-
         for (i_sb = 0; i_sb < 32; i_sb++)
         {
             if (!allocation[i_sb])
@@ -174,9 +172,8 @@ int adec_layer1_mono( adec_thread_t * p_adec, s16 * buffer )
             }
         }
 
-        DCT32 (sample, &p_adec->bank_0);
-        XXX_buf = buffer;
-        PCM (&p_adec->bank_0, &XXX_buf, 1);
+        DCT32( &p_adec->bank_0, sample );
+        PCM (&p_adec->bank_0, buffer, 1);
         buffer += 32;
     }
 
@@ -291,8 +288,6 @@ int adec_layer1_stereo( adec_thread_t * p_adec, s16 * buffer )
 
     for (s = 0; s < 12; s++)
     {
-        s16 * XXX_buf;
-
         for (i_sb = 0; i_sb < bound; i_sb++)
         {
             if (!allocation_0[i_sb])
@@ -343,12 +338,10 @@ int adec_layer1_stereo( adec_thread_t * p_adec, s16 * buffer )
             }
         }
 
-        DCT32 (sample_0, &p_adec->bank_0);
-        XXX_buf = buffer;
-        PCM (&p_adec->bank_0, &XXX_buf, 2);
-        DCT32 (sample_1, &p_adec->bank_1);
-        XXX_buf = buffer+1;
-        PCM (&p_adec->bank_1, &XXX_buf, 2);
+        DCT32( &p_adec->bank_0, sample_0 );
+        PCM (&p_adec->bank_0, buffer, 2);
+        DCT32( &p_adec->bank_1, sample_1 );
+        PCM (&p_adec->bank_1, buffer + 1, 2);
         buffer += 64;
     }
 
index 73dd904a0101b31b175c3712445b9d93648ca977..b4d9a7c20c35b223a1ddda7bd171db1a46771d8e 100644 (file)
@@ -2,7 +2,7 @@
  * adec_layer2.c: MPEG Layer II audio decoder
  *****************************************************************************
  * Copyright (C) 1999-2001 VideoLAN
- * $Id: adec_layer2.c,v 1.5 2001/12/30 07:09:55 sam Exp $
+ * $Id: adec_layer2.c,v 1.6 2002/02/24 22:06:50 sam Exp $
  *
  * Authors: Michel Kaempf <maxx@via.ecp.fr>
  *          Michel Lespinasse <walken@via.ecp.fr>
@@ -372,8 +372,6 @@ int adec_layer2_mono( adec_thread_t * p_adec, s16 * buffer )
     {
         for (gr1 = 0; gr1 < 4; gr1++)
         {
-            s16 * XXX_buf;
-
             for (sb = 0; sb < sblimit; sb++)
             {
                 int code;
@@ -437,14 +435,12 @@ int adec_layer2_mono( adec_thread_t * p_adec, s16 * buffer )
 
             for (s = 0; s < 3; s++)
             {
-                DCT32 (sample[s], &p_adec->bank_0);
-                XXX_buf = buffer;
-                PCM (&p_adec->bank_0, &XXX_buf, 2);
+                DCT32( &p_adec->bank_0, sample[s] );
+                PCM( &p_adec->bank_0, buffer, 2 );
 
                 /* FIXME: one shouldn't have to do it twice ! */
-                DCT32 (sample[s], &p_adec->bank_1);
-                XXX_buf = buffer+1;
-                PCM (&p_adec->bank_1, &XXX_buf, 2);
+                DCT32( &p_adec->bank_1, sample[s] );
+                PCM( &p_adec->bank_1, buffer + 1, 2 );
 
                 buffer += 64;
             }
@@ -798,8 +794,6 @@ int adec_layer2_stereo( adec_thread_t * p_adec, s16 * buffer )
     {
         for (gr1 = 0; gr1 < 4; gr1++)
         {
-            s16 * XXX_buf;
-
             for (sb = 0; sb < bound; sb++)
             {
                 int code;
@@ -983,13 +977,11 @@ int adec_layer2_stereo( adec_thread_t * p_adec, s16 * buffer )
 
             for (s = 0; s < 3; s++)
             {
-                DCT32 (sample_0[s], &p_adec->bank_0);
-                XXX_buf = buffer;
-                PCM (&p_adec->bank_0, &XXX_buf, 2);
+                DCT32( &p_adec->bank_0, sample_0[s] );
+                PCM( &p_adec->bank_0, buffer, 2 );
 
-                DCT32 (sample_1[s], &p_adec->bank_1);
-                XXX_buf = buffer+1;
-                PCM (&p_adec->bank_1, &XXX_buf, 2);
+                DCT32( &p_adec->bank_1, sample_1[s] );
+                PCM( &p_adec->bank_1, buffer + 1, 2 );
 
                 buffer += 64;
             }
index a68092fa0380a4ed2d518704cc9a6d7b910de78e..039b2246765c7e2fcfa7630ad3a6d5dcc3850a8a 100644 (file)
@@ -2,7 +2,7 @@
  * adec_math.c: Inverse Discrete Cosine Transform and Pulse Code Modulation
  *****************************************************************************
  * Copyright (C) 1999, 2000 VideoLAN
- * $Id: adec_math.c,v 1.1 2001/11/13 12:09:18 henri Exp $
+ * $Id: adec_math.c,v 1.2 2002/02/24 22:06:50 sam Exp $
  *
  * Authors: Michel Kaempf <maxx@via.ecp.fr>
  *          Michel Lespinasse <walken@via.ecp.fr>
@@ -34,7 +34,7 @@
  * See fastdct.ps, and fast.tar.gz for a (Fortran :) implementation.
  *****************************************************************************/
 
-void DCT32(float *x, adec_bank_t *b)
+void DCT32( adec_bank_t *b, float *x )
 {
     /* cosine coefficients */
     static const float c2  =  .70710678118655;
@@ -311,7 +311,7 @@ void DCT32(float *x, adec_bank_t *b)
  * Compute 32 PCM samples with a convolution product
  *****************************************************************************/
 
-void PCM(adec_bank_t *b, s16 **pcm, int jump)
+void PCM(adec_bank_t *b, s16 *p_pcm, int jump)
 {
     /* scale factor */
 #define F -32768
@@ -480,18 +480,18 @@ void PCM(adec_bank_t *b, s16 **pcm, int jump)
                 if ((tmp += *f++ * *v) > 32767)
                 {
                     /* ceiling saturation */
-                    **pcm = 0x7FFF;
+                    *p_pcm = 0x7FFF;
                 }
                 else if (tmp < -32768)
                 {
                     /* floor saturation */
-                    **pcm = 0x8000;
+                    *p_pcm = 0x8000;
                 }
                 else
                 {
-                    **pcm = (s16)tmp;
+                    *p_pcm = (s16)tmp;
                 }
-                *pcm += jump;
+                p_pcm += jump;
                 v += 15;
             }
             break;
@@ -517,17 +517,17 @@ void PCM(adec_bank_t *b, s16 **pcm, int jump)
                 tmp += *f++ * *v--;
                 if ((tmp += *f++ * *v) > 32767)
                 {
-                    **pcm = 0x7FFF;
+                    *p_pcm = 0x7FFF;
                 }
                 else if (tmp < -32768)
                 {
-                    **pcm = 0x8000;
+                    *p_pcm = 0x8000;
                 }
                 else
                 {
-                    **pcm = (s16)tmp;
+                    *p_pcm = (s16)tmp;
                 }
-                *pcm += jump;
+                p_pcm += jump;
                 v += 15;
             }
             break;
@@ -553,17 +553,17 @@ void PCM(adec_bank_t *b, s16 **pcm, int jump)
                 tmp += *f++ * *v--;
                 if ((tmp += *f++ * *v) > 32767)
                 {
-                    **pcm = 0x7FFF;
+                    *p_pcm = 0x7FFF;
                 }
                 else if (tmp < -32768)
                 {
-                    **pcm = 0x8000;
+                    *p_pcm = 0x8000;
                 }
                 else
                 {
-                    **pcm = (s16)tmp;
+                    *p_pcm = (s16)tmp;
                 }
-                *pcm += jump;
+                p_pcm += jump;
                 v += 15;
             }
             break;
@@ -589,17 +589,17 @@ void PCM(adec_bank_t *b, s16 **pcm, int jump)
                 tmp += *f++ * *v--;
                 if ((tmp += *f++ * *v) > 32767)
                 {
-                    **pcm = 0x7FFF;
+                    *p_pcm = 0x7FFF;
                 }
                 else if (tmp < -32768)
                 {
-                    **pcm = 0x8000;
+                    *p_pcm = 0x8000;
                 }
                 else
                 {
-                    **pcm = (s16)tmp;
+                    *p_pcm = (s16)tmp;
                 }
-                *pcm += jump;
+                p_pcm += jump;
                 v += 15;
             }
             break;
@@ -625,17 +625,17 @@ void PCM(adec_bank_t *b, s16 **pcm, int jump)
                 tmp += *f++ * *v--;
                 if ((tmp += *f++ * *v) > 32767)
                 {
-                    **pcm = 0x7FFF;
+                    *p_pcm = 0x7FFF;
                 }
                 else if (tmp < -32768)
                 {
-                    **pcm = 0x8000;
+                    *p_pcm = 0x8000;
                 }
                 else
                 {
-                    **pcm = (s16)tmp;
+                    *p_pcm = (s16)tmp;
                 }
-                *pcm += jump;
+                p_pcm += jump;
                 v += 15;
             }
             break;
@@ -661,17 +661,17 @@ void PCM(adec_bank_t *b, s16 **pcm, int jump)
                 tmp += *f++ * *v--;
                 if ((tmp += *f++ * *v) > 32767)
                 {
-                    **pcm = 0x7FFF;
+                    *p_pcm = 0x7FFF;
                 }
                 else if (tmp < -32768)
                 {
-                    **pcm = 0x8000;
+                    *p_pcm = 0x8000;
                 }
                 else
                 {
-                    **pcm = (s16)tmp;
+                    *p_pcm = (s16)tmp;
                 }
-                *pcm += jump;
+                p_pcm += jump;
                 v += 15;
             }
             break;
@@ -697,17 +697,17 @@ void PCM(adec_bank_t *b, s16 **pcm, int jump)
                 tmp += *f++ * *v--;
                 if ((tmp += *f++ * *v) > 32767)
                 {
-                    **pcm = 0x7FFF;
+                    *p_pcm = 0x7FFF;
                 }
                 else if (tmp < -32768)
                 {
-                    **pcm = 0x8000;
+                    *p_pcm = 0x8000;
                 }
                 else
                 {
-                    **pcm = (s16)tmp;
+                    *p_pcm = (s16)tmp;
                 }
-                *pcm += jump;
+                p_pcm += jump;
                 v += 15;
             }
             break;
@@ -733,17 +733,17 @@ void PCM(adec_bank_t *b, s16 **pcm, int jump)
                 tmp += *f++ * *v--;
                 if ((tmp += *f++ * *v) > 32767)
                 {
-                    **pcm = 0x7FFF;
+                    *p_pcm = 0x7FFF;
                 }
                 else if (tmp < -32768)
                 {
-                    **pcm = 0x8000;
+                    *p_pcm = 0x8000;
                 }
                 else
                 {
-                     **pcm = (s16)tmp;
+                     *p_pcm = (s16)tmp;
                 }
-                *pcm += jump;
+                p_pcm += jump;
                 v += 15;
             }
             break;
@@ -769,17 +769,17 @@ void PCM(adec_bank_t *b, s16 **pcm, int jump)
                 tmp += *f++ * *v--;
                 if ((tmp += *f++ * *v) > 32767)
                 {
-                    **pcm = 0x7FFF;
+                    *p_pcm = 0x7FFF;
                 }
                 else if (tmp < -32768)
                 {
-                    **pcm = 0x8000;
+                    *p_pcm = 0x8000;
                 }
                 else
                 {
-                    **pcm = (s16)tmp;
+                    *p_pcm = (s16)tmp;
                 }
-                *pcm += jump;
+                p_pcm += jump;
                 v += 15;
             }
             break;
@@ -805,17 +805,17 @@ void PCM(adec_bank_t *b, s16 **pcm, int jump)
                 tmp += *f++ * *v--;
                 if ((tmp += *f++ * *v) > 32767)
                 {
-                    **pcm = 0x7FFF;
+                    *p_pcm = 0x7FFF;
                 }
                 else if (tmp < -32768)
                 {
-                    **pcm = 0x8000;
+                    *p_pcm = 0x8000;
                 }
                 else
                 {
-                    **pcm = (s16)tmp;
+                    *p_pcm = (s16)tmp;
                 } 
-                *pcm += jump;
+                p_pcm += jump;
                 v += 15;
             }
             break;
@@ -841,17 +841,17 @@ void PCM(adec_bank_t *b, s16 **pcm, int jump)
                 tmp += *f++ * *v--;
                 if ((tmp += *f++ * *v) > 32767)
                 {
-                    **pcm = 0x7FFF;
+                    *p_pcm = 0x7FFF;
                 }
                 else if (tmp < -32768)
                 {    
-                    **pcm = 0x8000;
+                    *p_pcm = 0x8000;
                 }
                 else
                 {
-                    **pcm = (s16)tmp;
+                    *p_pcm = (s16)tmp;
                 }
-                *pcm += jump;
+                p_pcm += jump;
                 v += 15;
             }
             break;
@@ -877,17 +877,17 @@ void PCM(adec_bank_t *b, s16 **pcm, int jump)
                 tmp += *f++ * *v--;
                 if ((tmp += *f++ * *v) > 32767)
                 {
-                    **pcm = 0x7FFF;
+                    *p_pcm = 0x7FFF;
                 }
                 else if (tmp < -32768)
                 {
-                    **pcm = 0x8000;
+                    *p_pcm = 0x8000;
                 }
                 else
                 {
-                    **pcm = (s16)tmp;
+                    *p_pcm = (s16)tmp;
                 }
-                *pcm += jump;
+                p_pcm += jump;
                 v += 15;
             }
             break;
@@ -913,17 +913,17 @@ void PCM(adec_bank_t *b, s16 **pcm, int jump)
                 tmp += *f++ * *v--;
                 if ((tmp += *f++ * *v) > 32767)
                 {
-                    **pcm = 0x7FFF;
+                    *p_pcm = 0x7FFF;
                 }
                 else if (tmp < -32768)
                 {
-                    **pcm = 0x8000;
+                    *p_pcm = 0x8000;
                 }
                 else
                 {
-                    **pcm = (s16)tmp;
+                    *p_pcm = (s16)tmp;
                 }
-                *pcm += jump;
+                p_pcm += jump;
                 v += 15;
             }
             break;
@@ -949,17 +949,17 @@ void PCM(adec_bank_t *b, s16 **pcm, int jump)
                 tmp += *f++ * *v--;
                 if ((tmp += *f++ * *v) > 32767)
                 {
-                    **pcm = 0x7FFF;
+                    *p_pcm = 0x7FFF;
                 }
                 else if (tmp < -32768)
                 {
-                    **pcm = 0x8000;
+                    *p_pcm = 0x8000;
                 }
                 else
                 {
-                    **pcm = (s16)tmp;
+                    *p_pcm = (s16)tmp;
                 }
-                *pcm += jump;
+                p_pcm += jump;
                 v += 15;
             }
             break;
@@ -985,17 +985,17 @@ void PCM(adec_bank_t *b, s16 **pcm, int jump)
                 v += 15;
                 if ((tmp += *f++ * *v) > 32767)
                 {
-                    **pcm = 0x7FFF;
+                    *p_pcm = 0x7FFF;
                 }
                 else if (tmp < -32768)
                 {
-                    **pcm = 0x8000;
+                    *p_pcm = 0x8000;
                 }
                 else
                 {
-                    **pcm = (s16)tmp;
+                    *p_pcm = (s16)tmp;
                 }
-                *pcm += jump;
+                p_pcm += jump;
                 v += 15;
             }
             break;
@@ -1020,17 +1020,17 @@ void PCM(adec_bank_t *b, s16 **pcm, int jump)
                 tmp += *f++ * *v--;
                 if ((tmp += *f++ * *v) > 32767)
                 {
-                    **pcm = 0x7FFF;
+                    *p_pcm = 0x7FFF;
                 }
                 else if (tmp < -32768)
                 {
-                    **pcm = 0x8000;
+                    *p_pcm = 0x8000;
                 }
                 else
                 {
-                    **pcm = (s16)tmp;
+                    *p_pcm = (s16)tmp;
                 }
-                *pcm += jump;
+                p_pcm += jump;
                 v += 31;
             }
             break;
index 14e34222e0ff7969659d3dda2c68808f8f1d0326..11cd49a9bb56ed5437a25b10f859e41aa589620c 100644 (file)
@@ -2,7 +2,7 @@
  * adec_math.h : PCM and DCT
  *****************************************************************************
  * Copyright (C) 1999, 2000 VideoLAN
- * $Id: adec_math.h,v 1.1 2001/11/13 12:09:18 henri Exp $
+ * $Id: adec_math.h,v 1.2 2002/02/24 22:06:50 sam Exp $
  *
  * Authors: Michel Kaempf <maxx@via.ecp.fr>
  *
@@ -24,6 +24,6 @@
 /*****************************************************************************
  * Prototypes
  *****************************************************************************/
-void     DCT32(float *x, adec_bank_t *b);
-void     PCM(adec_bank_t *b, s16 **pcm, int jump);
+void     DCT32 ( adec_bank_t *, float * );
+void     PCM   ( adec_bank_t *, s16 *, int );
 
index 6d3e2041eae963facdf92c6b092aaee1da5c6c84..a171a654e8d41f722d294f5be1daf231d42f4a9a 100644 (file)
@@ -2,7 +2,7 @@
  * mpeg_adec.c: MPEG audio decoder thread
  *****************************************************************************
  * Copyright (C) 1999-2001 VideoLAN
- * $Id: mpeg_adec.c,v 1.20 2002/02/24 20:51:10 gbazin Exp $
+ * $Id: mpeg_adec.c,v 1.21 2002/02/24 22:06:50 sam Exp $
  *
  * Authors: Michel Kaempf <maxx@via.ecp.fr>
  *          Michel Lespinasse <walken@via.ecp.fr>
@@ -157,7 +157,7 @@ static int decoder_Run ( decoder_config_t * p_config )
  *****************************************************************************/
 static void DecodeThread( adec_thread_t * p_adec )
 {
-    s16 * buffer;
+    s16 *p_buffer;
     adec_sync_info_t sync_info;
 
     if( ! adec_SyncFrame (p_adec, &sync_info) )
@@ -168,31 +168,26 @@ static void DecodeThread( adec_thread_t * p_adec )
         /* Create the output fifo if it doesn't exist yet */
         if( p_adec->p_aout_fifo == NULL )
         {
-            int fifo_type;
-            int channels;
+            int i_channels;
             
             if( p_main->b_stereo )
             {
                 intf_WarnMsg( 4, "adec info: setting stereo output" );
-                fifo_type = AOUT_ADEC_STEREO_FIFO;
-                channels = 2;
+                i_channels = 2;
             }
             else if( sync_info.b_stereo )
             {
-                fifo_type = AOUT_ADEC_STEREO_FIFO;
-                channels = 2;
+                i_channels = 2;
             }
             else
             {
-                fifo_type = AOUT_ADEC_MONO_FIFO;
-                channels = 1;
+                i_channels = 1;
             }
-            p_adec->p_aout_fifo = aout_CreateFifo( fifo_type, channels,
-                    sync_info.sample_rate, 0, ADEC_FRAME_SIZE, NULL );
+            p_adec->p_aout_fifo = aout_CreateFifo( AOUT_FIFO_PCM, i_channels,
+                    sync_info.sample_rate, ADEC_FRAME_SIZE, NULL );
             if( p_adec->p_aout_fifo == NULL)
             {
-                intf_ErrMsg( "adec error: failed to create Audio Output "
-                        "Fifo." );
+                intf_ErrMsg( "adec error: failed to create aout fifo" );
                 p_adec->p_fifo->b_error = 1;
                 return;
             }
@@ -200,19 +195,19 @@ static void DecodeThread( adec_thread_t * p_adec )
 
         p_adec->i_sync = 1;
 
-        buffer = ((s16 *)p_adec->p_aout_fifo->buffer)
-                    + (p_adec->p_aout_fifo->l_end_frame * ADEC_FRAME_SIZE);
+        p_buffer = ((s16 *)p_adec->p_aout_fifo->buffer)
+                    + (p_adec->p_aout_fifo->i_end_frame * ADEC_FRAME_SIZE);
 
         CurrentPTS( &p_adec->bit_stream,
-            &p_adec->p_aout_fifo->date[p_adec->p_aout_fifo->l_end_frame],
+            &p_adec->p_aout_fifo->date[p_adec->p_aout_fifo->i_end_frame],
             NULL );
-        if( !p_adec->p_aout_fifo->date[p_adec->p_aout_fifo->l_end_frame] )
+        if( !p_adec->p_aout_fifo->date[p_adec->p_aout_fifo->i_end_frame] )
         {
-            p_adec->p_aout_fifo->date[p_adec->p_aout_fifo->l_end_frame] =
+            p_adec->p_aout_fifo->date[p_adec->p_aout_fifo->i_end_frame] =
                 LAST_MDATE;
         }
 
-        if( adec_DecodeFrame (p_adec, buffer) )
+        if( adec_DecodeFrame (p_adec, p_buffer) )
         {
             /* Ouch, failed decoding... We'll have to resync */
             p_adec->i_sync = 0;
@@ -220,8 +215,8 @@ static void DecodeThread( adec_thread_t * p_adec )
         else
         {
             vlc_mutex_lock (&p_adec->p_aout_fifo->data_lock);
-            p_adec->p_aout_fifo->l_end_frame =
-                (p_adec->p_aout_fifo->l_end_frame + 1) & AOUT_FIFO_SIZE;
+            p_adec->p_aout_fifo->i_end_frame =
+                (p_adec->p_aout_fifo->i_end_frame + 1) & AOUT_FIFO_SIZE;
             vlc_cond_signal (&p_adec->p_aout_fifo->data_wait);
             vlc_mutex_unlock (&p_adec->p_aout_fifo->data_lock);
         }
index 07d2017b2e30a6639561a55b5f32a1c03cbdc605..8a892ee829ab681b31135e4cc9eeb7259c541acf 100644 (file)
@@ -47,7 +47,7 @@ typedef struct aout_sys_s
  *****************************************************************************/
 static int     aout_Open        ( aout_thread_t *p_aout );
 static int     aout_SetFormat   ( aout_thread_t *p_aout );
-static long    aout_GetBufInfo  ( aout_thread_t *p_aout, long l_buffer_info );
+static int     aout_GetBufInfo  ( aout_thread_t *p_aout, int i_buffer_info );
 static void    aout_Play        ( aout_thread_t *p_aout,
                                   byte_t *buffer, int i_size );
 static void    aout_Close       ( aout_thread_t *p_aout );
@@ -144,7 +144,7 @@ static int aout_SetFormat( aout_thread_t *p_aout )
     pp.buf.block.frags_min   = 1;
     
     pp.format.interleave     = 1;
-    pp.format.rate           = p_aout->l_rate;
+    pp.format.rate           = p_aout->i_rate;
     pp.format.voices         = p_aout->i_channels;
 
     switch( p_aout->i_format )
@@ -161,7 +161,7 @@ static int aout_SetFormat( aout_thread_t *p_aout )
     }
 
     pp.buf.block.frag_size =
-        (((s64)p_aout->l_rate * AOUT_BUFFER_DURATION) / 1000000) *
+        (((s64)p_aout->i_rate * AOUT_BUFFER_DURATION) / 1000000) *
         p_aout->i_channels * i_bytes_per_sample;
 
     /* set parameters */
@@ -193,7 +193,7 @@ static int aout_SetFormat( aout_thread_t *p_aout )
  * of data to play, it switches to the "underrun" status. It has to
  * be flushed and re-prepared
  *****************************************************************************/
-static long aout_GetBufInfo( aout_thread_t *p_aout, long l_buffer_limit )
+static int aout_GetBufInfo( aout_thread_t *p_aout, int i_buffer_limit )
 {
     int i_ret;
     snd_pcm_channel_status_t status;
index 28743655bbd4d1b30a404dd833c45a328b44540d..2150b7e3afbb5c0f41b4f2088a10a7619f08d79b 100644 (file)
@@ -2,7 +2,7 @@
  * aout_sdl.c : audio sdl functions library
  *****************************************************************************
  * Copyright (C) 1999-2001 VideoLAN
- * $Id: aout_sdl.c,v 1.26 2002/02/24 20:51:10 gbazin Exp $
+ * $Id: aout_sdl.c,v 1.27 2002/02/24 22:06:50 sam Exp $
  *
  * Authors: Michel Kaempf <maxx@via.ecp.fr>
  *          Samuel Hocevar <sam@zoy.org>
@@ -63,7 +63,7 @@ typedef struct aout_sys_s
  *****************************************************************************/
 static int     aout_Open        ( aout_thread_t *p_aout );
 static int     aout_SetFormat   ( aout_thread_t *p_aout );
-static long    aout_GetBufInfo  ( aout_thread_t *p_aout, long l_buffer_info );
+static int     aout_GetBufInfo  ( aout_thread_t *p_aout, int i_buffer_info );
 static void    aout_Play        ( aout_thread_t *p_aout,
                                   byte_t *buffer, int i_size );
 static void    aout_Close       ( aout_thread_t *p_aout );
@@ -92,7 +92,6 @@ void _M( aout_getfunctions )( function_list_t * p_function_list )
 static int aout_Open( aout_thread_t *p_aout )
 {
     SDL_AudioSpec desired;
-    int i_channels = p_aout->b_stereo ? 2 : 1;
 
     if( SDL_WasInit( SDL_INIT_AUDIO ) != 0 )
     {
@@ -130,12 +129,12 @@ static int aout_Open( aout_thread_t *p_aout )
     p_aout->p_sys->audio_buf = malloc( OVERFLOWLIMIT );
 
     /* Initialize some variables */
-    desired.freq =     p_aout->l_rate;
 
     /* TODO: write conversion beetween AOUT_FORMAT_DEFAULT
      * AND AUDIO* from SDL. */
+    desired.freq       = p_aout->i_rate;
     desired.format     = AUDIO_S16LSB;                     /* stereo 16 bits */
-    desired.channels   = i_channels;
+    desired.channels   = p_aout->i_channels;
     desired.callback   = aout_SDLCallback;
     desired.userdata   = p_aout->p_sys;
     desired.samples    = 1024;
@@ -171,12 +170,11 @@ static int aout_SetFormat( aout_thread_t *p_aout )
 {
     /* TODO: finish and clean this */
     SDL_AudioSpec desired;
-    int i_stereo = p_aout->b_stereo ? 2 : 1;
 
     /*i_format = p_aout->i_format;*/
-    desired.freq       = p_aout->l_rate;             /* Set the output rate */
+    desired.freq       = p_aout->i_rate;             /* Set the output rate */
     desired.format     = AUDIO_S16LSB;                    /* stereo 16 bits */
-    desired.channels   = i_stereo;
+    desired.channels   = p_aout->i_channels;
     desired.callback   = aout_SDLCallback;
     desired.userdata   = p_aout->p_sys;
     desired.samples    = 2048;
@@ -201,16 +199,16 @@ static int aout_SetFormat( aout_thread_t *p_aout )
  * aout_GetBufInfo: buffer status query
  *****************************************************************************
  * returns the number of bytes in the audio buffer compared to the size of
- * l_buffer_limit...
+ * i_buffer_limit...
  *****************************************************************************/
-static long aout_GetBufInfo( aout_thread_t *p_aout, long l_buffer_limit )
+static int aout_GetBufInfo( aout_thread_t *p_aout, int i_buffer_limit )
 {
-    if(l_buffer_limit > p_aout->p_sys->i_audio_end)
+    if(i_buffer_limit > p_aout->p_sys->i_audio_end)
     {
         /* returning 0 here juste gives awful sound in the speakers :/ */
-        return( l_buffer_limit );
+        return( i_buffer_limit );
     }
-    return( p_aout->p_sys->i_audio_end - l_buffer_limit);
+    return( p_aout->p_sys->i_audio_end - i_buffer_limit);
 }
 
 /*****************************************************************************
index 65dfb2953ab0b52537e62b924f95aa38c69ac0eb..9aedf7df22a17da3c72217a3981984476c72223b 100644 (file)
@@ -2,7 +2,7 @@
  * waveout.c : Windows waveOut plugin for vlc
  *****************************************************************************
  * Copyright (C) 2001 VideoLAN
- * $Id: waveout.c,v 1.3 2002/02/24 20:51:10 gbazin Exp $
+ * $Id: waveout.c,v 1.4 2002/02/24 22:06:50 sam Exp $
  *
  * Authors: Gildas Bazin <gbazin@netcourrier.com>
  *      
@@ -88,7 +88,7 @@ typedef struct aout_sys_s
  *****************************************************************************/
 static int     aout_Open        ( aout_thread_t *p_aout );
 static int     aout_SetFormat   ( aout_thread_t *p_aout );
-static long    aout_GetBufInfo  ( aout_thread_t *p_aout, long l_buffer_info );
+static int     aout_GetBufInfo  ( aout_thread_t *p_aout, int i_buffer_info );
 static void    aout_Play        ( aout_thread_t *p_aout,
                                   byte_t *buffer, int i_size );
 static void    aout_Close       ( aout_thread_t *p_aout );
@@ -153,7 +153,7 @@ static int aout_SetFormat( aout_thread_t *p_aout )
     /* Check if the format has changed */
 
     if( (p_aout->p_sys->waveformat.nChannels != p_aout->i_channels) ||
-        (p_aout->p_sys->waveformat.nSamplesPerSec != p_aout->l_rate) )
+        (p_aout->p_sys->waveformat.nSamplesPerSec != p_aout->i_rate) )
     {
         if( waveOutClose( p_aout->p_sys->h_waveout ) == MMSYSERR_NOERROR )
         {
@@ -172,7 +172,7 @@ static int aout_SetFormat( aout_thread_t *p_aout )
  * returns the number of bytes in the audio buffer that have not yet been
  * sent to the sound device.
  *****************************************************************************/
-static long aout_GetBufInfo( aout_thread_t *p_aout, long l_buffer_limit )
+static int aout_GetBufInfo( aout_thread_t *p_aout, int i_buffer_limit )
 {
     MMTIME mmtime;
 
@@ -181,7 +181,7 @@ static long aout_GetBufInfo( aout_thread_t *p_aout, long l_buffer_limit )
         != MMSYSERR_NOERROR || (mmtime.wType != TIME_BYTES) )
     {
         intf_WarnMsg( 3, "aout: aout_GetBufInfo waveOutGetPosition failed");
-        return l_buffer_limit;
+        return i_buffer_limit;
     }
 
 
@@ -281,7 +281,7 @@ static int OpenWaveOutDevice( aout_thread_t *p_aout )
     /* Set sound format */
     p_aout->p_sys->waveformat.wFormatTag       = WAVE_FORMAT_PCM;
     p_aout->p_sys->waveformat.nChannels        = p_aout->i_channels;
-    p_aout->p_sys->waveformat.nSamplesPerSec   = p_aout->l_rate;
+    p_aout->p_sys->waveformat.nSamplesPerSec   = p_aout->i_rate;
     p_aout->p_sys->waveformat.wBitsPerSample   = 16;
     p_aout->p_sys->waveformat.nBlockAlign      =
         p_aout->p_sys->waveformat.wBitsPerSample / 8 * p_aout->i_channels;
diff --git a/src/audio_output/aout_common.c b/src/audio_output/aout_common.c
deleted file mode 100644 (file)
index a8860ce..0000000
+++ /dev/null
@@ -1,217 +0,0 @@
-/*****************************************************************************
- * aout_common.c: generic audio output functions
- *****************************************************************************
- * Copyright (C) 1999-2002 VideoLAN
- * $Id: aout_common.c,v 1.3 2002/02/19 00:50:19 sam Exp $
- *
- * Authors: Michel Kaempf <maxx@via.ecp.fr>
- *          Cyril Deguet <asmax@via.ecp.fr>
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- * 
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
- *****************************************************************************/
-
-/*****************************************************************************
- * Preamble
- *****************************************************************************/
-#include <stdio.h>                                           /* "intf_msg.h" */
-#include <stdlib.h>                            /* calloc(), malloc(), free() */
-#include <string.h>
-
-#include <videolan/vlc.h>
-
-#include "audio_output.h"
-#include "aout_common.h"
-
-
-/*****************************************************************************
- * Local prototypes
- *****************************************************************************/
-static int NextFrame( aout_thread_t * p_aout, aout_fifo_t * p_fifo,
-        mtime_t aout_date );
-/*****************************************************************************
- * Functions
- *****************************************************************************/
-
-/* Read data from decoder fifo, and put it in S32_buffer */
-void aout_FillBuffer( aout_thread_t * p_aout, aout_fifo_t * p_fifo )
-{
-    long l_buffer = 0;
-    long l_buffer_limit, l_units;
-
-    switch ( p_fifo->i_type )
-    {
-    case AOUT_EMPTY_FIFO:
-
-        break;
-
-    case AOUT_ADEC_MONO_FIFO:
-    case AOUT_ADEC_STEREO_FIFO:
-
-        l_units = p_aout->l_units;
-        while ( l_units > 0 )
-        {
-            if( !p_fifo->b_next_frame )
-            {
-                if( NextFrame(p_aout, p_fifo, p_aout->date + 
-                        ((((mtime_t)(l_buffer >> 1)) * 1000000) / 
-                        ((mtime_t)p_aout->l_rate))) )
-                {
-                    break;
-                }
-            }
-            l_buffer_limit = p_aout->l_units << p_aout->b_stereo;
-
-            while ( l_buffer < l_buffer_limit )
-            {
-                if( p_aout->b_stereo )
-                {
-                    p_aout->s32_buffer[l_buffer++] +=
-                        (s32)( ((s16 *)p_fifo->buffer)[2*p_fifo->l_unit] );
-                    p_aout->s32_buffer[l_buffer++] +=
-                        (s32)( ((s16 *)p_fifo->buffer)[2*p_fifo->l_unit+1] );
-                }
-                else
-                {
-                    p_aout->s32_buffer[l_buffer++] +=
-                        (s32)( ((s16 *)p_fifo->buffer)[p_fifo->l_unit] );
-                }
-
-                UpdateIncrement(&p_fifo->unit_increment, &p_fifo->l_unit);
-
-                if( p_fifo->l_unit >= ((AOUT_FIFO_SIZE + 1) * 
-                        (p_fifo->l_frame_size >> p_fifo->b_stereo)) )
-                {
-                    p_fifo->l_unit -= ((AOUT_FIFO_SIZE + 1) * 
-                            (p_fifo->l_frame_size >> p_fifo->b_stereo));
-                }
-            }
-            if( p_fifo->l_units > l_units )
-            {
-                p_fifo->l_units -= l_units;
-                break;
-            }
-            else
-            {
-                l_units -= p_fifo->l_units;
-
-                vlc_mutex_lock( &p_fifo->data_lock );
-                p_fifo->l_start_frame = p_fifo->l_next_frame;
-                vlc_cond_signal( &p_fifo->data_wait );
-                vlc_mutex_unlock( &p_fifo->data_lock );
-
-                /* p_fifo->b_start_frame = 1; */
-                p_fifo->l_next_frame += 1;
-                p_fifo->l_next_frame &= AOUT_FIFO_SIZE;
-                p_fifo->b_next_frame = 0;
-            }
-        }
-        break;
-
-    default:
-
-        intf_ErrMsg("aout error: unknown fifo type (%i)", p_fifo->i_type);
-        break;
-    }
-}
-
-/* Following functions are local */
-
-static int NextFrame( aout_thread_t * p_aout, aout_fifo_t * p_fifo,
-        mtime_t aout_date )
-{
-    long l_units, l_rate;
-    u64 l_delta;    
-
-    /* We take the lock */
-    vlc_mutex_lock( &p_fifo->data_lock );
-
-    /* Are we looking for a dated start frame ? */
-    if ( !p_fifo->b_start_frame )
-    {
-        while ( p_fifo->l_start_frame != p_fifo->l_end_frame )
-        {
-            if ( p_fifo->date[p_fifo->l_start_frame] != LAST_MDATE )
-            {
-                p_fifo->b_start_frame = 1;
-                p_fifo->l_next_frame = (p_fifo->l_start_frame + 1) & 
-                        AOUT_FIFO_SIZE;
-                p_fifo->l_unit = p_fifo->l_start_frame * 
-                        (p_fifo->l_frame_size >> (p_fifo->b_stereo));
-                break;
-            }
-            p_fifo->l_start_frame = (p_fifo->l_start_frame + 1) & 
-                    AOUT_FIFO_SIZE;
-        }
-
-        if ( p_fifo->l_start_frame == p_fifo->l_end_frame )
-        {
-            vlc_mutex_unlock( &p_fifo->data_lock );
-            return( -1 );
-        }
-    }
-
-    /* We are looking for the next dated frame */
-    /* FIXME : is the output fifo full ?? */
-    while ( !p_fifo->b_next_frame )
-    {
-        while ( p_fifo->l_next_frame != p_fifo->l_end_frame )
-        {
-            if ( p_fifo->date[p_fifo->l_next_frame] != LAST_MDATE )
-            {
-                p_fifo->b_next_frame = 1;
-                break;
-            }
-            p_fifo->l_next_frame = (p_fifo->l_next_frame + 1) & AOUT_FIFO_SIZE;
-        }
-
-        while ( p_fifo->l_next_frame == p_fifo->l_end_frame )
-        {
-            vlc_cond_wait( &p_fifo->data_wait, &p_fifo->data_lock );
-            if ( p_fifo->b_die )
-            {
-                vlc_mutex_unlock( &p_fifo->data_lock );
-                return( -1 );
-            }
-        }
-    }
-
-    l_units = ((p_fifo->l_next_frame - p_fifo->l_start_frame) & 
-            AOUT_FIFO_SIZE) * (p_fifo->l_frame_size >> (p_fifo->b_stereo));
-
-    l_delta = aout_date - p_fifo->date[p_fifo->l_start_frame];
-
-/* Resample if delta is too long */
-    if( abs(l_delta) > MAX_DELTA )
-    {
-        l_rate = p_fifo->l_rate + (l_delta / 256);
-    }
-    else
-    {
-        l_rate = p_fifo->l_rate;
-    }
-
-    InitializeIncrement( &p_fifo->unit_increment, l_rate, p_aout->l_rate );
-
-    p_fifo->l_units = (((l_units - (p_fifo->l_unit -
-            (p_fifo->l_start_frame * (p_fifo->l_frame_size >> 
-            (p_fifo->b_stereo))))) * p_aout->l_rate) / l_rate) + 1;
-
-    /* We release the lock before leaving */
-    vlc_mutex_unlock( &p_fifo->data_lock );
-    return( 0 );
-}
-
diff --git a/src/audio_output/aout_common.h b/src/audio_output/aout_common.h
deleted file mode 100644 (file)
index ea6f8c0..0000000
+++ /dev/null
@@ -1,146 +0,0 @@
-/*****************************************************************************
- * aout_common.h: audio output inner functions
- *****************************************************************************
- * Copyright (C) 1999, 2000, 2001 VideoLAN
- * $Id: aout_common.h,v 1.9 2002/01/15 11:51:11 asmax Exp $
- *
- * Authors: Michel Kaempf <maxx@via.ecp.fr>
- *          Cyril Deguet <asmax@via.ecp.fr>   
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- * 
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
- *****************************************************************************/
-
-
-/* Biggest difference allowed between scheduled playing date and actual date 
-   (in microseconds) */
-#define MAX_DELTA 10000
-
-
-/* Creating as many aout_Thread functions as configurations was one solution,
- * examining the different cases in the Thread loop of an unique function was
- * another. I chose the first solution. */
-void aout_U8Thread            ( aout_thread_t * p_aout );
-void aout_S8Thread            ( aout_thread_t * p_aout );
-void aout_U16Thread           ( aout_thread_t * p_aout );
-void aout_S16Thread           ( aout_thread_t * p_aout );
-void aout_SpdifThread         ( aout_thread_t * p_aout );
-void aout_FillBuffer          ( aout_thread_t * p_aout, aout_fifo_t * p_fifo );
-
-
-/* Generic main thread function "aout_XXXThread"
- */
-#define DECLARE_AOUT_THREAD( format, type, buffer_copy )                      \
-void aout_##format##Thread( aout_thread_t * p_aout )                          \
-{                                                                             \
-                                                                              \
-    int i_fifo;                                                               \
-    long l_buffer, l_buffer_limit, l_bytes;                                   \
-                                                                              \
-    /* As the s32_buffer was created with calloc(), we don't have to set this \
-     * memory to zero and we can immediately jump into the thread's loop */   \
-    while ( ! p_aout->b_die )                                                 \
-    {                                                                         \
-        vlc_mutex_lock( &p_aout->fifos_lock );                                \
-                                                                              \
-        for ( i_fifo = 0; i_fifo < AOUT_MAX_FIFOS; i_fifo++ )                 \
-        {                                                                     \
-            if( p_aout->fifo[i_fifo].b_die )                                  \
-            {                                                                 \
-                aout_FreeFifo( &p_aout->fifo[i_fifo] );                       \
-            }                                                                 \
-            else                                                              \
-            {                                                                 \
-                aout_FillBuffer( p_aout, &p_aout->fifo[i_fifo] );             \
-            }                                                                 \
-        }                                                                     \
-                                                                              \
-        vlc_mutex_unlock( &p_aout->fifos_lock );                              \
-                                                                              \
-        l_buffer_limit = p_aout->l_units << p_aout->b_stereo;                 \
-                                                                              \
-        for ( l_buffer = 0; l_buffer < l_buffer_limit; l_buffer++ )           \
-        {                                                                     \
-            ((type *)p_aout->buffer)[l_buffer] = (type)( buffer_copy *        \
-                    p_aout->i_volume / 256 );                                 \
-             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 + 4 *                  \
-                p_aout->i_latency) /                                          \
-                (sizeof(type) << p_aout->b_stereo))) * 1000000) /             \
-                ((mtime_t)p_aout->l_rate)) + p_main->i_desync;                \
-                                                                              \
-        p_aout->pf_play( p_aout, (byte_t *)p_aout->buffer, l_buffer_limit *   \
-                sizeof(type) );                                               \
-                                                                              \
-        if ( l_bytes > (l_buffer_limit * sizeof(type)) )                      \
-        {                                                                     \
-            msleep( p_aout->l_msleep );                                       \
-        }                                                                     \
-    }                                                                         \
-                                                                              \
-    vlc_mutex_lock( &p_aout->fifos_lock );                                    \
-                                                                              \
-    for ( i_fifo = 0; i_fifo < AOUT_MAX_FIFOS; i_fifo++ )                     \
-    {                                                                         \
-        aout_FreeFifo( &p_aout->fifo[i_fifo] );                               \
-    }                                                                         \
-                                                                              \
-    vlc_mutex_unlock( &p_aout->fifos_lock );                                  \
-                                                                              \
-}                                                                             \
-
-
-/*****************************************************************************
- * InitializeIncrement
- *****************************************************************************/
-static __inline__ void InitializeIncrement( aout_increment_t * p_increment,
-                                            long l_numerator,
-                                            long l_denominator )
-{
-    p_increment->l_remainder = -l_denominator;
-
-    p_increment->l_euclidean_integer = 0;
-    while ( l_numerator >= l_denominator )
-    {
-        p_increment->l_euclidean_integer++;
-        l_numerator -= l_denominator;
-    }
-
-    p_increment->l_euclidean_remainder = l_numerator;
-
-    p_increment->l_euclidean_denominator = l_denominator;
-}
-
-
-/*****************************************************************************
- * UpdateIncrement
- *****************************************************************************/
-static __inline__ void UpdateIncrement( aout_increment_t * p_increment, 
-        long * p_integer )
-{
-    if( (p_increment->l_remainder += p_increment->l_euclidean_remainder) >= 0 )
-    {
-        *p_integer += p_increment->l_euclidean_integer + 1;
-        p_increment->l_remainder -= p_increment->l_euclidean_denominator;
-    }
-    else
-    {
-        *p_integer += p_increment->l_euclidean_integer;
-    }
-}
-
index 3b635ac953a756c39d5dc0cdca0785eac5ab3428..dd02f46d06e9d3e43d643fb122ca448996a4108c 100644 (file)
@@ -2,7 +2,7 @@
  * aout_ext-dec.c : exported fifo management functions
  *****************************************************************************
  * Copyright (C) 1999-2001 VideoLAN
- * $Id: aout_ext-dec.c,v 1.12 2002/02/15 13:32:54 sam Exp $
+ * $Id: aout_ext-dec.c,v 1.13 2002/02/24 22:06:50 sam Exp $
  *
  * Authors: Michel Kaempf <maxx@via.ecp.fr>
  *          Cyril Deguet <asmax@via.ecp.fr>
 #include <videolan/vlc.h>
 
 #include "audio_output.h"
-#include "aout_common.h"
 
 /*****************************************************************************
  * aout_CreateFifo
  *****************************************************************************/
-aout_fifo_t * aout_CreateFifo( int i_type, int i_channels, long l_rate,
-                               long l_units, long l_frame_size,
-                               void *p_buffer )
+aout_fifo_t * aout_CreateFifo( int i_format, int i_channels, int i_rate,
+                               int i_frame_size, void *p_buffer )
 {
     aout_thread_t *p_aout;
-    int i_fifo;
-
-    intf_WarnMsg( 3, "aout info: fifo type %d, %d channels, rate %d, "
-                     "%d units, frame size %d",
-                     i_type, i_channels, l_rate, l_units, l_frame_size );
+    aout_fifo_t   *p_fifo = NULL;
+    int i_index;
 
     /* Spawn an audio output if there is none */
     vlc_mutex_lock( &p_aout_bank->lock );
@@ -55,7 +50,7 @@ aout_fifo_t * aout_CreateFifo( int i_type, int i_channels, long l_rate,
     {
         intf_WarnMsg( 1, "aout: no aout present, spawning one" );
 
-        p_aout = aout_CreateThread( NULL, i_channels, l_rate );
+        p_aout = aout_CreateThread( NULL, i_channels, i_rate );
 
         /* Everything failed */
         if( p_aout == NULL )
@@ -69,13 +64,13 @@ aout_fifo_t * aout_CreateFifo( int i_type, int i_channels, long l_rate,
     }
     /* temporary hack to switch output type (mainly for spdif)
      * FIXME: to be adapted when several output are available */
-    else if( p_aout_bank->pp_aout[0]->fifo[0].i_type != i_type )
+    else if( p_aout_bank->pp_aout[0]->fifo[0].i_format != i_format )
     {
         intf_WarnMsg( 1, "aout: changing aout type" );
 
         aout_DestroyThread( p_aout_bank->pp_aout[0], NULL );
 
-        p_aout = aout_CreateThread( NULL, i_channels, l_rate );
+        p_aout = aout_CreateThread( NULL, i_channels, i_rate );
 
         /* Everything failed */
         if( p_aout == NULL )
@@ -85,7 +80,6 @@ aout_fifo_t * aout_CreateFifo( int i_type, int i_channels, long l_rate,
         }
 
         p_aout_bank->pp_aout[0] = p_aout;
-
     }
     else
     {
@@ -96,18 +90,18 @@ aout_fifo_t * aout_CreateFifo( int i_type, int i_channels, long l_rate,
     /* Take the fifos lock */
     vlc_mutex_lock( &p_aout->fifos_lock );
 
-    /* Looking for a free fifo structure */
-    for( i_fifo = 0; i_fifo < AOUT_MAX_FIFOS; i_fifo++ )
+    /* Look for a free fifo structure */
+    for( i_index = 0; i_index < AOUT_MAX_FIFOS; i_index++ )
     {
-        if( p_aout->fifo[i_fifo].i_type == AOUT_EMPTY_FIFO )
+        if( p_aout->fifo[i_index].i_format == AOUT_FIFO_NONE )
         {
-            /* Not very clever, but at least we know which fifo it is */
-            p_aout->fifo[i_fifo].i_fifo = i_fifo;
+            p_fifo = &p_aout->fifo[i_index];
+            p_fifo->i_fifo = i_index;
             break;
         }
     }
 
-    if( i_fifo == AOUT_MAX_FIFOS )
+    if( p_fifo == NULL )
     {
         intf_ErrMsg( "aout error: no fifo available" );
         vlc_mutex_unlock( &p_aout->fifos_lock );
@@ -116,65 +110,56 @@ aout_fifo_t * aout_CreateFifo( int i_type, int i_channels, long l_rate,
     }
 
     /* Initialize the new fifo structure */
-    switch ( p_aout->fifo[i_fifo].i_type = i_type )
+    switch ( p_fifo->i_format = i_format )
     {
-        case AOUT_ADEC_MONO_FIFO:
-        case AOUT_ADEC_STEREO_FIFO:
-        case AOUT_ADEC_SPDIF_FIFO:
-            p_aout->fifo[i_fifo].b_die = 0;
-
-            p_aout->fifo[i_fifo].i_channels = i_channels;
-            p_aout->fifo[i_fifo].b_stereo = ( i_channels == 2 );
-            p_aout->fifo[i_fifo].l_rate = l_rate;
-
-            p_aout->fifo[i_fifo].l_frame_size = l_frame_size;
-            /* Allocate the memory needed to store the audio frames. As the
-             * fifo is a rotative fifo, we must be able to find out whether
-             * the fifo is full or empty, that's why we must in fact allocate
-             * memory for (AOUT_FIFO_SIZE+1) audio frames. */
-            p_aout->fifo[i_fifo].buffer = malloc( sizeof(s16) *
-                                   ( AOUT_FIFO_SIZE + 1 ) * l_frame_size );
-            if ( p_aout->fifo[i_fifo].buffer == NULL )
+        case AOUT_FIFO_PCM:
+        case AOUT_FIFO_SPDIF:
+            p_fifo->b_die = 0;
+
+            p_fifo->i_channels = i_channels;
+            p_fifo->i_rate = i_rate;
+            p_fifo->i_frame_size = i_frame_size;
+
+            p_fifo->i_unit_limit = (AOUT_FIFO_SIZE + 1)
+                                     * (i_frame_size / i_channels);
+
+            /* Allocate the memory needed to store the audio frames and their
+             * dates. As the fifo is a rotative fifo, we must be able to find
+             * out whether the fifo is full or empty, that's why we must in
+             * fact allocate memory for (AOUT_FIFO_SIZE+1) audio frames. */
+            p_fifo->date = malloc( ( sizeof(s16) * i_frame_size 
+                                      + sizeof(mtime_t) )
+                                   * ( AOUT_FIFO_SIZE + 1 ) );
+            if ( p_fifo->date == NULL )
             {
-                intf_ErrMsg( "aout error: cannot create frame buffer" );
-                p_aout->fifo[i_fifo].i_type = AOUT_EMPTY_FIFO;
+                intf_ErrMsg( "aout error: cannot create fifo data" );
+                p_fifo->i_format = AOUT_FIFO_NONE;
                 vlc_mutex_unlock( &p_aout->fifos_lock );
                 vlc_mutex_unlock( &p_aout_bank->lock );
                 return( NULL );
             }
 
-            /* Allocate the memory needed to store the dates of the frames */
-            p_aout->fifo[i_fifo].date =
-                           malloc( sizeof(mtime_t) * ( AOUT_FIFO_SIZE +  1) );
-
-            if ( p_aout->fifo[i_fifo].date == NULL )
-            {
-                intf_ErrMsg( "aout error: cannot create date buffer");
-                free( p_aout->fifo[i_fifo].buffer );
-                p_aout->fifo[i_fifo].i_type = AOUT_EMPTY_FIFO;
-                vlc_mutex_unlock( &p_aout->fifos_lock );
-                vlc_mutex_unlock( &p_aout_bank->lock );
-                return( NULL );
-            }
+            p_fifo->buffer = (void *)p_fifo->date + sizeof(mtime_t)
+                                                     * ( AOUT_FIFO_SIZE + 1 );
 
             /* Set the fifo's buffer as empty (the first frame that is to be
              * played is also the first frame that is not to be played) */
-            p_aout->fifo[i_fifo].l_start_frame = 0;
-            /* p_aout->fifo[i_fifo].l_next_frame = 0; */
-            p_aout->fifo[i_fifo].l_end_frame = 0;
+            p_fifo->i_start_frame = 0;
+            /* p_fifo->i_next_frame = 0; */
+            p_fifo->i_end_frame = 0;
 
             /* Waiting for the audio decoder to compute enough frames to work
              * out the fifo's current rate (as soon as the decoder has decoded
              * enough frames, the members of the fifo structure that are not
              * initialized now will be calculated) */
-            p_aout->fifo[i_fifo].b_start_frame = 0;
-            p_aout->fifo[i_fifo].b_next_frame = 0;
+            p_fifo->b_start_frame = 0;
+            p_fifo->b_next_frame = 0;
             break;
 
         default:
             intf_ErrMsg( "aout error: unknown fifo type 0x%x",
-                         p_aout->fifo[i_fifo].i_type );
-            p_aout->fifo[i_fifo].i_type = AOUT_EMPTY_FIFO;
+                         p_fifo->i_format );
+            p_fifo->i_format = AOUT_FIFO_NONE;
             vlc_mutex_unlock( &p_aout->fifos_lock );
             vlc_mutex_unlock( &p_aout_bank->lock );
             return( NULL );
@@ -184,12 +169,12 @@ aout_fifo_t * aout_CreateFifo( int i_type, int i_channels, long l_rate,
     vlc_mutex_unlock( &p_aout->fifos_lock );
     vlc_mutex_unlock( &p_aout_bank->lock );
 
-    intf_WarnMsg( 2, "aout info: fifo #%i allocated, %i channels, rate %li",
-                  p_aout->fifo[i_fifo].i_fifo, p_aout->fifo[i_fifo].i_channels,
-                  p_aout->fifo[i_fifo].l_rate );
+    intf_WarnMsg( 2, "aout info: fifo #%i allocated, %i channels, rate %li, "
+                     "frame size %i", p_fifo->i_fifo, p_fifo->i_channels,
+                     p_fifo->i_rate, p_fifo->i_frame_size );
 
     /* Return the pointer to the fifo structure */
-    return( &p_aout->fifo[i_fifo] );
+    return( p_fifo );
 }
 
 /*****************************************************************************
@@ -207,19 +192,17 @@ void aout_DestroyFifo( aout_fifo_t * p_fifo )
  *****************************************************************************/
 void aout_FreeFifo( aout_fifo_t * p_fifo )
 {
-    switch ( p_fifo->i_type )
+    switch ( p_fifo->i_format )
     {
-        case AOUT_EMPTY_FIFO:
+        case AOUT_FIFO_NONE:
 
             break;
 
-        case AOUT_ADEC_MONO_FIFO:
-        case AOUT_ADEC_STEREO_FIFO:
-        case AOUT_ADEC_SPDIF_FIFO:
+        case AOUT_FIFO_PCM:
+        case AOUT_FIFO_SPDIF:
 
-            free( p_fifo->buffer );
             free( p_fifo->date );
-            p_fifo->i_type = AOUT_EMPTY_FIFO;
+            p_fifo->i_format = AOUT_FIFO_NONE;
 
             break;
 
diff --git a/src/audio_output/aout_pcm.c b/src/audio_output/aout_pcm.c
new file mode 100644 (file)
index 0000000..f7c9f5f
--- /dev/null
@@ -0,0 +1,382 @@
+/*****************************************************************************
+ * aout_pcm.c: PCM audio output functions
+ *****************************************************************************
+ * Copyright (C) 1999-2002 VideoLAN
+ * $Id: aout_pcm.c,v 1.1 2002/02/24 22:06:50 sam Exp $
+ *
+ * Authors: Michel Kaempf <maxx@via.ecp.fr>
+ *          Cyril Deguet <asmax@via.ecp.fr>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ * 
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
+ *****************************************************************************/
+
+/*****************************************************************************
+ * Preamble
+ *****************************************************************************/
+#include <stdio.h>                                           /* "intf_msg.h" */
+#include <stdlib.h>                            /* calloc(), malloc(), free() */
+#include <string.h>
+
+#include <videolan/vlc.h>
+
+#include "audio_output.h"
+#include "aout_pcm.h"
+
+/* Biggest difference allowed between scheduled playing date and actual date 
+   (in microseconds) */
+#define MAX_DELTA 10000
+
+/*****************************************************************************
+ * Local prototypes
+ *****************************************************************************/
+static void FillBuffer( aout_thread_t * p_aout, aout_fifo_t * p_fifo );
+static int  NextFrame ( aout_thread_t * p_aout, aout_fifo_t * p_fifo,
+                        mtime_t aout_date );
+
+ /*****************************************************************************
+ * Functions
+ *****************************************************************************/
+void aout_PCMThread( aout_thread_t * p_aout )
+{
+    int i_fifo;
+    int i_buffer, i_buffer_limit, i_bytes;
+
+    /* As the s32_buffer was created with calloc(), we don't have to set this
+     * memory to zero and we can immediately jump into the thread's loop */
+    while ( ! p_aout->b_die )
+    {
+        vlc_mutex_lock( &p_aout->fifos_lock );
+        for ( i_fifo = 0; i_fifo < AOUT_MAX_FIFOS; i_fifo++ )
+        {
+            if( p_aout->fifo[i_fifo].b_die )
+            {
+                aout_FreeFifo( &p_aout->fifo[i_fifo] );
+            }
+            else
+            {
+                FillBuffer( p_aout, &p_aout->fifo[i_fifo] );
+            }
+        }
+        vlc_mutex_unlock( &p_aout->fifos_lock );
+
+        i_buffer_limit = p_aout->i_units * p_aout->i_channels;
+
+        switch ( p_aout->i_format )
+        {
+        case AOUT_FMT_U8:
+            for ( i_buffer = 0; i_buffer < i_buffer_limit; i_buffer++ )
+            {
+                ((u8*)p_aout->buffer)[i_buffer] = (u8)(
+                  (p_aout->s32_buffer[i_buffer] / AOUT_MAX_FIFOS / 256 + 128)
+                     * p_aout->i_volume / 256);
+                 p_aout->s32_buffer[i_buffer] = 0;
+            }
+            break;
+
+        case AOUT_FMT_S8:
+            for ( i_buffer = 0; i_buffer < i_buffer_limit; i_buffer++ )
+            {
+                ((s8*)p_aout->buffer)[i_buffer] = (s8)(
+                  p_aout->s32_buffer[i_buffer] / AOUT_MAX_FIFOS / 256
+                     * p_aout->i_volume / 256);
+                 p_aout->s32_buffer[i_buffer] = 0;
+            }
+            break;
+
+        case AOUT_FMT_U16_LE:
+        case AOUT_FMT_U16_BE:
+            for ( i_buffer = 0; i_buffer < i_buffer_limit; i_buffer++ )
+            {
+                ((u16*)p_aout->buffer)[i_buffer] = (u16)(
+                  (p_aout->s32_buffer[i_buffer] / AOUT_MAX_FIFOS + 128)
+                     * p_aout->i_volume / 256);
+                 p_aout->s32_buffer[i_buffer] = 0;
+            }
+            break;
+
+        case AOUT_FMT_S16_LE:
+        case AOUT_FMT_S16_BE:
+            for ( i_buffer = 0; i_buffer < i_buffer_limit; i_buffer++ )
+            {
+                ((s16*)p_aout->buffer)[i_buffer] = (s16)(
+                  p_aout->s32_buffer[i_buffer] / AOUT_MAX_FIFOS
+                     * p_aout->i_volume / 256);
+                 p_aout->s32_buffer[i_buffer] = 0;
+            }
+            break;
+        }
+
+        i_bytes = p_aout->pf_getbufinfo( p_aout, i_buffer_limit );
+
+        switch ( p_aout->i_format )
+        {
+        case AOUT_FMT_U8:
+        case AOUT_FMT_S8:
+            p_aout->date = mdate() + ((((mtime_t)((i_bytes + 4 *
+                p_aout->i_latency) / p_aout->i_channels)) * 1000000) /
+                ((mtime_t)p_aout->i_rate)) + p_main->i_desync;
+
+            p_aout->pf_play( p_aout, (byte_t *)p_aout->buffer,
+                             i_buffer_limit );
+            break;
+
+        case AOUT_FMT_U16_LE:
+        case AOUT_FMT_U16_BE:
+        case AOUT_FMT_S16_LE:
+        case AOUT_FMT_S16_BE:
+            p_aout->date = mdate() + ((((mtime_t)((i_bytes + 4 *
+                p_aout->i_latency) / (2 * p_aout->i_channels))) * 1000000) /
+                ((mtime_t)p_aout->i_rate)) + p_main->i_desync;
+
+            p_aout->pf_play( p_aout, (byte_t *)p_aout->buffer,
+                             i_buffer_limit * 2 );
+            break;
+        }
+
+        if ( i_bytes > i_buffer_limit )
+        {
+            msleep( p_aout->i_msleep );
+        }
+    }
+
+    vlc_mutex_lock( &p_aout->fifos_lock );
+    for ( i_fifo = 0; i_fifo < AOUT_MAX_FIFOS; i_fifo++ )
+    {
+        aout_FreeFifo( &p_aout->fifo[i_fifo] );
+    }
+    vlc_mutex_unlock( &p_aout->fifos_lock );
+}
+
+/* Following functions are local */
+
+/*****************************************************************************
+ * InitializeIncrement: change i_x/i_y to i_a+i_b/i_c
+ *****************************************************************************/
+static __inline__ void InitializeIncrement( aout_increment_t * p_inc,
+                                            int i_x, int i_y )
+{
+    p_inc->i_r = -i_y;
+    p_inc->i_a = 0;
+
+    while ( i_x >= i_y )
+    {
+        p_inc->i_a++;
+        i_x -= i_y;
+    }
+
+    p_inc->i_b = i_x;
+    p_inc->i_c = i_y;
+}
+
+/*****************************************************************************
+ * UpdateIncrement
+ *****************************************************************************/
+static __inline__ void UpdateIncrement( aout_increment_t * p_inc, 
+                                        int * pi_integer )
+{
+    if( (p_inc->i_r += p_inc->i_b) >= 0 )
+    {
+        *pi_integer += p_inc->i_a + 1;
+        p_inc->i_r -= p_inc->i_c;
+    }
+    else
+    {
+        *pi_integer += p_inc->i_a;
+    }
+}
+
+/*****************************************************************************
+ * FillBuffer: Read data from decoder fifo, and put it in S32_buffer
+ *****************************************************************************/
+static void FillBuffer( aout_thread_t * p_aout, aout_fifo_t * p_fifo )
+{
+    int i_buffer = 0;
+    int i_buffer_limit, i_units;
+
+    switch ( p_fifo->i_format )
+    {
+    case AOUT_FIFO_PCM:
+
+        i_units = p_aout->i_units;
+
+        /* While there are empty frames in the buffer, fill them */
+        while ( i_units > 0 )
+        {
+            /* If there is no next frame, wait for one */
+            if( !p_fifo->b_next_frame )
+            {
+                if( NextFrame(p_aout, p_fifo, p_aout->date + 
+                        ((((mtime_t)(i_buffer >> 1)) * 1000000) / 
+                        ((mtime_t)p_aout->i_rate))) )
+                {
+                    break;
+                }
+            }
+
+            i_buffer_limit = p_aout->i_units * p_aout->i_channels;
+
+            while ( i_buffer < i_buffer_limit )
+            {
+                /* FIXME: make this more generic */
+                if( p_aout->i_channels == 2 )
+                {
+                    p_aout->s32_buffer[i_buffer++] +=
+                        (s32)( ((s16 *)p_fifo->buffer)[2*p_fifo->i_unit] );
+                    p_aout->s32_buffer[i_buffer++] +=
+                        (s32)( ((s16 *)p_fifo->buffer)[2*p_fifo->i_unit+1] );
+                }
+                else if( p_aout->i_channels == 1 )
+                {
+                    p_aout->s32_buffer[i_buffer++] +=
+                        (s32)( ((s16 *)p_fifo->buffer)[p_fifo->i_unit] );
+                }
+                else
+                {
+                    intf_ErrMsg( "aout error: unsupported number of channels" );
+                }
+
+                UpdateIncrement(&p_fifo->unit_increment, &p_fifo->i_unit);
+
+                if( p_fifo->i_unit >= p_fifo->i_unit_limit )
+                {
+                    p_fifo->i_unit -= p_fifo->i_unit_limit;
+                }
+            }
+            if( p_fifo->i_units > i_units )
+            {
+                p_fifo->i_units -= i_units;
+                break;
+            }
+            else
+            {
+                i_units -= p_fifo->i_units;
+
+                vlc_mutex_lock( &p_fifo->data_lock );
+                p_fifo->i_start_frame = p_fifo->i_next_frame;
+             /* p_fifo->b_start_frame = 1; */
+                p_fifo->i_next_frame = AOUT_FIFO_INC( p_fifo->i_next_frame );
+                p_fifo->b_next_frame = 0;
+                vlc_cond_signal( &p_fifo->data_wait );
+                vlc_mutex_unlock( &p_fifo->data_lock );
+
+            }
+        }
+        break;
+
+    default:
+        break;
+    }
+}
+
+static int NextFrame( aout_thread_t * p_aout, aout_fifo_t * p_fifo,
+                      mtime_t aout_date )
+{
+    int i_units, i_units_dist, i_rate;
+    u64 i_delta;    
+
+    /* We take the lock */
+    vlc_mutex_lock( &p_fifo->data_lock );
+
+    /* Are we looking for a dated start frame ? */
+    if ( !p_fifo->b_start_frame )
+    {
+        while ( p_fifo->i_start_frame != p_fifo->i_end_frame )
+        {
+            if ( p_fifo->date[p_fifo->i_start_frame] != LAST_MDATE )
+            {
+                p_fifo->b_start_frame = 1;
+                p_fifo->i_next_frame = AOUT_FIFO_INC( p_fifo->i_start_frame );
+                p_fifo->i_unit = p_fifo->i_start_frame * 
+                        (p_fifo->i_frame_size / p_fifo->i_channels);
+                break;
+            }
+            p_fifo->i_start_frame = AOUT_FIFO_INC( p_fifo->i_start_frame );
+        }
+
+        if ( p_fifo->i_start_frame == p_fifo->i_end_frame )
+        {
+            vlc_mutex_unlock( &p_fifo->data_lock );
+            return( -1 );
+        }
+    }
+
+    /* We are looking for the next dated frame */
+    /* FIXME : is the output fifo full ?? -- pretty unlikely given its size */
+    while ( !p_fifo->b_next_frame )
+    {
+        while ( p_fifo->i_next_frame != p_fifo->i_end_frame )
+        {
+            if ( p_fifo->date[p_fifo->i_next_frame] != LAST_MDATE )
+            {
+                p_fifo->b_next_frame = 1;
+                break;
+            }
+            p_fifo->i_next_frame = AOUT_FIFO_INC( p_fifo->i_next_frame );
+        }
+
+        while ( p_fifo->i_next_frame == p_fifo->i_end_frame )
+        {
+            vlc_cond_wait( &p_fifo->data_wait, &p_fifo->data_lock );
+            if ( p_fifo->b_die )
+            {
+                vlc_mutex_unlock( &p_fifo->data_lock );
+                return( -1 );
+            }
+        }
+    }
+
+    i_units = ((p_fifo->i_next_frame - p_fifo->i_start_frame) & AOUT_FIFO_SIZE)
+               * (p_fifo->i_frame_size / p_fifo->i_channels);
+
+    i_delta = aout_date - p_fifo->date[p_fifo->i_start_frame];
+
+    /* Resample if delta is too long */
+    if( abs(i_delta) > MAX_DELTA )
+    {
+        i_rate = p_fifo->i_rate + (i_delta / 256);
+    }
+    else
+    {
+        i_rate = p_fifo->i_rate;
+    }
+
+    InitializeIncrement( &p_fifo->unit_increment, i_rate, p_aout->i_rate );
+
+    /* Calculate how many units we're going to write */
+    i_units_dist = p_fifo->i_unit - p_fifo->i_start_frame
+                                * (p_fifo->i_frame_size / p_fifo->i_channels);
+
+    /* Manage the fifo wrapping */
+    if( i_units_dist > p_fifo->i_unit_limit / 2 )
+    {
+        i_units -= (i_units_dist - p_fifo->i_unit_limit);
+    }
+    else if( i_units_dist < - p_fifo->i_unit_limit / 2 )
+    {
+        i_units -= (i_units_dist + p_fifo->i_unit_limit);
+    }
+    else
+    {
+        i_units -= i_units_dist;
+    }
+
+    p_fifo->i_units = 1 + ( i_units * p_aout->i_rate / i_rate );
+
+    /* We release the lock before leaving */
+    vlc_mutex_unlock( &p_fifo->data_lock );
+    return( 0 );
+}
+
diff --git a/src/audio_output/aout_pcm.h b/src/audio_output/aout_pcm.h
new file mode 100644 (file)
index 0000000..4571685
--- /dev/null
@@ -0,0 +1,26 @@
+/*****************************************************************************
+ * aout_pcm.h: PCM audio output functions
+ *****************************************************************************
+ * Copyright (C) 1999-2002 VideoLAN
+ * $Id: aout_pcm.h,v 1.1 2002/02/24 22:06:50 sam Exp $
+ *
+ * Authors: Michel Kaempf <maxx@via.ecp.fr>
+ *          Cyril Deguet <asmax@via.ecp.fr>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ * 
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
+ *****************************************************************************/
+
+void aout_PCMThread( aout_thread_t * p_aout );
+
index 7063fc67453c09208b8b7fdbf188fabbb5a7199c..e5fdff758949368f35fa4e35be1f79dfaf388aee 100644 (file)
@@ -1,8 +1,8 @@
 /*****************************************************************************
- * aout_spdif: ac3 passthrough output
+ * aout_spdif.c: AC3 passthrough output
  *****************************************************************************
  * Copyright (C) 2001 VideoLAN
- * $Id: aout_spdif.c,v 1.22 2002/02/19 00:50:19 sam Exp $
+ * $Id: aout_spdif.c,v 1.23 2002/02/24 22:06:50 sam Exp $
  *
  * Authors: Michel Kaempf <maxx@via.ecp.fr>
  *          Stéphane Borel <stef@via.ecp.fr>
@@ -32,7 +32,7 @@
 #include <videolan/vlc.h>
 
 #include "audio_output.h"
-#include "aout_common.h"
+#include "aout_spdif.h"
 
 /*****************************************************************************
  * aout_SpdifThread: audio output thread that sends raw spdif data
  *****************************************************************************/
 void aout_SpdifThread( aout_thread_t * p_aout )
 {
-  int         i_fifo;
-  mtime_t     m_frame_time = 0;
-  mtime_t     m_play;
-  mtime_t     m_old = 0;
+    int         i_fifo;
+    mtime_t     m_frame_time = 0;
+    mtime_t     m_play;
+    mtime_t     m_old = 0;
 
-
-  while( !p_aout->b_die )
-  {
-    for( i_fifo = 0 ; i_fifo < AOUT_MAX_FIFOS ; i_fifo++ )
+    while( !p_aout->b_die )
     {
-      /* the loop read each fifo so that we can change the stream
-       * on the fly but mulitplexing is not handled yet so
-       * the sound will be broken is more than one fifo has data */ 
-      /* TODO: write the muliplexer :) */
-      if( p_aout->fifo[i_fifo].i_type == AOUT_ADEC_SPDIF_FIFO )
-      {
-        vlc_mutex_lock( &p_aout->fifo[i_fifo].data_lock );
-        if( p_aout->fifo[i_fifo].b_die )
+        for( i_fifo = 0 ; i_fifo < AOUT_MAX_FIFOS ; i_fifo++ )
         {
-          vlc_mutex_unlock( &p_aout->fifo[i_fifo].data_lock );
-
-          vlc_mutex_lock( &p_aout->fifos_lock );
-          aout_FreeFifo( &p_aout->fifo[i_fifo] );
-          vlc_mutex_unlock( &p_aout->fifos_lock );
-        }
-        else if( !AOUT_FIFO_ISEMPTY( p_aout->fifo[i_fifo] ) )
-        {
-          /* Copy data from fifo to buffer to release the lock earlier */
-          memcpy( p_aout->buffer,
-                  (byte_t *)p_aout->fifo[i_fifo].buffer
-                          + p_aout->fifo[i_fifo].l_start_frame
-                          * SPDIF_FRAME_SIZE,
-                  SPDIF_FRAME_SIZE );
-
-          m_play = p_aout->fifo[i_fifo].date[p_aout->fifo[i_fifo].
-                       l_start_frame];
-
-          p_aout->fifo[i_fifo].l_start_frame =
-              (p_aout->fifo[i_fifo].l_start_frame + 1 )
-              & AOUT_FIFO_SIZE;
-
-          /* Compute the theorical duration of an ac3 frame */
-          m_frame_time = 1000000 * AC3_FRAME_SIZE
-                                 / p_aout->fifo[i_fifo].l_rate;
-
-          vlc_mutex_unlock( &p_aout->fifo[i_fifo].data_lock );
-
-          /* play spdif frame to the external decoder 
-           * the kernel driver will sleep until the
-           * dsp buffer is empty enough to accept the data */
-          if( m_play > ( mdate() - m_frame_time ) )
-          {
-            /* check continuity */
-            if( (m_play - m_old) != m_frame_time )
+            /* the loop read each fifo so that we can change the stream
+             * on the fly but mulitplexing is not handled yet so
+             * the sound will be broken is more than one fifo has data */ 
+            /* TODO: write the muliplexer :) */
+            if( p_aout->fifo[i_fifo].i_format == AOUT_FIFO_SPDIF )
             {
-              mwait( m_play - m_frame_time );
+                vlc_mutex_lock( &p_aout->fifo[i_fifo].data_lock );
+                if( p_aout->fifo[i_fifo].b_die )
+                {
+                    vlc_mutex_unlock( &p_aout->fifo[i_fifo].data_lock );
+
+                    vlc_mutex_lock( &p_aout->fifos_lock );
+                    aout_FreeFifo( &p_aout->fifo[i_fifo] );
+                    vlc_mutex_unlock( &p_aout->fifos_lock );
+                }
+                else if( !AOUT_FIFO_ISEMPTY( p_aout->fifo[i_fifo] ) )
+                {
+                    /* Copy data from fifo to buffer to release the
+                     * lock earlier */
+                    FAST_MEMCPY( p_aout->buffer,
+                                 (byte_t *)p_aout->fifo[i_fifo].buffer
+                                         + p_aout->fifo[i_fifo].i_start_frame
+                                         * SPDIF_FRAME_SIZE,
+                                 SPDIF_FRAME_SIZE );
+
+                    m_play = p_aout->fifo[i_fifo].date[p_aout->fifo[i_fifo].
+                                 i_start_frame];
+
+                    p_aout->fifo[i_fifo].i_start_frame =
+                        (p_aout->fifo[i_fifo].i_start_frame + 1 )
+                        & AOUT_FIFO_SIZE;
+
+                    /* Compute the theorical duration of an ac3 frame */
+                    m_frame_time = 1000000 * AC3_FRAME_SIZE
+                                           / p_aout->fifo[i_fifo].i_rate;
+
+                    vlc_mutex_unlock( &p_aout->fifo[i_fifo].data_lock );
+
+                    /* play spdif frame to the external decoder 
+                     * the kernel driver will sleep until the
+                     * dsp buffer is empty enough to accept the data */
+                    if( m_play > ( mdate() - m_frame_time ) )
+                    {
+                        /* check continuity */
+                        if( (m_play - m_old) != m_frame_time )
+                        {
+                            mwait( m_play - m_frame_time );
+                        }
+                        else
+                        {
+                            mwait( m_play - 2 * m_frame_time );
+                        }
+                        m_old = m_play;
+
+                        p_aout->pf_play( p_aout, (byte_t *)p_aout->buffer,
+                                         SPDIF_FRAME_SIZE );
+                    }
+                }
+                else
+                {
+                    vlc_mutex_unlock( &p_aout->fifo[i_fifo].data_lock );
+                    msleep( m_frame_time );
+                    intf_WarnMsg( 3, "aout warning: empty spdif fifo" );
+                }
             }
-            else
-            {
-              mwait( m_play - 2 * m_frame_time );
-            }
-            m_old = m_play;
-
-            p_aout->pf_play( p_aout,
-                             (byte_t *)p_aout->buffer,
-                             SPDIF_FRAME_SIZE );
-          }
-        }
-        else
-        {
-          vlc_mutex_unlock( &p_aout->fifo[i_fifo].data_lock );
-          msleep( m_frame_time );
-          intf_WarnMsg( 3, "aout warning: empty spdif fifo" );
         }
-      }
     }
-  }
 
-  vlc_mutex_lock( &p_aout->fifos_lock );
-
-  for ( i_fifo = 0; i_fifo < AOUT_MAX_FIFOS; i_fifo++ )
-  {
-    aout_FreeFifo( &p_aout->fifo[i_fifo] );
-  }
-
-  vlc_mutex_unlock( &p_aout->fifos_lock );
+    vlc_mutex_lock( &p_aout->fifos_lock );
+    for ( i_fifo = 0; i_fifo < AOUT_MAX_FIFOS; i_fifo++ )
+    {
+        aout_FreeFifo( &p_aout->fifo[i_fifo] );
+    }
+    vlc_mutex_unlock( &p_aout->fifos_lock );
 
-  return;
+    return;
 }
 
index a5917bb1879e7b0e886ee4d8aaf62724abea8ef9..c8f2d21c0c2023bf57cd084cac1c5ad4146287aa 100644 (file)
@@ -2,7 +2,7 @@
  * audio_output.c : audio output thread
  *****************************************************************************
  * Copyright (C) 1999-2001 VideoLAN
- * $Id: audio_output.c,v 1.77 2002/02/24 20:51:10 gbazin Exp $
+ * $Id: audio_output.c,v 1.78 2002/02/24 22:06:50 sam Exp $
  *
  * Authors: Michel Kaempf <maxx@via.ecp.fr>
  *          Cyril Deguet <asmax@via.ecp.fr>
 #endif
 
 #include "audio_output.h"
-#include "aout_common.h"
+
+#include "aout_pcm.h"
+#include "aout_spdif.h"
 
 /*****************************************************************************
  * Local prototypes
  *****************************************************************************/
-static int aout_SpawnThread( aout_thread_t * p_aout );
+static int  aout_SpawnThread ( aout_thread_t * p_aout );
 
 /*****************************************************************************
  * aout_InitBank: initialize the audio output bank.
@@ -78,7 +80,7 @@ void aout_EndBank ( void )
 /*****************************************************************************
  * aout_CreateThread: initialize audio thread
  *****************************************************************************/
-aout_thread_t *aout_CreateThread( int *pi_status, int i_channels, long l_rate )
+aout_thread_t *aout_CreateThread( int *pi_status, int i_channels, int i_rate )
 {
     aout_thread_t * p_aout;                             /* thread descriptor */
 #if 0
@@ -93,12 +95,9 @@ aout_thread_t *aout_CreateThread( int *pi_status, int i_channels, long l_rate )
     }
 
     p_aout->i_latency = 0;
-    p_aout->l_rate = config_GetIntVariable( AOUT_RATE_VAR );
+    p_aout->i_rate = config_GetIntVariable( AOUT_RATE_VAR );
     p_aout->i_channels = config_GetIntVariable( AOUT_MONO_VAR ) ? 1 : 2;
 
-    intf_WarnMsg( 3, "aout info: thread created, channels %d, rate %d",
-                  p_aout->i_channels, p_aout->l_rate );
-    
     /* Maybe we should pass this setting in argument */
     p_aout->i_format = AOUT_FORMAT_DEFAULT;
 
@@ -110,16 +109,13 @@ aout_thread_t *aout_CreateThread( int *pi_status, int i_channels, long l_rate )
         p_aout->i_format = AOUT_FMT_AC3;
     }
     
-    if( p_aout->l_rate == 0 )
+    if( p_aout->i_rate == 0 )
     {
         intf_ErrMsg( "aout error: null sample rate" );
         free( p_aout );
         return( NULL );
     }
 
-    /* FIXME: only works for i_channels == 1 or 2 ?? */
-    p_aout->b_stereo = ( p_aout->i_channels == 2 ) ? 1 : 0;
-
     /* Choose the best module */
     p_aout->p_module = module_Need( MODULE_CAPABILITY_AOUT,
                            config_GetPszVariable( AOUT_METHOD_VAR ), 
@@ -169,31 +165,14 @@ aout_thread_t *aout_CreateThread( int *pi_status, int i_channels, long l_rate )
     return( p_aout );
 }
 
-
-/*****************************************************************************
- * Declare the different aout thread functions
- *****************************************************************************/
-DECLARE_AOUT_THREAD( S16, s16, ( p_aout->s32_buffer[l_buffer] / 
-        AOUT_MAX_FIFOS ) )
-
-DECLARE_AOUT_THREAD( U16, u16, (( p_aout->s32_buffer[l_buffer] / 
-        AOUT_MAX_FIFOS) + 128) )
-        
-DECLARE_AOUT_THREAD( U8, u8, (( p_aout->s32_buffer[l_buffer] / 
-        AOUT_MAX_FIFOS / 256) + 128 ) )
-
-DECLARE_AOUT_THREAD( S8, s8, ( p_aout->s32_buffer[l_buffer] / 
-        AOUT_MAX_FIFOS / 256) )
-        
-
 /*****************************************************************************
  * aout_SpawnThread
  *****************************************************************************/
 static int aout_SpawnThread( aout_thread_t * p_aout )
 {
-    int     i_fifo;
-    long    l_bytes;
+    int     i_index, i_bytes;
     void (* pf_aout_thread)( aout_thread_t * ) = NULL;
+    char   *psz_format;
 
     /* We want the audio output thread to live */
     p_aout->b_die = 0;
@@ -201,121 +180,74 @@ static int aout_SpawnThread( aout_thread_t * p_aout )
 
     /* Initialize the fifos lock */
     vlc_mutex_init( &p_aout->fifos_lock );
+
     /* Initialize audio fifos : set all fifos as empty and initialize locks */
-    for ( i_fifo = 0; i_fifo < AOUT_MAX_FIFOS; i_fifo++ )
+    for ( i_index = 0; i_index < AOUT_MAX_FIFOS; i_index++ )
     {
-        p_aout->fifo[i_fifo].i_type = AOUT_EMPTY_FIFO;
-        vlc_mutex_init( &p_aout->fifo[i_fifo].data_lock );
-        vlc_cond_init( &p_aout->fifo[i_fifo].data_wait );
+        p_aout->fifo[i_index].i_format = AOUT_FIFO_NONE;
+        vlc_mutex_init( &p_aout->fifo[i_index].data_lock );
+        vlc_cond_init( &p_aout->fifo[i_index].data_wait );
     }
 
     /* Compute the size (in audio units) of the audio output buffer. Although
      * AOUT_BUFFER_DURATION is given in microseconds, the output rate is given
      * in Hz, that's why we need to divide by 10^6 microseconds (1 second) */
-    p_aout->l_units = (long)( ((s64)p_aout->l_rate * AOUT_BUFFER_DURATION) / 1000000 );
-    p_aout->l_msleep = (long)( ((s64)p_aout->l_units * 1000000) / (s64)p_aout->l_rate );
+    p_aout->i_units = ((s64)p_aout->i_rate * AOUT_BUFFER_DURATION) / 1000000;
+    p_aout->i_msleep = AOUT_BUFFER_DURATION / 4;
 
     /* Make pf_aout_thread point to the right thread function, and compute the
      * byte size of the audio output buffer */
-    switch ( p_aout->i_channels )
+    switch ( p_aout->i_format )
     {
-    /* Audio output is mono */
-    case 1:
-        switch ( p_aout->i_format )
-        {
-        case AOUT_FMT_U8:
-            intf_WarnMsg( 2, "aout info: unsigned 8 bits mono thread" );
-            l_bytes = 1 * sizeof(u8) * p_aout->l_units;
-            pf_aout_thread = aout_U8Thread;
-            break;
-
-        case AOUT_FMT_S8:
-            intf_WarnMsg( 2, "aout info: signed 8 bits mono thread" );
-            l_bytes = 1 * sizeof(s8) * p_aout->l_units;
-            pf_aout_thread = aout_S8Thread;
-            break;
-
-        case AOUT_FMT_U16_LE:
-        case AOUT_FMT_U16_BE:
-            intf_WarnMsg( 2, "aout info: unsigned 16 bits mono thread" );
-            l_bytes = 1 * sizeof(u16) * p_aout->l_units;
-            pf_aout_thread = aout_U16Thread;
-            break;
-
-        case AOUT_FMT_S16_LE:
-        case AOUT_FMT_S16_BE:
-            intf_WarnMsg( 2, "aout info: signed 16 bits mono thread" );
-            l_bytes = 1 * sizeof(s16) * p_aout->l_units;
-            pf_aout_thread = aout_S16Thread;
-            break;
-
-        default:
-            intf_ErrMsg( "aout error: unknown audio output format (%i)",
-                         p_aout->i_format );
-            return( -1 );
-        }
-        break;
-
-    /* Audio output is stereo */
-    case 2:
-        switch ( p_aout->i_format )
-        {
         case AOUT_FMT_U8:
-            intf_WarnMsg( 2, "aout info: unsigned 8 bits stereo thread" );
-            l_bytes = 2 * sizeof(u8) * p_aout->l_units;
-            pf_aout_thread = aout_U8Thread;
+            pf_aout_thread = aout_PCMThread;
+            psz_format = "unsigned 8 bits";
+            i_bytes = p_aout->i_units * p_aout->i_channels;
             break;
 
         case AOUT_FMT_S8:
-            intf_WarnMsg( 2, "aout info: signed 8 bits stereo thread" );
-            l_bytes = 2 * sizeof(s8) * p_aout->l_units;
-            pf_aout_thread = aout_S8Thread;
+            pf_aout_thread = aout_PCMThread;
+            psz_format = "signed 8 bits";
+            i_bytes = p_aout->i_units * p_aout->i_channels;
             break;
 
         case AOUT_FMT_U16_LE:
         case AOUT_FMT_U16_BE:
-            intf_WarnMsg( 2, "aout info: unsigned 16 bits stereo thread" );
-            l_bytes = 2 * sizeof(u16) * p_aout->l_units;
-            pf_aout_thread = aout_U16Thread;
+            pf_aout_thread = aout_PCMThread;
+            psz_format = "unsigned 16 bits";
+            i_bytes = 2 * p_aout->i_units * p_aout->i_channels;
             break;
 
         case AOUT_FMT_S16_LE:
         case AOUT_FMT_S16_BE:
-            intf_WarnMsg( 2, "aout info: signed 16 bits stereo thread" );
-            l_bytes = 2 * sizeof(s16) * p_aout->l_units;
-            pf_aout_thread = aout_S16Thread;
+            pf_aout_thread = aout_PCMThread;
+            psz_format = "signed 16 bits";
+            i_bytes = 2 * p_aout->i_units * p_aout->i_channels;
             break;
 
         case AOUT_FMT_AC3:
-            intf_WarnMsg( 2, "aout info: ac3 pass-through thread" );
-            l_bytes = SPDIF_FRAME_SIZE;
             pf_aout_thread = aout_SpdifThread;
+            psz_format = "ac3 pass-through";
+            i_bytes = SPDIF_FRAME_SIZE;
             break;
 
         default:
             intf_ErrMsg( "aout error: unknown audio output format %i",
                          p_aout->i_format );
             return( -1 );
-        }
-        break;
-
-    default:
-        intf_ErrMsg( "aout error: unknown number of audio channels (%i)",
-                     p_aout->i_channels );
-        return( -1 );
     }
 
     /* Allocate the memory needed by the audio output buffers, and set to zero
      * the s32 buffer's memory */
-    p_aout->buffer = malloc( l_bytes );
+    p_aout->buffer = malloc( i_bytes );
     if ( p_aout->buffer == NULL )
     {
         intf_ErrMsg( "aout error: cannot create output buffer" );
         return( -1 );
     }
 
-    p_aout->s32_buffer = (s32 *)calloc( p_aout->l_units,
-                                        sizeof(s32) << ( p_aout->b_stereo ) );
+    p_aout->s32_buffer = (s32 *)calloc( p_aout->i_units,
+                                        sizeof(s32) * p_aout->i_channels );
     if ( p_aout->s32_buffer == NULL )
     {
         intf_ErrMsg( "aout error: cannot create the s32 output buffer" );
@@ -336,7 +268,8 @@ static int aout_SpawnThread( aout_thread_t * p_aout )
         return( -1 );
     }
 
-    intf_WarnMsg( 2, "aout info: audio output thread %i spawned", getpid() );
+    intf_WarnMsg( 2, "aout info: %s thread spawned, %i channels, rate %i",
+                     psz_format, p_aout->i_channels, p_aout->i_rate );
     return( 0 );
 }
 
@@ -345,7 +278,7 @@ static int aout_SpawnThread( aout_thread_t * p_aout )
  *****************************************************************************/
 void aout_DestroyThread( aout_thread_t * p_aout, int *pi_status )
 {
-    int i_fifo;
+    int i_index;
     
     /* FIXME: pi_status is not handled correctly: check vout how to do!?? */
 
@@ -358,10 +291,10 @@ void aout_DestroyThread( aout_thread_t * p_aout, int *pi_status )
     free( p_aout->s32_buffer );
 
     /* Destroy the condition and mutex locks */
-    for ( i_fifo = 0; i_fifo < AOUT_MAX_FIFOS; i_fifo++ )
+    for ( i_index = 0; i_index < AOUT_MAX_FIFOS; i_index++ )
     {
-        vlc_mutex_destroy( &p_aout->fifo[i_fifo].data_lock );
-        vlc_cond_destroy( &p_aout->fifo[i_fifo].data_wait );
+        vlc_mutex_destroy( &p_aout->fifo[i_index].data_lock );
+        vlc_cond_destroy( &p_aout->fifo[i_index].data_wait );
     }
     vlc_mutex_destroy( &p_aout->fifos_lock );