Change the gmp download URL to https://gmplib.org/download
[vlc/gmpfix.git] / modules / audio_mixer / float.c
blob227069e696e063f017419d58b84612987b40627c
1 /*****************************************************************************
2 * float32.c : precise float32 audio volume implementation
3 *****************************************************************************
4 * Copyright (C) 2002 VLC authors and VideoLAN
5 * $Id$
7 * Authors: Christophe Massiot <massiot@via.ecp.fr>
9 * This program is free software; you can redistribute it and/or modify it
10 * under the terms of the GNU Lesser General Public License as published by
11 * the Free Software Foundation; either version 2.1 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public License
20 * along with this program; if not, write to the Free Software Foundation,
21 * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
22 *****************************************************************************/
24 /*****************************************************************************
25 * Preamble
26 *****************************************************************************/
28 #ifdef HAVE_CONFIG_H
29 # include "config.h"
30 #endif
32 #include <stddef.h>
33 #include <vlc_common.h>
34 #include <vlc_plugin.h>
35 #include <vlc_aout.h>
36 #include <vlc_aout_volume.h>
38 /*****************************************************************************
39 * Local prototypes
40 *****************************************************************************/
41 static int Create( vlc_object_t * );
43 /*****************************************************************************
44 * Module descriptor
45 *****************************************************************************/
46 vlc_module_begin ()
47 set_category( CAT_AUDIO )
48 set_subcategory( SUBCAT_AUDIO_MISC )
49 set_description( N_("Single precision audio volume") )
50 set_capability( "audio volume", 10 )
51 set_callbacks( Create, NULL )
52 vlc_module_end ()
54 /**
55 * Mixes a new output buffer
57 static void FilterFL32( audio_volume_t *p_volume, block_t *p_buffer,
58 float f_multiplier )
60 if( f_multiplier == 1.f )
61 return; /* nothing to do */
63 float *p = (float *)p_buffer->p_buffer;
64 for( size_t i = p_buffer->i_buffer / sizeof(*p); i > 0; i-- )
65 *(p++) *= f_multiplier;
67 (void) p_volume;
70 static void FilterFL64( audio_volume_t *p_volume, block_t *p_buffer,
71 float f_multiplier )
73 double *p = (double *)p_buffer->p_buffer;
74 double mult = f_multiplier;
75 if( mult == 1. )
76 return; /* nothing to do */
78 for( size_t i = p_buffer->i_buffer / sizeof(*p); i > 0; i-- )
79 *(p++) *= mult;
81 (void) p_volume;
84 /**
85 * Initializes the mixer
87 static int Create( vlc_object_t *p_this )
89 audio_volume_t *p_volume = (audio_volume_t *)p_this;
91 switch (p_volume->format)
93 case VLC_CODEC_FL32:
94 p_volume->amplify = FilterFL32;
95 break;
96 case VLC_CODEC_FL64:
97 p_volume->amplify = FilterFL64;
98 break;
99 default:
100 return -1;
102 return 0;