* New float32to* converter modules, courtesy of Xavier Maillard
authorChristophe Massiot <massiot@videolan.org>
Tue, 13 Aug 2002 22:42:23 +0000 (22:42 +0000)
committerChristophe Massiot <massiot@videolan.org>
Tue, 13 Aug 2002 22:42:23 +0000 (22:42 +0000)
  <zedek@fxgsproject.org>.
* Fixed a bug in float32tos16, where gcc over-optimized a little and
  caused problems on some platforms (eg. solaris).

AUTHORS
configure
configure.in
modules/audio_filter/converter/Makefile
modules/audio_filter/converter/float32tos16.c
modules/audio_filter/converter/float32tos8.c [new file with mode: 0644]
modules/audio_filter/converter/float32tou16.c [new file with mode: 0644]
modules/audio_filter/converter/float32tou8.c [new file with mode: 0644]

diff --git a/AUTHORS b/AUTHORS
index b877271..9d80141 100644 (file)
--- a/AUTHORS
+++ b/AUTHORS
@@ -293,6 +293,11 @@ E: paulus@linuxcare.com.au
 D: AltiVec IDCT and motion
 S: Australia
 
+N: Xavier Maillard
+E: zedek@fxgsproject.org
+D: audio converters
+S: France, Reims
+
 N: Wade Majors
 E: guru@startrek.com
 D: BeOS testing, icon integration, debugging and fixes
index d443df7..7249f61 100755 (executable)
--- a/configure
+++ b/configure
@@ -5670,7 +5670,7 @@ PLUGINS="${PLUGINS} demux/mpeg/es demux/mpeg/audio demux/mpeg/mpeg_system demux/
 PLUGINS="${PLUGINS} codec/mpeg_video/idct/idct codec/mpeg_video/idct/idctclassic codec/mpeg_video/motion/motion codec/mpeg_video/mpeg_video codec/spudec/spudec codec/spdif"
 #PLUGINS="${PLUGINS} codec/a52old/imdct/imdct codec/a52old/downmix/downmix codec/mpeg_audio/mpeg_audio codec/a52old/a52old codec/lpcm/lpcm"
 PLUGINS="${PLUGINS} video_filter/deinterlace/deinterlace video_filter/invert video_filter/wall video_filter/transform video_filter/distort video_filter/clone video_filter/crop"
-PLUGINS="${PLUGINS} audio_filter/converter/float32tos16 audio_filter/converter/a52tospdif"
+PLUGINS="${PLUGINS} audio_filter/converter/float32tos16 audio_filter/converter/float32tos8 audio_filter/converter/float32tou16 audio_filter/converter/float32tou8 audio_filter/converter/a52tospdif"
 PLUGINS="${PLUGINS} audio_filter/resampler/trivial"
 PLUGINS="${PLUGINS} audio_mixer/trivial audio_mixer/spdif"
 PLUGINS="${PLUGINS} audio_output/file"
@@ -8375,7 +8375,7 @@ fi
 
      if test "x${ESD_CONFIG}" != "xno"
      then
-       #PLUGINS="${PLUGINS} audio_output/esd"
+       PLUGINS="${PLUGINS} audio_output/esd"
        esd_CFLAGS="${esd_CFLAGS} `${ESD_CONFIG} --cflags`"
        esd_LDFLAGS="${esd_LDFLAGS} `${ESD_CONFIG} --libs`"
      fi
@@ -8426,7 +8426,7 @@ fi
 
      if test "x${ARTS_CONFIG}" != "xno"
      then
-       #PLUGINS="${PLUGINS} audio_output/arts"
+       PLUGINS="${PLUGINS} audio_output/arts"
        arts_CFLAGS="${arts_CFLAGS} `${ARTS_CONFIG} --cflags`"
        arts_LDFLAGS="${arts_LDFLAGS} `${ARTS_CONFIG} --libs `"
      fi
index c1bc842..3ed6ecd 100644 (file)
@@ -444,7 +444,7 @@ PLUGINS="${PLUGINS} demux/mpeg/es demux/mpeg/audio demux/mpeg/mpeg_system demux/
 PLUGINS="${PLUGINS} codec/mpeg_video/idct/idct codec/mpeg_video/idct/idctclassic codec/mpeg_video/motion/motion codec/mpeg_video/mpeg_video codec/spudec/spudec codec/spdif"
 #PLUGINS="${PLUGINS} codec/a52old/imdct/imdct codec/a52old/downmix/downmix codec/mpeg_audio/mpeg_audio codec/a52old/a52old codec/lpcm/lpcm"
 PLUGINS="${PLUGINS} video_filter/deinterlace/deinterlace video_filter/invert video_filter/wall video_filter/transform video_filter/distort video_filter/clone video_filter/crop"
-PLUGINS="${PLUGINS} audio_filter/converter/float32tos16 audio_filter/converter/a52tospdif"
+PLUGINS="${PLUGINS} audio_filter/converter/float32tos16 audio_filter/converter/float32tos8 audio_filter/converter/float32tou16 audio_filter/converter/float32tou8 audio_filter/converter/a52tospdif"
 PLUGINS="${PLUGINS} audio_filter/resampler/trivial"
 PLUGINS="${PLUGINS} audio_mixer/trivial audio_mixer/spdif"
 PLUGINS="${PLUGINS} audio_output/file"
index 89cfda0..a429bfe 100644 (file)
@@ -1,4 +1,7 @@
 float32tos16_SOURCES = float32tos16.c
+float32tos8_SOURCES = float32tos8.c
+float32tou16_SOURCES = float32tou16.c
+float32tou8_SOURCES = float32tou8.c
 a52tospdif_SOURCES = a52tospdif.c
 fixed32tos16_SOURCES = fixed32tos16.c
-fixed32tofloat32_SOURCES = fixed32tofloat32.c
\ No newline at end of file
+fixed32tofloat32_SOURCES = fixed32tofloat32.c
index d4f1819..8a77a36 100644 (file)
@@ -2,7 +2,7 @@
  * float32tos16.c : converter from float32 to signed 16 bits integer
  *****************************************************************************
  * Copyright (C) 2002 VideoLAN
- * $Id: float32tos16.c,v 1.5 2002/08/13 16:11:15 sam Exp $
+ * $Id: float32tos16.c,v 1.6 2002/08/13 22:42:23 massiot Exp $
  *
  * Authors: Christophe Massiot <massiot@via.ecp.fr>
  *
@@ -96,11 +96,12 @@ static void DoWork( aout_instance_t * p_aout, aout_filter_t * p_filter,
         else *p_out = *p_in * 32768.0;
 #else
         /* This is walken's trick based on IEEE float format. */
-        s32 * p_value = (s32 *)p_in;
-        *p_in += 384.0;
-        if ( *p_value > 0x43c07fff ) *p_out = 32767;
-        else if ( *p_value < 0x43bf8000 ) *p_out = -32768;
-        else *p_out = *p_value - 0x43c00000;
+        float f_in = *p_in + 384.0;
+        s32 i_in;
+        i_in = *(s32 *)&f_in;
+        if ( i_in > 0x43c07fff ) *p_out = 32767;
+        else if ( i_in < 0x43bf8000 ) *p_out = -32768;
+        else *p_out = i_in - 0x43c00000;
 #endif
         p_in++; p_out++;
     }
diff --git a/modules/audio_filter/converter/float32tos8.c b/modules/audio_filter/converter/float32tos8.c
new file mode 100644 (file)
index 0000000..c51b529
--- /dev/null
@@ -0,0 +1,100 @@
+/*****************************************************************************
+ * float32tos8.c : converter from float32 to signed 8 bits integer
+ *****************************************************************************
+ * Copyright (C) 2002 VideoLAN
+ * $Id: float32tos8.c,v 1.1 2002/08/13 22:42:23 massiot Exp $
+ *
+ * Authors: Xavier Maillard <zedek@fxgsproject.org>
+ *
+ * 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 <errno.h>
+#include <stdlib.h>                                      /* malloc(), free() */
+#include <string.h>
+
+#include <vlc/vlc.h>
+#include "audio_output.h"
+#include "aout_internal.h"
+
+/*****************************************************************************
+ * Local prototypes
+ *****************************************************************************/
+static int  Create    ( vlc_object_t * );
+
+static void DoWork    ( aout_instance_t *, aout_filter_t *, aout_buffer_t *,
+                        aout_buffer_t * );
+
+/*****************************************************************************
+ * Module descriptor
+ *****************************************************************************/
+vlc_module_begin();
+    set_description( _("aout filter for float32->s8 conversion") );
+    set_capability( "audio filter", 1 );
+    set_callbacks( Create, NULL );
+vlc_module_end();
+
+/*****************************************************************************
+ * Create: allocate trivial mixer
+ *****************************************************************************
+ * This function allocates and initializes a Crop vout method.
+ *****************************************************************************/
+static int Create( vlc_object_t *p_this )
+{
+    aout_filter_t * p_filter = (aout_filter_t *)p_this;
+
+    if ( p_filter->input.i_format != AOUT_FMT_FLOAT32
+          || p_filter->output.i_format != AOUT_FMT_S8 )
+    {
+        return -1;
+    }
+
+    if ( p_filter->input.i_rate != p_filter->output.i_rate
+          || p_filter->input.i_channels != p_filter->output.i_channels )
+    {
+        return -1;
+    }
+
+
+    p_filter->pf_do_work = DoWork;
+    p_filter->b_in_place = 1;
+
+    return 0;
+}
+
+/*****************************************************************************
+ * DoWork: convert a buffer
+ *****************************************************************************/
+static void DoWork( aout_instance_t * p_aout, aout_filter_t * p_filter,
+                    aout_buffer_t * p_in_buf, aout_buffer_t * p_out_buf )
+{
+    int i;
+    float * p_in = (float *)p_in_buf->p_buffer;
+    s8 * p_out = (s8 *)p_out_buf->p_buffer;
+
+    for ( i = 0; i < p_in_buf->i_nb_samples * p_filter->input.i_channels; i++ )
+    {
+        if ( *p_in >= 1.0 ) *p_out = 127;
+        else if ( *p_in < -1.0 ) *p_out = -128;
+        else *p_out = (s8)(*p_in * 128);
+        p_in++; p_out++;
+    }
+
+    p_out_buf->i_nb_samples = p_in_buf->i_nb_samples;
+}
+
diff --git a/modules/audio_filter/converter/float32tou16.c b/modules/audio_filter/converter/float32tou16.c
new file mode 100644 (file)
index 0000000..566a196
--- /dev/null
@@ -0,0 +1,99 @@
+/*****************************************************************************
+ * float32tou16.c : converter from float32 to unsigned 16 bits integer
+ *****************************************************************************
+ * Copyright (C) 2002 VideoLAN
+ * $Id: float32tou16.c,v 1.1 2002/08/13 22:42:23 massiot Exp $
+ *
+ * Authors: Xavier Maillard <zedek@fxgsproject.org>
+ *
+ * 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 <errno.h>
+#include <stdlib.h>                                      /* malloc(), free() */
+#include <string.h>
+
+#include <vlc/vlc.h>
+#include "audio_output.h"
+#include "aout_internal.h"
+
+/*****************************************************************************
+ * Local prototypes
+ *****************************************************************************/
+static int  Create    ( vlc_object_t * );
+
+static void DoWork    ( aout_instance_t *, aout_filter_t *, aout_buffer_t *,
+                        aout_buffer_t * );
+
+/*****************************************************************************
+ * Module descriptor
+ *****************************************************************************/
+vlc_module_begin();
+    set_description( _("aout filter for float32->u16 conversion") );
+    set_capability( "audio filter", 1 );
+    set_callbacks( Create, NULL );
+vlc_module_end();
+
+/*****************************************************************************
+ * Create: allocate trivial mixer
+ *****************************************************************************
+ * This function allocates and initializes a Crop vout method.
+ *****************************************************************************/
+static int Create( vlc_object_t *p_this )
+{
+    aout_filter_t * p_filter = (aout_filter_t *)p_this;
+
+    if ( p_filter->input.i_format != AOUT_FMT_FLOAT32
+          && p_filter->output.i_format != AOUT_FMT_U16_NE )
+    {
+        return -1;
+    }
+
+    if ( p_filter->input.i_rate != p_filter->output.i_rate
+          || p_filter->input.i_channels != p_filter->output.i_channels )
+    {
+        return -1;
+    }
+
+    p_filter->pf_do_work = DoWork;
+    p_filter->b_in_place = 1;
+
+    return 0;
+}
+
+/*****************************************************************************
+ * DoWork: convert a buffer
+ *****************************************************************************/
+static void DoWork( aout_instance_t * p_aout, aout_filter_t * p_filter,
+                    aout_buffer_t * p_in_buf, aout_buffer_t * p_out_buf )
+{
+    int i;
+    float * p_in = (float *)p_in_buf->p_buffer;
+    u16 * p_out = (u16 *)p_out_buf->p_buffer;
+
+    for ( i = 0; i < p_in_buf->i_nb_samples * p_filter->input.i_channels; i++ )
+    {
+        if ( *p_in >= 1.0 ) *p_out = 65535;
+        else if ( *p_in < -1.0 ) *p_out = 0;
+        else *p_out = (u16)(32768 + *p_in * 32768);
+        p_in++; p_out++;
+    }
+
+    p_out_buf->i_nb_samples = p_in_buf->i_nb_samples;
+}
+
diff --git a/modules/audio_filter/converter/float32tou8.c b/modules/audio_filter/converter/float32tou8.c
new file mode 100644 (file)
index 0000000..2f245a7
--- /dev/null
@@ -0,0 +1,100 @@
+/*****************************************************************************
+ * float32tou8.c : converter from float32 to unsigned 8 bits integer
+ *****************************************************************************
+ * Copyright (C) 2002 VideoLAN
+ * $Id: float32tou8.c,v 1.1 2002/08/13 22:42:23 massiot Exp $
+ *
+ * Authors: Xavier Maillard <zedek@fxgsproject.org>
+ *
+ * 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 <errno.h>
+#include <stdlib.h>                                      /* malloc(), free() */
+#include <string.h>
+
+#include <vlc/vlc.h>
+#include "audio_output.h"
+#include "aout_internal.h"
+
+/*****************************************************************************
+ * Local prototypes
+ *****************************************************************************/
+static int  Create    ( vlc_object_t * );
+
+static void DoWork    ( aout_instance_t *, aout_filter_t *, aout_buffer_t *,
+                        aout_buffer_t * );
+
+/*****************************************************************************
+ * Module descriptor
+ *****************************************************************************/
+vlc_module_begin();
+    set_description( _("aout filter for float32->u8 conversion") );
+    set_capability( "audio filter", 1 );
+    set_callbacks( Create, NULL );
+vlc_module_end();
+
+/*****************************************************************************
+ * Create: allocate trivial mixer
+ *****************************************************************************
+ * This function allocates and initializes a Crop vout method.
+ *****************************************************************************/
+static int Create( vlc_object_t *p_this )
+{
+    aout_filter_t * p_filter = (aout_filter_t *)p_this;
+
+    if ( p_filter->input.i_format != AOUT_FMT_FLOAT32
+          && p_filter->output.i_format != AOUT_FMT_U8 )
+    {
+        return -1;
+    }
+
+    if ( p_filter->input.i_rate != p_filter->output.i_rate
+          || p_filter->input.i_channels != p_filter->output.i_channels )
+    {
+        return -1;
+    }
+
+
+    p_filter->pf_do_work = DoWork;
+    p_filter->b_in_place = 1;
+
+    return 0;
+}
+
+/*****************************************************************************
+ * DoWork: convert a buffer
+ *****************************************************************************/
+static void DoWork( aout_instance_t * p_aout, aout_filter_t * p_filter,
+                    aout_buffer_t * p_in_buf, aout_buffer_t * p_out_buf )
+{
+    int i;
+    float * p_in = (float *)p_in_buf->p_buffer;
+    u8 * p_out = (u8 *)p_out_buf->p_buffer;
+
+    for ( i = 0; i < p_in_buf->i_nb_samples * p_filter->input.i_channels; i++ )
+    {
+        if ( *p_in >= 1.0 ) *p_out = 255;
+        else if ( *p_in < -1.0 ) *p_out = 0;
+        else *p_out = (u8)(128 + *p_in * 128);
+        p_in++; p_out++;
+    }
+
+    p_out_buf->i_nb_samples = p_in_buf->i_nb_samples;
+}
+