[vlc-commits] lua: fix equalizer setting code
Pierre Ynard
git at videolan.org
Mon May 21 01:00:19 CEST 2012
vlc/vlc-2.0 | branch: master | Pierre Ynard <linkfanel at yahoo.fr> | Mon May 21 00:34:12 2012 +0200| [e77f9d4e8e3ddf0ea3b1e8c0ee62f79799d6d6c4] | committer: Pierre Ynard
lua: fix equalizer setting code
(cherry picked from commit 71276f2b20747c9343b0741e117d3b480811df00)
Signed-off-by: Pierre Ynard <linkfanel at yahoo.fr>
> http://git.videolan.org/gitweb.cgi/vlc/vlc-2.0.git/?a=commit;h=e77f9d4e8e3ddf0ea3b1e8c0ee62f79799d6d6c4
---
modules/lua/libs/equalizer.c | 41 +++++++++++++++++++++++++----------------
1 file changed, 25 insertions(+), 16 deletions(-)
diff --git a/modules/lua/libs/equalizer.c b/modules/lua/libs/equalizer.c
index 4a8fb96..02ebbf9 100644
--- a/modules/lua/libs/equalizer.c
+++ b/modules/lua/libs/equalizer.c
@@ -209,7 +209,6 @@ static int vlclua_equalizer_set( lua_State *L )
if( !p_input )
return 0;
- int i_pos = 0 , j = 0;
audio_output_t *p_aout = input_GetAout( p_input );
vlc_object_release( p_input );
if( !p_aout )
@@ -226,26 +225,36 @@ static int vlclua_equalizer_set( lua_State *L )
float level = luaL_checknumber( L, 2 );
char *bands = var_GetString( p_aout, "equalizer-bands" );
- char newstr[7];
- while( j != bandid )
+
+ locale_t loc = newlocale (LC_NUMERIC_MASK, "C", NULL);
+ locale_t oldloc = uselocale (loc);
+ char *b = bands;
+ while( bandid > 0 )
{
- i_pos++;
- if( bands[i_pos] == '.' )
- {
- i_pos++;
- j++;
- }
+ float dummy = strtof( b, &b );
+ (void)dummy;
+ bandid--;
+ }
+ if( *b != '\0' )
+ *b++ = '\0';
+ float dummy = strtof( b, &b );
+ (void)dummy;
+
+ char *newstr;
+ if( asprintf( &newstr, "%s %.1f%s", bands, level, b ) != -1 )
+ {
+ var_SetString( p_aout, "equalizer-bands", newstr );
+ free( newstr );
}
- if( bandid != 0 )
- i_pos++;
- snprintf( newstr, sizeof ( newstr ) , "%6.1f", level);
- for( int i = 0 ; i < 6 ; i++ )
- bands[i_pos+i] = newstr[i];
- var_SetString( p_aout, "equalizer-bands", bands );
+ if( loc != (locale_t)0 )
+ {
+ uselocale (oldloc);
+ freelocale (loc);
+ }
free( bands );
vlc_object_release( p_aout );
- return 1;
+ return 0;
}
/*****************************************************************************
More information about the vlc-commits
mailing list