[vlc-devel] [PATCH 4/6] http lua: Update equalizer support

Ronald Wright logiconcepts819 at gmail.com
Sat Nov 28 07:31:04 CET 2015


Note:  Patches 2 through 6 must be applied all together, and patches 2 and 3
cannot be applied without patch 1.
---
 modules/lua/libs/equalizer.c                 | 253 +++++++++++++++++++++------
 share/lua/http/css/main.css                  |  17 ++
 share/lua/http/dialogs/equalizer_window.html |   3 +
 share/lua/http/js/controllers.js             |  59 ++++++-
 share/lua/http/mobile_equalizer.html         |   3 +
 share/lua/intf/modules/httprequests.lua      |   1 +
 6 files changed, 279 insertions(+), 57 deletions(-)

diff --git a/modules/lua/libs/equalizer.c b/modules/lua/libs/equalizer.c
index 512bae1..f366ce4 100644
--- a/modules/lua/libs/equalizer.c
+++ b/modules/lua/libs/equalizer.c
@@ -36,6 +36,7 @@
 #include <vlc_aout.h>
 #include <vlc_input.h>
 #include <vlc_charset.h>
+#include <vlc_eqz_util.h>
 
 #include "input.h"
 #include "../libs.h"
@@ -106,6 +107,8 @@ static int vlclua_preamp_set( lua_State *L )
 
 /*****************************************************************************
 Bands:
+
+10-band VLC equalizer:
 Band 0:  60 Hz
 Band 1: 170 Hz
 Band 2: 310 Hz
@@ -116,14 +119,74 @@ Band 6:  6 kHz
 Band 7: 12 kHz
 Band 8: 14 kHz
 Band 9: 16 kHz
+
+10-band ISO equalizer:
+Band 0:  31.5 Hz
+Band 1:  63   Hz
+Band 2: 125   Hz
+Band 3: 250   Hz
+Band 4: 500   Hz
+Band 5:   1  kHz
+Band 6:   2  kHz
+Band 7:   4  kHz
+Band 8:   8  kHz
+Band 9:  16  kHz
+
+15-band ISO equalizer:
+Band  0:  25  Hz
+Band  1:  40  Hz
+Band  2:  63  Hz
+Band  3: 100  Hz
+Band  4: 160  Hz
+Band  5: 250  Hz
+Band  6: 400  Hz
+Band  7: 630  Hz
+Band  8:   1 kHz
+Band  9: 1.6 kHz
+Band 10: 2.5 kHz
+Band 11:   4 kHz
+Band 12: 6.3 kHz
+Band 13:  10 kHz
+Band 14:  16 kHz
+
+31-band ISO equalizer:
+Band  0:  20     Hz
+Band  1:  25     Hz
+Band  2:  31.5   Hz
+Band  3:  40     Hz
+Band  4:  50     Hz
+Band  5:  63     Hz
+Band  6:  80     Hz
+Band  7: 100     Hz
+Band  8: 125     Hz
+Band  9: 160     Hz
+Band 10: 200     Hz
+Band 11: 250     Hz
+Band 12: 315     Hz
+Band 13: 400     Hz
+Band 14: 500     Hz
+Band 15: 630     Hz
+Band 16: 800     Hz
+Band 17:   1    kHz
+Band 18:   1.25 kHz
+Band 19:   1.6  kHz
+Band 20:   2    kHz
+Band 21:   2.5  kHz
+Band 22:   3.15 kHz
+Band 23:   4    kHz
+Band 24:   5    kHz
+Band 25:   6.3  kHz
+Band 26:   8    kHz
+Band 27:  10    kHz
+Band 28:  12.5  kHz
+Band 29:  16    kHz
+Band 30:  20    kHz
 *****************************************************************************/
 /*****************************************************************************
 * Return EQ level for all bands as a Table
 *****************************************************************************/
 static int vlclua_equalizer_get( lua_State *L )
 {
-    const unsigned bands = 10;
-
     playlist_t *p_playlist = vlclua_get_playlist_internal( L );
     audio_output_t *p_aout = playlist_GetAout( p_playlist );
     if( p_aout == NULL )
@@ -138,44 +201,69 @@ static int vlclua_equalizer_get( lua_State *L )
     }
     free( psz_af );
 
-    char *psz_bands_origin, *psz_bands;
-    psz_bands_origin = psz_bands = var_GetNonEmptyString( p_aout, "equalizer-bands" );
+    char *psz_bands = var_GetNonEmptyString( p_aout, "equalizer-bands" );
     if( !psz_bands )
     {
         vlc_object_release( p_aout );
         return 0;
     }
 
-    bool error = false;
-    locale_t loc = newlocale (LC_NUMERIC_MASK, "C", NULL);
-    locale_t oldloc = uselocale (loc);
-    lua_newtable( L );
-    for( unsigned i = 0; i < bands; i++ )
+    char *psz_band_count = var_InheritString( p_aout,
+            "equalizer-bands-count" );
+    if( !psz_band_count )
     {
-        float level = strtof( psz_bands, &psz_bands );
-        char *str;
-        if( asprintf( &str , "%f" , level ) == -1 )
+        free( psz_bands );
+        vlc_object_release( p_aout );
+        return 0;
+    }
+
+    bool b_vlcFreqs = var_InheritBool( p_aout, "equalizer-vlcfreqs" );
+    int i_type = EqzGetTypeNumber( VLC_OBJECT( p_aout ),
+                                   atoi( psz_band_count ), b_vlcFreqs );
+    if( i_type == EQZ_UNKNOWN_TYPE )
+        i_type = EQZ_VLC10_TYPE;
+
+    vlc_band_parse_t ctx;
+    bool error = vlc_eqz_util_band_parser_init( VLC_OBJECT( p_aout ), &ctx,
+        psz_bands, i_type, NULL ) != VLC_SUCCESS;
+    if( !error )
+    {
+        int i_bands = EqzGetNumBandsByType( i_type );
+        const float * pf_levels = vlc_eqz_util_get_amp_array( ctx );
+
+        locale_t loc = newlocale (LC_NUMERIC_MASK, "C", NULL);
+        locale_t oldloc = uselocale (loc);
+        lua_newtable( L );
+
+        for( int i = 0; i < i_bands; i++ )
         {
-            error = true;
-            break;
+            float level = pf_levels[i];
+            char *str;
+            if( asprintf( &str , "%f" , level ) == -1 )
+            {
+                error = true;
+                break;
+            }
+            lua_pushstring( L, str );
+            free(str);
+            if( asprintf( &str , "band id=\"%u\"", i ) == -1 )
+            {
+                error = true;
+                break;
+            }
+            lua_setfield( L , -2 , str );
+            free( str );
         }
-        lua_pushstring( L, str );
-        free(str);
-        if( asprintf( &str , "band id=\"%u\"", i ) == -1 )
+        vlc_eqz_util_band_parser_destroy( ctx );
+
+        if( loc != (locale_t)0 )
         {
-            error = true;
-            break;
+            uselocale (oldloc);
+            freelocale (loc);
         }
-        lua_setfield( L , -2 , str );
-        free( str );
-    }
-
-    free( psz_bands_origin );
-    if( loc != (locale_t)0 )
-    {
-        uselocale (oldloc);
-        freelocale (loc);
     }
+    free( psz_bands );
+    free( psz_band_count );
     vlc_object_release( p_aout );
     return error ? 0 : 1;
 }
@@ -187,7 +275,7 @@ static int vlclua_equalizer_get( lua_State *L )
 static int vlclua_equalizer_set( lua_State *L )
 {
     int bandid = luaL_checknumber( L, 1 );
-    if( bandid < 0 || bandid > 9)
+    if( bandid < 0 )
         return 0;
 
     playlist_t *p_playlist = vlclua_get_playlist_internal( L );
@@ -204,41 +292,103 @@ static int vlclua_equalizer_set( lua_State *L )
     }
     free( psz_af );
 
+    char * psz_band_count =
+        var_InheritString( p_aout, "equalizer-bands-count" );
+    bool b_vlcFreqs = var_InheritBool( p_aout, "equalizer-vlcfreqs" );
+    int i_type = EqzGetTypeNumber( VLC_OBJECT( p_aout ),
+                                   atoi( psz_band_count ), b_vlcFreqs );
+    if( i_type == EQZ_UNKNOWN_TYPE )
+        i_type = EQZ_VLC10_TYPE;
+    int i_bands = EqzGetNumBandsByType( i_type );
+    if( bandid >= i_bands )
+    {
+        vlc_object_release( p_aout );
+        return 0;
+    }
+
     float level = luaL_checknumber( L, 2 );
     char *bands = var_GetString( p_aout, "equalizer-bands" );
 
-    locale_t loc = newlocale (LC_NUMERIC_MASK, "C", NULL);
-    locale_t oldloc = uselocale (loc);
-    char *b = bands;
-    while( bandid > 0 )
+    vlc_band_parse_t ctx;
+    if( vlc_eqz_util_band_parser_init( VLC_OBJECT( p_aout ), &ctx,
+        bands, i_type, NULL ) == VLC_SUCCESS )
     {
-        float dummy = strtof( b, &b );
-        (void)dummy;
-        bandid--;
-    }
-    if( *b != '\0' )
-        *b++ = '\0';
-    float dummy = strtof( b, &b );
-    (void)dummy;
+        const float * pf_levels = vlc_eqz_util_get_amp_array( ctx );
+        char *newstr = NULL;
 
-    char *newstr;
-    if( asprintf( &newstr, "%s %.1f%s", bands, level, b ) != -1 )
-    {
-        var_SetString( p_aout, "equalizer-bands", newstr );
-        free( newstr );
-    }
+        locale_t loc = newlocale (LC_NUMERIC_MASK, "C", NULL);
+        locale_t oldloc = uselocale (loc);
 
-    if( loc != (locale_t)0 )
-    {
-        uselocale (oldloc);
-        freelocale (loc);
+        for( int i = 0; i < i_bands; i++ )
+        {
+            float f_level = i == bandid ? level : pf_levels[i];
+            char *psz;
+            if( asprintf( &psz, "%s %.1f", i ? newstr : "", f_level ) == -1 )
+                psz = NULL;
+
+            free( newstr );
+            newstr = psz;
+            if( unlikely( psz == NULL ) )
+                break;
+        }
+        vlc_eqz_util_band_parser_destroy( ctx );
+
+        /* For 10 bands, we must help VLC differentiate between VLC bands and
+         * ISO bands */
+        if( likely( newstr ) && i_bands == EQZ_ISO10_BANDS_MAX )
+        {
+            char id = EqzGetIdentifier( i_type );
+            char * psz;
+            if( asprintf( &psz, "%s %c", newstr, id ) == -1 )
+                psz = NULL;
+
+            free( newstr );
+            newstr = psz;
+        }
+
+        if( likely( newstr ) )
+        {
+            var_SetString( p_aout, "equalizer-bands", newstr );
+            free( newstr );
+        }
+
+        if( loc != (locale_t)0 )
+        {
+            uselocale (oldloc);
+            freelocale (loc);
+        }
     }
     free( bands );
+    free( psz_band_count );
     vlc_object_release( p_aout );
     return 0;
 }
 
 /*****************************************************************************
+* Get whether VLC frequencies are active
+*****************************************************************************/
+static int vlclua_usevlcfreqs_get( lua_State *L )
+{
+    playlist_t *p_playlist = vlclua_get_playlist_internal( L );
+    audio_output_t *p_aout = playlist_GetAout( p_playlist );
+    if( p_aout == NULL )
+        return 0;
+
+    char *psz_af = var_GetNonEmptyString( p_aout, "audio-filter" );
+    if( !psz_af || strstr ( psz_af, "equalizer" ) == NULL )
+    {
+        free( psz_af );
+        vlc_object_release( p_aout );
+        return 0;
+    }
+    free( psz_af );
+
+    lua_pushboolean( L, var_InheritBool( p_aout, "equalizer-vlcfreqs") );
+    vlc_object_release( p_aout );
+    return 1;
+}
+
+/*****************************************************************************
 * Set the preset specified by preset id
 *****************************************************************************/
 static int vlclua_equalizer_setpreset( lua_State *L )
@@ -296,6 +446,7 @@ static const luaL_Reg vlclua_equalizer_reg[] = {
     { "preampset", vlclua_preamp_set },
     { "equalizerget", vlclua_equalizer_get },
     { "equalizerset", vlclua_equalizer_set },
+    { "usingvlcfreqsget", vlclua_usevlcfreqs_get },
     { "enable", vlclua_equalizer_enable },
     { "presets",vlclua_equalizer_get_presets },
     { "setpreset", vlclua_equalizer_setpreset },
diff --git a/share/lua/http/css/main.css b/share/lua/http/css/main.css
index aebe6ce..5d52c2a 100644
--- a/share/lua/http/css/main.css
+++ b/share/lua/http/css/main.css
@@ -227,6 +227,18 @@ body{
 	font-size: 11px;
 }
 
+.eqtable{
+	display:table;
+}
+
+.eqrow{
+	display:table-row;
+}
+
+.eqcell{
+	display:table-cell;
+}
+
 #window_equalizer div div{
 	text-align: center;
 	font-size: 11px;
@@ -237,6 +249,11 @@ body{
 	height:80px !important ;
 }
 
+#window_equalizer_controls {
+	overflow-x: auto;
+	white-space: nowrap;
+}
+
 .eqBand{
 	margin-bottom: 10px;
 	margin-top: 10px;
diff --git a/share/lua/http/dialogs/equalizer_window.html b/share/lua/http/dialogs/equalizer_window.html
index a81bb13..edc9d1d 100755
--- a/share/lua/http/dialogs/equalizer_window.html
+++ b/share/lua/http/dialogs/equalizer_window.html
@@ -51,4 +51,7 @@
 	<div style="margin: 5px 5px 10px 5px;">
 		<div id="preamp" style="font-size: 18px;"></div>
 	</div>
+	<div style="margin: 5px 5px 5px 5px;">
+		<div id="window_equalizer_controls"><div class="eqtable"><div id="window_equalizer_control_row" class="eqrow"></div></div></div>
+	</div>
 </div>
diff --git a/share/lua/http/js/controllers.js b/share/lua/http/js/controllers.js
index 8c3a419..853ec93 100644
--- a/share/lua/http/js/controllers.js
+++ b/share/lua/http/js/controllers.js
@@ -9,6 +9,35 @@ function updateArt(url) {
     });
 }
 
+function getEqzBandFreqs(bandsCount, vlcFreqs) {
+    var freq;
+    if (bandsCount == 10) {
+        if (vlcFreqs) {
+            freq = ["60 Hz", "170 Hz", "310 Hz", "600 Hz", "1 kHz", "3 kHz",
+                    "6 kHz", "12 kHz", "14 kHz", "16 kHz"];
+        }
+        else {
+            freq = ["31.5 Hz", "63 Hz", "125 Hz", "250 Hz", "500 Hz", "1 kHz",
+                      "2 kHz", "4 kHz",  "8 kHz"," 16 kHz"];
+        }
+    }
+    else if (bandsCount == 15) {
+        freq = [  "25 Hz",  "40 Hz",  "63 Hz",  "100 Hz",  "160 Hz", "250 Hz",
+                 "400 Hz", "630 Hz",  "1 kHz", "1.6 KHz", "2.5 kHz",  "4 kHz",
+                "6.3 kHz", "10 kHz", "16 kHz"];
+    }
+    else if (bandsCount == 31) {
+        freq = [  "20 Hz",   "25 Hz", "31.5 Hz",    "40 Hz",   "50 Hz",
+                  "63 Hz",   "80 Hz",  "100 Hz",   "125 Hz",  "160 Hz",
+                 "200 Hz",  "250 Hz",  "315 Hz",   "400 Hz",  "500 Hz",
+                 "630 Hz",  "800 Hz",   "1 kHz", "1.25 kHz", "1.6 kHz",
+                  "2 kHz", "2.5 kHz", "3.15 Hz",    "4 kHz",   "5 kHz",
+                "6.3 kHz",   "8 kHz",  "10 kHz", "1.25 kHz", "1.6 kHz",
+                 "20 kHz"];
+    }
+    return freq;
+}
+
 function updateStatus() {
     $.ajax({
         url: 'requests/status.xml',
@@ -85,12 +114,21 @@ function updateStatus() {
                 }
 
             }
-            $('band', data).each(function () {
+            var bands = $('band', data);
+            bands.sort(function(a, b) {
+                return $(a).attr('id') - $(b).attr('id');
+            });
+            var vlcfreqs = $('vlcfreqs', data).text() == "true";
+            var freq = getEqzBandFreqs(bands.length, vlcfreqs);
+            var freqdisps = $('#window_equalizer_control_row').children('.eqcell').children('div').children('.eqz_freq_disp');
+            if (bands.length != freqdisps.length || vlcfreqs != (freqdisps.length > 0 && freqdisps.first().text() == "60 Hz")) {
+                $('#window_equalizer_control_row').empty();
+            }
+            bands.each(function () {
                 var id = $(this).attr('id');
                 var value = $(this).text() ? $(this).text() : 0;
-                var freq = ["60 Hz","170 Hz", "310 Hz", "600 Hz", "1 kHz","3 kHz", "6 kHz", "12 kHz" , "14 kHz" , "16 kHz" ];
                 if (!$('#eq_container' + id).length) {
-                    $('#window_equalizer').append('<div style="float:left;width:44px;" align="center" id="eq_container' + id + '"><div id="eq' + id + '_txt">' + value + 'dB</div><div class="eqBand" id="eq' + id + '" style="font-size: 18px;"></div><div>' + freq[id] + '</div></div>');
+                    $('#window_equalizer_control_row').append('<div class="eqcell"><div style="float:left;width:44px;" align="center" id="eq_container' + id + '"><div id="eq' + id + '_txt">' + value + 'dB</div><div class="eqBand" id="eq' + id + '" style="font-size: 18px; display: inline-block;"></div><div class="eqz_freq_disp">' + freq[id] + '</div><div style="height: 10px;"></div></div></div>');
                     $('#eq' + id).slider({
                         min: -20,
                         max: 20,
@@ -382,12 +420,21 @@ function updateEQ() {
     $.ajax({
         url: 'requests/status.xml',
         success: function (data, status, jqXHR) {
-            $('band', data).each(function () {
-                var freq = ["60 Hz","170 Hz", "310 Hz", "600 Hz", "1 kHz","3 kHz", "6 kHz", "12 kHz" , "14 kHz" , "16 kHz" ];
+            var bands = $('band', data);
+            bands.sort(function(a, b) {
+                return $(a).attr('id') - $(b).attr('id');
+            });
+            var vlcfreqs = $('vlcfreqs', data).text() == "true";
+            var freq = getEqzBandFreqs(bands.length, vlcfreqs);
+            var freqdisps = $('#window_equalizer_control_row').children('.eqcell').children('div').children('.eqz_freq_disp');
+            if (bands.length != freqdisps.length || vlcfreqs != (freqdisps.length > 0 && freqdisps.first().text() == "60 Hz")) {
+                $('#window_equalizer_control_row').empty();
+            }
+            bands.each(function () {
                 var id = $(this).attr('id');
                 var value = $(this).text() ? $(this).text() : 0;
                 if (!$('#eq_container' + id).length) {
-                    $('#window_equalizer').append('<div style="float:left;width:44px;" align="center" id="eq_container' + id + '"><div id="eq' + id + '_txt">' + value + 'dB</div><div class="eqBand" id="eq' + id + '" style="font-size: 18px;"></div><div>' + freq[id] + '</div></div>');
+                    $('#window_equalizer_control_row').append('<div class="eqcell"><div style="float:left;width:44px;" align="center" id="eq_container' + id + '"><div id="eq' + id + '_txt">' + value + 'dB</div><div class="eqBand" id="eq' + id + '" style="font-size: 18px; display: inline-block;"></div><div class="eqz_freq_disp">' + freq[id] + '</div><div style="height: 10px;"></div></div></div>');
                     $('#eq' + id).slider({
                         min: -20,
                         max: 20,
diff --git a/share/lua/http/mobile_equalizer.html b/share/lua/http/mobile_equalizer.html
index 7341109..258eb08 100644
--- a/share/lua/http/mobile_equalizer.html
+++ b/share/lua/http/mobile_equalizer.html
@@ -64,6 +64,9 @@
 			<div style="margin: 5px 5px 10px 5px;">
 				<div id="preamp" style="font-size: 22px;"></div>
 			</div>
+			<div style="margin: 5px 5px 5px 5px;">
+				<div id="window_equalizer_controls"><div class="eqtable"><div id="window_equalizer_control_row" class="eqrow"></div></div></div>
+			</div>
 		</div>
 	</body>
 </html>
diff --git a/share/lua/intf/modules/httprequests.lua b/share/lua/intf/modules/httprequests.lua
index e060cc1..1504057 100644
--- a/share/lua/intf/modules/httprequests.lua
+++ b/share/lua/intf/modules/httprequests.lua
@@ -507,6 +507,7 @@ getstatus = function (includecategories)
     s.equalizer={}
     s.equalizer.preamp=round(vlc.equalizer.preampget(),2)
     s.equalizer.bands=vlc.equalizer.equalizerget()
+    s.equalizer.vlcfreqs=vlc.equalizer.usingvlcfreqsget()
     if s.equalizer.bands ~= null then
         for k,i in pairs(s.equalizer.bands) do s.equalizer.bands[k]=round(i,2) end
         s.equalizer.presets=vlc.equalizer.presets()
-- 
1.9.1



More information about the vlc-devel mailing list