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 );
66 aout_instance_t *p_aout = input_GetAout( p_input );
67 vlc_object_release( p_input );
68 char *psz_af = var_GetNonEmptyString( p_aout, "audio-filter" );
69 if ( strstr ( psz_af, "equalizer" ) == NULL )
71 vlc_object_release( p_aout );
74 float preamp = var_GetFloat( p_aout, "equalizer-preamp");
75 lua_pushnumber( L, preamp );
76 vlc_object_release( p_aout );
82 /*****************************************************************************
83 * Set the preamp level
84 *****************************************************************************/
85 static int vlclua_preamp_set( lua_State *L )
87 input_thread_t *p_input = vlclua_get_input_internal( L );
90 aout_instance_t *p_aout = input_GetAout( p_input );
91 vlc_object_release( p_input );
96 char *psz_af = var_GetNonEmptyString( p_aout, "audio-filter" );
97 if ( strstr ( psz_af, "equalizer" ) == NULL )
99 vlc_object_release( p_aout );
102 float preamp = luaL_checknumber( L, 1 );
103 var_SetFloat( p_aout, "equalizer-preamp",preamp);
104 lua_pushnumber( L, preamp );
105 vlc_object_release( p_aout );
111 /*****************************************************************************
123 *****************************************************************************/
124 /*****************************************************************************
125 * Get the equalizer level for the specified band
126 *****************************************************************************/
127 static int vlclua_equalizer_get( lua_State *L )
129 input_thread_t *p_input = vlclua_get_input_internal( L );
133 aout_instance_t *p_aout = input_GetAout( p_input );
134 vlc_object_release( p_input );
139 char *psz_af = var_GetNonEmptyString( p_aout, "audio-filter" );
140 if ( strstr ( psz_af, "equalizer" ) == NULL )
142 vlc_object_release( p_aout );
146 int bandid = luaL_checknumber( L, 1 );
147 char *bands = var_GetNonEmptyString( p_aout, "equalizer-bands" );
148 locale_t loc = newlocale (LC_NUMERIC_MASK, "C", NULL);
149 locale_t oldloc = uselocale (loc);
152 level = strtof( bands, &bands);
155 if (loc != (locale_t)0)
162 vlc_object_release( p_aout );
165 lua_pushnumber( L, level );
166 vlc_object_release( p_aout );
171 /*****************************************************************************
172 * Set the equalizer level for the specified band
173 *****************************************************************************/
174 static int vlclua_equalizer_set( lua_State *L )
176 input_thread_t *p_input = vlclua_get_input_internal( L );
179 int i_pos = 0 , j = 0;
180 aout_instance_t *p_aout = input_GetAout( p_input );
181 vlc_object_release( p_input );
186 char *psz_af = var_GetNonEmptyString( p_aout, "audio-filter" );
187 if ( strstr ( psz_af, "equalizer" ) == NULL )
189 vlc_object_release( p_aout );
192 int bandid = luaL_checknumber( L, 1 );
193 float level = luaL_checknumber( L, 2 );
194 char *bands = var_GetString( p_aout, "equalizer-bands" );
199 if( bands[i_pos] == '.' )
207 snprintf( newstr, sizeof ( newstr ) , "%6.1f", level);
208 for( int i = 0 ; i < 6 ; i++ )
209 bands[i_pos+i] = newstr[i];
210 var_SetString( p_aout, "equalizer-bands",bands );
211 vlc_object_release( p_aout );
216 static const luaL_Reg vlclua_equalizer_reg[] = {
217 { "preampget", vlclua_preamp_get },
218 { "preampset", vlclua_preamp_set },
219 { "equalizerget", vlclua_equalizer_get },
220 { "equalizerset", vlclua_equalizer_set },
224 void luaopen_equalizer( lua_State *L )
227 luaL_register( L, NULL, vlclua_equalizer_reg );
228 lua_setfield( L, -2, "equalizer" );