I'm VideoLan gsoc 2011 student yuhong.<br><br>This is the filter porting from Mplayer.<br><br>/*****************************************************************************<br> * karaoke.c: karaoke filter<br> *****************************************************************************<br>
 * Copyright (C) 2011 the VideoLAN team<br> * $Id: 6a9dc2700bb1c0026a663a834b66666666666 $<br> *<br> * Edit By YuHong<br> *<br> * This program is free software; you can redistribute it and/or modify<br> * it under the terms of the GNU General Public License as published by<br>
 * the Free Software Foundation; either version 2 of the License, or<br> * (at your option) any later version.<br> *<br> * This program is distributed in the hope that it will be useful,<br> * but WITHOUT ANY WARRANTY; without even the implied warranty of<br>
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the<br> * GNU General Public License for more details.<br> *<br> * You should have received a copy of the GNU General Public License<br> * along with this program; if not, write to the Free Software<br>
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.<br> *****************************************************************************/<br><br>/*****************************************************************************<br>
 * Preamble<br> *****************************************************************************/<br><br>#ifdef HAVE_CONFIG_H<br># include "config.h"<br>#endif<br><br><br>#include <vlc_common.h><br>#include <vlc_plugin.h><br>
#include <vlc_aout.h><br>#include <vlc_filter.h><br><br>/*****************************************************************************<br> * Local prototypes<br> *****************************************************************************/<br>
<br>static int  Open     ( vlc_object_t * );<br>static void Close    ( vlc_object_t * );<br>static void *DoWork( filter_t *, block_t * );<br><br>/*****************************************************************************<br>
 * Module descriptor<br> *****************************************************************************/<br>vlc_module_begin ()<br>    set_description( N_("karaoke audio filter") )<br>    set_shortname( N_("karaoke af") )<br>
    set_category( CAT_AUDIO )<br>    add_shortcut( "karaoke" )<br>    set_capability( "audio filter", 0 )<br>    set_callbacks( Open, Close )<br>vlc_module_end ()<br><br>/*****************************************************************************<br>
 * Open: initialize and create stuff<br> *****************************************************************************/<br>static int Open( vlc_object_t *p_this )<br>{<br>    filter_t *p_filter = (filter_t*)p_this;<br>    p_filter->pf_audio_filter = DoWork;<br>
<br>    return VLC_SUCCESS;<br>}<br><br>/*****************************************************************************<br> * DoWork : Do karaoke filter<br> *****************************************************************************/<br>
static void *DoWork( filter_t *p_filter, block_t *p_in_buf )<br>{<br>    int i, i_chan;<br>    int i_samples = p_in_buf->i_nb_samples;<br>    int i_channels = aout_FormatNbChannels( &p_filter->fmt_in.audio );<br>
<br>    /* filter calculation */<br>    for( i = 0; i < i_samples; i++) {<br>        for( i_chan = 0; i_chan < i_channels; i_chan++ ) {<br>           p_in_buf[i] = (p_in_buf[i] - p_in_buf[i+1]) * 0.7;<br>           p_in_buf[i+1] = p_in_buf[i];<br>
        }<br>    }<br><br>}<br><br>/**********************************************************************<br> * Close<br> **********************************************************************/<br>static void Close( vlc_object_t *p_this )<br>
{<br>    filter_t *p_filter = (filter_t*)p_this;<br>    free(p_filter);<br>}<br>