Commit 694b6814 authored by Rémi Denis-Courmont's avatar Rémi Denis-Courmont

Normvol: convert to audio filter2

parent 4073c821
...@@ -47,6 +47,7 @@ ...@@ -47,6 +47,7 @@
#include <vlc_plugin.h> #include <vlc_plugin.h>
#include <vlc_aout.h> #include <vlc_aout.h>
#include <vlc_filter.h>
/***************************************************************************** /*****************************************************************************
* Local prototypes * Local prototypes
...@@ -54,10 +55,9 @@ ...@@ -54,10 +55,9 @@
static int Open ( vlc_object_t * ); static int Open ( vlc_object_t * );
static void Close ( vlc_object_t * ); static void Close ( vlc_object_t * );
static void DoWork ( aout_instance_t * , aout_filter_t *, static block_t *DoWork( filter_t *, block_t * );
aout_buffer_t * , aout_buffer_t *);
struct aout_filter_sys_t struct filter_sys_t
{ {
int i_nb; int i_nb;
float *p_last; float *p_last;
...@@ -89,7 +89,7 @@ vlc_module_begin () ...@@ -89,7 +89,7 @@ vlc_module_begin ()
true ) true )
add_float( "norm-max-level", 2.0, NULL, LEVEL_TEXT, add_float( "norm-max-level", 2.0, NULL, LEVEL_TEXT,
LEVEL_LONGTEXT, true ) LEVEL_LONGTEXT, true )
set_capability( "audio filter", 0 ) set_capability( "audio filter2", 0 )
set_callbacks( Open, Close ) set_callbacks( Open, Close )
vlc_module_end () vlc_module_end ()
...@@ -98,39 +98,32 @@ vlc_module_end () ...@@ -98,39 +98,32 @@ vlc_module_end ()
*****************************************************************************/ *****************************************************************************/
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;
bool b_fit = true; unsigned i_channels;
int i_channels; filter_sys_t *p_sys;
aout_filter_sys_t *p_sys;
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;
i_channels = aout_FormatNbChannels( &p_filter->fmt_in.audio ); i_channels = aout_FormatNbChannels( &p_filter->fmt_in.audio );
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;
p_sys->i_nb = var_CreateGetInteger( p_filter->p_parent, "norm-buff-size" ); p_sys->i_nb = var_CreateGetInteger( p_filter->p_parent, "norm-buff-size" );
...@@ -152,8 +145,7 @@ static int Open( vlc_object_t *p_this ) ...@@ -152,8 +145,7 @@ static int Open( vlc_object_t *p_this )
/***************************************************************************** /*****************************************************************************
* DoWork : normalizes and sends a buffer * DoWork : normalizes and sends a buffer
*****************************************************************************/ *****************************************************************************/
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 )
{ {
float *pf_sum; float *pf_sum;
float *pf_gain; float *pf_gain;
...@@ -162,25 +154,22 @@ static int Open( vlc_object_t *p_this ) ...@@ -162,25 +154,22 @@ static int Open( vlc_object_t *p_this )
int i_samples = p_in_buf->i_nb_samples; int i_samples = p_in_buf->i_nb_samples;
int i_channels = aout_FormatNbChannels( &p_filter->fmt_in.audio ); int i_channels = aout_FormatNbChannels( &p_filter->fmt_in.audio );
float *p_out = (float*)p_out_buf->p_buffer; float *p_out = (float*)p_in_buf->p_buffer;
float *p_in = (float*)p_in_buf->p_buffer; float *p_in = (float*)p_in_buf->p_buffer;
struct aout_filter_sys_t *p_sys = p_filter->p_sys; struct filter_sys_t *p_sys = p_filter->p_sys;
pf_sum = calloc( i_channels, sizeof(float) ); pf_sum = calloc( i_channels, sizeof(float) );
if( !pf_sum ) if( !pf_sum )
return; goto out;
pf_gain = malloc( sizeof(float) * i_channels ); pf_gain = malloc( sizeof(float) * i_channels );
if( !pf_gain ) if( !pf_gain )
{ {
free( pf_sum ); free( pf_sum );
return; goto out;
} }
p_out_buf->i_nb_samples = p_in_buf->i_nb_samples;
p_out_buf->i_buffer = p_in_buf->i_buffer;
/* Calculate the average power level on this buffer */ /* Calculate the average power level on this buffer */
for( i = 0 ; i < i_samples; i++ ) for( i = 0 ; i < i_samples; i++ )
{ {
...@@ -216,7 +205,7 @@ static int Open( vlc_object_t *p_this ) ...@@ -216,7 +205,7 @@ static int Open( vlc_object_t *p_this )
f_average = f_average / p_sys->i_nb; f_average = f_average / p_sys->i_nb;
/* Seuil arbitraire */ /* Seuil arbitraire */
p_sys->f_max = var_GetFloat( p_aout, "norm-max-level" ); p_sys->f_max = var_GetFloat( p_filter->p_parent, "norm-max-level" );
//fprintf(stderr,"Average %f, max %f\n", f_average, p_sys->f_max ); //fprintf(stderr,"Average %f, max %f\n", f_average, p_sys->f_max );
if( f_average > p_sys->f_max ) if( f_average > p_sys->f_max )
...@@ -242,7 +231,10 @@ static int Open( vlc_object_t *p_this ) ...@@ -242,7 +231,10 @@ static int Open( vlc_object_t *p_this )
free( pf_sum ); free( pf_sum );
free( pf_gain ); free( pf_gain );
return; return p_in_buf;
out:
block_Release( p_in_buf );
return NULL;
} }
/********************************************************************** /**********************************************************************
...@@ -250,8 +242,8 @@ static int Open( vlc_object_t *p_this ) ...@@ -250,8 +242,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;
free( p_sys->p_last ); free( p_sys->p_last );
free( p_sys ); free( p_sys );
......
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