1 /*****************************************************************************
3 *****************************************************************************
4 * Copyright (C) 2011 VideoLAN and VLC authors
7 * Authors: Akash Mehrotra < mehrotra <dot> akash <at> gmail <dot> com >
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 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 General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
22 *****************************************************************************/
24 /*****************************************************************************
26 *****************************************************************************/
35 #include <vlc_common.h>
37 #include <vlc_input.h>
38 #include <vlc_charset.h>
40 #include <lua.h> /* Low level lua C API */
41 #include <lauxlib.h> /* Higher level C API */
58 /*****************************************************************************
59 * Get the preamp level
60 *****************************************************************************/
61 static int vlclua_preamp_get( lua_State *L )
63 input_thread_t *p_input = vlclua_get_input_internal( L );
67 aout_instance_t *p_aout = input_GetAout( p_input );
68 vlc_object_release( p_input );
70 char *psz_af = var_GetNonEmptyString( p_aout, "audio-filter" );
71 if( strstr ( psz_af, "equalizer" ) == NULL )
73 vlc_object_release( p_aout );
77 lua_pushnumber( L, var_GetFloat( p_aout, "equalizer-preamp") );
78 vlc_object_release( p_aout );
83 /*****************************************************************************
84 * Set the preamp level
85 *****************************************************************************/
86 static int vlclua_preamp_set( lua_State *L )
88 input_thread_t *p_input = vlclua_get_input_internal( L );
92 aout_instance_t *p_aout = input_GetAout( p_input );
93 vlc_object_release( p_input );
97 char *psz_af = var_GetNonEmptyString( p_aout, "audio-filter" );
98 if( strstr ( psz_af, "equalizer" ) == NULL )
100 vlc_object_release( p_aout );
104 var_SetFloat( p_aout, "equalizer-preamp", luaL_checknumber( L, 1 ) );
105 vlc_object_release( p_aout );
110 /*****************************************************************************
122 *****************************************************************************/
123 /*****************************************************************************
124 * Get the equalizer level for the specified band
125 *****************************************************************************/
126 static int vlclua_equalizer_get( lua_State *L )
128 input_thread_t *p_input = vlclua_get_input_internal( L );
132 aout_instance_t *p_aout = input_GetAout( p_input );
133 vlc_object_release( p_input );
138 char *psz_af = var_GetNonEmptyString( p_aout, "audio-filter" );
139 if( strstr ( psz_af, "equalizer" ) == NULL )
141 vlc_object_release( p_aout );
145 int bandid = luaL_checknumber( L, 1 );
146 char *bands = var_GetNonEmptyString( p_aout, "equalizer-bands" );
147 locale_t loc = newlocale (LC_NUMERIC_MASK, "C", NULL);
148 locale_t oldloc = uselocale (loc);
151 level = strtof( bands, &bands);
154 if (loc != (locale_t)0)
161 vlc_object_release( p_aout );
164 lua_pushnumber( L, level );
172 /*****************************************************************************
173 * Set the equalizer level for the specified band
174 *****************************************************************************/
175 static int vlclua_equalizer_set( lua_State *L )
177 input_thread_t *p_input = vlclua_get_input_internal( L );
181 int i_pos = 0 , j = 0;
182 aout_instance_t *p_aout = input_GetAout( p_input );
183 vlc_object_release( p_input );
187 char *psz_af = var_GetNonEmptyString( p_aout, "audio-filter" );
188 if( strstr ( psz_af, "equalizer" ) == NULL )
190 vlc_object_release( p_aout );
194 int bandid = luaL_checknumber( L, 1 );
195 float level = luaL_checknumber( L, 2 );
196 char *bands = var_GetString( p_aout, "equalizer-bands" );
201 if( bands[i_pos] == '.' )
209 snprintf( newstr, sizeof ( newstr ) , "%6.1f", level);
210 for( int i = 0 ; i < 6 ; i++ )
211 bands[i_pos+i] = newstr[i];
212 var_SetString( p_aout, "equalizer-bands", bands );
214 vlc_object_release( p_aout );
219 static const luaL_Reg vlclua_equalizer_reg[] = {
220 { "preampget", vlclua_preamp_get },
221 { "preampset", vlclua_preamp_set },
222 { "equalizerget", vlclua_equalizer_get },
223 { "equalizerset", vlclua_equalizer_set },
228 void luaopen_equalizer( lua_State *L )
231 luaL_register( L, NULL, vlclua_equalizer_reg );
232 lua_setfield( L, -2, "equalizer" );