Difference between revisions of "Hacker Guide/Audio Filters"

From VideoLAN Wiki
Jump to navigation Jump to search
Line 4: Line 4:
==Module descriptor==
==Module descriptor==
  static int  Open    ( [http://www.videolan.org/developers/vlc/doc/doxygen/html/structvlc__object__t.html vlc_object_t *] );
  static int  Open    ( [http://www.videolan.org/developers/vlc/doc/doxygen/html/structvlc__object__t.html vlc_object_t] *p_this );
  static void Close    ( [http://www.videolan.org/developers/vlc/doc/doxygen/html/structvlc__object__t.html vlc_object_t *] );
  static void Close    ( [http://www.videolan.org/developers/vlc/doc/doxygen/html/structvlc__object__t.html vlc_object_t] *p_this );
  static void DoWork  ( [http://www.videolan.org/developers/vlc/doc/doxygen/html/structaout__instance__t.html aout_instance_t *], [http://www.videolan.org/developers/vlc/doc/doxygen/html/structaout__filter__t.html aout_filter_t *], [http://www.videolan.org/developers/vlc/doc/doxygen/html/structaout__buffer__t.html aout_buffer_t *], [http://www.videolan.org/developers/vlc/doc/doxygen/html/structaout__buffer__t.html aout_buffer_t *] );
  static void DoWork  ( [http://www.videolan.org/developers/vlc/doc/doxygen/html/structaout__instance__t.html aout_instance_t] *p_aout, [http://www.videolan.org/developers/vlc/doc/doxygen/html/structaout__filter__t.html aout_filter_t] *p_filter, [http://www.videolan.org/developers/vlc/doc/doxygen/html/structaout__buffer__t.html aout_buffer_t] *p_in_buf, [http://www.videolan.org/developers/vlc/doc/doxygen/html/structaout__buffer__t.html aout_buffer_t] *p_out_buf );

Revision as of 19:24, 13 September 2008


Writing an audio filter

Module descriptor

static int  Open     ( vlc_object_t *p_this );
static void Close    ( vlc_object_t *p_this );
static void DoWork   ( aout_instance_t *p_aout, aout_filter_t *p_filter, aout_buffer_t *p_in_buf, aout_buffer_t *p_out_buf );

    set_description( N_("audio filter x") );
    set_shortname( N_("audio filter x") );
    set_category( CAT_AUDIO );
    set_subcategory( SUBCAT_AUDIO_AFILTER );
    add_shortcut( "afx" );
    set_capability( "audio filter", 0 );
    set_callbacks( Open, Close );

Mandatory structures

  • aout_filter_sys_t

Input Data

Output Data

An audio filter module is constituted of a constructor, a destructor, and a p_filter->pf_do_work function. The constructor is passed a p_filter structure, and it returns 0 if it is able to do the whole transformation between p_filter->input and p_filter->output. If you can do only part of the transformation, say you can't do it (if the aout core doesn't find a fitting filter, it will split the transformation and ask you again).


Audio filters can be of three types :

  • Converters : change i_format (for instance from float32 to s16).
  • Resamplers : change i_rate (for instance from 48 kHz to 44.1 kHz).
  • Channel mixers : change i_physical_channels/i_original_channels (for instance from 5.1 to stereo).

Audio filters can also combine any of these types. For instance you can have an audio filter which transforms A/52 5.1 to float32 stereo.

The constructor must also set p_filter->b_in_place. If it's 0, the aout core will allocate a new buffer for the output. If it's 1, when you write a byte in the output buffer, it destroys the same byte in the input buffer (they share the same memory area). Some filters can work in place because they just do a linear transformation (like float32->s16), but most filters will want b_in_place = 0. The filter can allocate private data in p_filter->p_sys. Do not forget to deallocate it in the destructor.

The p_filter->pf_do_work gets an input and an output buffer as arguments, and process them. At the end of the processing, do not forget to set p_out_buf->i_nb_samples and p_out_buf->i_nb_bytes, since they aren't inited by the aout core (their values can change between input and output and it's not quite predictible).