Commit 4073c821 authored by Rémi Denis-Courmont's avatar Rémi Denis-Courmont

Equalizer: convert to audio filter2

parent a7c6e19e
...@@ -36,6 +36,7 @@ ...@@ -36,6 +36,7 @@
#include <vlc_charset.h> #include <vlc_charset.h>
#include <vlc_aout.h> #include <vlc_aout.h>
#include <vlc_filter.h>
#include "equalizer_presets.h" #include "equalizer_presets.h"
/* TODO: /* TODO:
...@@ -73,7 +74,7 @@ static void Close( vlc_object_t * ); ...@@ -73,7 +74,7 @@ static void Close( vlc_object_t * );
vlc_module_begin () vlc_module_begin ()
set_description( N_("Equalizer with 10 bands") ) set_description( N_("Equalizer with 10 bands") )
set_shortname( N_("Equalizer" ) ) set_shortname( N_("Equalizer" ) )
set_capability( "audio filter", 0 ) set_capability( "audio filter2", 0 )
set_category( CAT_AUDIO ) set_category( CAT_AUDIO )
set_subcategory( SUBCAT_AUDIO_AFILTER ) set_subcategory( SUBCAT_AUDIO_AFILTER )
...@@ -93,7 +94,7 @@ vlc_module_end () ...@@ -93,7 +94,7 @@ vlc_module_end ()
/***************************************************************************** /*****************************************************************************
* Local prototypes * Local prototypes
*****************************************************************************/ *****************************************************************************/
struct aout_filter_sys_t struct filter_sys_t
{ {
/* Filter static config */ /* Filter static config */
int i_band; int i_band;
...@@ -121,14 +122,12 @@ struct aout_filter_sys_t ...@@ -121,14 +122,12 @@ struct aout_filter_sys_t
vlc_mutex_t lock; vlc_mutex_t lock;
}; };
static void DoWork( aout_instance_t *, aout_filter_t *, static block_t *DoWork( filter_t *, block_t * );
aout_buffer_t *, aout_buffer_t * );
#define EQZ_IN_FACTOR (0.25) #define EQZ_IN_FACTOR (0.25)
static int EqzInit( aout_filter_t *, int ); static int EqzInit( filter_t *, int );
static void EqzFilter( aout_filter_t *, float *, float *, static void EqzFilter( filter_t *, float *, float *, int, int );
int, int ); static void EqzClean( filter_t * );
static void EqzClean( aout_filter_t * );
static int PresetCallback ( vlc_object_t *, char const *, vlc_value_t, static int PresetCallback ( vlc_object_t *, char const *, vlc_value_t,
vlc_value_t, void * ); vlc_value_t, void * );
...@@ -146,36 +145,29 @@ static int TwoPassCallback( vlc_object_t *, char const *, vlc_value_t, ...@@ -146,36 +145,29 @@ static int TwoPassCallback( vlc_object_t *, char const *, vlc_value_t,
*****************************************************************************/ *****************************************************************************/
static int Open( vlc_object_t *p_this ) static int Open( vlc_object_t *p_this )
{ {
aout_filter_t *p_filter = (aout_filter_t *)p_this; filter_t *p_filter = (filter_t *)p_this;
aout_filter_sys_t *p_sys; filter_sys_t *p_sys;
bool b_fit = true;
if( p_filter->fmt_in.audio.i_format != VLC_CODEC_FL32 || if( p_filter->fmt_in.audio.i_format != VLC_CODEC_FL32 ||
p_filter->fmt_out.audio.i_format != VLC_CODEC_FL32 ) p_filter->fmt_out.audio.i_format != VLC_CODEC_FL32 )
{ {
b_fit = false;
p_filter->fmt_in.audio.i_format = VLC_CODEC_FL32; p_filter->fmt_in.audio.i_format = VLC_CODEC_FL32;
p_filter->fmt_out.audio.i_format = VLC_CODEC_FL32; p_filter->fmt_out.audio.i_format = VLC_CODEC_FL32;
msg_Warn( p_filter, "bad input or output format" ); msg_Warn( p_filter, "bad input or output format" );
return VLC_EGENERIC;
} }
if ( !AOUT_FMTS_SIMILAR( &p_filter->fmt_in.audio, &p_filter->fmt_out.audio ) ) if ( !AOUT_FMTS_SIMILAR( &p_filter->fmt_in.audio, &p_filter->fmt_out.audio ) )
{ {
b_fit = false;
memcpy( &p_filter->fmt_out.audio, &p_filter->fmt_in.audio, memcpy( &p_filter->fmt_out.audio, &p_filter->fmt_in.audio,
sizeof(audio_sample_format_t) ); sizeof(audio_sample_format_t) );
msg_Warn( p_filter, "input and output formats are not similar" ); msg_Warn( p_filter, "input and output formats are not similar" );
}
if ( ! b_fit )
{
return VLC_EGENERIC; return VLC_EGENERIC;
} }
p_filter->pf_do_work = DoWork; p_filter->pf_audio_filter = DoWork;
p_filter->b_in_place = true;
/* Allocate structure */ /* Allocate structure */
p_sys = p_filter->p_sys = malloc( sizeof( aout_filter_sys_t ) ); p_sys = p_filter->p_sys = malloc( sizeof( *p_sys ) );
if( !p_sys ) if( !p_sys )
return VLC_ENOMEM; return VLC_ENOMEM;
...@@ -195,8 +187,8 @@ static int Open( vlc_object_t *p_this ) ...@@ -195,8 +187,8 @@ static int Open( vlc_object_t *p_this )
*****************************************************************************/ *****************************************************************************/
static void Close( vlc_object_t *p_this ) static void Close( vlc_object_t *p_this )
{ {
aout_filter_t *p_filter = (aout_filter_t *)p_this; filter_t *p_filter = (filter_t *)p_this;
aout_filter_sys_t *p_sys = p_filter->p_sys; filter_sys_t *p_sys = p_filter->p_sys;
EqzClean( p_filter ); EqzClean( p_filter );
vlc_mutex_destroy( &p_sys->lock ); vlc_mutex_destroy( &p_sys->lock );
...@@ -208,16 +200,12 @@ static void Close( vlc_object_t *p_this ) ...@@ -208,16 +200,12 @@ static void Close( vlc_object_t *p_this )
***************************************************************************** *****************************************************************************
* *
*****************************************************************************/ *****************************************************************************/
static void DoWork( aout_instance_t * p_aout, aout_filter_t * p_filter, static block_t * DoWork( filter_t * p_filter, block_t * p_in_buf )
aout_buffer_t * p_in_buf, aout_buffer_t * p_out_buf )
{ {
VLC_UNUSED(p_aout); EqzFilter( p_filter, (float*)p_in_buf->p_buffer,
p_out_buf->i_nb_samples = p_in_buf->i_nb_samples;
p_out_buf->i_buffer = p_in_buf->i_buffer;
EqzFilter( p_filter, (float*)p_out_buf->p_buffer,
(float*)p_in_buf->p_buffer, p_in_buf->i_nb_samples, (float*)p_in_buf->p_buffer, p_in_buf->i_nb_samples,
aout_FormatNbChannels( &p_filter->fmt_in.audio ) ); aout_FormatNbChannels( &p_filter->fmt_in.audio ) );
return p_in_buf;
} }
/***************************************************************************** /*****************************************************************************
...@@ -288,13 +276,13 @@ static inline float EqzConvertdB( float db ) ...@@ -288,13 +276,13 @@ static inline float EqzConvertdB( float db )
return EQZ_IN_FACTOR * ( pow( 10, db / 20.0 ) - 1.0 ); return EQZ_IN_FACTOR * ( pow( 10, db / 20.0 ) - 1.0 );
} }
static int EqzInit( aout_filter_t *p_filter, int i_rate ) static int EqzInit( filter_t *p_filter, int i_rate )
{ {
aout_filter_sys_t *p_sys = p_filter->p_sys; filter_sys_t *p_sys = p_filter->p_sys;
const eqz_config_t *p_cfg; const eqz_config_t *p_cfg;
int i, ch; int i, ch;
vlc_value_t val1, val2, val3; vlc_value_t val1, val2, val3;
aout_instance_t *p_aout = (aout_instance_t *)p_filter->p_parent; vlc_object_t *p_aout = p_filter->p_parent;
int i_ret = VLC_ENOMEM; int i_ret = VLC_ENOMEM;
/* Select the config */ /* Select the config */
...@@ -420,10 +408,10 @@ error: ...@@ -420,10 +408,10 @@ error:
return i_ret; return i_ret;
} }
static void EqzFilter( aout_filter_t *p_filter, float *out, float *in, static void EqzFilter( filter_t *p_filter, float *out, float *in,
int i_samples, int i_channels ) int i_samples, int i_channels )
{ {
aout_filter_sys_t *p_sys = p_filter->p_sys; filter_sys_t *p_sys = p_filter->p_sys;
int i, ch, j; int i, ch, j;
vlc_mutex_lock( &p_sys->lock ); vlc_mutex_lock( &p_sys->lock );
...@@ -483,10 +471,10 @@ static void EqzFilter( aout_filter_t *p_filter, float *out, float *in, ...@@ -483,10 +471,10 @@ static void EqzFilter( aout_filter_t *p_filter, float *out, float *in,
vlc_mutex_unlock( &p_sys->lock ); vlc_mutex_unlock( &p_sys->lock );
} }
static void EqzClean( aout_filter_t *p_filter ) static void EqzClean( filter_t *p_filter )
{ {
aout_filter_sys_t *p_sys = p_filter->p_sys; filter_sys_t *p_sys = p_filter->p_sys;
aout_instance_t *p_aout = (aout_instance_t *)p_filter->p_parent; vlc_object_t *p_aout = p_filter->p_parent;
var_DelCallback( p_aout, "equalizer-bands", BandsCallback, p_sys ); var_DelCallback( p_aout, "equalizer-bands", BandsCallback, p_sys );
var_DelCallback( p_aout, "equalizer-preset", PresetCallback, p_sys ); var_DelCallback( p_aout, "equalizer-preset", PresetCallback, p_sys );
...@@ -502,12 +490,11 @@ static void EqzClean( aout_filter_t *p_filter ) ...@@ -502,12 +490,11 @@ static void EqzClean( aout_filter_t *p_filter )
} }
static int PresetCallback( vlc_object_t *p_this, char const *psz_cmd, static int PresetCallback( vlc_object_t *p_aout, char const *psz_cmd,
vlc_value_t oldval, vlc_value_t newval, void *p_data ) vlc_value_t oldval, vlc_value_t newval, void *p_data )
{ {
VLC_UNUSED(psz_cmd); VLC_UNUSED(oldval); VLC_UNUSED(psz_cmd); VLC_UNUSED(oldval);
aout_filter_sys_t *p_sys = (aout_filter_sys_t *)p_data; filter_sys_t *p_sys = p_data;
aout_instance_t *p_aout = (aout_instance_t *)p_this;
const char *psz_preset = newval.psz_string; const char *psz_preset = newval.psz_string;
...@@ -572,7 +559,7 @@ static int PreampCallback( vlc_object_t *p_this, char const *psz_cmd, ...@@ -572,7 +559,7 @@ static int PreampCallback( vlc_object_t *p_this, char const *psz_cmd,
vlc_value_t oldval, vlc_value_t newval, void *p_data ) vlc_value_t oldval, vlc_value_t newval, void *p_data )
{ {
VLC_UNUSED(p_this); VLC_UNUSED(psz_cmd); VLC_UNUSED(oldval); VLC_UNUSED(p_this); VLC_UNUSED(psz_cmd); VLC_UNUSED(oldval);
aout_filter_sys_t *p_sys = (aout_filter_sys_t *)p_data; filter_sys_t *p_sys = p_data;
if( newval.f_float < -20.0 ) if( newval.f_float < -20.0 )
newval.f_float = -20.0; newval.f_float = -20.0;
...@@ -590,7 +577,7 @@ static int BandsCallback( vlc_object_t *p_this, char const *psz_cmd, ...@@ -590,7 +577,7 @@ static int BandsCallback( vlc_object_t *p_this, char const *psz_cmd,
vlc_value_t oldval, vlc_value_t newval, void *p_data ) vlc_value_t oldval, vlc_value_t newval, void *p_data )
{ {
VLC_UNUSED(p_this); VLC_UNUSED(psz_cmd); VLC_UNUSED(oldval); VLC_UNUSED(p_this); VLC_UNUSED(psz_cmd); VLC_UNUSED(oldval);
aout_filter_sys_t *p_sys = (aout_filter_sys_t *)p_data; filter_sys_t *p_sys = p_data;
const char *psz_bands = newval.psz_string; const char *psz_bands = newval.psz_string;
const char *p = psz_bands; const char *p = psz_bands;
char *psz_next; char *psz_next;
...@@ -623,7 +610,7 @@ static int TwoPassCallback( vlc_object_t *p_this, char const *psz_cmd, ...@@ -623,7 +610,7 @@ static int TwoPassCallback( vlc_object_t *p_this, char const *psz_cmd,
vlc_value_t oldval, vlc_value_t newval, void *p_data ) vlc_value_t oldval, vlc_value_t newval, void *p_data )
{ {
VLC_UNUSED(p_this); VLC_UNUSED(psz_cmd); VLC_UNUSED(oldval); VLC_UNUSED(p_this); VLC_UNUSED(psz_cmd); VLC_UNUSED(oldval);
aout_filter_sys_t *p_sys = (aout_filter_sys_t *)p_data; filter_sys_t *p_sys = p_data;
vlc_mutex_lock( &p_sys->lock ); vlc_mutex_lock( &p_sys->lock );
p_sys->b_2eqz = newval.b_bool; p_sys->b_2eqz = newval.b_bool;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment