[vlc-devel] karaoke filter

郭宇宏 yuhong.guo68 at gmail.com
Fri Apr 15 13:16:04 CEST 2011


The source code of MPlayer is like this:

// Filter data through filter
static af_data_t* play(struct af_instance_s* af, af_data_t* data)
{
  *  af_data_t*    c    = data;         // Current working data
    float*        a    = c->audio;     // Audio data
    int            len    = c->len/4;     // Number of samples in current
audio block
    int            nch    = c->nch;     // Number of channels
    register int  i;

    /*
        FIXME1 add a low band pass filter to avoid suppressing
        centered bass/drums
        FIXME2 better calculated* attenuation factor
    */

    for(i=0;i<len;i+=nch)
    {
        a[i] = (a[i] - a[i+1]) * 0.7;
        a[i+1]=a[i];
    }*

    return c;
}

// Allocate memory and set function pointers
static int af_open(af_instance_t* af){
    af->control    = control;
    af->uninit    = uninit;
    af->play    = play;
    af->mul        = 1;
    af->data    = calloc(1,sizeof(af_data_t));

    if(af->data == NULL)
        return AF_ERROR;

    return AF_OK;
}

// Description of this filter
af_info_t af_info_karaoke = {
    "Simple karaoke/voice-removal audio filter",
    "karaoke",
    "Reynaldo H. Verdejo Pinochet",
    "",
    AF_FLAGS_NOT_REENTRANT,
    af_open
};


According to your suggestion, I think  0.5 is more reasonable thanks.


2011/4/15 Juha Jeronen <juha.jeronen at jyu.fi>

> Hi,
>
> >> From 6e85c56990a90f84049485f03942bd8c224d2852 Mon Sep 17 00:00:00 2001
> >> From: yuhong <yuhong.guo at gmail.com>
> >> Date: Thu, 14 Apr 2011 22:56:08 +0800
> >> Subject: [PATCH] karaoke and sweep audio filters
> >> + * DoWork : Do karaoke filter
> >> +
> *****************************************************************************/
> >> +static block_t *DoWork( filter_t *p_filter, block_t *p_in_buf )
> >> +{
> >> +   int i, i_chan;
> >> +   int i_samples = p_in_buf->i_nb_samples/4;
> >> +   int i_channels = aout_FormatNbChannels( &p_filter->fmt_in.audio );
> >> +   float *p_in =  (float*)p_in_buf->p_buffer;
> >> +
> >> +   /* filter calculation */
> >> +   for( i = 0; i < i_samples; i+=i_channels) {
> >> +          p_in[i] = (p_in[i] - p_in[i+1]) * 0.7;
> >> +          p_in[i+1] = p_in[i];
> >> +   }
>
> Maybe everyone else knows this already, but mind if I ask why the
> multiplier is 0.7? Is it correct or should it be something else?
>
> (My intuition says 0.5 is needed to ensure that all peaks fit. Assuming
> signed 16-bit audio samples, if p_in[i] == 32767 and p_in[i+1] ==
> -32768, the difference is 65535. From this 65535*0.7 = 45874 > 32767,
> and the result doesn't fit into a signed 16-bit buffer.)
>
>  -J
>
> _______________________________________________
> vlc-devel mailing list
> To unsubscribe or modify your subscription options:
> http://mailman.videolan.org/listinfo/vlc-devel
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.videolan.org/pipermail/vlc-devel/attachments/20110415/9baa8fc4/attachment.html>


More information about the vlc-devel mailing list