]> git.sesse.net Git - vlc/blobdiff - modules/audio_filter/equalizer.c
- the creation of the audio filter pipeline when specifying user audio
[vlc] / modules / audio_filter / equalizer.c
index dd2a98f254148510c3dea0e4cd7de7bf7ca057bf..9d03e7dd9f78b73b356324ee0e6cd303635b2dd1 100644 (file)
@@ -1,7 +1,7 @@
 /*****************************************************************************
  * equalizer.c:
  *****************************************************************************
- * Copyright (C) 2004 VideoLAN
+ * Copyright (C) 2004 the VideoLAN team
  * $Id$
  *
  * Authors: Laurent Aimar <fenrir@via.ecp.fr>
@@ -32,6 +32,7 @@
 #include <vlc/aout.h>
 #include "aout_internal.h"
 
+#include "equalizer_presets.h"
 /* TODO:
  *  - add tables for other rates ( 22500, 11250, ...)
  *  - optimize a bit (you can hardly do slower ;)
@@ -60,29 +61,21 @@ static void Close( vlc_object_t * );
 #define PREAMP_TEXT N_("Global gain" )
 #define PREAMP_LONGTEXT N_("Set the global gain in dB (-20 ... 20)" )
 
-static char *preset_list[] = {
-    "flat", "classical", "club", "dance", "fullbass", "fullbasstreeble",
-    "fulltreeble", "headphones","largehall", "live", "party", "pop", "reggae",
-    "rock", "ska", "soft", "softrock", "techno"
-};
-static char *preset_list_text[] = {
-    N_("Flat"), N_("Classical"), N_("Club"), N_("Dance"), N_("Full bass"),
-    N_("Full bass and treeble"), N_("Full treeble"), N_("Headphones"),
-    N_("Large Hall"), N_("Live"), N_("Party"), N_("Pop"), N_("Reggae"),
-    N_("Rock"), N_("Ska"), N_("Soft"), N_("Soft rock"), N_("Techno"),
-};
-
 vlc_module_begin();
     set_description( _("Equalizer 10 bands") );
+    set_shortname( N_("Equalizer" ) );
     set_capability( "audio filter", 0 );
+    set_category( CAT_AUDIO );
+    set_subcategory( SUBCAT_AUDIO_AFILTER );
+
     add_string( "equalizer-preset", "flat", NULL, PRESET_TEXT,
-                PRESET_LONGTEXT, VLC_TRUE );
+                PRESET_LONGTEXT, VLC_FALSE );
         change_string_list( preset_list, preset_list_text, 0 );
     add_string( "equalizer-bands", NULL, NULL, BANDS_TEXT,
                 BANDS_LONGTEXT, VLC_TRUE );
     add_bool( "equalizer-2pass", 0, NULL, TWOPASS_TEXT,
               TWOPASS_LONGTEXT, VLC_TRUE );
-    add_float( "equalizer-preamp", 0.0, NULL, PREAMP_TEXT,
+    add_float( "equalizer-preamp", 12.0, NULL, PREAMP_TEXT,
                PREAMP_LONGTEXT, VLC_TRUE );
     set_callbacks( Open, Close );
     add_shortcut( "equalizer" );
@@ -91,7 +84,6 @@ vlc_module_end();
 /*****************************************************************************
  * Local prototypes
  *****************************************************************************/
-
 typedef struct aout_filter_sys_t
 {
     /* Filter static config */
@@ -144,16 +136,26 @@ static int Open( vlc_object_t *p_this )
 {
     aout_filter_t     *p_filter = (aout_filter_t *)p_this;
     aout_filter_sys_t *p_sys;
+    vlc_bool_t         b_fit = VLC_TRUE;
 
     if( p_filter->input.i_format != VLC_FOURCC('f','l','3','2' ) ||
         p_filter->output.i_format != VLC_FOURCC('f','l','3','2') )
     {
+        b_fit = VLC_FALSE;
+        p_filter->input.i_format = VLC_FOURCC('f','l','3','2');
+        p_filter->output.i_format = VLC_FOURCC('f','l','3','2');
         msg_Warn( p_filter, "Bad input or output format" );
-        return VLC_EGENERIC;
     }
     if ( !AOUT_FMTS_SIMILAR( &p_filter->input, &p_filter->output ) )
     {
+        b_fit = VLC_FALSE;
+        memcpy( &p_filter->output, &p_filter->input,
+                sizeof(audio_sample_format_t) );
         msg_Warn( p_filter, "input and output formats are not similar" );
+    }
+
+    if ( ! b_fit )
+    {
         return VLC_EGENERIC;
     }
 
@@ -210,7 +212,7 @@ typedef struct
         float f_alpha;
         float f_beta;
         float f_gamma;
-    } band[];
+    } band[EQZ_BANDS_MAX];
 
 } eqz_config_t;
 
@@ -248,130 +250,6 @@ static const eqz_config_t eqz_config_48000_10b =
     }
 };
 
-typedef struct
-{
-    char *psz_name;
-    int  i_band;
-    float f_preamp;
-    float f_amp[];
-} eqz_preset_t;
-
-static const eqz_preset_t eqz_preset_flat_10b=
-{
-    "flat", 10, 12.0,
-    { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 },
-};
-static const eqz_preset_t eqz_preset_classical_10b=
-{
-    "classical", 10, 12.0,
-    { -1.11022e-15, -1.11022e-15, -1.11022e-15, -1.11022e-15, -1.11022e-15, -1.11022e-15, -7.2, -7.2, -7.2, -9.6 }
-};
-static const eqz_preset_t eqz_preset_club_10b=
-{
-    "club", 10, 6.0,
-    { -1.11022e-15, -1.11022e-15, 8, 5.6, 5.6, 5.6, 3.2, -1.11022e-15, -1.11022e-15, -1.11022e-15 }
-};
-static const eqz_preset_t eqz_preset_dance_10b=
-{
-    "dance", 10, 5.0,
-    { 9.6, 7.2, 2.4, -1.11022e-15, -1.11022e-15, -5.6, -7.2, -7.2, -1.11022e-15, -1.11022e-15 }
-};
-static const eqz_preset_t eqz_preset_fullbass_10b=
-{
-    "fullbass", 10, 5.0,
-    { -8, 9.6, 9.6, 5.6, 1.6, -4, -8, -10.4, -11.2, -11.2  }
-};
-static const eqz_preset_t eqz_preset_fullbasstreeble_10b=
-{
-    "fullbasstreeble", 10, 4.0,
-    { 7.2, 5.6, -1.11022e-15, -7.2, -4.8, 1.6, 8, 11.2, 12, 12 }
-};
-
-static const eqz_preset_t eqz_preset_fulltreeble_10b=
-{
-    "fulltreeble", 10, 3.0,
-    { -9.6, -9.6, -9.6, -4, 2.4, 11.2, 16, 16, 16, 16.8 }
-};
-static const eqz_preset_t eqz_preset_headphones_10b=
-{
-    "headphones", 10, 4.0,
-    { 4.8, 11.2, 5.6, -3.2, -2.4, 1.6, 4.8, 9.6, 12.8, 14.4 }
-};
-static const eqz_preset_t eqz_preset_largehall_10b=
-{
-    "largehall", 10, 5.0,
-    { 10.4, 10.4, 5.6, 5.6, -1.11022e-15, -4.8, -4.8, -4.8, -1.11022e-15, -1.11022e-15 }
-};
-static const eqz_preset_t eqz_preset_live_10b=
-{
-    "live", 10, 7.0,
-    { -4.8, -1.11022e-15, 4, 5.6, 5.6, 5.6, 4, 2.4, 2.4, 2.4 }
-};
-static const eqz_preset_t eqz_preset_party_10b=
-{
-    "party", 10, 6.0,
-    { 7.2, 7.2, -1.11022e-15, -1.11022e-15, -1.11022e-15, -1.11022e-15, -1.11022e-15, -1.11022e-15, 7.2, 7.2 }
-};
-static const eqz_preset_t eqz_preset_pop_10b=
-{
-    "pop", 10, 6.0,
-    { -1.6, 4.8, 7.2, 8, 5.6, -1.11022e-15, -2.4, -2.4, -1.6, -1.6 }
-};
-static const eqz_preset_t eqz_preset_reggae_10b=
-{
-    "reggae", 10, 8.0,
-    { -1.11022e-15, -1.11022e-15, -1.11022e-15, -5.6, -1.11022e-15, 6.4, 6.4, -1.11022e-15, -1.11022e-15, -1.11022e-15 }
-};
-static const eqz_preset_t eqz_preset_rock_10b=
-{
-    "rock", 10, 5.0,
-    { 8, 4.8, -5.6, -8, -3.2, 4, 8.8, 11.2, 11.2, 11.2 }
-};
-static const eqz_preset_t eqz_preset_ska_10b=
-{
-    "ska", 10, 6.0,
-    { -2.4, -4.8, -4, -1.11022e-15, 4, 5.6, 8.8, 9.6, 11.2, 9.6 }
-};
-static const eqz_preset_t eqz_preset_soft_10b=
-{
-    "soft", 10, 5.0,
-    { 4.8, 1.6, -1.11022e-15, -2.4, -1.11022e-15, 4, 8, 9.6, 11.2, 12 }
-};
-static const eqz_preset_t eqz_preset_softrock_10b=
-{
-    "softrock", 10, 7.0,
-    { 4, 4, 2.4, -1.11022e-15, -4, -5.6, -3.2, -1.11022e-15, 2.4, 8.8 }
-};
-static const eqz_preset_t eqz_preset_techno_10b=
-{
-    "techno", 10, 5.0,
-    { 8, 5.6, -1.11022e-15, -5.6, -4.8, -1.11022e-15, 8, 9.6, 9.6, 8.8 }
-};
-
-static const eqz_preset_t *eqz_preset_10b[] =
-{
-    &eqz_preset_flat_10b,
-    &eqz_preset_classical_10b,
-    &eqz_preset_club_10b,
-    &eqz_preset_dance_10b,
-    &eqz_preset_fullbass_10b,
-    &eqz_preset_fullbasstreeble_10b,
-    &eqz_preset_fulltreeble_10b,
-    &eqz_preset_headphones_10b,
-    &eqz_preset_largehall_10b,
-    &eqz_preset_live_10b,
-    &eqz_preset_party_10b,
-    &eqz_preset_pop_10b,
-    &eqz_preset_reggae_10b,
-    &eqz_preset_rock_10b,
-    &eqz_preset_ska_10b,
-    &eqz_preset_soft_10b,
-    &eqz_preset_softrock_10b,
-    &eqz_preset_techno_10b,
-    NULL
-};
-
-
 static inline float EqzConvertdB( float db )
 {
     /* Map it to gain,
@@ -472,6 +350,11 @@ static int EqzInit( aout_filter_t *p_filter, int i_rate )
     /* Register preset bands (for intf) if : */
     /* We have no bands info --> the preset info must be given to the intf */
     /* or The bands info matches the preset */
+    if (p_sys->psz_newbands == NULL)
+    {
+        msg_Err(p_filter, "No preset selected");
+        return (VLC_EGENERIC);
+    }
     if( ( *(val2.psz_string) &&
         strstr( p_sys->psz_newbands, val2.psz_string ) ) || !*val2.psz_string )
     {
@@ -668,7 +551,7 @@ static int BandsCallback( vlc_object_t *p_this, char const *psz_cmd,
             p_sys->f_amp[i] = EqzConvertdB( f );
 
             if( !*p ) break; /* end of line */
-            p++;
+            p=p_next+1;
         }
     }