]> git.sesse.net Git - vlc/blob - modules/audio_filter/converter/float.c
6fbe0cea39a7446ced3ec482f5cba22d3b66af78
[vlc] / modules / audio_filter / converter / float.c
1 /*****************************************************************************
2  * float.c: Floating point audio format conversions
3  *****************************************************************************
4  * Copyright (C) 2002, 2006-2009 the VideoLAN team
5  * $Id$
6  *
7  * Authors: Jean-Paul Saman <jpsaman _at_ videolan _dot_ org>
8  *          Christophe Massiot <massiot@via.ecp.fr>
9  *          Samuel Hocevar <sam@zoy.org>
10  *          Xavier Maillard <zedek@fxgsproject.org>
11  *          Henri Fallon <henri@videolan.org>
12  *          Gildas Bazin <gbazin@netcourrier.com>
13  *
14  * This program is free software; you can redistribute it and/or modify
15  * it under the terms of the GNU General Public License as published by
16  * the Free Software Foundation; either version 2 of the License, or
17  * (at your option) any later version.
18  *
19  * This program is distributed in the hope that it will be useful,
20  * but WITHOUT ANY WARRANTY; without even the implied warranty of
21  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
22  * GNU General Public License for more details.
23  *
24  * You should have received a copy of the GNU General Public License
25  * along with this program; if not, write to the Free Software
26  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
27  *****************************************************************************/
28
29 /*****************************************************************************
30  * Preamble
31  *****************************************************************************/
32 #ifdef HAVE_CONFIG_H
33 # include "config.h"
34 #endif
35
36 #include <vlc_common.h>
37 #include <vlc_plugin.h>
38 #include <vlc_aout.h>
39 #include <vlc_filter.h>
40
41 /*****************************************************************************
42  * Local prototypes
43  *****************************************************************************/
44 static int  Create_F32ToFL32 ( vlc_object_t * );
45 static block_t *Do_F32ToFL32( filter_t *, block_t * );
46 static block_t *Do_FL32ToF32 ( filter_t *, block_t * );
47
48 /*****************************************************************************
49  * Module descriptor
50  *****************************************************************************/
51 vlc_module_begin ()
52     set_description( N_("Floating-point audio format conversions") )
53     add_submodule ()
54         set_capability( "audio filter2", 10 )
55         set_callbacks( Create_F32ToFL32, NULL )
56 vlc_module_end ()
57
58 /*****************************************************************************
59  * Fixed 32 to Float 32 and backwards
60  *****************************************************************************/
61 static int Create_F32ToFL32( vlc_object_t *p_this )
62 {
63     filter_t * p_filter = (filter_t *)p_this;
64
65     if( ( p_filter->fmt_in.audio.i_format != VLC_CODEC_FI32
66            || p_filter->fmt_out.audio.i_format != VLC_CODEC_FL32 )
67       && ( p_filter->fmt_in.audio.i_format != VLC_CODEC_FL32
68             || p_filter->fmt_out.audio.i_format != VLC_CODEC_FI32 ) )
69     {
70         return VLC_EGENERIC;
71     }
72
73     if ( !AOUT_FMTS_SIMILAR( &p_filter->fmt_in.audio, &p_filter->fmt_out.audio ) )
74     {
75         return VLC_EGENERIC;
76     }
77
78     if( p_filter->fmt_in.audio.i_format == VLC_CODEC_FI32 )
79     {
80         p_filter->pf_audio_filter = Do_F32ToFL32;
81     }
82     else
83     {
84         p_filter->pf_audio_filter = Do_FL32ToF32;
85     }
86
87     return VLC_SUCCESS;
88 }
89
90 static block_t *Do_F32ToFL32( filter_t * p_filter, block_t * p_in_buf )
91 {
92     int i;
93     vlc_fixed_t * p_in = (vlc_fixed_t *)p_in_buf->p_buffer;
94     float * p_out = (float *)p_in_buf->p_buffer;
95
96     for ( i = p_in_buf->i_nb_samples
97                * aout_FormatNbChannels( &p_filter->fmt_in.audio ) ; i-- ; )
98     {
99         *p_out++ = (float)*p_in++ / (float)FIXED32_ONE;
100     }
101     return p_in_buf;
102 }
103
104 static block_t *Do_FL32ToF32( filter_t * p_filter, block_t * p_in_buf )
105 {
106     int i;
107     float * p_in = (float *)p_in_buf->p_buffer;
108     vlc_fixed_t * p_out = (vlc_fixed_t *)p_in_buf->p_buffer;
109
110     for ( i = p_in_buf->i_nb_samples
111                * aout_FormatNbChannels( &p_filter->fmt_in.audio ) ; i-- ; )
112     {
113         *p_out++ = (vlc_fixed_t)( *p_in++ * (float)FIXED32_ONE );
114     }
115     return p_in_buf;
116 }