From 7cde22ed8c2041a4396f5a7ad8da7fa1aadf1d5f Mon Sep 17 00:00:00 2001 From: =?utf8?q?R=C3=A9mi=20Denis-Courmont?= Date: Sun, 27 Sep 2009 21:02:36 +0300 Subject: [PATCH] audio_format replaces converter_float and converter_fixed --- configure.ac | 4 - modules/audio_filter/converter/Modules.am | 4 +- modules/audio_filter/converter/fixed.c | 241 -------- modules/audio_filter/converter/float.c | 705 ---------------------- 4 files changed, 1 insertion(+), 953 deletions(-) delete mode 100644 modules/audio_filter/converter/fixed.c delete mode 100644 modules/audio_filter/converter/float.c diff --git a/configure.ac b/configure.ac index 31bf3d250c..0676d7062f 100644 --- a/configure.ac +++ b/configure.ac @@ -1264,10 +1264,8 @@ if test "${SYS}" != "mingwce"; then VLC_ADD_PLUGIN([equalizer]) VLC_ADD_PLUGIN([param_eq]) VLC_ADD_PLUGIN([scaletempo]) - VLC_ADD_PLUGIN([converter_float]) VLC_ADD_PLUGIN([a52tospdif]) VLC_ADD_PLUGIN([dtstospdif]) - VLC_ADD_PLUGIN([audio_format]) ALIASES="${ALIASES} rvlc" fi @@ -1281,10 +1279,8 @@ if test "${SYS}" = "mingwce"; then VLC_ADD_PLUGIN([simple_channel_mixer]) VLC_ADD_PLUGIN([headphone_channel_mixer]) VLC_ADD_PLUGIN([normvol]) - VLC_ADD_PLUGIN([converter_float]) VLC_ADD_PLUGIN([a52tospdif]) VLC_ADD_PLUGIN([dtstospdif]) - VLC_ADD_PLUGIN([audio_format]) VLC_ADD_PLUGIN([i420_yuy2]) VLC_ADD_PLUGIN([i422_yuy2]) VLC_ADD_PLUGIN([i420_ymga]) diff --git a/modules/audio_filter/converter/Modules.am b/modules/audio_filter/converter/Modules.am index 2311ebcab4..43aa469688 100644 --- a/modules/audio_filter/converter/Modules.am +++ b/modules/audio_filter/converter/Modules.am @@ -1,5 +1,3 @@ -SOURCES_converter_fixed = fixed.c -SOURCES_converter_float = float.c SOURCES_converter_neon = neon.c SOURCES_a52tospdif = a52tospdif.c SOURCES_a52tofloat32 = a52tofloat32.c @@ -9,7 +7,7 @@ SOURCES_mpgatofixed32 = mpgatofixed32.c SOURCES_audio_format = format.c libvlc_LTLIBRARIES += \ - libconverter_fixed_plugin.la \ + libaudio_format_plugin.la \ $(NULL) if HAVE_NEON libvlc_LTLIBRARIES += libconverter_neon_plugin.la diff --git a/modules/audio_filter/converter/fixed.c b/modules/audio_filter/converter/fixed.c deleted file mode 100644 index db82c6cab8..0000000000 --- a/modules/audio_filter/converter/fixed.c +++ /dev/null @@ -1,241 +0,0 @@ -/***************************************************************************** - * fixed.c: Fixed-point audio format conversions - ***************************************************************************** - * Copyright (C) 2002, 2006 the VideoLAN team - * $Id$ - * - * Authors: Jean-Paul Saman - * Marc Ariberti - * Samuel Hocevar - * - * 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., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA. - *****************************************************************************/ - -/***************************************************************************** - * Preamble - *****************************************************************************/ - -#ifdef HAVE_CONFIG_H -# include "config.h" -#endif - -#include -#include -#include - -/***************************************************************************** - * Local prototypes - *****************************************************************************/ -static int Create_F32ToS16 ( vlc_object_t * ); -static void Do_F32ToS16( aout_instance_t *, aout_filter_t *, aout_buffer_t *, - aout_buffer_t * ); - -static int Create_S16ToF32 ( vlc_object_t * ); -static void Do_S16ToF32( aout_instance_t *, aout_filter_t *, aout_buffer_t *, - aout_buffer_t * ); - -static int Create_U8ToF32 ( vlc_object_t * ); -static void Do_U8ToF32( aout_instance_t *, aout_filter_t *, aout_buffer_t *, - aout_buffer_t * ); - -/***************************************************************************** - * Module descriptor - *****************************************************************************/ -vlc_module_begin () - set_description( N_("Fixed point audio format conversions") ) - add_submodule () - set_callbacks( Create_F32ToS16, NULL ) - set_capability( "audio filter", 10 ) - add_submodule () - set_callbacks( Create_S16ToF32, NULL ) - set_capability( "audio filter", 15 ) - add_submodule () - set_callbacks( Create_U8ToF32, NULL ) - set_capability( "audio filter", 1 ) -vlc_module_end () - -/***************************************************************************** - * F32 to S16 - *****************************************************************************/ -static int Create_F32ToS16( vlc_object_t *p_this ) -{ - aout_filter_t * p_filter = (aout_filter_t *)p_this; - - if ( p_filter->fmt_in.audio.i_format != VLC_CODEC_FI32 - || p_filter->fmt_out.audio.i_format != VLC_CODEC_S16N ) - { - return -1; - } - - if ( !AOUT_FMTS_SIMILAR( &p_filter->fmt_in.audio, &p_filter->fmt_out.audio ) ) - { - return -1; - } - - p_filter->pf_do_work = Do_F32ToS16; - p_filter->b_in_place = 1; - - return VLC_SUCCESS;; -} - -/***************************************************************************** - * support routines borrowed from mpg321 (file: mad.c), which is distributed - * under GPL license - * - * mpg321 was written by Joe Drew , and based upon 'plaympeg' - * from the smpeg sources, which was written by various people from Loki Software - * (http://www.lokigames.com). - * - * It also incorporates some source from mad, written by Robert Leslie - *****************************************************************************/ - -/* The following two routines and data structure are from the ever-brilliant - Rob Leslie. -*/ - -#define VLC_F_FRACBITS 28 - -# if VLC_F_FRACBITS == 28 -# define VLC_F(x) ((vlc_fixed_t) (x##L)) -# endif - -# define VLC_F_ONE VLC_F(0x10000000) - -/***************************************************************************** - * s24_to_s16_pcm: Scale a 24 bit pcm sample to a 16 bit pcm sample. - *****************************************************************************/ -static inline int16_t s24_to_s16_pcm(vlc_fixed_t sample) -{ - /* round */ - sample += (1L << (VLC_F_FRACBITS - 16)); - - /* clip */ - if (sample >= VLC_F_ONE) - sample = VLC_F_ONE - 1; - else if (sample < -VLC_F_ONE) - sample = -VLC_F_ONE; - - /* quantize */ - return (sample >> (VLC_F_FRACBITS + 1 - 16)); -} - -static void Do_F32ToS16( aout_instance_t * p_aout, aout_filter_t * p_filter, - aout_buffer_t * p_in_buf, aout_buffer_t * p_out_buf ) -{ - VLC_UNUSED(p_aout); - int i; - vlc_fixed_t * p_in = (vlc_fixed_t *)p_in_buf->p_buffer; - int16_t * p_out = (int16_t *)p_out_buf->p_buffer; - - for ( i = p_in_buf->i_nb_samples - * aout_FormatNbChannels( &p_filter->fmt_in.audio ) ; i-- ; ) - { - /* 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_buffer = p_in_buf->i_buffer / 2; -} - - -/***************************************************************************** - * S16 to F32 - *****************************************************************************/ -static int Create_S16ToF32( vlc_object_t *p_this ) -{ - aout_filter_t * p_filter = (aout_filter_t *)p_this; - - if ( p_filter->fmt_out.audio.i_format != VLC_CODEC_FI32 - || p_filter->fmt_in.audio.i_format != VLC_CODEC_S16N ) - { - return -1; - } - - if ( !AOUT_FMTS_SIMILAR( &p_filter->fmt_in.audio, &p_filter->fmt_out.audio ) ) - { - return -1; - } - - p_filter->pf_do_work = Do_S16ToF32; - p_filter->b_in_place = 1; - - return 0; -} - -static void Do_S16ToF32( aout_instance_t * p_aout, aout_filter_t * p_filter, - aout_buffer_t * p_in_buf, aout_buffer_t * p_out_buf ) -{ - VLC_UNUSED(p_aout); - int i = p_in_buf->i_nb_samples * aout_FormatNbChannels( &p_filter->fmt_in.audio ); - - /* We start from the end because b_in_place is true */ - int16_t * p_in = (int16_t *)p_in_buf->p_buffer + i - 1; - vlc_fixed_t * p_out = (vlc_fixed_t *)p_out_buf->p_buffer + i - 1; - - while( i-- ) - { - *p_out = (vlc_fixed_t)( (int32_t)(*p_in) * (FIXED32_ONE >> 16) ); - p_in--; p_out--; - } - - p_out_buf->i_nb_samples = p_in_buf->i_nb_samples; - p_out_buf->i_buffer = p_in_buf->i_buffer - * sizeof(vlc_fixed_t) / sizeof(int16_t); -} - - -/***************************************************************************** - * U8 to F32 - *****************************************************************************/ -static int Create_U8ToF32( vlc_object_t *p_this ) -{ - aout_filter_t * p_filter = (aout_filter_t *)p_this; - - if ( p_filter->fmt_in.audio.i_format != VLC_CODEC_U8 - || p_filter->fmt_out.audio.i_format != VLC_CODEC_FI32 ) - { - return -1; - } - - if ( !AOUT_FMTS_SIMILAR( &p_filter->fmt_in.audio, &p_filter->fmt_out.audio ) ) - { - return -1; - } - - p_filter->pf_do_work = Do_U8ToF32; - p_filter->b_in_place = true; - - return 0; -} - -static void Do_U8ToF32( aout_instance_t * p_aout, aout_filter_t * p_filter, - aout_buffer_t * p_in_buf, aout_buffer_t * p_out_buf ) -{ - VLC_UNUSED(p_aout); - int i = p_in_buf->i_nb_samples * aout_FormatNbChannels( &p_filter->fmt_in.audio ); - - /* We start from the end because b_in_place is true */ - uint8_t * p_in = (uint8_t *)p_in_buf->p_buffer + i - 1; - vlc_fixed_t * p_out = (vlc_fixed_t *)p_out_buf->p_buffer + i - 1; - - while( i-- ) - { - *p_out = (vlc_fixed_t)( (int32_t)(*p_in - 128) * (FIXED32_ONE / 128) ); - p_in--; p_out--; - } - - p_out_buf->i_nb_samples = p_in_buf->i_nb_samples; - p_out_buf->i_buffer = p_in_buf->i_buffer * sizeof(vlc_fixed_t); -} diff --git a/modules/audio_filter/converter/float.c b/modules/audio_filter/converter/float.c deleted file mode 100644 index 41bf5e456b..0000000000 --- a/modules/audio_filter/converter/float.c +++ /dev/null @@ -1,705 +0,0 @@ -/***************************************************************************** - * float.c: Floating point audio format conversions - ***************************************************************************** - * Copyright (C) 2002, 2006 the VideoLAN team - * $Id$ - * - * Authors: Jean-Paul Saman - * Christophe Massiot - * Samuel Hocevar - * Xavier Maillard - * Henri Fallon - * Gildas Bazin - * - * 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., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA. - *****************************************************************************/ - -/***************************************************************************** - * Preamble - *****************************************************************************/ -#ifdef HAVE_CONFIG_H -# include "config.h" -#endif - -#include -#include - -#ifdef HAVE_UNISTD_H -# include -#endif - -#include - -/***************************************************************************** - * Local prototypes - *****************************************************************************/ -static int Create_F32ToFL32 ( vlc_object_t * ); -static void Do_F32ToFL32( aout_instance_t *, aout_filter_t *, aout_buffer_t *, - aout_buffer_t * ); -static void Do_FL32ToF32 ( aout_instance_t *, aout_filter_t *, aout_buffer_t *, - aout_buffer_t * ); - -static int Create_FL32ToS16 ( vlc_object_t * ); -static void Do_FL32ToS16( aout_instance_t *, aout_filter_t *, aout_buffer_t *, - aout_buffer_t * ); - -static int Create_FL32ToS8 ( vlc_object_t * ); -static void Do_FL32ToS8( aout_instance_t *, aout_filter_t *, aout_buffer_t *, - aout_buffer_t * ); - -static int Create_FL32ToU16 ( vlc_object_t * ); -static void Do_FL32ToU16( aout_instance_t *, aout_filter_t *, aout_buffer_t *, - aout_buffer_t * ); - -static int Create_FL32ToU8 ( vlc_object_t * ); -static void Do_FL32ToU8( aout_instance_t *, aout_filter_t *, aout_buffer_t *, - aout_buffer_t * ); - -static int Create_S16ToFL32( vlc_object_t * ); -static void Do_S16ToFL32( aout_instance_t *, aout_filter_t *, aout_buffer_t *, - aout_buffer_t * ); -static void Do_S24ToFL32( aout_instance_t *, aout_filter_t *, aout_buffer_t *, - aout_buffer_t * ); -static void Do_S32ToFL32( aout_instance_t *, aout_filter_t *, aout_buffer_t *, - aout_buffer_t * ); - -static int Create_S16ToFL32_SW( vlc_object_t * ); -static void Do_S16ToFL32_SW( aout_instance_t *, aout_filter_t *, aout_buffer_t *, - aout_buffer_t * ); -static void Do_S24ToFL32_SW( aout_instance_t *, aout_filter_t *, aout_buffer_t *, - aout_buffer_t * ); -static void Do_S32ToFL32_SW( aout_instance_t *, aout_filter_t *, aout_buffer_t *, - aout_buffer_t * ); - -static int Create_S8ToFL32( vlc_object_t * ); -static void Do_S8ToFL32( aout_instance_t *, aout_filter_t *, aout_buffer_t *, - aout_buffer_t * ); - -static int Create_U8ToFL32( vlc_object_t * ); -static void Do_U8ToFL32( aout_instance_t *, aout_filter_t *, aout_buffer_t *, - aout_buffer_t * ); - -/***************************************************************************** - * Module descriptor - *****************************************************************************/ -vlc_module_begin () - set_description( N_("Floating-point audio format conversions") ) - add_submodule () - set_capability( "audio filter", 10 ) - set_callbacks( Create_F32ToFL32, NULL ) - add_submodule () - set_capability( "audio filter", 1 ) - set_callbacks( Create_FL32ToS16, NULL ) - add_submodule () - set_capability( "audio filter", 1 ) - set_callbacks( Create_FL32ToS8, NULL ) - add_submodule () - set_capability( "audio filter", 1 ) - set_callbacks( Create_FL32ToU16, NULL ) - add_submodule () - set_capability( "audio filter", 1 ) - set_callbacks( Create_FL32ToU8, NULL ) - add_submodule () - set_capability( "audio filter", 1 ) - set_callbacks( Create_S16ToFL32, NULL ) - add_submodule () - set_capability( "audio filter", 1 ) - set_callbacks( Create_S16ToFL32_SW, NULL ) /* Endianness conversion*/ - add_submodule () - set_capability( "audio filter", 1 ) - set_callbacks( Create_S8ToFL32, NULL ) - add_submodule () - set_capability( "audio filter", 1 ) - set_callbacks( Create_U8ToFL32, NULL ) -vlc_module_end () - -/***************************************************************************** - * Fixed 32 to Float 32 and backwards - *****************************************************************************/ -static int Create_F32ToFL32( vlc_object_t *p_this ) -{ - aout_filter_t * p_filter = (aout_filter_t *)p_this; - - if( ( p_filter->fmt_in.audio.i_format != VLC_CODEC_FI32 - || p_filter->fmt_out.audio.i_format != VLC_CODEC_FL32 ) - && ( p_filter->fmt_in.audio.i_format != VLC_CODEC_FL32 - || p_filter->fmt_out.audio.i_format != VLC_CODEC_FI32 ) ) - { - return -1; - } - - if ( !AOUT_FMTS_SIMILAR( &p_filter->fmt_in.audio, &p_filter->fmt_out.audio ) ) - { - return -1; - } - - if( p_filter->fmt_in.audio.i_format == VLC_CODEC_FI32 ) - { - p_filter->pf_do_work = Do_F32ToFL32; - } - else - { - p_filter->pf_do_work = Do_FL32ToF32; - } - - p_filter->b_in_place = 1; - - return 0; -} - -static void Do_F32ToFL32( aout_instance_t * p_aout, aout_filter_t * p_filter, - aout_buffer_t * p_in_buf, aout_buffer_t * p_out_buf ) -{ - VLC_UNUSED(p_aout); - int i; - vlc_fixed_t * p_in = (vlc_fixed_t *)p_in_buf->p_buffer; - float * p_out = (float *)p_out_buf->p_buffer; - - for ( i = p_in_buf->i_nb_samples - * aout_FormatNbChannels( &p_filter->fmt_in.audio ) ; i-- ; ) - { - *p_out++ = (float)*p_in++ / (float)FIXED32_ONE; - } - - p_out_buf->i_nb_samples = p_in_buf->i_nb_samples; - p_out_buf->i_buffer = p_in_buf->i_buffer; -} - -static void Do_FL32ToF32( aout_instance_t * p_aout, aout_filter_t * p_filter, - aout_buffer_t * p_in_buf, aout_buffer_t * p_out_buf ) -{ - VLC_UNUSED(p_aout); - int i; - float * p_in = (float *)p_in_buf->p_buffer; - vlc_fixed_t * p_out = (vlc_fixed_t *)p_out_buf->p_buffer; - - for ( i = p_in_buf->i_nb_samples - * aout_FormatNbChannels( &p_filter->fmt_in.audio ) ; i-- ; ) - { - *p_out++ = (vlc_fixed_t)( *p_in++ * (float)FIXED32_ONE ); - } - - p_out_buf->i_nb_samples = p_in_buf->i_nb_samples; - p_out_buf->i_buffer = p_in_buf->i_buffer; -} - -/***************************************************************************** - * FL32 To S16 - *****************************************************************************/ -static int Create_FL32ToS16( vlc_object_t *p_this ) -{ - aout_filter_t * p_filter = (aout_filter_t *)p_this; - - if ( p_filter->fmt_in.audio.i_format != VLC_CODEC_FL32 - || p_filter->fmt_out.audio.i_format != VLC_CODEC_S16N ) - { - return -1; - } - - if ( !AOUT_FMTS_SIMILAR( &p_filter->fmt_in.audio, &p_filter->fmt_out.audio ) ) - { - return -1; - } - - p_filter->pf_do_work = Do_FL32ToS16; - p_filter->b_in_place = 1; - - return 0; -} - -static void Do_FL32ToS16( aout_instance_t * p_aout, aout_filter_t * p_filter, - aout_buffer_t * p_in_buf, aout_buffer_t * p_out_buf ) -{ - VLC_UNUSED(p_aout); - int i; - float * p_in = (float *)p_in_buf->p_buffer; - int16_t * p_out = (int16_t *)p_out_buf->p_buffer; - - for ( i = p_in_buf->i_nb_samples - * aout_FormatNbChannels( &p_filter->fmt_in.audio ); i-- ; ) - { -#if 0 - /* Slow version. */ - if ( *p_in >= 1.0 ) *p_out = 32767; - else if ( *p_in < -1.0 ) *p_out = -32768; - else *p_out = *p_in * 32768.0; -#else - /* This is walken's trick based on IEEE float format. */ - union { float f; int32_t i; } u; - u.f = *p_in + 384.0; - if ( u.i > 0x43c07fff ) *p_out = 32767; - else if ( u.i < 0x43bf8000 ) *p_out = -32768; - else *p_out = u.i - 0x43c00000; -#endif - p_in++; p_out++; - } - - p_out_buf->i_nb_samples = p_in_buf->i_nb_samples; - p_out_buf->i_buffer = p_in_buf->i_buffer / 2; -} - -/***************************************************************************** - * FL32 To S8 - *****************************************************************************/ -static int Create_FL32ToS8( vlc_object_t *p_this ) -{ - aout_filter_t * p_filter = (aout_filter_t *)p_this; - - if ( p_filter->fmt_in.audio.i_format != VLC_CODEC_FL32 - || p_filter->fmt_out.audio.i_format != VLC_CODEC_S8 ) - { - return -1; - } - - if ( !AOUT_FMTS_SIMILAR( &p_filter->fmt_in.audio, &p_filter->fmt_out.audio ) ) - { - return -1; - } - - p_filter->pf_do_work = Do_FL32ToS8; - p_filter->b_in_place = 1; - - return 0; -} - -static void Do_FL32ToS8( aout_instance_t * p_aout, aout_filter_t * p_filter, - aout_buffer_t * p_in_buf, aout_buffer_t * p_out_buf ) -{ - VLC_UNUSED(p_aout); - int i; - float * p_in = (float *)p_in_buf->p_buffer; - int8_t * p_out = (int8_t *)p_out_buf->p_buffer; - - for ( i = p_in_buf->i_nb_samples - * aout_FormatNbChannels( &p_filter->fmt_in.audio ); i-- ; ) - { - if ( *p_in >= 1.0 ) *p_out = 127; - else if ( *p_in < -1.0 ) *p_out = -128; - else *p_out = (int8_t)(*p_in * 128); - p_in++; p_out++; - } - - p_out_buf->i_nb_samples = p_in_buf->i_nb_samples; - p_out_buf->i_buffer = p_in_buf->i_buffer / 4; -} - -/***************************************************************************** - * FL32 To U16 - *****************************************************************************/ -static int Create_FL32ToU16( vlc_object_t *p_this ) -{ - aout_filter_t * p_filter = (aout_filter_t *)p_this; - - if ( p_filter->fmt_in.audio.i_format != VLC_CODEC_FL32 - || p_filter->fmt_out.audio.i_format != VLC_CODEC_U16N ) - { - return -1; - } - - if ( !AOUT_FMTS_SIMILAR( &p_filter->fmt_in.audio, &p_filter->fmt_out.audio ) ) - { - return -1; - } - - p_filter->pf_do_work = Do_FL32ToU16; - p_filter->b_in_place = 1; - - return 0; -} - -static void Do_FL32ToU16( aout_instance_t * p_aout, aout_filter_t * p_filter, - aout_buffer_t * p_in_buf, aout_buffer_t * p_out_buf ) -{ - VLC_UNUSED(p_aout); - int i; - float * p_in = (float *)p_in_buf->p_buffer; - uint16_t * p_out = (uint16_t *)p_out_buf->p_buffer; - - for ( i = p_in_buf->i_nb_samples - * aout_FormatNbChannels( &p_filter->fmt_in.audio ); i-- ; ) - { - if ( *p_in >= 1.0 ) *p_out = 65535; - else if ( *p_in < -1.0 ) *p_out = 0; - else *p_out = (uint16_t)(32768 + *p_in * 32768); - p_in++; p_out++; - } - - p_out_buf->i_nb_samples = p_in_buf->i_nb_samples; - p_out_buf->i_buffer = p_in_buf->i_buffer / 2; -} - -/***************************************************************************** - * FL32 To U8 - *****************************************************************************/ -static int Create_FL32ToU8( vlc_object_t *p_this ) -{ - aout_filter_t * p_filter = (aout_filter_t *)p_this; - - if ( p_filter->fmt_in.audio.i_format != VLC_CODEC_FL32 - || p_filter->fmt_out.audio.i_format != VLC_CODEC_U8 ) - { - return -1; - } - - if ( !AOUT_FMTS_SIMILAR( &p_filter->fmt_in.audio, &p_filter->fmt_out.audio ) ) - { - return -1; - } - - p_filter->pf_do_work = Do_FL32ToU8; - p_filter->b_in_place = 1; - - return 0; -} - -static void Do_FL32ToU8( aout_instance_t * p_aout, aout_filter_t * p_filter, - aout_buffer_t * p_in_buf, aout_buffer_t * p_out_buf ) -{ - VLC_UNUSED(p_aout); - int i; - float * p_in = (float *)p_in_buf->p_buffer; - uint8_t * p_out = (uint8_t *)p_out_buf->p_buffer; - - for ( i = p_in_buf->i_nb_samples - * aout_FormatNbChannels( &p_filter->fmt_in.audio ); i-- ; ) - { - if ( *p_in >= 1.0 ) *p_out = 255; - else if ( *p_in < -1.0 ) *p_out = 0; - else *p_out = (uint8_t)(128 + *p_in * 128); - p_in++; p_out++; - } - - p_out_buf->i_nb_samples = p_in_buf->i_nb_samples; - p_out_buf->i_buffer = p_in_buf->i_buffer / 4; -} - -/***************************************************************************** - * S16 To Float32 - *****************************************************************************/ -static int Create_S16ToFL32( vlc_object_t *p_this ) -{ - aout_filter_t * p_filter = (aout_filter_t *)p_this; - - if ( ( p_filter->fmt_in.audio.i_format != VLC_CODEC_S16N && - p_filter->fmt_in.audio.i_format != VLC_CODEC_S24N && - p_filter->fmt_in.audio.i_format != VLC_CODEC_S32N ) - || p_filter->fmt_out.audio.i_format != VLC_CODEC_FL32 ) - { - return -1; - } - - if ( !AOUT_FMTS_SIMILAR( &p_filter->fmt_in.audio, &p_filter->fmt_out.audio ) ) - { - return -1; - } - - if( p_filter->fmt_in.audio.i_format == VLC_CODEC_S32N ) - p_filter->pf_do_work = Do_S32ToFL32; - else if( p_filter->fmt_in.audio.i_format == VLC_CODEC_S24N ) - p_filter->pf_do_work = Do_S24ToFL32; - else - p_filter->pf_do_work = Do_S16ToFL32; - - p_filter->b_in_place = true; - - return 0; -} - -static void Do_S16ToFL32( aout_instance_t * p_aout, aout_filter_t * p_filter, - aout_buffer_t * p_in_buf, aout_buffer_t * p_out_buf ) -{ - VLC_UNUSED(p_aout); - int i = p_in_buf->i_nb_samples * aout_FormatNbChannels( &p_filter->fmt_in.audio ); - - /* We start from the end because b_in_place is true */ - int16_t * p_in = (int16_t *)p_in_buf->p_buffer + i - 1; - float * p_out = (float *)p_out_buf->p_buffer + i - 1; - - while( i-- ) - { -#if 0 - /* Slow version */ - *p_out = (float)*p_in / 32768.0; -#else - /* This is walken's trick based on IEEE float format. On my PIII - * this takes 16 seconds to perform one billion conversions, instead - * of 19 seconds for the above division. */ - union { float f; int32_t i; } u; - u.i = *p_in + 0x43c00000; - *p_out = u.f - 384.0; -#endif - - p_in--; p_out--; - } - - p_out_buf->i_nb_samples = p_in_buf->i_nb_samples; - p_out_buf->i_buffer = p_in_buf->i_buffer * 4 / 2; -} - -static void Do_S24ToFL32( aout_instance_t * p_aout, aout_filter_t * p_filter, - aout_buffer_t * p_in_buf, aout_buffer_t * p_out_buf ) -{ - VLC_UNUSED(p_aout); - int i = p_in_buf->i_nb_samples * aout_FormatNbChannels( &p_filter->fmt_in.audio ); - - /* We start from the end because b_in_place is true */ - uint8_t * p_in = (uint8_t *)p_in_buf->p_buffer + (i - 1) * 3; - float * p_out = (float *)p_out_buf->p_buffer + i - 1; - - while( i-- ) - { -#ifdef WORDS_BIGENDIAN - *p_out = ((float)( (((int32_t)*(int16_t *)(p_in)) << 8) + p_in[2])) -#else - *p_out = ((float)( (((int32_t)*(int16_t *)(p_in+1)) << 8) + p_in[0])) -#endif - / 8388608.0; - - p_in -= 3; p_out--; - } - - p_out_buf->i_nb_samples = p_in_buf->i_nb_samples; - p_out_buf->i_buffer = p_in_buf->i_buffer * 4 / 3; -} - -static void Do_S32ToFL32( aout_instance_t * p_aout, aout_filter_t * p_filter, - aout_buffer_t * p_in_buf, aout_buffer_t * p_out_buf ) -{ - VLC_UNUSED(p_aout); - int i = p_in_buf->i_nb_samples * aout_FormatNbChannels( &p_filter->fmt_in.audio ); - - /* We start from the end because b_in_place is true */ - int32_t * p_in = (int32_t *)p_in_buf->p_buffer + i - 1; - float * p_out = (float *)p_out_buf->p_buffer + i - 1; - - while( i-- ) - { - *p_out-- = (float)*p_in-- / 2147483648.0; - } - - p_out_buf->i_nb_samples = p_in_buf->i_nb_samples; - p_out_buf->i_buffer = p_in_buf->i_buffer * 4 / 4; -} - -/***************************************************************************** - * S16 To Float32 with endianness conversion - *****************************************************************************/ -static int Create_S16ToFL32_SW( vlc_object_t *p_this ) -{ - aout_filter_t * p_filter = (aout_filter_t *)p_this; - - if ( !AOUT_FMTS_SIMILAR( &p_filter->fmt_in.audio, &p_filter->fmt_out.audio ) ) - { - return -1; - } - - if ( (p_filter->fmt_in.audio.i_format == VLC_CODEC_S16L || - p_filter->fmt_in.audio.i_format == VLC_CODEC_S16B) - && p_filter->fmt_out.audio.i_format == VLC_CODEC_FL32 - && p_filter->fmt_in.audio.i_format != VLC_CODEC_S16N ) - { - p_filter->pf_do_work = Do_S16ToFL32_SW; - p_filter->b_in_place = true; - - return 0; - } - - if ( (p_filter->fmt_in.audio.i_format == VLC_CODEC_S24L || - p_filter->fmt_in.audio.i_format == VLC_CODEC_S24B) - && p_filter->fmt_out.audio.i_format == VLC_CODEC_FL32 - && p_filter->fmt_in.audio.i_format != VLC_CODEC_S24N ) - { - p_filter->pf_do_work = Do_S24ToFL32_SW; - p_filter->b_in_place = true; - - return 0; - } - - if ( (p_filter->fmt_in.audio.i_format == VLC_CODEC_S32L || - p_filter->fmt_in.audio.i_format == VLC_CODEC_S32B) - && p_filter->fmt_out.audio.i_format == VLC_CODEC_FL32 - && p_filter->fmt_in.audio.i_format != VLC_CODEC_S32N ) - { - p_filter->pf_do_work = Do_S32ToFL32_SW; - p_filter->b_in_place = true; - - return 0; - } - - return -1; -} - -static void Do_S16ToFL32_SW( aout_instance_t * p_aout, aout_filter_t * p_filter, - aout_buffer_t * p_in_buf, aout_buffer_t * p_out_buf ) -{ - VLC_UNUSED(p_aout); - int i = p_in_buf->i_nb_samples * aout_FormatNbChannels( &p_filter->fmt_in.audio ); - - /* We start from the end because b_in_place is true */ - int16_t * p_in; - float * p_out = (float *)p_out_buf->p_buffer + i - 1; - - int16_t p_swabbed[i]; - - swab( p_in_buf->p_buffer, p_swabbed, i * sizeof(int16_t) ); - p_in = p_swabbed + i - 1; - - - while( i-- ) - *p_out-- = (float)*p_in-- / 32768.0; - - p_out_buf->i_nb_samples = p_in_buf->i_nb_samples; - p_out_buf->i_buffer = p_in_buf->i_buffer * 4 / 2; -} - -static void Do_S24ToFL32_SW( aout_instance_t * p_aout, aout_filter_t * p_filter, - aout_buffer_t * p_in_buf, aout_buffer_t * p_out_buf ) -{ - VLC_UNUSED(p_aout); - int i = p_in_buf->i_nb_samples * aout_FormatNbChannels( &p_filter->fmt_in.audio ); - - /* We start from the end because b_in_place is true */ - uint8_t * p_in = (uint8_t *)p_in_buf->p_buffer + (i - 1) * 3; - float * p_out = (float *)p_out_buf->p_buffer + i - 1; - - uint8_t p_tmp[3]; - - while( i-- ) - { - p_tmp[0] = p_in[2]; - p_tmp[1] = p_in[1]; - p_tmp[2] = p_in[0]; - -#ifdef WORDS_BIGENDIAN - *p_out = ((float)( (((int32_t)*(int16_t *)(p_tmp)) << 8) + p_tmp[2])) -#else - *p_out = ((float)( (((int32_t)*(int16_t *)(p_tmp+1)) << 8) + p_tmp[0])) -#endif - / 8388608.0; - - p_in -= 3; p_out--; - } - - p_out_buf->i_nb_samples = p_in_buf->i_nb_samples; - p_out_buf->i_buffer = p_in_buf->i_buffer * 4 / 3; -} - -static void Do_S32ToFL32_SW( aout_instance_t * p_aout, aout_filter_t * p_filter, - aout_buffer_t * p_in_buf, aout_buffer_t * p_out_buf ) -{ - VLC_UNUSED(p_aout); - int i = p_in_buf->i_nb_samples * aout_FormatNbChannels( &p_filter->fmt_in.audio ); - - /* We start from the end because b_in_place is true */ - int32_t * p_in = (int32_t *)p_in_buf->p_buffer + i - 1; - float * p_out = (float *)p_out_buf->p_buffer + i - 1; - - while( i-- ) - { - *p_out-- = (float)*p_in-- / 2147483648.0; - } - - p_out_buf->i_nb_samples = p_in_buf->i_nb_samples; - p_out_buf->i_buffer = p_in_buf->i_buffer * 4 / 4; -} - - -/***************************************************************************** - * S8 To FL32 - *****************************************************************************/ -static int Create_S8ToFL32( vlc_object_t *p_this ) -{ - aout_filter_t * p_filter = (aout_filter_t *)p_this; - - if ( p_filter->fmt_in.audio.i_format != VLC_CODEC_S8 - || p_filter->fmt_out.audio.i_format != VLC_CODEC_FL32 ) - { - return -1; - } - - if ( !AOUT_FMTS_SIMILAR( &p_filter->fmt_in.audio, &p_filter->fmt_out.audio ) ) - { - return -1; - } - - p_filter->pf_do_work = Do_S8ToFL32; - p_filter->b_in_place = true; - - return 0; -} - -static void Do_S8ToFL32( aout_instance_t * p_aout, aout_filter_t * p_filter, - aout_buffer_t * p_in_buf, aout_buffer_t * p_out_buf ) -{ - VLC_UNUSED(p_aout); - int i = p_in_buf->i_nb_samples * aout_FormatNbChannels( &p_filter->fmt_in.audio ); - - /* We start from the end because b_in_place is true */ - int8_t * p_in = (int8_t *)p_in_buf->p_buffer + i - 1; - float * p_out = (float *)p_out_buf->p_buffer + i - 1; - - while( i-- ) - { - *p_out = (float)(*p_in) / 128.0; - p_in--; p_out--; - } - - p_out_buf->i_nb_samples = p_in_buf->i_nb_samples; - p_out_buf->i_buffer = p_in_buf->i_buffer * sizeof(float); -} - -/***************************************************************************** - * U8 To FL32 - *****************************************************************************/ -static int Create_U8ToFL32( vlc_object_t *p_this ) -{ - aout_filter_t * p_filter = (aout_filter_t *)p_this; - - if ( p_filter->fmt_in.audio.i_format != VLC_CODEC_U8 - || p_filter->fmt_out.audio.i_format != VLC_CODEC_FL32 ) - { - return -1; - } - - if ( !AOUT_FMTS_SIMILAR( &p_filter->fmt_in.audio, &p_filter->fmt_out.audio ) ) - { - return -1; - } - - p_filter->pf_do_work = Do_U8ToFL32; - p_filter->b_in_place = true; - - return 0; -} - -static void Do_U8ToFL32( aout_instance_t * p_aout, aout_filter_t * p_filter, - aout_buffer_t * p_in_buf, aout_buffer_t * p_out_buf ) -{ - VLC_UNUSED(p_aout); - int i = p_in_buf->i_nb_samples * aout_FormatNbChannels( &p_filter->fmt_in.audio ); - - /* We start from the end because b_in_place is true */ - uint8_t * p_in = (uint8_t *)p_in_buf->p_buffer + i - 1; - float * p_out = (float *)p_out_buf->p_buffer + i - 1; - - while( i-- ) - { - *p_out = ((float)*p_in -128) / 128.0; - p_in--; p_out--; - } - - p_out_buf->i_nb_samples = p_in_buf->i_nb_samples; - p_out_buf->i_buffer = p_in_buf->i_buffer * sizeof(float); -} -- 2.39.5