From: Christophe Massiot Date: Tue, 13 Aug 2002 22:42:23 +0000 (+0000) Subject: * New float32to* converter modules, courtesy of Xavier Maillard X-Git-Tag: 0.5.0~1086 X-Git-Url: https://git.sesse.net/?a=commitdiff_plain;h=321841006c653a16649202899df357f15e49ea64;p=vlc * New float32to* converter modules, courtesy of Xavier Maillard . * Fixed a bug in float32tos16, where gcc over-optimized a little and caused problems on some platforms (eg. solaris). --- diff --git a/AUTHORS b/AUTHORS index b8772719ab..9d80141dcc 100644 --- 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 diff --git a/configure b/configure index d443df75b9..7249f61677 100755 --- 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 diff --git a/configure.in b/configure.in index c1bc842dc7..3ed6ecdedc 100644 --- a/configure.in +++ b/configure.in @@ -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" diff --git a/modules/audio_filter/converter/Makefile b/modules/audio_filter/converter/Makefile index 89cfda009e..a429bfe425 100644 --- a/modules/audio_filter/converter/Makefile +++ b/modules/audio_filter/converter/Makefile @@ -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 diff --git a/modules/audio_filter/converter/float32tos16.c b/modules/audio_filter/converter/float32tos16.c index d4f1819f1a..8a77a36fe9 100644 --- a/modules/audio_filter/converter/float32tos16.c +++ b/modules/audio_filter/converter/float32tos16.c @@ -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 * @@ -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 index 0000000000..c51b5294fd --- /dev/null +++ b/modules/audio_filter/converter/float32tos8.c @@ -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 + * + * 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 +#include /* malloc(), free() */ +#include + +#include +#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 index 0000000000..566a196368 --- /dev/null +++ b/modules/audio_filter/converter/float32tou16.c @@ -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 + * + * 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 +#include /* malloc(), free() */ +#include + +#include +#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 index 0000000000..2f245a77dc --- /dev/null +++ b/modules/audio_filter/converter/float32tou8.c @@ -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 + * + * 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 +#include /* malloc(), free() */ +#include + +#include +#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; +} +