]> git.sesse.net Git - vlc/blobdiff - modules/audio_filter/converter/fixed32tos16.c
* modules/demux/real.c: improved cook support. We now try to send audio subpackets...
[vlc] / modules / audio_filter / converter / fixed32tos16.c
index 2070f248d36dbaf94672a8f4f6a1a050ed7a9da7..ce7cd4a16ceabc9819f2de2446a478fdd913bbec 100644 (file)
@@ -1,8 +1,8 @@
 /*****************************************************************************
  * fixed32tos16.c : converter from fixed32 to signed 16 bits integer
  *****************************************************************************
- * Copyright (C) 2002 VideoLAN
- * $Id: fixed32tos16.c,v 1.6 2002/09/30 21:32:32 massiot Exp $
+ * Copyright (C) 2002 the VideoLAN team
+ * $Id$
  *
  * Authors: Jean-Paul Saman <jpsaman@wxs.nl>
  *
@@ -24,7 +24,6 @@
 /*****************************************************************************
  * Preamble
  *****************************************************************************/
-#include <errno.h>
 #include <stdlib.h>                                      /* malloc(), free() */
 #include <string.h>
 
@@ -44,6 +43,8 @@ static void DoWork    ( aout_instance_t *, aout_filter_t *, aout_buffer_t *,
  * Module descriptor
  *****************************************************************************/
 vlc_module_begin();
+    set_category( CAT_AUDIO );
+    set_subcategory( SUBCAT_AUDIO_MISC );
     set_description( _("audio filter for fixed32->s16 conversion") );
     set_capability( "audio filter", 10 );
     set_callbacks( Create, NULL );
@@ -93,10 +94,10 @@ static int Create( vlc_object_t *p_this )
 #define VLC_F_FRACBITS  28
 
 # if VLC_F_FRACBITS == 28
-#  define VLC_F(x)             ((vlc_fixed_t) (x##L))
+#  define VLC_F(x) ((vlc_fixed_t) (x##L))
 # endif
 
-# define VLC_F_ONE             VLC_F(0x10000000)
+# define VLC_F_ONE VLC_F(0x10000000)
 
 struct audio_dither {
     vlc_fixed_t error[3];
@@ -116,8 +117,8 @@ static inline unsigned long prng(unsigned long state)
  * NAME:        mpg321_s24_to_s16_pcm()
  * DESCRIPTION: generic linear sample quantize and dither routine
  ********************************************************************/
-static inline s16 mpg321_s24_to_s16_pcm(unsigned int bits, vlc_fixed_t sample,
-                                    struct audio_dither *dither)
+static inline int16_t mpg321_s24_to_s16_pcm(unsigned int bits, vlc_fixed_t sample,
+                                            struct audio_dither *dither)
 {
     unsigned int scalebits;
     vlc_fixed_t output, mask, random;
@@ -172,7 +173,7 @@ static inline s16 mpg321_s24_to_s16_pcm(unsigned int bits, vlc_fixed_t sample,
 /*****************************************************************************
  * s24_to_s16_pcm: Scale a 24 bit pcm sample to a 16 bit pcm sample.
  *****************************************************************************/
-static inline s16 s24_to_s16_pcm(vlc_fixed_t sample)
+static inline int16_t s24_to_s16_pcm(vlc_fixed_t sample)
 {
   /* round */
   sample += (1L << (VLC_F_FRACBITS - 16));
@@ -195,25 +196,20 @@ static void DoWork( aout_instance_t * p_aout, aout_filter_t * p_filter,
 {
     int i;
     vlc_fixed_t * p_in = (vlc_fixed_t *)p_in_buf->p_buffer;
-    s16 * p_out = (s16 *)p_out_buf->p_buffer;
-    s16 sample;
-//    static struct audio_dither dither;
+    int16_t * p_out = (int16_t *)p_out_buf->p_buffer;
+#if 0
+    static struct audio_dither dither;
+#endif
 
-    for ( i = p_in_buf->i_nb_samples * p_filter->input.i_channels ; i-- ; )
+    for ( i = p_in_buf->i_nb_samples
+               * aout_FormatNbChannels( &p_filter->input ) ; i-- ; )
     {
+#if 0
         /* Accurate scaling */
-//        p_out = mpg321_s24_to_s16_pcm(16, *p_in++, &dither);
-        /* Fast Scaling */
-        sample = s24_to_s16_pcm(*p_in++);
-
-#ifndef WORDS_BIGENDIAN
-        *p_out++ = (s16) (sample >> 0);
-        *p_out++ = (s16) (sample >> 8);
-#else
-        *p_out++ = (s16) (sample >> 8);
-        *p_out++ = (s16) (sample >> 0);
+        *p_out++ = mpg321_s24_to_s16_pcm(16, *p_in++, &dither);
 #endif
-//        p_in++; p_out++;
+        /* Fast Scaling */
+        *p_out++ = s24_to_s16_pcm(*p_in++);
     }
     p_out_buf->i_nb_samples = p_in_buf->i_nb_samples;
     p_out_buf->i_nb_bytes = p_in_buf->i_nb_bytes / 2;